send receipt to server when clearing unread state so notif count clears

This commit is contained in:
Bruno Windels 2020-08-21 15:16:57 +02:00
parent 9b16119e7b
commit 2bfbb41ee7
3 changed files with 25 additions and 1 deletions

View File

@ -136,6 +136,11 @@ export class HomeServerApi {
return this._put(`/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`, {}, content, options);
}
receipt(roomId, receiptType, eventId, options = null) {
return this._post(`/rooms/${encodeURIComponent(roomId)}/receipt/${encodeURIComponent(receiptType)}/${encodeURIComponent(eventId)}`,
{}, {}, options);
}
passwordLogin(username, password, options = null) {
return this._post("/login", null, {
"type": "m.login.password",

View File

@ -201,8 +201,23 @@ export class Room extends EventEmitter {
return this._summary.notificationCount;
}
async _getLastEventId() {
const lastKey = this._syncWriter.lastMessageKey;
if (lastKey) {
const txn = await this._storage.readTxn([
this._storage.storeNames.timelineEvents,
]);
const eventEntry = await txn.timelineEvents.get(this._roomId, lastKey);
return eventEntry?.event?.event_id;
}
}
async clearUnread() {
if (this.isUnread) {
if (this.isUnread || this.notificationCount) {
const lastEventId = await this._getLastEventId();
if (lastEventId) {
await this._hsApi.receipt(this._roomId, "m.read", lastEventId);
}
const txn = await this._storage.readWriteTxn([
this._storage.storeNames.roomSummary,
]);

View File

@ -209,6 +209,10 @@ export class SyncWriter {
afterSync(newLiveKey) {
this._lastLiveKey = newLiveKey;
}
get lastMessageKey() {
return this._lastLiveKey;
}
}
//import MemoryStorage from "../storage/memory/MemoryStorage.js";