From 004e3cb924ea5db1d89c5606afdf07693cf485f7 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Mon, 16 May 2022 13:40:34 +0530 Subject: [PATCH 1/4] Add room type in room summary --- src/matrix/Session.js | 1 + src/matrix/room/BaseRoom.js | 4 ++++ src/matrix/room/Room.js | 2 +- src/matrix/room/RoomSummary.js | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index cd676fc5..41c8493c 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -56,6 +56,7 @@ const PUSHER_KEY = "pusher"; export class Session { // sessionInfo contains deviceId, userId and homeserver constructor({storage, hsApi, sessionInfo, olm, olmWorker, platform, mediaRepository}) { + window.session = this this._platform = platform; this._storage = storage; this._hsApi = hsApi; diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index b8f172d0..e7fb54d4 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -409,6 +409,10 @@ export class BaseRoom extends EventEmitter { return this._roomId; } + get type() { + return this._summary.data.type; + } + get lastMessageTimestamp() { return this._summary.data.lastMessageTimestamp; } diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 796474d3..38982786 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -23,7 +23,7 @@ import {WrappedError} from "../error.js" import {Heroes} from "./members/Heroes.js"; import {AttachmentUpload} from "./AttachmentUpload.js"; import {DecryptionSource} from "../e2ee/common.js"; -import {iterateResponseStateEvents} from "./common.js"; +import {iterateResponseStateEvents} from "./common"; import {PowerLevels, EVENT_TYPE as POWERLEVELS_EVENT_TYPE } from "./PowerLevels.js"; const EVENT_ENCRYPTED_TYPE = "m.room.encrypted"; diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index 62608683..c9114594 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -82,6 +82,7 @@ export function processStateEvent(data, event, ownUserId) { if (event.type === "m.room.create") { data = data.cloneIfNeeded(); data.lastMessageTimestamp = event.origin_server_ts; + data.type = event.content?.type ?? null; } else if (event.type === "m.room.encryption") { const algorithm = event.content?.algorithm; if (!data.encryption && algorithm === MEGOLM_ALGORITHM) { @@ -167,6 +168,7 @@ export class SummaryData { constructor(copy, roomId) { this.roomId = copy ? copy.roomId : roomId; this.name = copy ? copy.name : null; + this.type = copy ? copy.type : null; this.lastMessageTimestamp = copy ? copy.lastMessageTimestamp : null; this.isUnread = copy ? copy.isUnread : false; this.encryption = copy ? copy.encryption : null; From d37910c5ac2227ff11e159d9e616bcb95a152f9c Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Mon, 16 May 2022 13:53:14 +0530 Subject: [PATCH 2/4] Add getStateEvent in room --- src/matrix/Session.js | 1 - src/matrix/room/BaseRoom.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 41c8493c..cd676fc5 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -56,7 +56,6 @@ const PUSHER_KEY = "pusher"; export class Session { // sessionInfo contains deviceId, userId and homeserver constructor({storage, hsApi, sessionInfo, olm, olmWorker, platform, mediaRepository}) { - window.session = this this._platform = platform; this._storage = storage; this._hsApi = hsApi; diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index e7fb54d4..441146fb 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -73,6 +73,11 @@ export class BaseRoom extends EventEmitter { return value; } + async getStateEvent(type, key = '') { + const txn = await this._storage.readTxn(['roomState']); + return txn.roomState.get(this.id, type, key); + } + async _addStateObserver(stateObserver, txn) { if (!txn) { txn = await this._storage.readTxn([this._storage.storeNames.roomState]); From 01cb66ccbf93b191eab9ea132c2eeba71ee51619 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Tue, 17 May 2022 12:27:20 +0530 Subject: [PATCH 3/4] Add isDirectMessage in base room --- src/matrix/room/BaseRoom.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 441146fb..7865723b 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -455,6 +455,10 @@ export class BaseRoom extends EventEmitter { return this._summary.data.membership; } + get isDirectMessage() { + return this._summary.data.isDirectMessage; + } + isDirectMessageForUserId(userId) { if (this._summary.data.dmUserId === userId) { return true; From 203a832c474145ddcdd82834993bdf895eb6f5c3 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Thu, 19 May 2022 21:32:38 +0530 Subject: [PATCH 4/4] Export attachment upload --- src/lib.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.ts b/src/lib.ts index 854248c2..6e93be14 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -21,6 +21,7 @@ export {ConsoleReporter} from "./logging/ConsoleReporter"; export {Platform} from "./platform/web/Platform.js"; export {Client, LoadStatus} from "./matrix/Client.js"; export {RoomStatus} from "./matrix/room/common"; +export {AttachmentUpload} from "./matrix/room/AttachmentUpload"; export {CallIntent} from "./matrix/calls/callEventTypes"; // export everything needed to observe state events on all rooms using session.observeRoomState export type {RoomStateHandler} from "./matrix/room/state/types";