Skip to content

Commit d1407d3

Browse files
authored
[CLNP-5921] Sync thread message with groupchannel message update (#1273)
[CLNP-5921](https://sendbird.atlassian.net/browse/CLNP-5921) ### Changelog * Fixed an issue where editing a text parent message in a channel did not update the corresponding parent message in the Thread area in real-time. [CLNP-5921]: https://sendbird.atlassian.net/browse/CLNP-5921?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 9bd64b8 commit d1407d3

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/modules/GroupChannel/context/GroupChannelProvider.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,15 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
320320
},
321321
);
322322

323-
const messageActions = useMessageActions({ ...props, ...messageDataSource, scrollToBottom, quoteMessage, replyType });
323+
const messageActions = useMessageActions({
324+
...props,
325+
...messageDataSource,
326+
scrollToBottom,
327+
quoteMessage,
328+
replyType,
329+
pubSub: config.pubSub,
330+
channel: currentChannel,
331+
});
324332

325333
return (
326334
<GroupChannelContext.Provider

src/modules/GroupChannel/context/hooks/useMessageActions.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { match } from 'ts-pattern';
22
import { useCallback } from 'react';
33
import { useGroupChannelMessages } from '@sendbird/uikit-tools';
4-
import { MessageMetaArray } from '@sendbird/chat/message';
54
import type {
65
BaseMessageCreateParams,
76
FileMessage,
@@ -12,6 +11,7 @@ import type {
1211
UserMessageCreateParams,
1312
UserMessageUpdateParams,
1413
} from '@sendbird/chat/message';
14+
import { MessageMetaArray } from '@sendbird/chat/message';
1515

1616
import {
1717
META_ARRAY_MESSAGE_TYPE_KEY,
@@ -20,10 +20,12 @@ import {
2020
VOICE_MESSAGE_FILE_NAME,
2121
VOICE_MESSAGE_MIME_TYPE,
2222
} from '../../../../utils/consts';
23-
import type { SendableMessageType, CoreMessageType } from '../../../../utils';
23+
import type { CoreMessageType, SendableMessageType } from '../../../../utils';
2424
import type { ReplyType } from '../../../../types';
2525
import type { GroupChannelProviderProps, OnBeforeHandler } from '../GroupChannelProvider';
2626
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
27+
import { PublishingModuleType, PUBSUB_TOPICS, SBUGlobalPubSub } from '../../../../lib/pubSub/topics';
28+
import { GroupChannel } from '@sendbird/chat/groupChannel';
2729

2830
type MessageListDataSource = ReturnType<typeof useGroupChannelMessages>;
2931
type MessageActions = {
@@ -38,6 +40,8 @@ interface Params extends GroupChannelProviderProps, MessageListDataSource {
3840
scrollToBottom(animated?: boolean): Promise<void>;
3941
quoteMessage?: SendableMessageType | null;
4042
replyType: ReplyType;
43+
pubSub: SBUGlobalPubSub;
44+
channel: GroupChannel;
4145
}
4246

4347
const pass = <T>(value: T) => value;
@@ -68,6 +72,8 @@ export function useMessageActions(params: Params): MessageActions {
6872
scrollToBottom,
6973
quoteMessage,
7074
replyType,
75+
channel,
76+
pubSub,
7177
} = params;
7278
const { eventHandlers } = useSendbirdStateContext();
7379
const buildInternalMessageParams = useCallback(
@@ -185,9 +191,18 @@ export function useMessageActions(params: Params): MessageActions {
185191
async (messageId: number, params: UserMessageUpdateParams) => {
186192
const internalParams = buildInternalMessageParams<UserMessageUpdateParams>(params);
187193
const processedParams = await processParams(onBeforeUpdateUserMessage, internalParams, 'update');
188-
return updateUserMessage(messageId, processedParams);
194+
return updateUserMessage(messageId, processedParams)
195+
.then((message) => {
196+
pubSub.publish(PUBSUB_TOPICS.UPDATE_USER_MESSAGE, {
197+
channel,
198+
message,
199+
publishingModules: [PublishingModuleType.CHANNEL],
200+
});
201+
202+
return message;
203+
});
189204
},
190-
[buildInternalMessageParams, updateUserMessage, processParams],
205+
[buildInternalMessageParams, updateUserMessage, processParams, channel?.url],
191206
),
192207
};
193208
}

0 commit comments

Comments
 (0)