1
1
import { match } from 'ts-pattern' ;
2
2
import { useCallback } from 'react' ;
3
3
import { useGroupChannelMessages } from '@sendbird/uikit-tools' ;
4
- import { MessageMetaArray } from '@sendbird/chat/message' ;
5
4
import type {
6
5
BaseMessageCreateParams ,
7
6
FileMessage ,
@@ -12,6 +11,7 @@ import type {
12
11
UserMessageCreateParams ,
13
12
UserMessageUpdateParams ,
14
13
} from '@sendbird/chat/message' ;
14
+ import { MessageMetaArray } from '@sendbird/chat/message' ;
15
15
16
16
import {
17
17
META_ARRAY_MESSAGE_TYPE_KEY ,
@@ -20,10 +20,12 @@ import {
20
20
VOICE_MESSAGE_FILE_NAME ,
21
21
VOICE_MESSAGE_MIME_TYPE ,
22
22
} from '../../../../utils/consts' ;
23
- import type { SendableMessageType , CoreMessageType } from '../../../../utils' ;
23
+ import type { CoreMessageType , SendableMessageType } from '../../../../utils' ;
24
24
import type { ReplyType } from '../../../../types' ;
25
25
import type { GroupChannelProviderProps , OnBeforeHandler } from '../GroupChannelProvider' ;
26
26
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext' ;
27
+ import { PublishingModuleType , PUBSUB_TOPICS , SBUGlobalPubSub } from '../../../../lib/pubSub/topics' ;
28
+ import { GroupChannel } from '@sendbird/chat/groupChannel' ;
27
29
28
30
type MessageListDataSource = ReturnType < typeof useGroupChannelMessages > ;
29
31
type MessageActions = {
@@ -38,6 +40,8 @@ interface Params extends GroupChannelProviderProps, MessageListDataSource {
38
40
scrollToBottom ( animated ?: boolean ) : Promise < void > ;
39
41
quoteMessage ?: SendableMessageType | null ;
40
42
replyType : ReplyType ;
43
+ pubSub : SBUGlobalPubSub ;
44
+ channel : GroupChannel ;
41
45
}
42
46
43
47
const pass = < T > ( value : T ) => value ;
@@ -68,6 +72,8 @@ export function useMessageActions(params: Params): MessageActions {
68
72
scrollToBottom,
69
73
quoteMessage,
70
74
replyType,
75
+ channel,
76
+ pubSub,
71
77
} = params ;
72
78
const { eventHandlers } = useSendbirdStateContext ( ) ;
73
79
const buildInternalMessageParams = useCallback (
@@ -185,9 +191,18 @@ export function useMessageActions(params: Params): MessageActions {
185
191
async ( messageId : number , params : UserMessageUpdateParams ) => {
186
192
const internalParams = buildInternalMessageParams < UserMessageUpdateParams > ( params ) ;
187
193
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
+ } ) ;
189
204
} ,
190
- [ buildInternalMessageParams , updateUserMessage , processParams ] ,
205
+ [ buildInternalMessageParams , updateUserMessage , processParams , channel ?. url ] ,
191
206
) ,
192
207
} ;
193
208
}
0 commit comments