1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Sync knock rooms (#3703)

Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
Co-authored-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
This commit is contained in:
maheichyk
2023-09-06 20:10:14 +03:00
committed by GitHub
parent 88ec0e3e17
commit 6c307d4c63
7 changed files with 320 additions and 4 deletions

View File

@@ -16,8 +16,9 @@ limitations under the License.
*/
import { ReceiptType } from "../../src/@types/read_receipts";
import { IJoinedRoom, ISyncResponse, SyncAccumulator } from "../../src/sync-accumulator";
import { IJoinedRoom, IKnockedRoom, IStrippedState, ISyncResponse, SyncAccumulator } from "../../src/sync-accumulator";
import { IRoomSummary } from "../../src";
import * as utils from "../test-utils/test-utils";
// The event body & unsigned object get frozen to assert that they don't get altered
// by the impl
@@ -95,6 +96,13 @@ describe("SyncAccumulator", function () {
},
},
},
knock: {
"!knock": {
knock_state: {
events: [member("alice", "knock")],
},
},
},
},
} as unknown as ISyncResponse;
sa.accumulate(res);
@@ -287,6 +295,71 @@ describe("SyncAccumulator", function () {
expect(sa.getJSON().accountData[0]).toEqual(acc2);
});
it("should accumulate knock state", () => {
const initKnockState = {
events: [member("alice", "knock")],
};
sa.accumulate(
syncSkeleton(
{},
{
knock_state: initKnockState,
},
),
);
expect(sa.getJSON().roomsData.knock["!knock:bar"].knock_state).toBe(initKnockState);
sa.accumulate(
syncSkeleton(
{},
{
knock_state: {
events: [
utils.mkEvent({
user: "alice",
room: "!knock:bar",
type: "m.room.name",
content: {
name: "Room 1",
},
}) as IStrippedState,
],
},
},
),
);
expect(
sa.getJSON().roomsData.knock["!knock:bar"].knock_state.events.find((e) => e.type === "m.room.name")?.content
.name,
).toEqual("Room 1");
sa.accumulate(
syncSkeleton(
{},
{
knock_state: {
events: [
utils.mkEvent({
user: "alice",
room: "!knock:bar",
type: "m.room.name",
content: {
name: "Room 2",
},
}) as IStrippedState,
],
},
},
),
);
expect(
sa.getJSON().roomsData.knock["!knock:bar"].knock_state.events.find((e) => e.type === "m.room.name")?.content
.name,
).toEqual("Room 2");
});
it("should accumulate read receipts", () => {
const receipt1 = {
type: "m.receipt",
@@ -601,7 +674,7 @@ describe("SyncAccumulator", function () {
});
});
function syncSkeleton(joinObj: Partial<IJoinedRoom>): ISyncResponse {
function syncSkeleton(joinObj: Partial<IJoinedRoom>, knockObj?: Partial<IKnockedRoom>): ISyncResponse {
joinObj = joinObj || {};
return {
next_batch: "abc",
@@ -609,6 +682,11 @@ function syncSkeleton(joinObj: Partial<IJoinedRoom>): ISyncResponse {
join: {
"!foo:bar": joinObj,
},
knock: knockObj
? {
"!knock:bar": knockObj,
}
: undefined,
},
} as unknown as ISyncResponse;
}