mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-24 18:59:17 +00:00
Stop messages flickering through the file panel as they are sent (#34608)
* Stop messages flickering through the file panel as they are sent A filtered timeline set is handed the room's pending events unless it is told otherwise, and those are the whole room's pending events rather than the ones the filter would have kept. So every message typed into the room appeared in the file panel for as long as it took the remote echo to arrive, at which point the filter finally threw it out again. The file panel now asks for its timeline set without them. Nothing is lost by that: a file sent from the panel still appears the moment it is sent, because the panel adds live events itself and checks the message type while doing so, which the pending list never did. Tests: the file panel asks for a timeline set which does not carry the room's pending events. * Filter the pending events a filtered timeline set shows Suppressing the file panel's pending events wholesale was the wrong lever: it is an all-or-nothing switch on the room's detached pending list, so it also hid files the user had just sent, and the e2e caught the panel staying empty. Filter them instead. A timeline set already carries the filter it was built with, so the pending events it hands the panel can be held to the same test as the events the server returns. Files being sent still appear immediately; the text messages that used to flicker through never qualify. Panels with no filter, which is every other caller, are untouched. --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -1609,8 +1609,16 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||
// if we're at the end of the live timeline, append the pending events
|
||||
if (!this.timelineWindow!.canPaginate(EventTimeline.FORWARDS)) {
|
||||
const pendingEvents = this.props.timelineSet.getPendingEvents();
|
||||
// Pending events are the whole room's, so a filtered timeline set is handed events its
|
||||
// own filter would never accept. Without this every message being sent flickers through
|
||||
// panels like the file panel until its remote echo arrives and the filter rejects it.
|
||||
const filter = this.props.timelineSet.getFilter?.();
|
||||
events.push(
|
||||
...pendingEvents.filter((event) => {
|
||||
if (filter && !filter.filterRoomTimeline([event]).length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { shouldLiveInRoom, threadId } = this.props.timelineSet.room!.eventShouldLiveIn(
|
||||
event,
|
||||
pendingEvents,
|
||||
|
||||
@@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { EventTimelineSet, PendingEventOrdering, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { EventStatus, EventTimelineSet, Filter, PendingEventOrdering, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { screen, render, waitFor } from "jest-matrix-react";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
@@ -49,6 +49,39 @@ describe("FilePanel", () => {
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("does not show a pending message that its filter rejects", async () => {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const room = new Room("!room:server", cli, cli.getSafeUserId(), {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
});
|
||||
|
||||
const filter = new Filter(cli.getSafeUserId());
|
||||
filter.setDefinition({ room: { timeline: { contains_url: true, types: ["m.room.message"] } } });
|
||||
const timelineSet = new EventTimelineSet(room, { filter });
|
||||
room.getOrCreateFilteredTimelineSet = jest.fn().mockReturnValue(timelineSet);
|
||||
mocked(cli.getRoom).mockReturnValue(room);
|
||||
|
||||
// A text message being sent carries no url, so the file filter rejects it. It is still one of
|
||||
// the room's pending events, which the panel is handed in full.
|
||||
const pending = mkEvent({
|
||||
event: true,
|
||||
type: "m.room.message",
|
||||
user: cli.getSafeUserId(),
|
||||
room: room.roomId,
|
||||
content: { msgtype: "m.text", body: "a message being sent" },
|
||||
});
|
||||
pending.setStatus(EventStatus.SENDING);
|
||||
room.addPendingEvent(pending, "txn-text");
|
||||
|
||||
render(
|
||||
<FilePanel roomId={room.roomId} onClose={jest.fn()} />,
|
||||
clientAndSDKContextRenderOptions(cli, SDKContextClass.instance),
|
||||
);
|
||||
await screen.findByText("No files visible in this room");
|
||||
|
||||
expect(screen.queryByText("a message being sent")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe("addEncryptedLiveEvent", () => {
|
||||
it("should add file msgtype event to filtered timelineSet", async () => {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
|
||||
Reference in New Issue
Block a user