Skip to content

[FEAT] New System Level Events #2529

@hcfw007

Description

@hcfw007

By system level events, I mean events like 'SCAN', 'LOGIN', 'FRIENDSHIP', etc.
In my opinion, current event system requires some updates.

  • Event name and classification is not unified. e.g. There are different events for room, like 'Room-Join', 'Room-Leave', etc, but there is only one 'Friendship' event。
  • Event types did not cover important notifications, espiecally info change.

We do have 'Dirty' events to invalid cache, that is working well. However you cannot listen to 'Dirty' event in bot level. So if want to know if and when some contact info has changed, there's nothing I can do. If it's a room, I can listen to 'Room-Topic' event, so there should also be a 'Contact-Name' event.

Giving more thoughts, there might be more notifications that cannot be classified into any current event. Especially for 'Wecom', because it's too closed to 'Wechat' there are lots of identification checks that you need to do with 'Wechat' on your phone.

So here's my proposal:
Step 1: Implement more events for important contact and room info changes, like, 'Room-Owner', 'Contact-Name', 'Contact-ALias', etc.
Step 2: Going further on this route, we could have an 'Update' event for any payload change on classes. It's like kinda like dirty. The listener, on my opinion, should be like this:

type WechatyEventListenerUpdate             = (info: InfoUpdateInterface) => void | Promise<void>

export const ContactImportantFields = [
  'name', 'tags', 'alias', 'phone', 'description', 'corporation',
] as const

export const RoomImportantFields = [
  'topic', 'memberIdList', 'ownerId',
] as const

type ContactImportantKeys = typeof ContactImportantFields[number]
type RoomImportantKeys = typeof RoomImportantFields[number]

type ContactUpdatableKeys = Omit<PUPPET.payloads.Contact, ContactImportantKeys>
type RoomUpdateableKeys = Omit<PUPPET.payloads.Room, RoomImportantKeys>

type PayloadTypeToUpdateInterface<U> = {
  [SubType in keyof U]: {
    type: SubType,
    id: string,
    updates: InfoUpdateValuePair<U[SubType]>[],
  }
}[keyof U]

export type InfoUpdateValuePair<U> = {
  [SubType in keyof U]: {
    key: SubType,
    oldValue?: U[SubType],
    newValue?: U[SubType],
  }
}[keyof U]

export type InfoUpdateInterface = PayloadTypeToUpdateInterface<{
  [PUPPET.types.Payload.Contact]: ContactUpdatableKeys,
  [PUPPET.types.Payload.Room]: RoomUpdateableKeys,
}>

export type ContactUpdatableValuePair = InfoUpdateValuePair<ContactUpdatableKeys>
export type RoomUpdatableValuePair = InfoUpdateValuePair<RoomUpdateableKeys>

export type ContactValuePair = InfoUpdateValuePair<PUPPET.payloads.Contact>
export type RoomValuePair = InfoUpdateValuePair<PUPPET.payloads.Room>

Step 3: I haven't think it through, but there should be a more generic system level event for those events that cannot be classified. These events usually will not kick you offline entirely, but will limit the ability of your account. e.g. You might not be able to post moments before you check your identity on your phone with 'Wechat'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions