@@ -13,6 +13,10 @@ class ContactSelf(wechaty: Wechaty, id: String) : Contact(wechaty, id) {
1313 puppet.setContactAvatar(super .id, fileBox)
1414 }
1515
16+ fun getAvatar (fileBox : FileBox ) {
17+ puppet.setContactAvatar(super .id, fileBox)
18+ }
19+
1620 fun setName (name : String ){
1721 puppet.contactSelfName(name).get()
1822 sync()
@@ -29,6 +33,17 @@ class ContactSelf(wechaty: Wechaty, id: String) : Contact(wechaty, id) {
2933 sync()
3034 }
3135 }
36+ fun setSignature (signature : String ) {
37+
38+ var puppetId: String? = puppet.selfId()
39+
40+ let {
41+ puppetId != null
42+ }.run {
43+ puppet.contactSelfSignature(signature).get()
44+ sync()
45+ }
46+ }
3247
3348 fun qrcode (): Future <String > {
3449 log.info(" Contact, qrcode()" )
@@ -49,15 +64,33 @@ class ContactSelf(wechaty: Wechaty, id: String) : Contact(wechaty, id) {
4964 guardQrCodeValue(qrcodeValue)
5065 }
5166 }
67+ fun getQrcode (): Future <String > {
68+ log.info(" Contact, qrcode()" )
69+
70+ val puppetId: String = try {
71+ this .puppet.selfId().toString()
72+ }
73+ catch (e: Exception ) {
74+ throw Exception (" Can not get qrcode, user might be either not logged in or already logged out" )
75+ }
76+
77+ if (this .id != = puppetId) {
78+ throw Exception (" only can get qrcode for the login userself" )
79+ }
80+
81+ return CompletableFuture .supplyAsync {
82+ val qrcodeValue = this .puppet.contactSelfQRCode().get()
83+ guardQrCodeValue(qrcodeValue)
84+ }
85+ }
5286
5387 fun name (name : String? ): String? {
5488 if (name == null ) {
5589 return super .name()
5690 }
5791 val puppetId = try {
5892 this .puppet.selfId()
59- }
60- catch (e: Exception ) {
93+ } catch (e: Exception ) {
6194 throw Exception (" Can not get qrcode, user might be either not logged in or already logged out" )
6295 }
6396 if (this .id != = puppetId) {
@@ -67,22 +100,21 @@ class ContactSelf(wechaty: Wechaty, id: String) : Contact(wechaty, id) {
67100 return null
68101 }
69102
70- // fun signature (signature: String): Future<Void> {
71- // log.debug("ContactSelf, signature()")
72- //
73- // val puppetId = try {
74- // this.puppet.selfId()
75- // }
76- // catch (e: Exception) {
77- // throw Exception("Can not get qrcode, user might be either not logged in or already logged out")
78- // }
79- //
80- // if (this.id !== puppetId) {
81- // throw Exception("only can get qrcode for the login userself")
82- // }
83- // // maybe
84- // return this.puppet.contactSelfSignature(signature)
85- // }
103+ fun getName (name : String? ): String? {
104+ if (name == null ) {
105+ return super .name()
106+ }
107+ val puppetId = try {
108+ this .puppet.selfId()
109+ } catch (e: Exception ) {
110+ throw Exception (" Can not get qrcode, user might be either not logged in or already logged out" )
111+ }
112+ if (this .id != = puppetId) {
113+ throw Exception (" only can get qrcode for the login userself" )
114+ }
115+ this .puppet.contactSelfName(name)
116+ return null
117+ }
86118
87119 companion object {
88120 private val log = LoggerFactory .getLogger(ContactSelf ::class .java)
0 commit comments