11import { match } from 'ts-pattern' ;
22import { useCallback } from 'react' ;
33import { useGroupChannelMessages } from '@sendbird/uikit-tools' ;
4- import { MessageMetaArray } from '@sendbird/chat/message' ;
54import 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
1616import {
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' ;
2424import type { ReplyType } from '../../../../types' ;
2525import type { GroupChannelProviderProps , OnBeforeHandler } from '../GroupChannelProvider' ;
2626import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext' ;
27+ import { PublishingModuleType , PUBSUB_TOPICS , SBUGlobalPubSub } from '../../../../lib/pubSub/topics' ;
28+ import { GroupChannel } from '@sendbird/chat/groupChannel' ;
2729
2830type MessageListDataSource = ReturnType < typeof useGroupChannelMessages > ;
2931type 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
4347const 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