Skip to content

Commit

Permalink
only create a filter for sync when not in a guest user session
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfame committed Mar 7, 2023
1 parent 8b71ac9 commit 2efd344
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/matrix/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ export class Session {
return this._callHandler;
}

async isGuestSession() {
if (typeof this._guestUser !== 'undefined') {
return this._guestUser;
}
const whoami = await this._hsApi.whoami().response();
this._guestUser = whoami.is_guest;
return Boolean(whoami.is_guest);
}

_setupCallHandler() {
this._callHandler = new CallHandler({
clock: this._platform.clock,
Expand Down
3 changes: 2 additions & 1 deletion src/matrix/Sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export class Sync {

async _syncRequest(syncToken, timeout, log) {
let {syncFilterId} = this._session;
if (typeof syncFilterId !== "string") {
let isGuest = await this._session.isGuestSession();
if (!isGuest && typeof syncFilterId !== "string") {
this._currentRequest = this._hsApi.createFilter(this._session.user.id, {room: {state: {lazy_load_members: true}}}, {log});
syncFilterId = (await this._currentRequest.response()).filter_id;
}
Expand Down
4 changes: 4 additions & 0 deletions src/matrix/net/HomeServerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ export class HomeServerApi {
});
}

whoami(): IHomeServerRequest {
return this._get( "/account/whoami", undefined, undefined, { prefix: CS_V3_PREFIX } );
}

createFilter(userId: string, filter: Record<string, any>, options?: BaseRequestOptions): IHomeServerRequest {
return this._post(`/user/${encodeURIComponent(userId)}/filter`, {}, filter, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/matrix/sessioninfo/localstorage/SessionInfoStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ export class SessionInfoStorage implements ISessionInfoStorage {
sessions = sessions.filter(s => s.id !== sessionId);
localStorage.setItem(this._name, JSON.stringify(sessions));
}

}

0 comments on commit 2efd344

Please sign in to comment.