Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-peas-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes thread replies keeping the "sent" single checkmark after everyone had read the thread, only switching to the "viewed" double checkmark once a new message was sent in that thread.
5 changes: 5 additions & 0 deletions apps/meteor/server/hooks/messages/processThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export async function processThreads(message: IMessage, room: IRoom, options?: S

await notifyUsersOnReply(message, replies);
await metaData(message, parentMessage, replies);

if (!isEditedMessage(message)) {
Comment thread
ricardogarim marked this conversation as resolved.
callbacks.runAsync('afterReadMessages', room, { uid: message.u._id, tmid: message.tmid });
Comment thread
ricardogarim marked this conversation as resolved.
Comment thread
ricardogarim marked this conversation as resolved.
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (!options?.skipNotifications) {
await notification(message, room, replies);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { expect } from 'chai';
import { beforeEach, describe, it } from 'mocha';
import p from 'proxyquire';
import sinon from 'sinon';

import { createFakeMessage, createFakeRoom } from '../../../../mocks/data';

const modelsMock = { Messages: { findOneById: sinon.stub() } };
const getMentionsMock = sinon.stub();
const replyMock = sinon.stub();
const callbacksRunAsyncMock = sinon.stub();

const { processThreads } = p.noCallThru().load('../../../../../server/hooks/messages/processThreads.ts', {
'@rocket.chat/models': modelsMock,
'meteor/meteor': { Meteor: { startup: sinon.stub() } },
'./notifyUsersOnMessage': { updateThreadUsersSubscriptions: sinon.stub(), getMentions: getMentionsMock },
'./sendNotificationsOnMessage': { sendMessageNotifications: sinon.stub() },
'../../lib/callbacks': {
callbacks: { runAsync: callbacksRunAsyncMock, add: sinon.stub(), remove: sinon.stub(), priority: { LOW: 'low' } },
},
'../../lib/messaging/threads/functions': { reply: replyMock },
'../../lib/notifyListener': { notifyOnMessageChange: sinon.stub() },
'../../settings': { settings: { watch: sinon.stub() } },
});

describe('processThreads', () => {
const room = createFakeRoom();
const parentMessage = createFakeMessage({ rid: room._id, tcount: 1, replies: [] });
const author = { _id: 'authorId', username: 'author' };

const threadReply = (overrides: Record<string, unknown> = {}) =>
createFakeMessage({ rid: room._id, tmid: parentMessage._id, u: author, ...overrides });

beforeEach(() => {
callbacksRunAsyncMock.reset();
replyMock.reset();
modelsMock.Messages.findOneById.reset();
modelsMock.Messages.findOneById.resolves(parentMessage);
getMentionsMock.reset();
getMentionsMock.resolves({ mentionIds: [] });
});

it('should mark the thread as read for the author of the reply', async () => {
await processThreads(threadReply(), room);

expect(callbacksRunAsyncMock.calledWith('afterReadMessages', room, { uid: author._id, tmid: parentMessage._id })).to.be.true;
});

it('should mark the thread as read only after the thread metadata is updated', async () => {
await processThreads(threadReply(), room);

expect(replyMock.calledBefore(callbacksRunAsyncMock)).to.be.true;
Comment thread
ricardogarim marked this conversation as resolved.
});

it('should not mark anything as read when the message is not a thread reply', async () => {
await processThreads(createFakeMessage({ rid: room._id, u: author }), room);

expect(callbacksRunAsyncMock.called).to.be.false;
});

it('should not mark anything as read when the message was edited', async () => {
await processThreads(threadReply({ editedAt: new Date(), editedBy: author }), room);

expect(callbacksRunAsyncMock.called).to.be.false;
});
});
Loading