[FIX] Rooms not being marked as read sometimes (#16397)

* fix bug

* Update readMessages.js

* Update readMessages.js
pull/16403/head
Guilherme Gazzo 5 years ago committed by GitHub
parent 859cebc0cf
commit 9504c5b872
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      app/ui-utils/client/lib/readMessages.js
  2. 2
      app/ui/client/lib/chatMessages.js
  3. 12
      app/ui/client/views/app/room.js
  4. 3
      client/startup/startup.js

@ -1,6 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import _ from 'underscore';
import EventEmitter from 'wolfy87-eventemitter';
import { RoomHistoryManager } from './RoomHistoryManager';
@ -23,32 +22,15 @@ export const readMessage = new class extends EventEmitter {
constructor() {
super();
this.debug = false;
this.read = _.debounce((force) => this.readNow(force), 2000);
this.enable();
}
readNow(force) {
this.log('--------------');
this.log('readMessage -> readNow init process force:', force);
if ((force !== true) && (this.enabled === false)) {
read(rid = Session.get('openedRoom')) {
if (!this.enabled) {
this.log('readMessage -> readNow canceled by enabled: false');
return;
}
const rid = Session.get('openedRoom');
if (rid == null) {
this.log('readMessage -> readNow canceled, no rid informed');
return;
}
if (force === true) {
this.log('readMessage -> readNow via force rid:', rid);
return Meteor.call('readMessages', rid, () => {
RoomHistoryManager.getRoom(rid).unreadNotLoaded.set(0);
return this.emit(rid);
});
}
const subscription = ChatSubscription.findOne({ rid });
if (subscription == null) {
@ -81,8 +63,15 @@ export const readMessage = new class extends EventEmitter {
return;
}
this.log('readMessage -> readNow rid:', rid);
Meteor.call('readMessages', rid, () => {
return this.readNow(rid);
}
readNow(rid = Session.get('openedRoom')) {
if (rid == null) {
this.log('readMessage -> readNow canceled, no rid informed');
return;
}
return Meteor.call('readMessages', rid, () => {
RoomHistoryManager.getRoom(rid).unreadNotLoaded.set(0);
return this.emit(rid);
});
@ -177,7 +166,7 @@ Meteor.startup(function() {
.on('blur', () => readMessage.disable())
.on('focus', () => {
readMessage.enable();
readMessage.readNow();
readMessage.read();
})
.on('touchend', () => {
readMessage.enable();
@ -185,7 +174,7 @@ Meteor.startup(function() {
.on('keyup', (e) => {
const key = e.which;
if (key === 27) { // ESCAPE KEY
readMessage.readNow(true);
readMessage.readNow();
}
});
});

@ -267,7 +267,7 @@ export class ChatMessages {
}
if (msg) {
readMessage.readNow(true);
readMessage.readNow(rid);
$('.message.first-unread').removeClass('first-unread');
const message = await promises.run('onClientBeforeSendMessage', {

@ -760,8 +760,8 @@ Template.room.events({
Session.set(`uploading-cancel-${ this.id }`, true);
},
'click .unread-bar > button.mark-read'() {
readMessage.readNow(true);
'click .unread-bar > button.mark-read'(e, t) {
readMessage.readNow(t.data._id);
},
'click .unread-bar > button.jump-to'(e, t) {
@ -1274,9 +1274,13 @@ Template.room.onRendered(function() {
});
}, 300);
const read = _.debounce(function() {
readMessage.read(rid);
}, 500);
this.autorun(() => {
const subscription = Subscriptions.findOne({ rid }, { fields: { alert: 1, unread: 1 } });
readMessage.read();
read();
return subscription && (subscription.alert || subscription.unread) && readMessage.refreshUnreadMark(rid);
});
@ -1305,7 +1309,7 @@ Template.room.onRendered(function() {
Rooms.findOne(rid);
const count = this.state.get('count');
if (count === 0) {
return readMessage.read();
return read();
}
readMessage.refreshUnreadMark(rid);
});

@ -3,6 +3,7 @@ import { Tracker } from 'meteor/tracker';
import { Session } from 'meteor/session';
import { TimeSync } from 'meteor/mizzao:timesync';
import { UserPresence } from 'meteor/konecty:user-presence';
import { Accounts } from 'meteor/accounts-base';
import toastr from 'toastr';
import hljs from '../../app/markdown/lib/hljs';
@ -21,6 +22,8 @@ if (window.DISABLE_ANIMATION) {
}
Meteor.startup(function() {
Accounts.onLogout(() => Session.set('openedRoom', null));
TimeSync.loggingEnabled = false;
Session.setDefault('AvatarRandom', 0);

Loading…
Cancel
Save