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

wip...

上级 21b0884b
......@@ -72,7 +72,8 @@ export interface MockRoomRawPayload {
export class PuppetMock extends Puppet {
/**
* Watchdog Timeout in Seconds
* if set this value, the parent Puppet class will use it to init watchdog
* if set this value, the default timeout value will be overwrited,
* and the parent Puppet class will use it to init watchdog
*/
protected [WATCHDOG_TIMEOUT] = 30
......
......@@ -795,10 +795,8 @@ export class Bridge extends PadchatRpc {
* add syncRoomMember task to the queue
*/
this.delayQueueExecutor.execute(
() => {
this.syncRoomMember(roomId)
},
'syncRoomMember(' + roomId + ')',
() => this.syncRoomMember(roomId),
`syncRoomMember(${roomId})`,
)
log.silly('PuppetPadchatBridge', 'syncContactsAndRooms() added sync room(%s) task to delayQueueExecutor', roomId)
......
......@@ -233,7 +233,7 @@ export class PuppetPadchat extends Puppet {
}
protected onPadchatMessage(rawPayload: PadchatMessagePayload) {
protected async onPadchatMessage(rawPayload: PadchatMessagePayload): Promise<void> {
log.verbose('PuppetPadchat', 'onPadchatMessage({id=%s, type=%s(%s)})',
rawPayload.msg_id,
PadchatMessageType[rawPayload.sub_type],
......@@ -252,9 +252,48 @@ export class PuppetPadchat extends Puppet {
case PadchatMessageType.Sys:
console.log('sys message:', rawPayload)
// this.emit('room-join', roomId, inviteeIdList, inviterId)
// this.emit('room-leave', roomId, leaverIdList, remover)
// this.emit('room-topic', roomId, topic, oldTopic, changerId)
const roomJoin = pfHelper.roomJoinMessageParser(rawPayload)
if (roomJoin) {
const inviteeNameList = roomJoin.inviteeNameList
const inviterName = roomJoin.inviterName
const roomId = roomJoin.roomId
const inviteeIdList = await Promise.all(
inviteeNameList.map(inviteeName => this.roomMemberSearch(roomId, inviteeName))
)
const inviterId = await this.roomMemberSearch(roomId, inviterName)
this.emit('room-join', roomId, inviteeIdList, inviterId)
}
const roomLeave = pfHelper.roomLeaveMessageParser(rawPayload)
if (roomLeave) {
const leaverNameList = roomLeave.leaverNameList
const removerName = roomLeave.removerName
const roomId = roomLeave.roomId
const leaverIdList = await Promise.all(
leaverNameList.map(leaverName => this.roomMemberSearch(roomId, leaverName))
)
const removerId = await this.roomMemberSearch(roomId, removerName)
this.emit('room-leave', roomId, leaverIdList, removerId)
}
const roomTopic = pfHelper.roomTopicMessageParser(rawPayload)
if (roomTopic) {
const changerName = roomTopic.changerName
const newTopic = roomTopic.topic
const roomId = roomTopic.roomId
const roomPayload = await this.roomPayload(roomId)
const oldTopic = roomPayload.topic
const changerId = await this.roomMemberSearch(roomId, changerName)
this.emit('room-topic', roomId, newTopic, oldTopic, changerId)
}
break
......
......@@ -404,6 +404,25 @@ export class PadchatPureFunctionHelper {
const decodedObject: T = JSON.parse(decodedText)
return decodedObject
}
public roomJoinMessageParser(rawPayload: PadchatMessagePayload): RoomJoinPayload {
const roomJoinPayload
= roomJoin.inviteeNameList
const inviterName = roomJoin.inviterName
const roomId = roomJoin.roomId
}
public roomLeaveMessageParser(rawPayload: PadchatMessagePayload): RoomLeavePayload {
const roomJoinPayload
roomLeave.leaverNameList
const removerName = roomLeave.removerName
const roomId = roomLeave.roomId
}
public roomTopicMessageParser(rawPayload: PadchatMessagePayload): RoomTopicPayload {
const roomJoinPayload
roomTopic.changerName
const newTopic = roomTopic.topic
const roomId = roomTopic.roomId
}
}
export default PadchatPureFunctionHelper
......@@ -99,7 +99,8 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* Watchdog Timeout in Seconds
* if set this value, the parent Puppet class will use it to init watchdog
* if set this value, the default timeout value will be overwrited,
* and the parent Puppet class will use it to init watchdog
*/
protected [WATCHDOG_TIMEOUT]?: number // Watchdog timeout, in seconds
......@@ -186,17 +187,17 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*
*
*/
public emit(event: 'error', error: string) : boolean
public emit(event: 'friend', requestId: string) : boolean
public emit(event: 'login', contactId: string) : boolean
public emit(event: 'logout', contactId: string) : boolean
public emit(event: 'message', messageId: string) : boolean
public emit(event: 'room-join', roomId: string, inviteeIdList: string[], inviterId: string) : boolean
public emit(event: 'room-leave', roomId: string, leaverIdList: string[], remover?: string) : boolean
public emit(event: 'room-topic', roomId: string, topic: string, oldTopic: string, changerId: string) : boolean
public emit(event: 'scan', qrcode: string, status: number, data?: string) : boolean
public emit(event: 'start') : boolean
public emit(event: 'stop') : boolean
public emit(event: 'error', error: string) : boolean
public emit(event: 'friend', requestId: string) : boolean
public emit(event: 'login', contactId: string) : boolean
public emit(event: 'logout', contactId: string) : boolean
public emit(event: 'message', messageId: string) : boolean
public emit(event: 'room-join', roomId: string, inviteeIdList: string[], inviterId: string) : boolean
public emit(event: 'room-leave', roomId: string, leaverIdList: string[], remover?: string) : boolean
public emit(event: 'room-topic', roomId: string, newTopic: string, oldTopic: string, changerId: string) : boolean
public emit(event: 'scan', qrcode: string, status: number, data?: string) : boolean
public emit(event: 'start') : boolean
public emit(event: 'stop') : boolean
// Internal Usage: watchdog
public emit(event: 'watchdog', food: WatchdogFood) : boolean
......@@ -216,17 +217,17 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*
*
*/
public on(event: 'error', listener: (error: string) => void) : this
public on(event: 'friend', listener: (requestId: string) => void) : this
public on(event: 'login', listener: (contactId: string) => void) : this
public on(event: 'logout', listener: (contactId: string) => void) : this
public on(event: 'message', listener: (messageId: string) => void) : this
public on(event: 'room-join', listener: (roomId: string, inviteeIdList: string[], inviterId: string) => void) : this
public on(event: 'room-leave', listener: (roomId: string, leaverIdList : string[], removerId?: string) => void) : this
public on(event: 'room-topic', listener: (roomId: string, topic: string, oldTopic: string, changerId: string) => void) : this
public on(event: 'scan', listener: (qrcode: string, status: number, data?: string) => void) : this
public on(event: 'start', listener: () => void) : this
public on(event: 'stop', listener: () => void) : this
public on(event: 'error', listener: (error: string) => void) : this
public on(event: 'friend', listener: (requestId: string) => void) : this
public on(event: 'login', listener: (contactId: string) => void) : this
public on(event: 'logout', listener: (contactId: string) => void) : this
public on(event: 'message', listener: (messageId: string) => void) : this
public on(event: 'room-join', listener: (roomId: string, inviteeIdList: string[], inviterId: string) => void) : this
public on(event: 'room-leave', listener: (roomId: string, leaverIdList : string[], removerId?: string) => void) : this
public on(event: 'room-topic', listener: (roomId: string, newTopic: string, oldTopic: string, changerId: string) => void) : this
public on(event: 'scan', listener: (qrcode: string, status: number, data?: string) => void) : this
public on(event: 'start', listener: () => void) : this
public on(event: 'stop', listener: () => void) : this
// Internal Usage: watchdog
public on(event: 'watchdog', listener: (data: WatchdogFood) => void) : this
......
......@@ -245,18 +245,18 @@ export class Wechaty extends Accessory implements Sayable {
return Wechaty.version(forceNpm)
}
public emit(event: 'error' , error: Error) : boolean
public emit(event: 'friend' , request: FriendRequest) : boolean
public emit(event: 'heartbeat' , data: any) : boolean
public emit(event: 'logout' , user: ContactSelf) : boolean
public emit(event: 'login' , user: ContactSelf) : boolean
public emit(event: 'message' , message: Message) : boolean
public emit(event: 'room-join' , room: Room, inviteeList : Contact[], inviter : Contact) : boolean
public emit(event: 'room-leave' , room: Room, leaverList : Contact[], remover? : Contact) : boolean
public emit(event: 'room-topic' , room: Room, topic: string, oldTopic: string, changer: Contact) : boolean
public emit(event: 'scan' , qrcode: string, status: number, data?: string) : boolean
public emit(event: 'start') : boolean
public emit(event: 'stop') : boolean
public emit(event: 'error' , error: Error) : boolean
public emit(event: 'friend' , request: FriendRequest) : boolean
public emit(event: 'heartbeat' , data: any) : boolean
public emit(event: 'logout' , user: ContactSelf) : boolean
public emit(event: 'login' , user: ContactSelf) : boolean
public emit(event: 'message' , message: Message) : boolean
public emit(event: 'room-join' , room: Room, inviteeList : Contact[], inviter : Contact) : boolean
public emit(event: 'room-leave' , room: Room, leaverList : Contact[], remover? : Contact) : boolean
public emit(event: 'room-topic' , room: Room, newTopic: string, oldTopic: string, changer: Contact) : boolean
public emit(event: 'scan' , qrcode: string, status: number, data?: string) : boolean
public emit(event: 'start') : boolean
public emit(event: 'stop') : boolean
// guard for the above event: make sure it includes all the possible values
public emit(event: never, listener: never): never
......@@ -268,18 +268,18 @@ export class Wechaty extends Accessory implements Sayable {
return super.emit(event, ...args)
}
public on(event: 'error' , listener: string | ((this: Wechaty, error: Error) => void)) : this
public on(event: 'friend' , listener: string | ((this: Wechaty, request: FriendRequest) => void)) : this
public on(event: 'heartbeat' , listener: string | ((this: Wechaty, data: any) => void)) : this
public on(event: 'logout' , listener: string | ((this: Wechaty, user: ContactSelf) => void)) : this
public on(event: 'login' , listener: string | ((this: Wechaty, user: ContactSelf) => void)) : this
public on(event: 'message' , listener: string | ((this: Wechaty, message: Message) => void)) : this
public on(event: 'room-join' , listener: string | ((this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void)) : this
public on(event: 'room-leave' , listener: string | ((this: Wechaty, room: Room, leaverList: Contact[], remover?: Contact) => void)) : this
public on(event: 'room-topic' , listener: string | ((this: Wechaty, room: Room, topic: string, oldTopic: string, changer: Contact) => void)) : this
public on(event: 'scan' , listener: string | ((this: Wechaty, qrcode: string, status: number, data?: string) => void)) : this
public on(event: 'start' , listener: string | ((this: Wechaty) => void)) : this
public on(event: 'stop' , listener: string | ((this: Wechaty) => void)) : this
public on(event: 'error' , listener: string | ((this: Wechaty, error: Error) => void)) : this
public on(event: 'friend' , listener: string | ((this: Wechaty, request: FriendRequest) => void)) : this
public on(event: 'heartbeat' , listener: string | ((this: Wechaty, data: any) => void)) : this
public on(event: 'logout' , listener: string | ((this: Wechaty, user: ContactSelf) => void)) : this
public on(event: 'login' , listener: string | ((this: Wechaty, user: ContactSelf) => void)) : this
public on(event: 'message' , listener: string | ((this: Wechaty, message: Message) => void)) : this
public on(event: 'room-join' , listener: string | ((this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void)) : this
public on(event: 'room-leave' , listener: string | ((this: Wechaty, room: Room, leaverList: Contact[], remover?: Contact) => void)) : this
public on(event: 'room-topic' , listener: string | ((this: Wechaty, room: Room, newTopic: string, oldTopic: string, changer: Contact) => void)) : this
public on(event: 'scan' , listener: string | ((this: Wechaty, qrcode: string, status: number, data?: string) => void)) : this
public on(event: 'start' , listener: string | ((this: Wechaty) => void)) : this
public on(event: 'stop' , listener: string | ((this: Wechaty) => void)) : this
// guard for the above event: make sure it includes all the possible values
public on(event: never, listener: never): never
......@@ -321,7 +321,7 @@ export class Wechaty extends Accessory implements Sayable {
* @property {Function} friend -(this: Wechaty, request?: FriendRequest) => void
* @property {Function} message -(this: Wechaty, message: Message) => void
* @property {Function} room-join -(this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void
* @property {Function} room-topic -(this: Wechaty, room: Room, topic: string, oldTopic: string, changer: Contact) => void
* @property {Function} room-topic -(this: Wechaty, room: Room, newTopic: string, oldTopic: string, changer: Contact) => void
* @property {Function} room-leave -(this: Wechaty, room: Room, leaverList: Contact[]) => void
*/
......@@ -629,15 +629,15 @@ export class Wechaty extends Accessory implements Sayable {
case 'room-topic':
puppet.removeAllListeners('room-topic')
puppet.on('room-topic', async (roomId, topic, oldTopic, changerId) => {
puppet.on('room-topic', async (roomId, newTopic, oldTopic, changerId) => {
const room = this.Room.load(roomId)
await room.ready()
const changer = this.Contact.load(changerId)
await changer.ready()
this.emit('room-topic', room, topic, oldTopic, changer)
room.emit('topic', topic, oldTopic, changer)
this.emit('room-topic', room, newTopic, oldTopic, changer)
room.emit('topic', newTopic, oldTopic, changer)
})
break
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册