提交 2f870350 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 d39fa4e3
...@@ -53,7 +53,7 @@ import { ...@@ -53,7 +53,7 @@ import {
WXSendMsgType, WXSendMsgType,
WXLoadWxDatType, WXLoadWxDatType,
WXQRCodeLoginType, WXQRCodeLoginType,
WXCheckQRCodeStatus, // WXCheckQRCodeStatus,
StandardType, StandardType,
WXAddChatRoomMemberType, WXAddChatRoomMemberType,
WXLogoutType, WXLogoutType,
...@@ -335,22 +335,21 @@ export class PadchatRpc extends EventEmitter { ...@@ -335,22 +335,21 @@ export class PadchatRpc extends EventEmitter {
} }
public async WXGetQRCode(): Promise<WXGetQRCodeType> { public async WXGetQRCode(): Promise<WXGetQRCodeType> {
let result = await this.rpcCall('WXGetQRCode') const result = await this.rpcCall('WXGetQRCode')
if (!result || !(result.qr_code)) { // if (!result || !(result.qr_code)) {
result = await this.WXGetQRCodeTwice() // result = await this.WXGetQRCodeTwice()
} // }
return result return result
} }
private async WXGetQRCodeTwice(): Promise<WXGetQRCodeType> { // private async WXGetQRCodeTwice(): Promise<WXGetQRCodeType> {
await this.WXInitialize() // await this.WXInitialize()
const resultTwice = await this.rpcCall('WXGetQRCode') // const resultTwice = await this.rpcCall('WXGetQRCode')
if (!resultTwice || !(resultTwice.qr_code)) { // if (!resultTwice || !(resultTwice.qr_code)) {
throw Error('WXGetQRCodeTwice error! canot get result from websocket server when calling WXGetQRCode after WXInitialize') // throw Error('WXGetQRCodeTwice error! canot get result from websocket server when calling WXGetQRCode after WXInitialize')
} // }
return resultTwice // return resultTwice
} // }
public async WXCheckQRCode(): Promise<WXCheckQRCodePayload> { public async WXCheckQRCode(): Promise<WXCheckQRCodePayload> {
// this.checkQrcode() // this.checkQrcode()
...@@ -439,14 +438,14 @@ export class PadchatRpc extends EventEmitter { ...@@ -439,14 +438,14 @@ export class PadchatRpc extends EventEmitter {
// TODO: should show result here // TODO: should show result here
const result = await this.rpcCall('WXLoginRequest', token) const result = await this.rpcCall('WXLoginRequest', token)
log.silly('PadchatRpc', 'WXLoginRequest result: %s, type: %s', JSON.stringify(result), typeof result) log.silly('PadchatRpc', 'WXLoginRequest result: %s, type: %s', JSON.stringify(result), typeof result)
if (!result || result.status !== 0) { // if (!result || result.status !== 0) {
await this.WXGetQRCode() // await this.WXGetQRCode()
return // return
} else { // } else {
// check qrcode status // // check qrcode status
log.silly('PadchatRpc', 'WXLoginRequest begin to check whether user has clicked confirm login') // log.silly('PadchatRpc', 'WXLoginRequest begin to check whether user has clicked confirm login')
this.checkQrcode() // this.checkQrcode()
} // }
return result return result
} }
...@@ -635,58 +634,58 @@ export class PadchatRpc extends EventEmitter { ...@@ -635,58 +634,58 @@ export class PadchatRpc extends EventEmitter {
throw Error('PadchatRpc, WXQRCodeLogin, unknown status: ' + result.status) throw Error('PadchatRpc, WXQRCodeLogin, unknown status: ' + result.status)
} }
public async checkQrcode(): Promise<void> { // public async checkQrcode(): Promise<void> {
log.verbose('PadchatRpc', 'checkQrcode') // log.verbose('PadchatRpc', 'checkQrcode')
const result = await this.WXCheckQRCode() // const result = await this.WXCheckQRCode()
if (result && result.status === WXCheckQRCodeStatus.WaitScan) { // if (result && result.status === WXCheckQRCodeStatus.WaitScan) {
log.verbose('PadchatRpc', 'checkQrcode: Please scan the Qrcode!') // log.verbose('PadchatRpc', 'checkQrcode: Please scan the Qrcode!')
setTimeout(() => { // setTimeout(() => {
this.checkQrcode() // this.checkQrcode()
}, 1000) // }, 1000)
return // return
} // }
if (result && result.status === WXCheckQRCodeStatus.WaitConfirm) { // if (result && result.status === WXCheckQRCodeStatus.WaitConfirm) {
log.silly('PadchatRpc', 'checkQrcode: Had scan the Qrcode, but not Login!') // log.silly('PadchatRpc', 'checkQrcode: Had scan the Qrcode, but not Login!')
setTimeout(() => { // setTimeout(() => {
this.checkQrcode() // this.checkQrcode()
}, 1000) // }, 1000)
return // return
} // }
if (result && result.status === WXCheckQRCodeStatus.Confirmed) { // if (result && result.status === WXCheckQRCodeStatus.Confirmed) {
log.silly('PadchatRpc', 'checkQrcode: Trying to login... please wait') // log.silly('PadchatRpc', 'checkQrcode: Trying to login... please wait')
if (!result.user_name || !result.password) { // if (!result.user_name || !result.password) {
throw Error('PadchatRpc, checkQrcode, cannot get username or password here, return!') // throw Error('PadchatRpc, checkQrcode, cannot get username or password here, return!')
} // }
// this.username = result.user_name // // this.username = result.user_name
// this.nickname = result.nick_name // // this.nickname = result.nick_name
// this.password = result.password // // this.password = result.password
// this.WXQRCodeLogin(this.username, this.password) // // this.WXQRCodeLogin(this.username, this.password)
return // return
} // }
if (result && result.status === WXCheckQRCodeStatus.Timeout) { // if (result && result.status === WXCheckQRCodeStatus.Timeout) {
log.silly('PadchatRpc', 'checkQrcode: Timeout') // log.silly('PadchatRpc', 'checkQrcode: Timeout')
return // return
} // }
if (result && result.status === WXCheckQRCodeStatus.Cancel) { // if (result && result.status === WXCheckQRCodeStatus.Cancel) {
log.silly('PadchatRpc', 'checkQrcode: Cancel by user') // log.silly('PadchatRpc', 'checkQrcode: Cancel by user')
return // return
} // }
log.warn('PadchatRpc', 'checkQrcode: not know the reason, return data: %s', JSON.stringify(result)) // log.warn('PadchatRpc', 'checkQrcode: not know the reason, return data: %s', JSON.stringify(result))
return // return
} // }
public async WXSetUserRemark(id: string, remark: string): Promise<StandardType> { public async WXSetUserRemark(id: string, remark: string): Promise<StandardType> {
const result = await this.rpcCall('WXSetUserRemark', id, remark) const result = await this.rpcCall('WXSetUserRemark', id, remark)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册