-
Notifications
You must be signed in to change notification settings - Fork 13.6k
fix: skip unread alert on room rename when system message is disabled #40872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rish106-hub
wants to merge
6
commits into
RocketChat:develop
Choose a base branch
from
rish106-hub:fix/issue-40778-room-rename-unread-notification
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−7
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f584c60
fix(meteor): skip unread alert on room rename if system message hidden
rish106-hub 09138dd
test(channel-settings): add unit tests for saveRoomName sysMes alert …
rish106-hub 1c3d93f
test(channel-settings): assert Rooms.setNameById called in all sysMes…
rish106-hub 742cfdb
Merge branch 'develop' into fix/issue-40778-room-rename-unread-notifi…
rish106-hub b41065e
fix(messages text index): use explicit short names to avoid MongoDB n…
rish106-hub 6e6ad8d
Merge branch 'develop' into fix/issue-40778-room-rename-unread-notifi…
rish106-hub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@rocket.chat/meteor": patch | ||
| --- | ||
|
|
||
| Fix: Room rename no longer triggers an unread alert for members if the "Room name changed" system message is hidden in room settings. |
105 changes: 105 additions & 0 deletions
105
apps/meteor/app/channel-settings/server/functions/saveRoomName.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { expect } from 'chai'; | ||
| import { describe, it, beforeEach } from 'mocha'; | ||
| import proxyquire from 'proxyquire'; | ||
| import sinon from 'sinon'; | ||
|
|
||
| const sandbox = sinon.createSandbox(); | ||
|
|
||
| const mocks = { | ||
| Rooms: { | ||
| findOneById: sandbox.stub(), | ||
| setNameById: sandbox.stub().resolves({ modifiedCount: 1 }), | ||
| setFnameById: sandbox.stub().resolves({ modifiedCount: 1 }), | ||
| }, | ||
| Subscriptions: { | ||
| updateNameAndAlertByRoomId: sandbox.stub().resolves({ modifiedCount: 1 }), | ||
| updateNameAndFnameByRoomId: sandbox.stub().resolves({ modifiedCount: 1 }), | ||
| updateFnameByRoomId: sandbox.stub().resolves({ modifiedCount: 1 }), | ||
| }, | ||
| Integrations: { | ||
| updateRoomName: sandbox.stub().resolves(), | ||
| }, | ||
| Message: { | ||
| saveSystemMessage: sandbox.stub().resolves(), | ||
| }, | ||
| Room: { | ||
| beforeNameChange: sandbox.stub().resolves(), | ||
| }, | ||
| roomCoordinator: { | ||
| getRoomDirectives: sandbox.stub().returns({ preventRenaming: () => false }), | ||
| }, | ||
| checkUsernameAvailability: sandbox.stub().resolves(true), | ||
| getValidRoomName: sandbox.stub().callsFake((name: string) => Promise.resolve(name)), | ||
| notifyOnIntegrationChangedByChannels: sandbox.stub().resolves(), | ||
| notifyOnSubscriptionChangedByRoomId: sandbox.stub().resolves(), | ||
| callbacks: { | ||
| run: sandbox.stub().resolves(), | ||
| }, | ||
| isRoomNativeFederated: sandbox.stub().returns(false), | ||
| }; | ||
|
|
||
| const { saveRoomName } = proxyquire.noCallThru().load('./saveRoomName', { | ||
| '@rocket.chat/core-services': { Message: mocks.Message, Room: mocks.Room }, | ||
| '@rocket.chat/core-typings': { isRoomNativeFederated: mocks.isRoomNativeFederated }, | ||
| '@rocket.chat/models': { Integrations: mocks.Integrations, Rooms: mocks.Rooms, Subscriptions: mocks.Subscriptions }, | ||
| 'meteor/meteor': { Meteor: { Error: class MeteorError extends Error {} } }, | ||
| '../../../../server/lib/callbacks': { callbacks: mocks.callbacks }, | ||
| '../../../../server/lib/rooms/roomCoordinator': { roomCoordinator: mocks.roomCoordinator }, | ||
| '../../../lib/server/functions/checkUsernameAvailability': { checkUsernameAvailability: mocks.checkUsernameAvailability }, | ||
| '../../../lib/server/lib/notifyListener': { | ||
| notifyOnIntegrationChangedByChannels: mocks.notifyOnIntegrationChangedByChannels, | ||
| notifyOnSubscriptionChangedByRoomId: mocks.notifyOnSubscriptionChangedByRoomId, | ||
| }, | ||
| '../../../utils/server/lib/getValidRoomName': { getValidRoomName: mocks.getValidRoomName }, | ||
| }); | ||
|
|
||
| const fakeUser = { _id: 'user1', username: 'user1' } as any; | ||
|
|
||
| describe('saveRoomName — sysMes unread alert behavior', () => { | ||
| beforeEach(() => { | ||
| sandbox.resetHistory(); | ||
| mocks.checkUsernameAvailability.resolves(true); | ||
| mocks.isRoomNativeFederated.returns(false); | ||
| }); | ||
|
|
||
| it('triggers unread alert when sysMes does not include "r"', async () => { | ||
| mocks.Rooms.findOneById.resolves({ _id: 'room1', t: 'c', name: 'old-name', sysMes: ['uj', 'ul'] }); | ||
|
|
||
| await saveRoomName('room1', 'new-name', fakeUser); | ||
|
|
||
| expect(mocks.Rooms.setNameById.calledOnceWith('room1', 'new-name', 'new-name')).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndAlertByRoomId.calledOnce).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndFnameByRoomId.called).to.be.false; | ||
| }); | ||
|
|
||
| it('skips unread alert when sysMes includes "r"', async () => { | ||
| mocks.Rooms.findOneById.resolves({ _id: 'room1', t: 'c', name: 'old-name', sysMes: ['uj', 'r', 'ul'] }); | ||
|
|
||
| await saveRoomName('room1', 'new-name', fakeUser); | ||
|
|
||
| expect(mocks.Rooms.setNameById.calledOnceWith('room1', 'new-name', 'new-name')).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndFnameByRoomId.calledOnce).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndAlertByRoomId.called).to.be.false; | ||
| }); | ||
|
|
||
| it('triggers unread alert when sysMes is undefined (safe fallback)', async () => { | ||
| mocks.Rooms.findOneById.resolves({ _id: 'room1', t: 'c', name: 'old-name' }); | ||
|
|
||
| await saveRoomName('room1', 'new-name', fakeUser); | ||
|
|
||
| expect(mocks.Rooms.setNameById.calledOnceWith('room1', 'new-name', 'new-name')).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndAlertByRoomId.calledOnce).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndFnameByRoomId.called).to.be.false; | ||
| }); | ||
|
|
||
| it('does not match partial tokens like "rp" as the "r" system message type', async () => { | ||
| mocks.Rooms.findOneById.resolves({ _id: 'room1', t: 'c', name: 'old-name', sysMes: ['rp', 'ru'] }); | ||
|
|
||
| await saveRoomName('room1', 'new-name', fakeUser); | ||
|
|
||
| expect(mocks.Rooms.setNameById.calledOnceWith('room1', 'new-name', 'new-name')).to.be.true; | ||
| // 'rp'/'ru' are not 'r', so alert should still fire | ||
| expect(mocks.Subscriptions.updateNameAndAlertByRoomId.calledOnce).to.be.true; | ||
| expect(mocks.Subscriptions.updateNameAndFnameByRoomId.called).to.be.false; | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.