Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jan 15, 2025
1 parent 6c91b8d commit 006a80b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/sliding-sync-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ClientEvent, IStoredClientOpts, MatrixClient } from "./client.ts";
import {
ISyncStateData,
SyncState,
_createAndReEmitRoom,
_createAndSetupRoom,
SyncApiOptions,
defaultClientOpts,
defaultSyncApiOpts,
Expand Down Expand Up @@ -388,8 +388,7 @@ export class SlidingSyncSdk {
logger.debug("initial flag not set but no stored room exists for room ", roomId, roomData);
return;
}
room = _createAndReEmitRoom(this.client, roomId, this.opts);
this.client.store.storeRoom(room);
room = _createAndSetupRoom(this.client, roomId, this.opts);
}
await this.processRoomData(this.client, room!, roomData);
}
Expand Down
19 changes: 13 additions & 6 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class SyncApi {
}

public createRoom(roomId: string): Room {
const room = _createAndReEmitRoom(this.client, roomId, this.opts);
const room = _createAndSetupRoom(this.client, roomId, this.opts);

room.on(RoomStateEvent.Marker, (markerEvent, markerFoundOptions) => {
this.onMarkerStateEvent(room, markerEvent, markerFoundOptions);
Expand Down Expand Up @@ -410,7 +410,6 @@ export class SyncApi {

const client = this.client;
this._peekRoom = this.createRoom(roomId);
client.store.storeRoom(this._peekRoom);
return this.client.roomInitialSync(roomId, limit).then((response) => {
if (this._peekRoom?.roomId !== roomId) {
throw new Error("Peeking aborted");
Expand Down Expand Up @@ -1682,7 +1681,6 @@ export class SyncApi {
let isBrandNewRoom = false;
if (!room) {
room = this.createRoom(roomId);
client.store.storeRoom(room);
isBrandNewRoom = true;
}
return {
Expand Down Expand Up @@ -1940,9 +1938,17 @@ export class SyncApi {
};
}

// /!\ This function is not intended for public use! It's only exported from
// here in order to share some common logic with sliding-sync-sdk.ts.
export function _createAndReEmitRoom(client: MatrixClient, roomId: string, opts: Partial<IStoredClientOpts>): Room {
/**
* Creates a new room, wires up the client remitter for it, and adds it to the client store.
* @param client the client using which to create the room
* @param roomId the ID of the room to create
* @param opts the options to use when creating the room
* @internal
* @privateRemarks
* /!\ This function is not intended for public use! It's only exported from
* here in order to share some common logic with sliding-sync-sdk.ts.
*/
export function _createAndSetupRoom(client: MatrixClient, roomId: string, opts: Partial<IStoredClientOpts>): Room {
const { timelineSupport } = client;

const room = new Room(roomId, client, client.getUserId()!, {
Expand Down Expand Up @@ -1983,6 +1989,7 @@ export function _createAndReEmitRoom(client: MatrixClient, roomId: string, opts:
RoomMemberEvent.Membership,
]);
});
client.store.storeRoom(room);

return room;
}

0 comments on commit 006a80b

Please sign in to comment.