瀏覽代碼

feat(chat) use the original message ID for processing

This is a prerequisite for operations that rely on previous messages, such as reactions.
factor2
Patrick He 1 年之前
父節點
當前提交
8bfa65987d
沒有連結到貢獻者的電子郵件帳戶。

+ 3
- 3
modules/API/API.js 查看文件

@@ -1338,14 +1338,14 @@ class API {
1338 1338
      * @returns {void}
1339 1339
      */
1340 1340
     notifyReceivedChatMessage(
1341
-            { body, id, nick, privateMessage, ts } = {}) {
1342
-        if (APP.conference.isLocalId(id)) {
1341
+            { body, from, nick, privateMessage, ts } = {}) {
1342
+        if (APP.conference.isLocalId(from)) {
1343 1343
             return;
1344 1344
         }
1345 1345
 
1346 1346
         this._sendEvent({
1347 1347
             name: 'incoming-message',
1348
-            from: id,
1348
+            from,
1349 1349
             message: body,
1350 1350
             nick,
1351 1351
             privateMessage,

+ 2
- 2
react/features/breakout-rooms/middleware.ts 查看文件

@@ -83,12 +83,12 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
83 83
         const { messages } = getState()['features/chat'];
84 84
 
85 85
         messages?.forEach(m => {
86
-            if (m.messageType === MESSAGE_TYPE_REMOTE && !getParticipantById(getState(), m.id)) {
86
+            if (m.messageType === MESSAGE_TYPE_REMOTE && !getParticipantById(getState(), m.participantId)) {
87 87
                 const rooms: IRooms = action.rooms;
88 88
 
89 89
                 for (const room of Object.values(rooms)) {
90 90
                     const participants = room.participants || {};
91
-                    const matchedJid = Object.keys(participants).find(jid => jid.endsWith(m.id));
91
+                    const matchedJid = Object.keys(participants).find(jid => jid.endsWith(m.participantId));
92 92
 
93 93
                     if (matchedJid) {
94 94
                         m.displayName = participants[matchedJid].displayName;

+ 2
- 2
react/features/chat/components/AbstractMessageContainer.ts 查看文件

@@ -36,13 +36,13 @@ export default class AbstractMessageContainer<P extends IProps, S> extends Compo
36 36
         for (let i = 0; i < messagesCount; i++) {
37 37
             const message = this.props.messages[i];
38 38
 
39
-            if (message.id === currentGroupParticipantId) {
39
+            if (message.participantId === currentGroupParticipantId) {
40 40
                 currentGrouping.push(message);
41 41
             } else {
42 42
                 currentGrouping.length && groups.push(currentGrouping);
43 43
 
44 44
                 currentGrouping = [ message ];
45
-                currentGroupParticipantId = message.id;
45
+                currentGroupParticipantId = message.participantId;
46 46
             }
47 47
         }
48 48
 

+ 2
- 2
react/features/chat/components/native/ChatMessage.tsx 查看文件

@@ -113,7 +113,7 @@ class ChatMessage extends Component<IChatMessageProps> {
113 113
             <View style = { styles.avatarWrapper }>
114 114
                 { this.props.showAvatar && <Avatar
115 115
                     displayName = { message.displayName }
116
-                    participantId = { message.id }
116
+                    participantId = { message.participantId }
117 117
                     size = { styles.avatarWrapper.width } />
118 118
                 }
119 119
             </View>
@@ -175,7 +175,7 @@ class ChatMessage extends Component<IChatMessageProps> {
175 175
             <View style = { styles.replyContainer as ViewStyle }>
176 176
                 <PrivateMessageButton
177 177
                     isLobbyMessage = { lobbyChat }
178
-                    participantID = { message.id }
178
+                    participantID = { message.participantId }
179 179
                     reply = { true }
180 180
                     showLabel = { false }
181 181
                     toggledStyles = { styles.replyStyles } />

+ 1
- 1
react/features/chat/components/web/ChatMessage.tsx 查看文件

@@ -197,7 +197,7 @@ const ChatMessage = ({
197 197
                                 className = { classes.replyButtonContainer }>
198 198
                                 <PrivateMessageButton
199 199
                                     isLobbyMessage = { message.lobbyChat }
200
-                                    participantID = { message.id } />
200
+                                    participantID = { message.participantId } />
201 201
                             </div>
202 202
                         )}
203 203
                 </div>

+ 1
- 1
react/features/chat/components/web/ChatMessageGroup.tsx 查看文件

@@ -66,7 +66,7 @@ const ChatMessageGroup = ({ className = '', messages }: IProps) => {
66 66
         <div className = { clsx(classes.groupContainer, className) }>
67 67
             <Avatar
68 68
                 className = { clsx(classes.avatar, 'avatar') }
69
-                participantId = { messages[0].id }
69
+                participantId = { messages[0].participantId }
70 70
                 size = { 32 } />
71 71
             <div className = { `${classes.messageGroup} chat-message-group ${className}` }>
72 72
                 {messages.map((message, i) => (

+ 1
- 1
react/features/chat/functions.ts 查看文件

@@ -172,7 +172,7 @@ export function getMessageText(message: IMessage) {
172 172
  */
173 173
 export function getCanReplyToMessage(state: IReduxState, message: IMessage) {
174 174
     const { knocking } = state['features/lobby'];
175
-    const participant = getParticipantById(state, message.id);
175
+    const participant = getParticipantById(state, message.participantId);
176 176
 
177 177
     return Boolean(participant)
178 178
         && (message.privateMessage || (message.lobbyChat && !knocking))

+ 44
- 34
react/features/chat/middleware.ts 查看文件

@@ -125,7 +125,7 @@ MiddlewareRegistry.register(store => next => action => {
125 125
             store.dispatch(pushReactions(data.reactions));
126 126
 
127 127
             _handleReceivedMessage(store, {
128
-                id: participant.getId(),
128
+                participantId: participant.getId(),
129 129
                 message: getReactionMessageFromBuffer(data.reactions),
130 130
                 privateMessage: false,
131 131
                 lobbyChat: false,
@@ -137,12 +137,12 @@ MiddlewareRegistry.register(store => next => action => {
137 137
     }
138 138
 
139 139
     case NON_PARTICIPANT_MESSAGE_RECEIVED: {
140
-        const { id, json: data } = action;
140
+        const { participantId, json: data } = action;
141 141
 
142 142
         if (data?.type === MESSAGE_TYPE_SYSTEM && data.message) {
143 143
             _handleReceivedMessage(store, {
144 144
                 displayName: data.displayName ?? i18next.t('chat.systemDisplayName'),
145
-                id,
145
+                participantId,
146 146
                 lobbyChat: false,
147 147
                 message: data.message,
148 148
                 privateMessage: true,
@@ -213,7 +213,7 @@ MiddlewareRegistry.register(store => next => action => {
213 213
     case ADD_REACTION_MESSAGE: {
214 214
         if (localParticipant?.id) {
215 215
             _handleReceivedMessage(store, {
216
-                id: localParticipant.id,
216
+                participantId: localParticipant.id,
217 217
                 message: action.message,
218 218
                 privateMessage: false,
219 219
                 timestamp: Date.now(),
@@ -274,25 +274,30 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
274 274
 
275 275
     conference.on(
276 276
         JitsiConferenceEvents.MESSAGE_RECEIVED,
277
-        // eslint-disable-next-line max-params
278
-        (id: string, message: string, timestamp: number, displayName: string, isGuest?: boolean) => {
277
+        /* eslint-disable max-params */
278
+        (participantId: string, message: string, timestamp: number,
279
+                displayName: string, isGuest: boolean, messageId: string) => {
280
+        /* eslint-enable max-params */
279 281
             _onConferenceMessageReceived(store, {
280
-                id: id || displayName, // in case of messages coming from visitors we can have unknown id
282
+                // in case of messages coming from visitors we can have unknown id
283
+                participantId: participantId || displayName,
281 284
                 message,
282 285
                 timestamp,
283 286
                 displayName,
284 287
                 isGuest,
288
+                messageId,
285 289
                 privateMessage: false });
286 290
         }
287 291
     );
288 292
 
289 293
     conference.on(
290 294
         JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
291
-        (id: string, message: string, timestamp: number) => {
295
+        (participantId: string, message: string, timestamp: number, messageId: string) => {
292 296
             _onConferenceMessageReceived(store, {
293
-                id,
297
+                participantId,
294 298
                 message,
295 299
                 timestamp,
300
+                messageId,
296 301
                 privateMessage: true
297 302
             });
298 303
         }
@@ -311,25 +316,29 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
311 316
  * @param {Object} message - The message object.
312 317
  * @returns {void}
313 318
  */
314
-function _onConferenceMessageReceived(store: IStore, { displayName, id, isGuest, message, timestamp, privateMessage }: {
315
-    displayName?: string; id: string; isGuest?: boolean;
316
-    message: string; privateMessage: boolean; timestamp: number; }) {
319
+function _onConferenceMessageReceived(store: IStore,
320
+        { displayName, isGuest, message, messageId, participantId, privateMessage, timestamp }: {
321
+        displayName?: string; isGuest?: boolean; message: string; messageId?: string;
322
+        participantId: string; privateMessage: boolean; timestamp: number; }
323
+) {
324
+
317 325
     const isGif = isGifMessage(message);
318 326
 
319 327
     if (isGif) {
320
-        _handleGifMessageReceived(store, id, message);
328
+        _handleGifMessageReceived(store, participantId, message);
321 329
         if (getGifDisplayMode(store.getState()) === 'tile') {
322 330
             return;
323 331
         }
324 332
     }
325 333
     _handleReceivedMessage(store, {
326 334
         displayName,
327
-        id,
328 335
         isGuest,
336
+        participantId,
329 337
         message,
330 338
         privateMessage,
331 339
         lobbyChat: false,
332
-        timestamp
340
+        timestamp,
341
+        messageId
333 342
     }, true, isGif);
334 343
 }
335 344
 
@@ -337,14 +346,14 @@ function _onConferenceMessageReceived(store: IStore, { displayName, id, isGuest,
337 346
  * Handles a received gif message.
338 347
  *
339 348
  * @param {Object} store - Redux store.
340
- * @param {string} id - Id of the participant that sent the message.
349
+ * @param {string} participantId - Id of the participant that sent the message.
341 350
  * @param {string} message - The message sent.
342 351
  * @returns {void}
343 352
  */
344
-function _handleGifMessageReceived(store: IStore, id: string, message: string) {
353
+function _handleGifMessageReceived(store: IStore, participantId: string, message: string) {
345 354
     const url = message.substring(GIF_PREFIX.length, message.length - 1);
346 355
 
347
-    store.dispatch(addGif(id, url));
356
+    store.dispatch(addGif(participantId, url));
348 357
 }
349 358
 
350 359
 /**
@@ -374,7 +383,7 @@ function _handleChatError({ dispatch }: IStore, error: Error) {
374 383
 export function handleLobbyMessageReceived(message: string, participantId: string) {
375 384
     return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
376 385
         _handleReceivedMessage({ dispatch,
377
-            getState }, { id: participantId,
386
+            getState }, { participantId,
378 387
             message,
379 388
             privateMessage: false,
380 389
             lobbyChat: true,
@@ -387,18 +396,18 @@ export function handleLobbyMessageReceived(message: string, participantId: strin
387 396
  * Function to get lobby chat user display name.
388 397
  *
389 398
  * @param {Store} state - The Redux store.
390
- * @param {string} id - The knocking participant id.
399
+ * @param {string} participantId - The knocking participant id.
391 400
  * @returns {string}
392 401
  */
393
-function getLobbyChatDisplayName(state: IReduxState, id: string) {
402
+function getLobbyChatDisplayName(state: IReduxState, participantId: string) {
394 403
     const { knockingParticipants } = state['features/lobby'];
395 404
     const { lobbyMessageRecipient } = state['features/chat'];
396 405
 
397
-    if (id === lobbyMessageRecipient?.id) {
406
+    if (participantId === lobbyMessageRecipient?.id) {
398 407
         return lobbyMessageRecipient.name;
399 408
     }
400 409
 
401
-    const knockingParticipant = knockingParticipants.find(p => p.id === id);
410
+    const knockingParticipant = knockingParticipants.find(p => p.id === participantId);
402 411
 
403 412
     if (knockingParticipant) {
404 413
         return knockingParticipant.name;
@@ -417,9 +426,9 @@ function getLobbyChatDisplayName(state: IReduxState, id: string) {
417 426
  * @returns {void}
418 427
  */
419 428
 function _handleReceivedMessage({ dispatch, getState }: IStore,
420
-        { displayName, id, isGuest, message, privateMessage, timestamp, lobbyChat }: {
421
-        displayName?: string; id: string; isGuest?: boolean; lobbyChat: boolean;
422
-        message: string; privateMessage: boolean; timestamp: number; },
429
+        { displayName, isGuest, lobbyChat, message, messageId, participantId, privateMessage, timestamp }: {
430
+        displayName?: string; isGuest?: boolean; lobbyChat: boolean; message: string;
431
+        messageId?: string; participantId: string; privateMessage: boolean; timestamp: number; },
423 432
         shouldPlaySound = true,
424 433
         isReaction = false
425 434
 ) {
@@ -434,12 +443,12 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,
434 443
 
435 444
     // Provide a default for the case when a message is being
436 445
     // backfilled for a participant that has left the conference.
437
-    const participant = getParticipantById(state, id) || { local: undefined };
446
+    const participant = getParticipantById(state, participantId) || { local: undefined };
438 447
 
439 448
     const localParticipant = getLocalParticipant(getState);
440 449
     let displayNameToShow = lobbyChat
441
-        ? getLobbyChatDisplayName(state, id)
442
-        : displayName || getParticipantDisplayName(state, id);
450
+        ? getLobbyChatDisplayName(state, participantId)
451
+        : displayName || getParticipantDisplayName(state, participantId);
443 452
     const hasRead = participant.local || isChatOpen;
444 453
     const timestampToDate = timestamp ? new Date(timestamp) : new Date();
445 454
     const millisecondsTimestamp = timestampToDate.getTime();
@@ -455,13 +464,14 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,
455 464
     dispatch(addMessage({
456 465
         displayName: displayNameToShow,
457 466
         hasRead,
458
-        id,
467
+        participantId,
459 468
         messageType: participant.local ? MESSAGE_TYPE_LOCAL : MESSAGE_TYPE_REMOTE,
460 469
         message,
461 470
         privateMessage,
462 471
         lobbyChat,
463 472
         recipient: getParticipantDisplayName(state, localParticipant?.id ?? ''),
464 473
         timestamp: millisecondsTimestamp,
474
+        messageId,
465 475
         isReaction
466 476
     }));
467 477
 
@@ -477,7 +487,7 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,
477 487
 
478 488
         APP.API.notifyReceivedChatMessage({
479 489
             body: message,
480
-            id,
490
+            from: participantId,
481 491
             nick: displayNameToShow,
482 492
             privateMessage,
483 493
             ts: timestamp
@@ -512,7 +522,7 @@ function _persistSentPrivateMessage({ dispatch, getState }: IStore, recipientID:
512 522
     dispatch(addMessage({
513 523
         displayName,
514 524
         hasRead: true,
515
-        id: localParticipant.id,
525
+        participantId: localParticipant.id,
516 526
         messageType: MESSAGE_TYPE_LOCAL,
517 527
         message,
518 528
         privateMessage: !isLobbyPrivateMessage,
@@ -562,7 +572,7 @@ function _shouldSendPrivateMessageTo(state: IReduxState, action: AnyAction) {
562 572
 
563 573
     if (lastMessage.privateMessage) {
564 574
         // We show the notice if the last received message was private.
565
-        return lastMessage.id;
575
+        return lastMessage.participantId;
566 576
     }
567 577
 
568 578
     // But messages may come rapidly, we want to protect our users from mis-sending a message
@@ -577,7 +587,7 @@ function _shouldSendPrivateMessageTo(state: IReduxState, action: AnyAction) {
577 587
         ? recentPrivateMessages[0] : recentPrivateMessages[recentPrivateMessages.length - 1];
578 588
 
579 589
     if (recentPrivateMessage) {
580
-        return recentPrivateMessage.id;
590
+        return recentPrivateMessage.participantId;
581 591
     }
582 592
 
583 593
     return undefined;

+ 2
- 4
react/features/chat/reducer.ts 查看文件

@@ -1,5 +1,3 @@
1
-import { v4 as uuidv4 } from 'uuid';
2
-
3 1
 import { ILocalParticipant, IParticipant } from '../base/participants/types';
4 2
 import ReducerRegistry from '../base/redux/ReducerRegistry';
5 3
 
@@ -48,9 +46,9 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, ac
48 46
         const newMessage: IMessage = {
49 47
             displayName: action.displayName,
50 48
             error: action.error,
51
-            id: action.id,
49
+            participantId: action.participantId,
52 50
             isReaction: action.isReaction,
53
-            messageId: uuidv4(),
51
+            messageId: action.messageId,
54 52
             messageType: action.messageType,
55 53
             message: action.message,
56 54
             privateMessage: action.privateMessage,

+ 1
- 1
react/features/chat/types.ts 查看文件

@@ -5,12 +5,12 @@ import { IStore } from '../app/types';
5 5
 export interface IMessage {
6 6
     displayName: string;
7 7
     error?: Object;
8
-    id: string;
9 8
     isReaction: boolean;
10 9
     lobbyChat: boolean;
11 10
     message: string;
12 11
     messageId: string;
13 12
     messageType: string;
13
+    participantId: string;
14 14
     privateMessage: boolean;
15 15
     recipient: string;
16 16
     timestamp: number;

Loading…
取消
儲存