Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

bugfix: fix in-reply-to previews not disappearing when swapping rooms #9278

Merged
merged 7 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions cypress/e2e/sliding-sync/sliding-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,69 @@ describe("Sliding Sync", () => {
cy.get('.mx_RoomSublist[aria-label="Favourites"]').contains(".mx_RoomTile", "Favourite DM").should("exist");
cy.get('.mx_RoomSublist[aria-label="People"]').contains(".mx_RoomTile", "Favourite DM").should("not.exist");
});

// Regression test for a bug in SS mode, but would be useful to have in non-SS mode too.
// This ensures we are setting RoomViewStore state correctly.
it("should clear the reply to field when swapping rooms", () => {
cy.createRoom({ name: "Other Room" }).as("roomA").then(() => cy.contains(".mx_RoomSublist", "Other Room"));
cy.get<string>("@roomId").then((roomId) => {
return cy.sendEvent(roomId, null, "m.room.message", {
body: "Hello world",
msgtype: "m.text",
});
});
// select the room
cy.contains(".mx_RoomTile", "Test Room").click();
cy.get(".mx_ReplyPreview").should("not.exist");
// click reply-to on the Hello World message
cy.contains(".mx_EventTile", "Hello world").find('.mx_AccessibleButton[aria-label="Reply"]').click(
{ force: true },
);
// check it's visible
cy.get(".mx_ReplyPreview").should("exist");
// now click Other Room
cy.contains(".mx_RoomTile", "Other Room").click();
// ensure the reply-to disappears
cy.get(".mx_ReplyPreview").should("not.exist");
// click back
cy.contains(".mx_RoomTile", "Test Room").click();
// ensure the reply-to reappears
cy.get(".mx_ReplyPreview").should("exist");
});

// Regression test for https://github.com/vector-im/element-web/issues/21462
it("should not cancel replies when permalinks are clicked ", () => {
cy.get<string>("@roomId").then((roomId) => {
// we require a first message as you cannot click the permalink text with the avatar in the way
return cy.sendEvent(roomId, null, "m.room.message", {
body: "First message",
msgtype: "m.text",
}).then(() => {
return cy.sendEvent(roomId, null, "m.room.message", {
body: "Permalink me",
msgtype: "m.text",
});
}).then(() => {
cy.sendEvent(roomId, null, "m.room.message", {
body: "Reply to me",
msgtype: "m.text",
});
});
});
// select the room
cy.contains(".mx_RoomTile", "Test Room").click();
cy.get(".mx_ReplyPreview").should("not.exist");
// click reply-to on the Reply to me message
cy.contains(".mx_EventTile", "Reply to me").find('.mx_AccessibleButton[aria-label="Reply"]').click(
{ force: true },
);
// check it's visible
cy.get(".mx_ReplyPreview").should("exist");
// now click on the permalink for Permalink me
cy.contains(".mx_EventTile", "Permalink me").find("a").click({ force: true });
// make sure it is now selected with the little green |
cy.contains(".mx_EventTile_selected", "Permalink me").should("exist");
// ensure the reply-to does not disappear
cy.get(".mx_ReplyPreview").should("exist");
});
});
5 changes: 3 additions & 2 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ export class RoomViewStore extends Store<ActionPayload> {
// Allow being given an event to be replied to when switching rooms but sanity check its for this room
if (payload.replyingToEvent?.getRoomId() === payload.room_id) {
newState.replyingToEvent = payload.replyingToEvent;
} else if (this.state.roomId === payload.room_id) {
// if the room isn't being changed, e.g visiting a permalink then maintain replyingToEvent
} else if (this.state.replyingToEvent?.getRoomId() === payload.room_id) {
// if the reply-to matches the desired room, e.g visiting a permalink then maintain replyingToEvent
// See https://github.com/vector-im/element-web/issues/21462
newState.replyingToEvent = this.state.replyingToEvent;
}

Expand Down
16 changes: 16 additions & 0 deletions test/stores/RoomViewStore-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as testUtils from '../test-utils';
import { flushPromises, getMockClientWithEventEmitter } from '../test-utils';
import SettingsStore from '../../src/settings/SettingsStore';
import { SlidingSyncManager } from '../../src/SlidingSyncManager';
import { TimelineRenderingType } from '../../src/contexts/RoomContext';

const dispatch = testUtils.getDispatchForStore(RoomViewStore.instance);

Expand Down Expand Up @@ -88,6 +89,21 @@ describe('RoomViewStore', function() {
expect(mockClient.joinRoom).toHaveBeenCalledWith(alias, { viaServers: [] });
});

it('remembers the event being replied to when swapping rooms', async () => {
dispatch({ action: Action.ViewRoom, room_id: '!randomcharacters:aser.ver' });
await flushPromises();
const replyToEvent = {
getRoomId: () => '!randomcharacters:aser.ver',
};
dispatch({ action: 'reply_to_event', event: replyToEvent, context: TimelineRenderingType.Room });
await flushPromises();
expect(RoomViewStore.instance.getQuotingEvent()).toEqual(replyToEvent);
// view the same room, should remember the event.
dispatch({ action: Action.ViewRoom, room_id: '!randomcharacters:aser.ver' });
await flushPromises();
expect(RoomViewStore.instance.getQuotingEvent()).toEqual(replyToEvent);
});

describe('Sliding Sync', function() {
beforeEach(() => {
jest.spyOn(SettingsStore, 'getValue').mockImplementation((settingName, roomId, value) => {
Expand Down