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

use UserName: string for FriendRequest args

上级 4e49759a
......@@ -18,7 +18,6 @@
const Wechaty = require('../wechaty')
const Config = require('../config')
const Contact = require('../contact')
const FriendRequest = require('../friend-request')
const log = require('../brolog-env')
......@@ -47,44 +46,46 @@ class PuppetWebFriendRequest extends FriendRequest {
}
this.type = 'receive'
return this
}
confirm(contact) {
log.verbose('PuppetWebFriendRequest', 'confirm(%s)', contact)
confirm(contactId) {
log.verbose('PuppetWebFriendRequest', 'confirm(%s)', contactId)
if (!contact instanceof Contact) {
contact = Contact.load(contact)
if (!contactId) {
throw new Error('contactId not found')
}
this.contact = contact
this.type = 'confirm'
this.contactId = contactId
this.type = 'confirm'
}
send(contact, hello = 'Hi') {
log.verbose('PuppetWebFriendRequest', 'send(%s)', contact)
send(contactId, hello = 'Hi') {
log.verbose('PuppetWebFriendRequest', 'send(%s)', contactId)
if (!contact instanceof Contact) {
contact = Contact.load(contact)
if (!contactId) {
throw new Error('contactId not found')
}
this.contact = contact
this.type = 'send'
this.contactId = contactId
this.type = 'send'
if (hello) {
this.hello = hello
}
return Config.puppetInstance()
.friendRequestSend(contact, hello)
.friendRequestSend(contactId, hello)
}
accept() {
log.verbose('FriendRequest', 'accept() %s', this.contact)
log.verbose('FriendRequest', 'accept() %s', this.contactId)
if (this.type !== 'receive') {
throw new Error('request on a ' + this.type + ' type')
}
return Config.puppetInstance()
.friendRequestAccept(this.contact, this.ticket)
.friendRequestAccept(this.contactId, this.ticket)
}
}
......
......@@ -421,34 +421,34 @@ class PuppetWeb extends Puppet {
/**
* FriendRequest
*/
friendRequestSend(contact, message) {
friendRequestSend(contactId, message) {
if (!this.bridge) {
return Promise.reject(new Error('fail: no bridge(yet)!'))
}
if (!contact || !contact instanceof Contact) {
throw new Error('contact not found')
if (!contactId) {
throw new Error('contactId not found')
}
return this.bridge.verifyUserRequest(contact.id, message)
return this.bridge.verifyUserRequest(contactId, message)
.catch(e => {
log.warn('PuppetWeb', 'friendRequestSend(%s, %s) rejected: %s', contact, message, e.message)
log.warn('PuppetWeb', 'friendRequestSend(%s, %s) rejected: %s', contactId, message, e.message)
throw e
})
}
friendRequestAccept(contact, ticket) {
friendRequestAccept(contactId, ticket) {
if (!this.bridge) {
return Promise.reject(new Error('fail: no bridge(yet)!'))
}
if (!contact || !contact instanceof Contact || !ticket) {
throw new Error('contact or ticket not found')
if (!contactId || !ticket) {
throw new Error('contactId or ticket not found')
}
return this.bridge.verifyUserOk(contact.id, ticket)
return this.bridge.verifyUserOk(contactId, ticket)
.catch(e => {
log.warn('PuppetWeb', 'friendRequestAccept(%s, %s) rejected: %s', contact, ticket, e.message)
log.warn('PuppetWeb', 'friendRequestAccept(%s, %s) rejected: %s', contactId, ticket, e.message)
throw e
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册