Skip to content

Commit

Permalink
Update membership object on member events
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Dec 5, 2024
1 parent ad356f3 commit 43a0f99
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,12 +1553,20 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
break;
case 'member.added':
case 'member.updated':
if (event.member?.user_id) {
if (event.member?.user) {
channelState.members = {
...channelState.members,
[event.member.user_id]: event.member,
[event.member.user.id]: event.member,
};
}

if (
typeof channelState.membership.user?.id === 'string' &&
typeof event.member?.user?.id === 'string' &&
event.member.user.id === channelState.membership.user.id
) {
channelState.membership = event.member;
}
break;
case 'member.removed':
if (event.user?.id) {
Expand All @@ -1569,6 +1577,8 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
delete newMembers[event.user.id];

channelState.members = newMembers;

// TODO?: unset membership
}
break;
case 'notification.mark_unread': {
Expand Down Expand Up @@ -1710,7 +1720,10 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
}
}

this.state.membership = state.membership || {};
this.state.membership = {
...this.state.membership,
...state.membership,
};

const messages = state.messages || [];
if (!this.state.messages) {
Expand Down

0 comments on commit 43a0f99

Please sign in to comment.