Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add logic to handle roleChange event in stream #1080

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/restapi/src/lib/pushstream/DataModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class DataModifier {
return this.mapToRequestEvent(data, includeRaw);
case GroupEventType.Remove:
return this.mapToRemoveEvent(data, includeRaw);
case GroupEventType.RoleChange:
return this.mapToRoleChangeEvent(data, includeRaw);
default:
console.warn('Unknown eventType:', data.eventType);
return data;
Expand Down Expand Up @@ -124,6 +126,23 @@ export class DataModifier {
return eventData;
}

private static mapToRoleChangeEvent(data: any, includeRaw: boolean): any {
// Whatever the structure of your RemoveEvent, modify accordingly
const eventData: RemoveEvent = {
origin: data.messageOrigin,
timestamp: data.timestamp,
chatId: data.chatId,
from: data.from,
to: data.to,
event: GroupEventType.Remove,
};

if (includeRaw) {
eventData.raw = { verificationProof: data.verificationProof };
}
return eventData;
}

private static buildChatGroupEventMetaAndRaw(
incomingData: any,
includeRaw: boolean
Expand Down Expand Up @@ -203,7 +222,6 @@ export class DataModifier {
includeRaw = false,
eventType: MessageEventType
): MessageEvent {

if (data.hasIntent === false && eventType === 'message') {
eventType = MessageEventType.Request;
}
Expand Down
1 change: 1 addition & 0 deletions packages/restapi/src/lib/pushstream/pushStreamTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export enum GroupEventType {
UpdateGroup = 'updateGroup',
JoinGroup = 'joinGroup',
LeaveGroup = 'leaveGroup',
RoleChange = 'roleChange',
Remove = 'remove',
}

Expand Down
Loading