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

perf: prevent filtering a message which is being reacted to #2514

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,13 @@ const ChannelInner = <

const updateMessage = (
updatedMessage: MessageToSend<StreamChatGenerics> | StreamMessage<StreamChatGenerics>,
timestampChanged = true,
) => {
// add the message to the local channel state
channel.state.addMessageSorted(updatedMessage as MessageResponse<StreamChatGenerics>, true);
channel.state.addMessageSorted(
updatedMessage as MessageResponse<StreamChatGenerics>,
timestampChanged,
);

dispatch({
channel,
Expand Down
6 changes: 3 additions & 3 deletions src/components/Message/hooks/useReactionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const useReactionHandler = <
const tempMessage = createMessagePreview(add, newReaction, message);

try {
updateMessage(tempMessage);
updateMessage(tempMessage, false);
// @ts-expect-error
thread?.upsertReplyLocally({ message: tempMessage });

Expand All @@ -102,10 +102,10 @@ export const useReactionHandler = <
: await channel.deleteReaction(id, type);

// seems useless as we're expecting WS event to come in and replace this anyway
updateMessage(messageResponse.message);
updateMessage(messageResponse.message, false);
} catch (error) {
// revert to the original message if the API call fails
updateMessage(message);
updateMessage(message, false);
// @ts-expect-error
thread?.upsertReplyLocally({ message });
}
Expand Down
2 changes: 1 addition & 1 deletion src/context/ChannelActionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type ChannelActionContextValue<
setQuotedMessage: React.Dispatch<
React.SetStateAction<StreamMessage<StreamChatGenerics> | undefined>
>;
updateMessage: (message: StreamMessage<StreamChatGenerics>) => void;
updateMessage: (message: StreamMessage<StreamChatGenerics>, timestampChanged?: boolean) => void;
};

export const ChannelActionContext = React.createContext<ChannelActionContextValue | undefined>(
Expand Down
Loading