@@ -2,6 +2,8 @@ package io.github.wechaty.user
22
33import io.github.wechaty.Wechaty
44import io.github.wechaty.filebox.FileBox
5+ import io.github.wechaty.utils.QrcodeUtils.Companion.guardQrCodeValue
6+ import org.slf4j.LoggerFactory
57import java.util.concurrent.CompletableFuture
68import java.util.concurrent.Future
79
@@ -19,4 +21,62 @@ class ContactSelf(wechaty: Wechaty,id: String) : Contact(wechaty,id){
1921
2022 }
2123
24+ fun qrcode (): Future <String > {
25+ log.info(" Contact, qrcode()" )
26+
27+ val puppetId: String = try {
28+ this .puppet.selfId().toString()
29+ }
30+ catch (e: Exception ) {
31+ throw Exception (" Can not get qrcode, user might be either not logged in or already logged out" )
32+ }
33+
34+ if (this .id != = puppetId) {
35+ throw Exception (" only can get qrcode for the login userself" )
36+ }
37+
38+ return CompletableFuture .supplyAsync {
39+ val qrcodeValue = this .puppet.contactSelfQRCode().get()
40+ guardQrCodeValue(qrcodeValue)
41+ }
42+ }
43+
44+ fun name (name : String? ): String? {
45+ if (name == null ) {
46+ return super .name()
47+ }
48+ val puppetId = try {
49+ this .puppet.selfId()
50+ }
51+ catch (e: Exception ) {
52+ throw Exception (" Can not get qrcode, user might be either not logged in or already logged out" )
53+ }
54+ if (this .id != = puppetId) {
55+ throw Exception (" only can get qrcode for the login userself" )
56+ }
57+ this .puppet.contactSelfName(name)
58+ return null
59+ }
60+
61+ fun signature (signature : String ): Future <Void > {
62+ log.debug(" ContactSelf, signature()" )
63+
64+ val puppetId = try {
65+ this .puppet.selfId()
66+ }
67+ catch (e: Exception ) {
68+ throw Exception (" Can not get qrcode, user might be either not logged in or already logged out" )
69+ }
70+
71+ if (this .id != = puppetId) {
72+ throw Exception (" only can get qrcode for the login userself" )
73+ }
74+
75+ return this .puppet.contactSelfSignature(signature)
76+ }
77+
78+ companion object {
79+ private val log = LoggerFactory .getLogger(ContactSelf ::class .java)
80+ }
81+
2282}
0 commit comments