浏览代码

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
      * @returns {void}
1338
      * @returns {void}
1339
      */
1339
      */
1340
     notifyReceivedChatMessage(
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
             return;
1343
             return;
1344
         }
1344
         }
1345
 
1345
 
1346
         this._sendEvent({
1346
         this._sendEvent({
1347
             name: 'incoming-message',
1347
             name: 'incoming-message',
1348
-            from: id,
1348
+            from,
1349
             message: body,
1349
             message: body,
1350
             nick,
1350
             nick,
1351
             privateMessage,
1351
             privateMessage,

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

83
         const { messages } = getState()['features/chat'];
83
         const { messages } = getState()['features/chat'];
84
 
84
 
85
         messages?.forEach(m => {
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
                 const rooms: IRooms = action.rooms;
87
                 const rooms: IRooms = action.rooms;
88
 
88
 
89
                 for (const room of Object.values(rooms)) {
89
                 for (const room of Object.values(rooms)) {
90
                     const participants = room.participants || {};
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
                     if (matchedJid) {
93
                     if (matchedJid) {
94
                         m.displayName = participants[matchedJid].displayName;
94
                         m.displayName = participants[matchedJid].displayName;

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

36
         for (let i = 0; i < messagesCount; i++) {
36
         for (let i = 0; i < messagesCount; i++) {
37
             const message = this.props.messages[i];
37
             const message = this.props.messages[i];
38
 
38
 
39
-            if (message.id === currentGroupParticipantId) {
39
+            if (message.participantId === currentGroupParticipantId) {
40
                 currentGrouping.push(message);
40
                 currentGrouping.push(message);
41
             } else {
41
             } else {
42
                 currentGrouping.length && groups.push(currentGrouping);
42
                 currentGrouping.length && groups.push(currentGrouping);
43
 
43
 
44
                 currentGrouping = [ message ];
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
             <View style = { styles.avatarWrapper }>
113
             <View style = { styles.avatarWrapper }>
114
                 { this.props.showAvatar && <Avatar
114
                 { this.props.showAvatar && <Avatar
115
                     displayName = { message.displayName }
115
                     displayName = { message.displayName }
116
-                    participantId = { message.id }
116
+                    participantId = { message.participantId }
117
                     size = { styles.avatarWrapper.width } />
117
                     size = { styles.avatarWrapper.width } />
118
                 }
118
                 }
119
             </View>
119
             </View>
175
             <View style = { styles.replyContainer as ViewStyle }>
175
             <View style = { styles.replyContainer as ViewStyle }>
176
                 <PrivateMessageButton
176
                 <PrivateMessageButton
177
                     isLobbyMessage = { lobbyChat }
177
                     isLobbyMessage = { lobbyChat }
178
-                    participantID = { message.id }
178
+                    participantID = { message.participantId }
179
                     reply = { true }
179
                     reply = { true }
180
                     showLabel = { false }
180
                     showLabel = { false }
181
                     toggledStyles = { styles.replyStyles } />
181
                     toggledStyles = { styles.replyStyles } />

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

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

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

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

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

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

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

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

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

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

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

5
 export interface IMessage {
5
 export interface IMessage {
6
     displayName: string;
6
     displayName: string;
7
     error?: Object;
7
     error?: Object;
8
-    id: string;
9
     isReaction: boolean;
8
     isReaction: boolean;
10
     lobbyChat: boolean;
9
     lobbyChat: boolean;
11
     message: string;
10
     message: string;
12
     messageId: string;
11
     messageId: string;
13
     messageType: string;
12
     messageType: string;
13
+    participantId: string;
14
     privateMessage: boolean;
14
     privateMessage: boolean;
15
     recipient: string;
15
     recipient: string;
16
     timestamp: number;
16
     timestamp: number;

正在加载...
取消
保存