revert prev changes + marking read now based on received_at

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

@ -729,8 +729,8 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
divClasses.push('flash-green-once'); divClasses.push('flash-green-once');
} }
const onVisible = (inView: boolean) => { const onVisible = (inView: boolean | Object) => {
if (inView && shouldMarkReadWhenVisible && window.isFocused()) { if (inView === true && shouldMarkReadWhenVisible && window.isFocused()) {
// mark the message as read. // mark the message as read.
// this will trigger the expire timer. // this will trigger the expire timer.
void markRead(Date.now()); void markRead(Date.now());

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { useFocus } from '../../hooks/useFocus'; import { useFocus } from '../../hooks/useFocus';
import { InView } from 'react-intersection-observer'; import { InView, useInView } from 'react-intersection-observer';
type ReadableMessageProps = { type ReadableMessageProps = {
children: React.ReactNode; children: React.ReactNode;
@ -11,6 +11,22 @@ type ReadableMessageProps = {
}; };
export const ReadableMessage = (props: ReadableMessageProps) => { export const ReadableMessage = (props: ReadableMessageProps) => {
/*const { ref, inView, entry } = useInView({
threshold: 1,
delay: 200,
triggerOnce: true,
trackVisibility: true,
});
const { onChange } = props;
useFocus(() => onChange(inView));
return (
<div ref={ref} id={props.id} onContextMenu={props.onContextMenu} className={props.className} onChange={onChange}>
{props.children}
</div>
)*/
const { onChange } = props; const { onChange } = props;
useFocus(onChange); useFocus(onChange);

@ -92,7 +92,6 @@ export interface ConversationAttributes {
triggerNotificationsFor: ConversationNotificationSettingType; triggerNotificationsFor: ConversationNotificationSettingType;
isTrustedForAttachmentDownload: boolean; isTrustedForAttachmentDownload: boolean;
isPinned: boolean; isPinned: boolean;
lastReadTimestamp: number;
} }
export interface ConversationAttributesOptionals { export interface ConversationAttributesOptionals {
@ -161,7 +160,6 @@ 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,
}); });
}; };
@ -190,13 +188,7 @@ 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 = (readAt: number) => { this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true });
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;
@ -910,9 +902,6 @@ 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 });

@ -1047,7 +1047,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public async markRead(readAt: number) { public async markRead(readAt: number) {
this.markReadNoCommit(readAt); this.markReadNoCommit(readAt);
this.getConversation()?.markRead(readAt); this.getConversation()?.markRead(this.attributes.received_at);
await this.commit(); await this.commit();
} }

Loading…
Cancel
Save