Skip to content

Commit

Permalink
Merge pull request #15656 from RocketChat/read-receipts-ignore-subscr…
Browse files Browse the repository at this point in the history
…iptions-without-ls

[FIX] Read Receipts were not working properly with subscriptions without ls
  • Loading branch information
rodrigok committed Oct 24, 2019
1 parent d29d0ed commit 37b2f3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ export class Subscriptions extends Base {
getMinimumLastSeenByRoomId(rid) {
return this.db.findOne({
rid,
ls: {
$exists: true,
},
}, {
sort: {
ls: 1,
Expand Down
6 changes: 5 additions & 1 deletion imports/message-read-receipt/server/lib/ReadReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const debounceByRoomId = function(fn) {
const updateMessages = debounceByRoomId(Meteor.bindEnvironment(({ _id, lm }) => {
// @TODO maybe store firstSubscription in room object so we don't need to call the above update method
const firstSubscription = Subscriptions.getMinimumLastSeenByRoomId(_id);
if (!firstSubscription) {
return;
}

Messages.setAsRead(_id, firstSubscription.ls);

if (lm <= firstSubscription.ls) {
Expand Down Expand Up @@ -53,7 +57,7 @@ export const ReadReceipt = {

// this will usually happens if the message sender is the only one on the room
const firstSubscription = Subscriptions.getMinimumLastSeenByRoomId(roomId);
if (message.unread && message.ts < firstSubscription.ls) {
if (firstSubscription && message.unread && message.ts < firstSubscription.ls) {
Messages.setAsReadById(message._id, firstSubscription.ls);
}

Expand Down

0 comments on commit 37b2f3b

Please sign in to comment.