don't mark message as read if app isn't focused

pull/1778/head
Brice-W 4 years ago
parent bf76abacee
commit 936f9a3efc

@ -3,12 +3,15 @@
'use strict'; 'use strict';
let windowFocused = false; let windowFocused = false;
let windowFocusedListener = function() {}
window.addEventListener('blur', () => { window.addEventListener('blur', () => {
windowFocused = false; windowFocused = false;
}); });
window.addEventListener('focus', () => { window.addEventListener('focus', () => {
windowFocused = true; windowFocused = true;
windowFocusedListener();
}); });
window.isFocused = () => windowFocused; window.isFocused = () => windowFocused;
window.setFocusListener = (listener) => windowFocusedListener = listener;
})(); })();

@ -59,7 +59,7 @@
// If message is unread, we mark it read. Otherwise, we update the expiration // If message is unread, we mark it read. Otherwise, we update the expiration
// timer to the time specified by the read sync if it's earlier than // timer to the time specified by the read sync if it's earlier than
// the previous read time. // the previous read time.
if (message.isUnread()) { if (message.isUnread() && window.isFocused()) {
await message.markRead(readAt); await message.markRead(readAt);
// onReadMessage may result in messages older than this one being // onReadMessage may result in messages older than this one being

@ -713,7 +713,7 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
const isShowingImage = this.isShowingImage(); const isShowingImage = this.isShowingImage();
const isIncoming = direction === 'incoming'; const isIncoming = direction === 'incoming';
const shouldMarkReadWhenVisible = isIncoming && isUnread; const shouldMarkReadWhenVisible = isIncoming && isUnread && window.isFocused();
const divClasses = ['session-message-wrapper']; const divClasses = ['session-message-wrapper'];
if (selected) { if (selected) {

@ -75,6 +75,7 @@ export class SessionMessagesList extends React.Component<Props, State> {
this.messageContainerRef = this.props.messageContainerRef; this.messageContainerRef = this.props.messageContainerRef;
this.ignoreScrollEvents = true; this.ignoreScrollEvents = true;
window.setFocusListener(() => this.updateReadMessages());
} }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -378,7 +379,7 @@ export class SessionMessagesList extends React.Component<Props, State> {
return; return;
} }
if (this.getScrollOffsetBottomPx() === 0) { if (this.getScrollOffsetBottomPx() === 0 && window.isFocused()) {
void conversation.markRead(messages[0].attributes.received_at); void conversation.markRead(messages[0].attributes.received_at);
} }
} }

2
ts/window.d.ts vendored

@ -40,6 +40,8 @@ declare global {
getFriendsFromContacts: any; getFriendsFromContacts: any;
getSettingValue: any; getSettingValue: any;
i18n: LocalizerType; i18n: LocalizerType;
isFocused: any;
setFocusListener: (listener: any) => any;
libloki: Libloki; libloki: Libloki;
libsignal: LibsignalProtocol; libsignal: LibsignalProtocol;
log: any; log: any;

Loading…
Cancel
Save