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

add boolean return value to FriendRequest.{send,accept}

上级 c99fc3a2
......@@ -30,7 +30,7 @@ export abstract class FriendRequest {
}
}
public abstract send(contact: Contact, hello: string): Promise<void>
public abstract accept(): Promise<void>
public abstract send(contact: Contact, hello: string): Promise<boolean>
public abstract accept(): Promise<boolean>
}
......@@ -216,26 +216,26 @@ export class Bridge {
})
}
public verifyUserRequest(contactId, hello): Promise<void> {
public verifyUserRequest(contactId, hello): Promise<boolean> {
log.verbose('PuppetWebBridge', 'verifyUserRequest(%s, %s)', contactId, hello)
if (!contactId) {
throw new Error('no valid contactId')
}
return this.proxyWechaty('verifyUserRequest', contactId, hello)
return this.proxyWechaty('verifyUserRequestAsync', contactId, hello)
.catch(e => {
log.error('PuppetWebBridge', 'verifyUserRequest(%s, %s) exception: %s', contactId, hello, e.message)
throw e
})
}
public verifyUserOk(contactId, ticket): Promise<void> {
public verifyUserOk(contactId, ticket): Promise<boolean> {
log.verbose('PuppetWebBridge', 'verifyUserOk(%s, %s)', contactId, ticket)
if (!contactId || !ticket) {
throw new Error('no valid contactId or ticket')
}
return this.proxyWechaty('verifyUserOk', contactId, ticket)
return this.proxyWechaty('verifyUserOkAsync', contactId, ticket)
.catch(e => {
log.error('PuppetWebBridge', 'verifyUserOk(%s, %s) exception: %s', contactId, ticket, e.message)
throw e
......
......@@ -21,9 +21,9 @@ const retryPromise = require('retry-promise').default
import { Contact } from '../contact'
import {
Config
, RecommendInfo
, log
Config,
RecommendInfo,
log,
} from '../config'
import { FriendRequest } from '../friend-request'
......@@ -75,7 +75,7 @@ class PuppetWebFriendRequest extends FriendRequest {
this.type = 'confirm'
}
public async send(contact: Contact, hello = 'Hi'): Promise<void> {
public async send(contact: Contact, hello = 'Hi'): Promise<boolean> {
log.verbose('PuppetWebFriendRequest', 'send(%s)', contact)
if (!contact) {
......@@ -88,20 +88,19 @@ class PuppetWebFriendRequest extends FriendRequest {
this.hello = hello
}
await Config.puppetInstance()
return Config.puppetInstance()
.friendRequestSend(contact, hello)
return
}
public async accept(): Promise<void> {
public async accept(): Promise<boolean> {
log.verbose('FriendRequest', 'accept() %s', this.contact)
if (this.type !== 'receive') {
throw new Error('request on a ' + this.type + ' type')
throw new Error('request is not a `receive` type. it is a ' + this.type + ' type')
}
await Config.puppetInstance()
.friendRequestAccept(this.contact, this.ticket)
const ret = await Config.puppetInstance()
.friendRequestAccept(this.contact, this.ticket)
const max = 20
const backoff = 300
......@@ -127,7 +126,7 @@ class PuppetWebFriendRequest extends FriendRequest {
log.warn('PuppetWebFriendRequest', 'accept() rejected for contact %s because %s', this.contact, e && e.message || e)
})
return
return ret
}
}
......
......@@ -477,7 +477,7 @@ export class PuppetWeb extends Puppet {
/**
* FriendRequest
*/
public async friendRequestSend(contact: Contact, hello: string): Promise<any> {
public async friendRequestSend(contact: Contact, hello: string): Promise<boolean> {
if (!this.bridge) {
return Promise.reject(new Error('fail: no bridge(yet)!'))
}
......@@ -494,7 +494,7 @@ export class PuppetWeb extends Puppet {
}
}
public async friendRequestAccept(contact: Contact, ticket: string): Promise<any> {
public async friendRequestAccept(contact: Contact, ticket: string): Promise<boolean> {
if (!this.bridge) {
return Promise.reject(new Error('fail: no bridge(yet)!'))
}
......
......@@ -667,7 +667,13 @@
})
}
function verifyUserRequest(UserName, VerifyContent) {
function verifyUserRequestAsync(UserName, VerifyContent) {
var callback = arguments[arguments.length - 1]
if (typeof callback !== 'function') {
// here we should in sync mode, because there's no callback
throw new Error('async method need to be called via webdriver.executeAsyncScript')
}
VerifyContent = VerifyContent || '';
var contactFactory = WechatyBro.glue.contactFactory
......@@ -685,13 +691,21 @@
.then(function() { // succ
// alert('ok')
log('friendAdd(' + UserName + ', ' + VerifyContent + ') done')
callback(true)
}, function(t) { // fail
// alert('not ok')
log('friendAdd(' + UserName + ', ' + VerifyContent + ') fail: ' + t)
callback(false)
})
}
function verifyUserOk(UserName, Ticket) {
var callback = arguments[arguments.length - 1]
if (typeof callback !== 'function') {
// here we should in sync mode, because there's no callback
throw new Error('async method need to be called via webdriver.executeAsyncScript')
}
var contactFactory = WechatyBro.glue.contactFactory
var confFactory = WechatyBro.glue.confFactory
......@@ -703,9 +717,11 @@
}).then(function() { // succ
// alert('ok')
log('friendVerify(' + UserName + ', ' + Ticket + ') done')
}, function() { // fail
callback(true)
}, function(err) { // fail
// alert('err')
log('friendVerify(' + UserName + ', ' + Ticket + ') fail')
callback(false)
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册