|
1 | | -/* eslint-disable react/prop-types */ |
| 1 | +/* eslint-disable react-hooks/rules-of-hooks */ |
2 | 2 | import React, { useState, useEffect, useCallback, useRef } from 'react'; |
3 | 3 | import PropTypes from 'prop-types'; |
| 4 | +import generateApiKey from 'generate-api-key'; |
4 | 5 |
|
5 | 6 | import { MatrixEventEvent, RoomEvent, THREAD_RELATION_TYPE } from 'matrix-js-sdk'; |
6 | 7 |
|
7 | 8 | import clone from 'clone'; |
8 | 9 | import hljs from 'highlight.js'; |
9 | 10 | import * as linkify from 'linkifyjs'; |
| 11 | +import cons from '@src/client/state/cons'; |
10 | 12 |
|
11 | 13 | import Text from '../../atoms/text/Text'; |
12 | 14 | import { hljsFixer, resizeWindowChecker, toast } from '../../../util/tools'; |
@@ -770,7 +772,6 @@ function MessageReactionGroup({ roomTimeline, mEvent }) { |
770 | 772 | .sort((a, b) => reactions[a].index - reactions[b].index) |
771 | 773 | .slice(0, reactionLimit); |
772 | 774 |
|
773 | | - // eslint-disable-next-line react-hooks/rules-of-hooks |
774 | 775 | useEffect(() => mediaFix(itemEmbed, embedHeight, setEmbedHeight)); |
775 | 776 |
|
776 | 777 | return ( |
@@ -895,7 +896,6 @@ const MessageOptions = React.memo( |
895 | 896 | selectRoom(roomId, eventId, eventId); |
896 | 897 | }; |
897 | 898 |
|
898 | | - // eslint-disable-next-line react-hooks/rules-of-hooks |
899 | 899 | useEffect(() => { |
900 | 900 | const newForceThread = (value) => setIsForceThreadVisible(value); |
901 | 901 | matrixAppearance.on('forceThreadButton', newForceThread); |
@@ -1065,8 +1065,12 @@ const MessageThreadSummary = React.memo(({ thread }) => { |
1065 | 1065 | selectRoom(thread.roomId, undefined, thread.rootEvent?.getId()); |
1066 | 1066 | } |
1067 | 1067 |
|
1068 | | - thread.on(RoomEvent.Timeline, () => { |
1069 | | - setLastReply(thread.lastReply()); |
| 1068 | + useEffect(() => { |
| 1069 | + const threadTimelineUpdate = () => setLastReply(thread.lastReply()); |
| 1070 | + thread.on(RoomEvent.Timeline, threadTimelineUpdate); |
| 1071 | + return () => { |
| 1072 | + thread.off(RoomEvent.Timeline, threadTimelineUpdate); |
| 1073 | + }; |
1070 | 1074 | }); |
1071 | 1075 |
|
1072 | 1076 | return ( |
@@ -1260,13 +1264,15 @@ function Message({ |
1260 | 1264 | refRoomInput, |
1261 | 1265 | }) { |
1262 | 1266 | // Get Room Data |
| 1267 | + const { notifications } = initMatrix; |
1263 | 1268 | const appearanceSettings = getAppearance(); |
1264 | 1269 | $(timelineSVRef?.current).trigger('scroll'); |
1265 | 1270 | const mx = initMatrix.matrixClient; |
1266 | 1271 | const roomId = mEvent.getRoomId(); |
1267 | 1272 | const threadId = mEvent.getThread()?.id; |
1268 | 1273 | const { editedTimeline, reactionTimeline } = roomTimeline ?? {}; |
1269 | 1274 |
|
| 1275 | + const [existThread, updateExistThread] = useState(typeof threadId === 'string'); |
1270 | 1276 | const [embeds, setEmbeds] = useState([]); |
1271 | 1277 | const [embedHeight, setEmbedHeight] = useState(null); |
1272 | 1278 | const itemEmbed = useRef(null); |
@@ -1368,7 +1374,6 @@ function Message({ |
1368 | 1374 | } |
1369 | 1375 | } |
1370 | 1376 |
|
1371 | | - // eslint-disable-next-line react-hooks/rules-of-hooks |
1372 | 1377 | useEffect(() => { |
1373 | 1378 | const bodyUrls = []; |
1374 | 1379 | if (typeof body === 'string' && body.length > 0) { |
@@ -1466,9 +1471,22 @@ function Message({ |
1466 | 1471 | }; |
1467 | 1472 | }, []); |
1468 | 1473 |
|
1469 | | - // eslint-disable-next-line react-hooks/rules-of-hooks |
1470 | 1474 | useEffect(() => mediaFix(itemEmbed, embedHeight, setEmbedHeight)); |
1471 | 1475 |
|
| 1476 | + useEffect(() => { |
| 1477 | + const threadUpdate = (tth) => { |
| 1478 | + const thread = mEvent.getThread(); |
| 1479 | + if (thread && tth.id === thread.id) { |
| 1480 | + if (!existThread) updateExistThread(true); |
| 1481 | + } |
| 1482 | + }; |
| 1483 | + |
| 1484 | + notifications.on(cons.events.notifications.THREAD_NOTIFICATION, threadUpdate); |
| 1485 | + return () => { |
| 1486 | + notifications.off(cons.events.notifications.THREAD_NOTIFICATION, threadUpdate); |
| 1487 | + }; |
| 1488 | + }); |
| 1489 | + |
1472 | 1490 | // Normal Message |
1473 | 1491 | if (msgType !== 'm.bad.encrypted') { |
1474 | 1492 | // Return Data |
@@ -1553,7 +1571,12 @@ function Message({ |
1553 | 1571 | <div ref={itemEmbed} className="message-embed message-url-embed"> |
1554 | 1572 | {embeds.map((embed) => { |
1555 | 1573 | if (embed.data) |
1556 | | - return <Embed key={`msg_embed_${embed.eventId}`} embed={embed.data} />; |
| 1574 | + return ( |
| 1575 | + <Embed |
| 1576 | + key={`msg_embed_${embed.eventId}_${generateApiKey()}`} |
| 1577 | + embed={embed.data} |
| 1578 | + /> |
| 1579 | + ); |
1557 | 1580 | })} |
1558 | 1581 | </div> |
1559 | 1582 | ) : null} |
|
0 commit comments