Merge pull request #737 from vector-im/add-room-type-in-summary

Add room type in summary
This commit is contained in:
Robert Long 2022-05-19 13:19:44 -07:00 committed by GitHub
commit 28c699939e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

@ -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";

View file

@ -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]);
@ -409,6 +414,10 @@ export class BaseRoom extends EventEmitter {
return this._roomId;
}
get type() {
return this._summary.data.type;
}
get lastMessageTimestamp() {
return this._summary.data.lastMessageTimestamp;
}
@ -446,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;

View file

@ -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;