Skip to content

Commit 9b3b5f7

Browse files
committed
use grpc method to call
1 parent 13be9df commit 9b3b5f7

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

wechaty-puppet-hostie/src/main/scala/wechaty/hostie/support/ContactRawSupport.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package wechaty.hostie.support
22

33
import com.google.protobuf.StringValue
4+
import io.github.wechaty.grpc.PuppetGrpc
45
import io.github.wechaty.grpc.puppet.Contact
56
import io.github.wechaty.grpc.puppet.Contact.ContactPayloadRequest
67
import wechaty.puppet.ResourceBox
@@ -84,7 +85,7 @@ trait ContactRawSupport {
8485

8586
override protected def contactRawPayload(contactID: String): Future[ContactPayload] = {
8687
val request = ContactPayloadRequest.newBuilder().setId(contactID).build()
87-
asyncCallback(asyncGrpcClient.contactPayload,request){response =>
88+
asyncCallback(PuppetGrpc.getContactPayloadMethod,request){ response =>
8889
val contact = new ContactPayload
8990
contact.id = response.getId
9091
contact.gender = wechaty.puppet.schemas.Contact.ContactGender.apply(response.getGenderValue)

wechaty-puppet-hostie/src/main/scala/wechaty/hostie/support/GrpcSupport.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import io.github.wechaty.grpc.puppet.Contact.ContactPayloadRequest
99
import io.github.wechaty.grpc.puppet.{Base, Contact}
1010
import io.github.wechaty.grpc.puppet.Event.EventRequest
1111
import io.grpc.stub.ClientCalls.asyncUnaryCall
12-
import io.grpc.stub.StreamObserver
13-
import io.grpc.{ClientCall, ManagedChannel, ManagedChannelBuilder}
12+
import io.grpc.stub.{ClientCalls, StreamObserver}
13+
import io.grpc.{ClientCall, ManagedChannel, ManagedChannelBuilder, MethodDescriptor}
1414
import wechaty.hostie.PuppetHostie
1515
import wechaty.puppet.schemas.Contact.ContactPayload
1616

@@ -139,14 +139,14 @@ trait GrpcSupport {
139139
}
140140
}
141141

142-
type ClientCall[ReqT,RespT]=(ReqT,StreamObserver[RespT])=>Unit
143142
type ClientCallback[RespT,T]=RespT => T
144-
protected def asyncCall[ReqT,RespT](call: ClientCall[ReqT, RespT], req: ReqT): Unit = {
143+
protected def asyncCall[ReqT,RespT](call: MethodDescriptor[ReqT, RespT], req: ReqT): Unit = {
145144
asyncCallback(call,req)(resp=> resp)
146145
}
147-
protected def asyncCallback[ReqT,RespT,T](call: ClientCall[ReqT, RespT], req: ReqT)(callback:ClientCallback[RespT,T]):Future[T]= {
146+
def asyncCallback[ReqT, RespT,T](callMethod: MethodDescriptor[ReqT, RespT], req: ReqT)(callback:ClientCallback[RespT,T]): Future[T]= {
147+
val call = channel.newCall(callMethod,asyncGrpcClient.getCallOptions)
148148
val promise = Promise[T]
149-
call(req,new StreamObserver[RespT] {
149+
ClientCalls.asyncUnaryCall(call,req,new StreamObserver[RespT] {
150150
override def onNext(value: RespT): Unit = {
151151
val result = callback(value)
152152
promise.success(result)

wechaty-puppet-padplus/src/main/scala/wechaty/padplus/support/LocalStoreSupport.scala

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import wechaty.padplus.schemas.ModelMessage.PadplusMessagePayload
88
import wechaty.padplus.schemas.ModelRoom.{PadplusRoomMemberMap, PadplusRoomPayload}
99
import wechaty.puppet.schemas.Puppet.objectMapper
1010

11+
import scala.language.implicitConversions
12+
1113
/**
1214
*
1315
* @author <a href="mailto:[email protected]">Jun Tsai</a>

0 commit comments

Comments
 (0)