Make pinned messages more reliably reflect edits (#7920)

* Inject edits from /relations API into pinned messages

Signed-off-by: Robin Townsend <robin@robin.town>

* Limit returned relations, because we only need one

Signed-off-by: Robin Townsend <robin@robin.town>

* Fetch pinned message edits in parallel

Signed-off-by: Robin Townsend <robin@robin.town>
pull/21833/head
Robin 2022-03-02 12:21:23 -05:00 committed by GitHub
parent aadb64615f
commit 8f68a43ee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -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";
@ -102,14 +102,22 @@ 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've found
if (edit) event.makeReplaced(edit);
return event;
}
} catch (err) {