add method to clear unread state

This commit is contained in:
Bruno Windels 2020-08-21 11:56:10 +02:00
parent 4419b3366e
commit 739d74bf9c
2 changed files with 26 additions and 0 deletions

View file

@ -184,6 +184,23 @@ export class Room extends EventEmitter {
return this._summary.avatarUrl;
}
async clearUnread() {
const txn = await this._storage.readWriteTxn([
this._storage.storeNames.roomSummary,
]);
let data;
try {
data = this._summary.writeClearUnread(txn);
} catch (err) {
txn.abort();
throw err;
}
await txn.complete();
this._summary.applyChanges(data);
this.emit("change");
this._emitCollectionChange(this);
}
/** @public */
async openTimeline() {
if (this._timeline) {

View file

@ -191,6 +191,15 @@ export class RoomSummary {
return this._data.lastPaginationToken;
}
writeClearUnread(txn) {
const data = new SummaryData(this._data);
data.isUnread = false;
data.notificationCount = 0;
data.highlightCount = 0;
txn.roomSummary.set(data.serialize());
return data;
}
writeHasFetchedMembers(value, txn) {
const data = new SummaryData(this._data);
data.hasFetchedMembers = value;