forked from mystiq/hydrogen-web
allow observing the room status
This commit is contained in:
parent
243d105aad
commit
1b83ae7d8a
1 changed files with 26 additions and 1 deletions
|
@ -39,7 +39,7 @@ import {
|
||||||
writeKey as ssssWriteKey,
|
writeKey as ssssWriteKey,
|
||||||
} from "./ssss/index.js";
|
} from "./ssss/index.js";
|
||||||
import {SecretStorage} from "./ssss/SecretStorage.js";
|
import {SecretStorage} from "./ssss/SecretStorage.js";
|
||||||
import {ObservableValue} from "../observable/ObservableValue.js";
|
import {ObservableValue, RetainedObservableValue} from "../observable/ObservableValue.js";
|
||||||
|
|
||||||
const PICKLE_KEY = "DEFAULT_KEY";
|
const PICKLE_KEY = "DEFAULT_KEY";
|
||||||
const PUSHER_KEY = "pusher";
|
const PUSHER_KEY = "pusher";
|
||||||
|
@ -71,6 +71,7 @@ export class Session {
|
||||||
this._olmWorker = olmWorker;
|
this._olmWorker = olmWorker;
|
||||||
this._sessionBackup = null;
|
this._sessionBackup = null;
|
||||||
this._hasSecretStorageKey = new ObservableValue(null);
|
this._hasSecretStorageKey = new ObservableValue(null);
|
||||||
|
this._observedRoomStatus = new Map();
|
||||||
|
|
||||||
if (olm) {
|
if (olm) {
|
||||||
this._olmUtil = new olm.Utility();
|
this._olmUtil = new olm.Utility();
|
||||||
|
@ -400,6 +401,8 @@ export class Session {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
addRoomAfterSync(room) {
|
addRoomAfterSync(room) {
|
||||||
this._rooms.add(room.id, room);
|
this._rooms.add(room.id, room);
|
||||||
|
const statusObservable = this._observedRoomStatus.get(room.id);
|
||||||
|
statusObservable?.set(RoomStatus.joined);
|
||||||
}
|
}
|
||||||
|
|
||||||
get invites() {
|
get invites() {
|
||||||
|
@ -421,16 +424,26 @@ export class Session {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
addInviteAfterSync(invite) {
|
addInviteAfterSync(invite) {
|
||||||
this._invites.add(invite.id, invite);
|
this._invites.add(invite.id, invite);
|
||||||
|
const statusObservable = this._observedRoomStatus.get(invite.id);
|
||||||
|
if (statusObservable) {
|
||||||
|
statusObservable.set(statusObservable.get().withInvited());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
removeInviteAfterSync(invite) {
|
removeInviteAfterSync(invite) {
|
||||||
this._invites.remove(invite.id);
|
this._invites.remove(invite.id);
|
||||||
|
const statusObservable = this._observedRoomStatus.get(invite.id);
|
||||||
|
if (statusObservable) {
|
||||||
|
statusObservable.set(statusObservable.get().withoutInvited());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
archiveRoomAfterSync(room) {
|
archiveRoomAfterSync(room) {
|
||||||
this._rooms.remove(room.id);
|
this._rooms.remove(room.id);
|
||||||
|
const statusObservable = this._observedRoomStatus.get(room.id);
|
||||||
|
statusObservable?.set(RoomStatus.archived);
|
||||||
if (this._archivedRooms) {
|
if (this._archivedRooms) {
|
||||||
this._archivedRooms.add(room.id, room);
|
this._archivedRooms.add(room.id, room);
|
||||||
}
|
}
|
||||||
|
@ -623,6 +636,18 @@ export class Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async observeRoomStatus(roomId) {
|
||||||
|
let observable = this._observedRoomStatus.get(roomId);
|
||||||
|
if (!observable) {
|
||||||
|
const status = await this.getRoomStatus(roomId);
|
||||||
|
observable = new RetainedObservableValue(status, () => {
|
||||||
|
this._observedRoomStatus.delete(roomId);
|
||||||
|
});
|
||||||
|
this._observedRoomStatus.set(roomId, observable);
|
||||||
|
}
|
||||||
|
return observable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tests() {
|
export function tests() {
|
||||||
|
|
Loading…
Reference in a new issue