From b99c8c1c7edbc44788335e4f297a640ecf19185c Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Mon, 28 Feb 2022 13:37:51 -0500 Subject: [PATCH 1/3] Inject edits from /relations API into pinned messages Signed-off-by: Robin Townsend --- .../views/right_panel/PinnedMessagesCard.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/views/right_panel/PinnedMessagesCard.tsx b/src/components/views/right_panel/PinnedMessagesCard.tsx index 7e4bc3a7ae6..3ca3a8e9221 100644 --- a/src/components/views/right_panel/PinnedMessagesCard.tsx +++ b/src/components/views/right_panel/PinnedMessagesCard.tsx @@ -17,7 +17,7 @@ limitations under the License. import React, { useCallback, useContext, useEffect, useState } from "react"; import { Room, RoomEvent } from "matrix-js-sdk/src/models/room"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; -import { EventType } from 'matrix-js-sdk/src/@types/event'; +import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event'; import { logger } from "matrix-js-sdk/src/logger"; import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; @@ -110,6 +110,16 @@ const PinnedMessagesCard = ({ room, onClose }: IProps) => { if (event && PinningUtils.isPinnable(event)) { // Inject sender information event.sender = room.getMember(event.getSender()); + + // Also inject any edits we find + // The latest edit comes first, so we don't need to worry about paginating + const { events: edits } = await cli.relations( + room.roomId, eventId, RelationType.Replace, event.getType(), + ); + if (edits.length) { + event.makeReplaced(edits[0]); + } + return event; } } catch (err) { From a95930effea68e75cae5ec30cbe7b12e783b1317 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Mon, 28 Feb 2022 13:49:16 -0500 Subject: [PATCH 2/3] Limit returned relations, because we only need one Signed-off-by: Robin Townsend --- src/components/views/right_panel/PinnedMessagesCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/right_panel/PinnedMessagesCard.tsx b/src/components/views/right_panel/PinnedMessagesCard.tsx index 3ca3a8e9221..ea8c0364120 100644 --- a/src/components/views/right_panel/PinnedMessagesCard.tsx +++ b/src/components/views/right_panel/PinnedMessagesCard.tsx @@ -114,7 +114,7 @@ const PinnedMessagesCard = ({ room, onClose }: IProps) => { // Also inject any edits we find // The latest edit comes first, so we don't need to worry about paginating const { events: edits } = await cli.relations( - room.roomId, eventId, RelationType.Replace, event.getType(), + room.roomId, eventId, RelationType.Replace, event.getType(), { limit: 1 }, ); if (edits.length) { event.makeReplaced(edits[0]); From d6a8c3fc6bcfc5393bda501ffe34f64db9a66ef0 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 2 Mar 2022 11:24:57 -0500 Subject: [PATCH 3/3] Fetch pinned message edits in parallel Signed-off-by: Robin Townsend --- .../views/right_panel/PinnedMessagesCard.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/components/views/right_panel/PinnedMessagesCard.tsx b/src/components/views/right_panel/PinnedMessagesCard.tsx index ea8c0364120..d6a5139b5e6 100644 --- a/src/components/views/right_panel/PinnedMessagesCard.tsx +++ b/src/components/views/right_panel/PinnedMessagesCard.tsx @@ -102,23 +102,21 @@ const PinnedMessagesCard = ({ room, onClose }: IProps) => { if (localEvent) return localEvent; try { - const evJson = await cli.fetchRoomEvent(room.roomId, eventId); + // Fetch the event and latest edit in parallel + const [evJson, { events: [edit] }] = await Promise.all([ + cli.fetchRoomEvent(room.roomId, eventId), + cli.relations(room.roomId, eventId, RelationType.Replace, null, { limit: 1 }), + ]); const event = new MatrixEvent(evJson); if (event.isEncrypted()) { await cli.decryptEventIfNeeded(event); // TODO await? } + if (event && PinningUtils.isPinnable(event)) { // Inject sender information event.sender = room.getMember(event.getSender()); - - // Also inject any edits we find - // The latest edit comes first, so we don't need to worry about paginating - const { events: edits } = await cli.relations( - room.roomId, eventId, RelationType.Replace, event.getType(), { limit: 1 }, - ); - if (edits.length) { - event.makeReplaced(edits[0]); - } + // Also inject any edits we've found + if (edit) event.makeReplaced(edit); return event; }