Skip to content

Commit

Permalink
chore: fixed reaction updates on useGroupChannelMessagesWithCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Apr 28, 2023
1 parent 068f584 commit 43ee963
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ export const useGroupChannelMessagesWithCollection: UseGroupChannelMessages = (s
onMessagesAdded: (_, __, messages) => {
channelMarkAsRead(_.source);

const incomingMessages = messages.filter((it) => !isMyMessage(it, sdk.currentUser.userId));
const incomingMessages = messages.filter((it) => {
switch (_.source) {
case MessageEventSource.EVENT_MESSAGE_SENT_PENDING:
case MessageEventSource.EVENT_MESSAGE_SENT_SUCCESS:
case MessageEventSource.EVENT_MESSAGE_SENT_FAILED:
return !isMyMessage(it, sdk.currentUser.userId);
default:
return true;
}
});

if (incomingMessages.length > 0) {
updateMessages(incomingMessages, false, sdk.currentUser.userId);

Expand All @@ -97,7 +107,15 @@ export const useGroupChannelMessagesWithCollection: UseGroupChannelMessages = (s
onMessagesUpdated: (_, __, messages) => {
channelMarkAsRead(_.source);

const incomingMessages = messages.filter((it) => !isMyMessage(it, sdk.currentUser.userId));
const incomingMessages = messages.filter((it) => {
switch (_.source) {
case MessageEventSource.EVENT_MESSAGE_UPDATED:
return !isMyMessage(it, sdk.currentUser.userId);
default:
return true;
}
});

if (incomingMessages.length > 0) {
// NOTE: admin message is not added via onMessagesAdded handler, not checked yet is this a bug.
updateMessages(messages, false, sdk.currentUser.userId);
Expand Down Expand Up @@ -225,8 +243,8 @@ export const useGroupChannelMessagesWithCollection: UseGroupChannelMessages = (s
resolve(sentMessage);
}
})
.onFailed((err, _failedMessage) => {
// updateMessages([failedMessage], false, sdk.currentUser.userId);
.onFailed((err, failedMessage) => {
updateMessages([failedMessage], false, sdk.currentUser.userId);
reject(err);
});
});
Expand All @@ -249,8 +267,8 @@ export const useGroupChannelMessagesWithCollection: UseGroupChannelMessages = (s
resolve(sentMessage as SendbirdFileMessage);
}
})
.onFailed((err, _failedMessage) => {
// updateMessages([failedMessage], false, sdk.currentUser.userId);
.onFailed((err, failedMessage) => {
updateMessages([failedMessage], false, sdk.currentUser.userId);
reject(err);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ export const useGroupChannelMessagesWithQuery: UseGroupChannelMessages = (sdk, c
deleteMessages([messageId], []);
deleteNewMessages([messageId], []);
},
async onReactionUpdated(eventChannel, reactionEvent) {
if (isDifferentChannel(channel, eventChannel)) return;

const message = await sdk.message.getMessage({
messageId: reactionEvent.messageId,
includeReactions: true,
includeParentMessageInfo: true,
includeThreadInfo: true,
includeMetaArray: true,
channelUrl: channel.url,
channelType: channel.channelType,
});
updateMessages([message], false, sdk.currentUser.userId);
},
// Channels
onChannelChanged: channelUpdater,
onChannelFrozen: channelUpdater,
Expand Down

0 comments on commit 43ee963

Please sign in to comment.