Add option to allow disabling read receipts

This commit is contained in:
Half-Shot 2023-11-07 16:58:21 +00:00
parent bf7c2fe614
commit 7b35a25627
2 changed files with 10 additions and 3 deletions

View File

@ -33,6 +33,7 @@ export class RoomViewModel extends ErrorReportViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
const {room, tileClassForEntry} = options; const {room, tileClassForEntry} = options;
this._sendReadReceipt = options.sendReadReceipt ?? true;
this._room = room; this._room = room;
this._timelineVM = null; this._timelineVM = null;
this._tileClassForEntry = tileClassForEntry ?? defaultTileClassForEntry; this._tileClassForEntry = tileClassForEntry ?? defaultTileClassForEntry;
@ -127,7 +128,7 @@ export class RoomViewModel extends ErrorReportViewModel {
this._clearUnreadTimout = this.clock.createTimeout(2000); this._clearUnreadTimout = this.clock.createTimeout(2000);
try { try {
await this._clearUnreadTimout.elapsed(); await this._clearUnreadTimout.elapsed();
await this._room.clearUnread(log); await this._room.clearUnread(log, this._sendReadReceipt);
this._clearUnreadTimout = null; this._clearUnreadTimout = null;
} catch (err) { } catch (err) {
if (err.name === "AbortError") { if (err.name === "AbortError") {

View File

@ -430,7 +430,13 @@ export class Room extends BaseRoom {
} }
} }
async clearUnread(log = null) { /**
* Clear the unreaad count in the room, and optionally send a read receipt
* @param {*} log Logger
* @param {boolean} sendReceipt Should a receipt be sent.
* @returns
*/
async clearUnread(log = null, sendReceipt = true) {
if (this.isUnread || this.notificationCount) { if (this.isUnread || this.notificationCount) {
return await this._platform.logger.wrapOrRun(log, "clearUnread", async log => { return await this._platform.logger.wrapOrRun(log, "clearUnread", async log => {
log.set("id", this.id); log.set("id", this.id);
@ -449,7 +455,7 @@ export class Room extends BaseRoom {
this._emitUpdate(); this._emitUpdate();
try { try {
const lastEventId = await this._getLastEventId(); const lastEventId = sendReceipt && await this._getLastEventId();
if (lastEventId) { if (lastEventId) {
await this._hsApi.receipt(this._roomId, "m.read", lastEventId); await this._hsApi.receipt(this._roomId, "m.read", lastEventId);
} }