Skip to content

Commit 840b209

Browse files
committed
#25 add GetContactSelf method
1 parent 4370d84 commit 840b209

File tree

6 files changed

+45
-54
lines changed

6 files changed

+45
-54
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ trait GrpcSupport {
151151
val result = callback(value)
152152
promise.success(result)
153153
}
154-
override def onError(t: Throwable): Unit = promise.failure(t)
154+
override def onError(t: Throwable): Unit = {
155+
logger.error(t.getMessage,t)
156+
promise.failure(t)
157+
}
155158
override def onCompleted(): Unit = {
156159
if(!promise.isCompleted) promise.failure(new IllegalStateException("server completed"))
157160
}

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

+11-28
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import javax.imageio.ImageIO
1111
import wechaty.padplus.PuppetPadplus
1212
import wechaty.padplus.grpc.PadPlusServerOuterClass.{ApiType, ResponseType, StreamResponse}
1313
import wechaty.padplus.schemas.GrpcSchemas.GrpcQrCodeLogin
14-
import wechaty.padplus.schemas.ModelContact.{GetContactSelfInfoGrpcResponse, GrpcContactPayload, PadplusContactPayload}
14+
import wechaty.padplus.schemas.ModelContact.{GrpcContactPayload, PadplusContactPayload}
1515
import wechaty.padplus.schemas.ModelRoom.GrpcRoomPayload
1616
import wechaty.padplus.schemas.ModelUser.ScanData
1717
import wechaty.padplus.schemas.PadplusEnums.QrcodeStatus
@@ -61,9 +61,6 @@ trait ContactRawSupport extends LazyLogging{
6161
asyncRequestNothing(ApiType.GET_CONTACT,Some(json.toString)).flatMap(_=>promise.future)
6262
}
6363
}
64-
def getContactSelfInfo():Future[GetContactSelfInfoGrpcResponse]={
65-
asyncRequest[GetContactSelfInfoGrpcResponse](ApiType.GET_CONTACT_SELF_INFO)
66-
}
6764

6865
protected def loginPartialFunction(response: StreamResponse): PartialFunction[ResponseType, Unit] = {
6966
case ResponseType.QRCODE_SCAN =>
@@ -82,9 +79,9 @@ trait ContactRawSupport extends LazyLogging{
8279
//二维码的参数设置
8380
val hints = new util.HashMap[DecodeHintType, String]();
8481
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); //设置二维码的编码
85-
//得到解析结果,
86-
val result = multiFormatReader.decode(binaryBitmap, hints);
87-
val payload = new EventScanPayload
82+
//得到解析结果,
83+
val result = multiFormatReader.decode(binaryBitmap, hints);
84+
val payload = new EventScanPayload
8885
payload.qrcode = result.getText
8986
logger.debug("Scan QR Code to login: %s\nhttps://wechaty.github.io/qrcode/%s\n".format(payload.status, payload.qrcode))
9087
emit(PuppetEventName.SCAN, payload)
@@ -104,9 +101,9 @@ trait ContactRawSupport extends LazyLogging{
104101
eventLoginPayload.contactId = padplusContactPayload.userName
105102
emit(PuppetEventName.LOGIN, eventLoginPayload)
106103

107-
Future {
108-
getContact(padplusContactPayload.userName)
109-
}
104+
getContact(padplusContactPayload.userName).foreach(payload=>{
105+
this.savePadplusContactPayload(payload)
106+
})
110107
case ResponseType.AUTO_LOGIN =>
111108
logger.debug("response data:{}", response.getData)
112109
val autoLoginData = objectMapper.readTree(response.getData)
@@ -126,14 +123,10 @@ trait ContactRawSupport extends LazyLogging{
126123
selfId = Some(rawContactPayload.userName)
127124
}
128125

129-
// contactSelfInfo { padplusContact =>
130-
// selfId = Some(padplusContact.userName)
131-
// logger.debug("contactSelf:{}", padplusContact)
132-
// savePadplusContactPayload(padplusContact)
133-
// val eventLoginPayload = new EventLoginPayload
134-
// eventLoginPayload.contactId = padplusContact.userName
135-
// emit(PuppetEventName.LOGIN, eventLoginPayload)
136-
// }
126+
contactSelfInfo().foreach(payload=>{
127+
savePadplusContactPayload(payload)
128+
})
129+
137130
} else {
138131
deleteUin()
139132
asyncRequest(ApiType.GET_QRCODE)
@@ -183,18 +176,8 @@ trait ContactRawSupport extends LazyLogging{
183176
val scanData = objectMapper.readValue(scanRawData, classOf[ScanData])
184177
QrcodeStatus(scanData.status.intValue()) match {
185178
case QrcodeStatus.Scanned =>
186-
187179
case QrcodeStatus.Confirmed =>
188-
// contactSelfInfo { padplusContact =>
189-
// selfId = Some(padplusContact.userName)
190-
// logger.debug("contactSelf:{}", padplusContact)
191-
// savePadplusContactPayload(padplusContact)
192-
// val eventLoginPayload = new EventLoginPayload
193-
// eventLoginPayload.contactId = padplusContact.userName
194-
// emit(PuppetEventName.LOGIN, eventLoginPayload)
195-
// }
196180
case QrcodeStatus.Canceled | QrcodeStatus.Expired =>
197-
198181
}
199182
}
200183

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

+24-23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import wechaty.padplus.schemas.ModelContact.{GetContactSelfInfoGrpcResponse, Pad
66
import wechaty.puppet.schemas.Contact.ContactGender
77
import wechaty.puppet.support.ContactSelfSupport
88

9+
import scala.concurrent.Future
10+
911
/**
1012
*
1113
* @author <a href="mailto:[email protected]">Jun Tsai</a>
@@ -26,28 +28,27 @@ trait ContactSelfRawSupport {
2628

2729
override def logout(): Unit = ???
2830

29-
def contactSelfInfo(callback:PadplusContactPayload=>Unit):Unit={
30-
// asyncRequest[GetContactSelfInfoGrpcResponse](ApiType.GET_CONTACT_SELF_INFO)
31-
asyncRequest[GetContactSelfInfoGrpcResponse](ApiType.GET_CONTACT_SELF_INFO).map{ contactPayload =>
32-
val payload = new PadplusContactPayload
33-
payload.alias = contactPayload.alias;
34-
payload.bigHeadUrl = contactPayload.bigHeadImg;
35-
payload.city = contactPayload.city
36-
payload.contactFlag = 3
37-
payload.contactType = 0
38-
payload.country = contactPayload.country
39-
payload.nickName = contactPayload.nickName
40-
payload.province = contactPayload.province
41-
payload.remark = ""
42-
payload.sex = ContactGender(contactPayload.sex)
43-
payload.signature = contactPayload.signature
44-
payload.smallHeadUrl = contactPayload.smallHeadImg
45-
payload.stranger = ""
46-
payload.tagList = ""
47-
payload.ticket = ""
48-
payload.userName = contactPayload.userName
49-
payload.verifyFlag = 0
50-
callback(payload)
51-
}
31+
def contactSelfInfo():Future[PadplusContactPayload]={
32+
asyncRequest[GetContactSelfInfoGrpcResponse](ApiType.GET_CONTACT_SELF_INFO).map(response =>{
33+
val payload = new PadplusContactPayload
34+
payload.alias = response.alias;
35+
payload.bigHeadUrl = response.bigHeadImg;
36+
payload.city = response.city
37+
payload.contactFlag = 3
38+
payload.contactType = 0
39+
payload.country = response.country
40+
payload.nickName = response.nickName
41+
payload.province = response.province
42+
payload.remark = ""
43+
payload.sex = ContactGender(response.sex)
44+
payload.signature = response.signature
45+
payload.smallHeadUrl = response.smallHeadImg
46+
payload.stranger = ""
47+
payload.tagList = ""
48+
payload.ticket = ""
49+
payload.userName = response.userName
50+
payload.verifyFlag = 0
51+
payload
52+
})
5253
}
5354
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ trait GrpcSupport {
218218
promise.success(result)
219219
}
220220

221-
override def onError(t: Throwable): Unit = promise.failure(t)
221+
override def onError(t: Throwable): Unit = {
222+
logger.error(t.getMessage,t)
223+
promise.failure(t)
224+
}
222225

223226
override def onCompleted(): Unit = {
224227
if (!promise.isCompleted) promise.failure(new IllegalStateException("server completed"))

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

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ trait MessageRawSupport {
4646
// case _ => uploadFile(file.name,file.toStream)
4747
// }
4848

49+
4950
/*
5051
data = {
5152
fileName,

wechaty-puppet/src/main/scala/wechaty/puppet/support/MessageSupport.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait MessageSupport {
3333

3434
def messageSendContact(conversationId: String, contactId: String): String
3535

36-
def messageSendFile (conversationId: String, file: ResourceBox): String
36+
def messageSendFile(conversationId: String, file: ResourceBox): String
3737

3838
def messageSendMiniProgram(conversationId: String, miniProgramPayload: MiniProgramPayload): String
3939

0 commit comments

Comments
 (0)