Skip to content

Commit

Permalink
fix: support receive message from bot self, related issue #91
Browse files Browse the repository at this point in the history
  • Loading branch information
su-chang committed Jan 26, 2022
1 parent 2e2c80c commit e95ba42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Manager extends EventEmitter {
.then(() => logger.verbose('start() whatsapp.initialize() done'))
.catch(async e => {
logger.error('start() whatsapp.initialize() rejection: %s', e)
await sleep(500)
await sleep(2 * 1000)
await this.start(session)
})

Expand Down Expand Up @@ -269,6 +269,7 @@ export class Manager extends EventEmitter {
this.emit('room-topic', roomJoinPayload)
}
if (notification.type === GroupNotificationType.CREATE) {
// FIXME: how to reuse roomMemberList from room-mixin
const roomChat = await this.getChatById((notification.id as any).remote) as GroupChat
const members = roomChat.participants.map(participant => participant.id._serialized)

Expand Down Expand Up @@ -304,6 +305,12 @@ export class Manager extends EventEmitter {

private async onMessageAck (message: Message) {
logger.info(`onMessageAck(${JSON.stringify(message)})`)
if (message.id.fromMe && message.ack === 1) {
const messageId = message.id.id
const cacheManager = await this.getCacheManager()
await cacheManager.setMessageRawPayload(messageId, message)
this.emit('message', { messageId })
}
}

private async onMessageCreate (message: Message) {
Expand Down
1 change: 1 addition & 0 deletions src/puppet-mixins/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export async function roomQRCode (this: PuppetWhatsapp, roomId: string): Promise
export async function roomMemberList (this: PuppetWhatsapp, roomId: string): Promise<string[]> {
logger.info('roomMemberList(%s)', roomId)
const chat = await this.manager.getChatById(roomId) as GroupChat
// FIXME: How to deal with pendingParticipants? Maybe we should find which case could has this attribute.
return chat.participants.map(p => p.id._serialized)
}

Expand Down

0 comments on commit e95ba42

Please sign in to comment.