update in marking read message

This commit is contained in:
Brice-W 2021-07-16 13:32:58 +10:00
parent c38d2a5ea7
commit db46c2960b
3 changed files with 20 additions and 3 deletions

View file

@ -31,7 +31,7 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
useFocus(onChange);
return (
<InView {...props} as="div" threshold={1} delay={200} triggerOnce={true}>
<InView {...props} as="div" threshold={1} delay={200} triggerOnce={false}>
{props.children}
</InView>
);

View file

@ -92,6 +92,7 @@ export interface ConversationAttributes {
triggerNotificationsFor: ConversationNotificationSettingType;
isTrustedForAttachmentDownload: boolean;
isPinned: boolean;
lastReadTimestamp: number;
}
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
isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so
isPinned: false,
lastReadTimestamp: 0,
});
};
@ -188,7 +190,16 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000);
this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 });
//start right away the function is called, and wait 1sec before calling it again
this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true });
//this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true });
const markReadBouncy = _.debounce(this.markReadBouncy, 1000, { leading: true })
this.markRead = (newestUnreadDate: number) => {
const lastReadTimestamp = this.get('lastReadTimestamp');
if (newestUnreadDate > lastReadTimestamp)
this.set({
lastReadTimestamp: newestUnreadDate,
});
markReadBouncy(newestUnreadDate);
}
// Listening for out-of-band data updates
this.typingRefreshTimer = null;
@ -903,6 +914,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) {
const lastReadTimestamp = this.get('lastReadTimestamp');
if (newestUnreadDate < lastReadTimestamp) {
return;
}
const options = providedOptions || {};
_.defaults(options, { sendReadReceipts: true });
@ -948,7 +964,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const cachedUnreadCountOnConvo = this.get('unreadCount');
if (cachedUnreadCountOnConvo !== read.length) {
// reset the unreadCount on the convo to the real one coming from markRead messages on the db
this.set({ unreadCount: 0 });
this.set({ unreadCount: realUnreadCount });
await this.commit();
} else {
// window?.log?.info('markRead(): nothing newly read.');

View file

@ -89,6 +89,7 @@ export class MockConversation {
triggerNotificationsFor: 'all',
isTrustedForAttachmentDownload: false,
isPinned: false,
lastReadTimestamp: 0,
};
}