This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 808
Prevent unnecessary m.direct updates #9805
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d560931
Prevent unnecessary m.direct updates
weeman1337 035b515
Replace object with Map
weeman1337 392f0e4
Clean up comment; simplify code
weeman1337 a1a1907
Merge branch 'develop' into weeman1337/prevent-set-redundant-dm-room
weeman1337 20d9eb3
Fix rte flaky test (#9811)
florianduros be1e575
Snap in PiP widget when content changed (#9797)
weeman1337 16fb043
Check modified at the end of setDMRoom
weeman1337 3b4f64c
Revert "Snap in PiP widget when content changed (#9797)"
weeman1337 a8a70f8
Revert "Fix rte flaky test (#9811)"
weeman1337 be2c54f
Merge branch 'develop' into weeman1337/prevent-set-redundant-dm-room
weeman1337 640807c
Merge branch 'develop' into weeman1337/prevent-set-redundant-dm-room
weeman1337 d5d6b45
Update src/Rooms.ts
weeman1337 10df5e1
Merge branch 'develop' into weeman1337/prevent-set-redundant-dm-room
weeman1337 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| /* | ||
| Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { mocked } from "jest-mock"; | ||
| import { EventType, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix"; | ||
|
|
||
| import { setDMRoom } from "../src/Rooms"; | ||
| import { mkEvent, stubClient } from "./test-utils"; | ||
|
|
||
| describe("setDMRoom", () => { | ||
| const userId1 = "@user1:example.com"; | ||
| const userId2 = "@user2:example.com"; | ||
| const userId3 = "@user3:example.com"; | ||
| const roomId1 = "!room1:example.com"; | ||
| const roomId2 = "!room2:example.com"; | ||
| const roomId3 = "!room3:example.com"; | ||
| const roomId4 = "!room4:example.com"; | ||
| let client: MatrixClient; | ||
|
|
||
| beforeEach(() => { | ||
| client = mocked(stubClient()); | ||
| client.getAccountData = jest.fn().mockImplementation((eventType: string): MatrixEvent | undefined => { | ||
| if (eventType === EventType.Direct) { | ||
| return mkEvent({ | ||
| event: true, | ||
| content: { | ||
| [userId1]: [roomId1, roomId2], | ||
| [userId2]: [roomId3], | ||
| }, | ||
| type: EventType.Direct, | ||
| user: client.getSafeUserId(), | ||
| }); | ||
| } | ||
|
|
||
| return undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe("when logged in as a guest and marking a room as DM", () => { | ||
| beforeEach(() => { | ||
| mocked(client.isGuest).mockReturnValue(true); | ||
| setDMRoom(roomId1, userId1); | ||
| }); | ||
|
|
||
| it("should not update the account data", () => { | ||
| expect(client.setAccountData).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when adding a new room to an existing DM relation", () => { | ||
| beforeEach(() => { | ||
| setDMRoom(roomId4, userId1); | ||
| }); | ||
|
|
||
| it("should update the account data accordingly", () => { | ||
| expect(client.setAccountData).toHaveBeenCalledWith(EventType.Direct, { | ||
| [userId1]: [roomId1, roomId2, roomId4], | ||
| [userId2]: [roomId3], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when adding a new DM room", () => { | ||
| beforeEach(() => { | ||
| setDMRoom(roomId4, userId3); | ||
| }); | ||
|
|
||
| it("should update the account data accordingly", () => { | ||
| expect(client.setAccountData).toHaveBeenCalledWith(EventType.Direct, { | ||
| [userId1]: [roomId1, roomId2], | ||
| [userId2]: [roomId3], | ||
| [userId3]: [roomId4], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when trying to add a DM, that already exists", () => { | ||
| beforeEach(() => { | ||
| setDMRoom(roomId1, userId1); | ||
| }); | ||
|
|
||
| it("should not update the account data", () => { | ||
| expect(client.setAccountData).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when removing an existing DM", () => { | ||
| beforeEach(() => { | ||
| setDMRoom(roomId1, null); | ||
| }); | ||
|
|
||
| it("should update the account data accordingly", () => { | ||
| expect(client.setAccountData).toHaveBeenCalledWith(EventType.Direct, { | ||
| [userId1]: [roomId2], | ||
| [userId2]: [roomId3], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when removing an unknown room", () => { | ||
| beforeEach(() => { | ||
| setDMRoom(roomId4, null); | ||
| }); | ||
|
|
||
| it("should not update the account data", () => { | ||
| expect(client.setAccountData).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when the direct event is undefined", () => { | ||
| beforeEach(() => { | ||
| mocked(client.getAccountData).mockReturnValue(undefined); | ||
| setDMRoom(roomId1, userId1); | ||
| }); | ||
|
|
||
| it("should update the account data accordingly", () => { | ||
| expect(client.setAccountData).toHaveBeenCalledWith(EventType.Direct, { | ||
| [userId1]: [roomId1], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("when the current content is undefined", () => { | ||
| beforeEach(() => { | ||
| // @ts-ignore | ||
| mocked(client.getAccountData).mockReturnValue({ | ||
| getContent: jest.fn(), | ||
| }); | ||
| setDMRoom(roomId1, userId1); | ||
| }); | ||
|
|
||
| it("should update the account data accordingly", () => { | ||
| expect(client.setAccountData).toHaveBeenCalledWith(EventType.Direct, { | ||
| [userId1]: [roomId1], | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.