Skip to content

Commit

Permalink
fix: 🐛 allow empty room-announce changer
Browse files Browse the repository at this point in the history
  • Loading branch information
hcfw007 committed Aug 19, 2024
1 parent c7722ed commit 1d53f3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/schemas/room-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type RoomEventListenerJoin = (this: RoomInterface, inviteeList: ContactInterf
type RoomEventListenerLeave = (this: RoomInterface, leaverList: ContactInterface[], remover?: ContactInterface, date?: Date) => void | Promise<void>
type RoomEventListenerMessage = (this: RoomInterface, message: MessageInterface, date?: Date) => void | Promise<void>
type RoomEventListenerTopic = (this: RoomInterface, topic: string, oldTopic: string, changer: ContactInterface, date?: Date) => void | Promise<void>
type RoomEventListenerAnnounce= (this: RoomInterface, announce: string, changer: ContactInterface, oldAnnounce?: string, date?: Date) => void | Promise<void>
type RoomEventListenerAnnounce= (this: RoomInterface, announce: string, changer?: ContactInterface, oldAnnounce?: string, date?: Date) => void | Promise<void>
type RoomEventListenerOwner = (this: RoomInterface, newOwner: ContactInterface, oldOwner: ContactInterface) => void | Promise<void>

interface RoomEventListeners {
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/wechaty-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type WechatyEventListenerRoomInvite = (roomInvitation: RoomInvitationInt
type WechatyEventListenerRoomJoin = (room: RoomInterface, inviteeList: ContactInterface[], inviter: ContactInterface, date?: Date) => void | Promise<void>
type WechatyEventListenerRoomLeave = (room: RoomInterface, leaverList: ContactInterface[], remover?: ContactInterface, date?: Date) => void | Promise<void>
type WechatyEventListenerRoomTopic = (room: RoomInterface, newTopic: string, oldTopic: string, changer: ContactInterface, date?: Date) => void | Promise<void>
type WechatyEventListenerRoomAnnounce = (room: RoomInterface, newAnnounce: string, changer: ContactInterface, oldAnnounce?: string, date?: Date) => void | Promise<void>
type WechatyEventListenerRoomAnnounce = (room: RoomInterface, newAnnounce: string, changer?: ContactInterface, oldAnnounce?: string, date?: Date) => void | Promise<void>
type WechatyEventListenerRoomOwner = (room: RoomInterface, newOwner: ContactInterface, oldOwner: ContactInterface) => void | Promise<void>
type WechatyEventListenerScan = (qrcode: string, status: PUPPET.types.ScanStatus, data: string, type: PUPPET.types.ScanType, createDate: Date, expireDate?: Date) => void | Promise<void>
type WechatyEventListenerStartStop = () => void | Promise<void>
Expand Down
10 changes: 7 additions & 3 deletions src/wechaty-mixins/puppet-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,13 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
}

await room.sync()
const changer = await this.Contact.find({ id: payload.changerId })
if (!changer) {
throw new Error('no changer found for id: ' + payload.changerId)
let changer: ContactInterface | undefined
try {
if (payload.changerId) {
changer = await this.Contact.find({ id: payload.changerId })
}
} catch (e) {
log.warn('room-announce', 'room-announce event error: %s', (e as Error).message)
}
const date = timestampToDate(payload.timestamp)
this.emit('room-announce', room, payload.newAnnounce, changer, payload.oldAnnounce, date)
Expand Down

0 comments on commit 1d53f3f

Please sign in to comment.