adding lastReadTimestamp property

pull/1778/head
Brice-W 4 years ago
parent 151fc758c0
commit 14ef4cd39a

@ -92,6 +92,7 @@ export interface ConversationAttributes {
triggerNotificationsFor: ConversationNotificationSettingType; triggerNotificationsFor: ConversationNotificationSettingType;
isTrustedForAttachmentDownload: boolean; isTrustedForAttachmentDownload: boolean;
isPinned: boolean; isPinned: boolean;
lastReadTimestamp: number;
} }
export interface ConversationAttributesOptionals { export interface ConversationAttributesOptionals {
@ -160,6 +161,7 @@ export const fillConvoAttributesWithDefaults = (
triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default
isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so
isPinned: false, isPinned: false,
lastReadTimestamp: 0,
}); });
}; };
@ -188,7 +190,13 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000); this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000);
this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 });
//start right away the function is called, and wait 1sec before calling it again //start right away the function is called, and wait 1sec before calling it again
this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); this.markRead = (readAt: number) => {
const lastReadTimestamp = this.get('lastReadTimestamp');
if (readAt > lastReadTimestamp) {
this.set('lastReadTimestamp', readAt);
}
_.debounce(this.markReadBouncy, 1000, { leading: true });
}
// Listening for out-of-band data updates // Listening for out-of-band data updates
this.typingRefreshTimer = null; this.typingRefreshTimer = null;
@ -902,6 +910,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) {
if (this.get('lastReadTimestamp') >= 0) {
return;
}
const options = providedOptions || {}; const options = providedOptions || {};
_.defaults(options, { sendReadReceipts: true }); _.defaults(options, { sendReadReceipts: true });

Loading…
Cancel
Save