Skip to content

Commit ccd825f

Browse files
Remove knock state on join (#4977)
Signed-off-by: Svajunas Budrys <[email protected]>
1 parent b313eb5 commit ccd825f

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

spec/unit/sync-accumulator.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,49 @@ describe("SyncAccumulator", function () {
571571
expect(sa.getJSON().roomsData.knock["!knock:bar"]).toBeUndefined();
572572
});
573573

574+
it("should delete knock state when room transitions from knock to join", () => {
575+
const initKnockState = makeKnockState();
576+
sa.accumulate(
577+
syncSkeleton(
578+
{},
579+
{},
580+
{},
581+
{
582+
knock_state: initKnockState,
583+
},
584+
),
585+
);
586+
expect(sa.getJSON().roomsData.knock["!knock:bar"].knock_state).toBe(initKnockState);
587+
588+
// Room transitions from knock to join (e.g., after approval and joining)
589+
const joinState = {
590+
account_data: { events: [] },
591+
ephemeral: { events: [] },
592+
unread_notifications: {},
593+
state: {
594+
events: [member("bob", KnownMembership.Join)],
595+
},
596+
};
597+
598+
const syncResponse = {
599+
next_batch: "abc",
600+
rooms: {
601+
join: {
602+
"!knock:bar": joinState,
603+
},
604+
invite: {},
605+
leave: {},
606+
},
607+
} as unknown as ISyncResponse;
608+
609+
sa.accumulate(syncResponse);
610+
611+
expect(sa.getJSON().roomsData.knock["!knock:bar"]).toBeUndefined();
612+
expect(sa.getJSON().roomsData.join["!knock:bar"].state?.events[0]?.content.membership).toEqual(
613+
KnownMembership.Join,
614+
);
615+
});
616+
574617
it("should accumulate read receipts", () => {
575618
const receipt1 = {
576619
type: "m.receipt",

src/sync-accumulator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ export class SyncAccumulator {
317317
break;
318318

319319
case Category.Join:
320-
if (this.inviteRooms[roomId]) {
320+
if (this.knockRooms[roomId]) {
321+
// delete knock state on join
322+
delete this.knockRooms[roomId];
323+
} else if (this.inviteRooms[roomId]) {
321324
// (1)
322325
// was previously invite, now join. We expect /sync to give
323326
// the entire state and timeline on 'join', so delete previous

0 commit comments

Comments
 (0)