-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix: read receipts not turning blue when all active users have read #39246
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
abhinavkrin
wants to merge
22
commits into
develop
Choose a base branch
from
fix/read-receipts-ignore-deactivated-users
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.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
aad915d
fix: read receipts not turning blue when all active users have read
abhinavkrin f24d4ea
added changeset
abhinavkrin f6f0360
unarchive subscription of only active users
abhinavkrin 6b40a46
minor change
abhinavkrin 2c503f1
Merge branch 'develop' into fix/read-receipts-ignore-deactivated-users
abhinavkrin 6d56a2b
Merge branch 'develop' into fix/read-receipts-ignore-deactivated-users
abhinavkrin f530108
Merge branch 'develop' into fix/read-receipts-ignore-deactivated-users
abhinavkrin d081e06
test fix
abhinavkrin 3cf6407
Merge branch 'develop' into fix/read-receipts-ignore-deactivated-users
abhinavkrin 5d4e979
requested changes
abhinavkrin d1ce974
requested changes
abhinavkrin 39dfaff
minor improvement
abhinavkrin a8ae48d
requested changes
abhinavkrin 2a3559f
requested changes
abhinavkrin 0c6af04
requested changes
abhinavkrin 7deda6b
refactor: apply PR review feedback
abhinavkrin f0aeb1f
style: run prettier to fix line length in tests
abhinavkrin 8422dd9
Apply suggestion from @abhinavkrin
abhinavkrin 05c8922
improved tests
abhinavkrin b8b2fc7
switched from aggregation to normal queries
abhinavkrin 3f7a15c
update tests
abhinavkrin 10ff7eb
minor changes
abhinavkrin 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,7 @@ | ||
| --- | ||
| '@rocket.chat/model-typings': patch | ||
| '@rocket.chat/models': patch | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Fixes an issue where messages appeared as unread even when all active users had read them. Read receipts now correctly ignore deactivated users. |
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
40 changes: 40 additions & 0 deletions
40
apps/meteor/app/lib/server/functions/unarchiveUserSubscriptions.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,40 @@ | ||
| import { Rooms, Subscriptions } from '@rocket.chat/models'; | ||
|
|
||
| const BATCH_SIZE = 100_000; | ||
|
|
||
| async function getArchivedRoomIds(rids: string[]): Promise<Set<string>> { | ||
| const archivedRoomIds = new Set<string>(); | ||
|
|
||
| for (let i = 0; i < rids.length; i += BATCH_SIZE) { | ||
| const batch = await Rooms.findManyArchivedByRoomIds(rids.slice(i, i + BATCH_SIZE), { projection: { _id: 1 } }).toArray(); | ||
| for (const r of batch) { | ||
| archivedRoomIds.add(r._id); | ||
| } | ||
| } | ||
|
|
||
| return archivedRoomIds; | ||
| } | ||
|
|
||
| async function unarchiveSubscriptionsByIds(ids: string[]): Promise<void> { | ||
| for (let i = 0; i < ids.length; i += BATCH_SIZE) { | ||
| await Subscriptions.unarchiveByIds(ids.slice(i, i + BATCH_SIZE)); | ||
| } | ||
| } | ||
|
|
||
| export const unarchiveUserSubscriptions = async (userId: string): Promise<boolean> => { | ||
| const archivedSubs = await Subscriptions.findArchivedByUserId(userId, { projection: { rid: 1 } }).toArray(); | ||
|
|
||
| if (!archivedSubs.length) { | ||
| return false; | ||
| } | ||
|
|
||
| const archivedRoomIds = await getArchivedRoomIds(archivedSubs.map((s) => s.rid)); | ||
| const idsToUnarchive = archivedSubs.filter((s) => !archivedRoomIds.has(s.rid)).map((s) => s._id); | ||
|
|
||
| if (!idsToUnarchive.length) { | ||
| return false; | ||
| } | ||
|
|
||
| await unarchiveSubscriptionsByIds(idsToUnarchive); | ||
| return true; | ||
| }; |
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,24 @@ | ||
| import type { IUser } from '@rocket.chat/core-typings'; | ||
| import { Subscriptions } from '@rocket.chat/models'; | ||
|
|
||
| import { callbacks } from '../../../../server/lib/callbacks'; | ||
| import { unarchiveUserSubscriptions } from '../functions/unarchiveUserSubscriptions'; | ||
| import { notifyOnSubscriptionChangedByUserId } from '../lib/notifyListener'; | ||
|
|
||
| const handleDeactivateUser = async (user: IUser): Promise<void> => { | ||
| const { modifiedCount } = await Subscriptions.setArchivedByUserId(user._id, true); | ||
| if (modifiedCount) { | ||
| void notifyOnSubscriptionChangedByUserId(user._id); | ||
| } | ||
| }; | ||
|
|
||
| const handleActivateUser = async (user: IUser): Promise<void> => { | ||
| const unarchived = await unarchiveUserSubscriptions(user._id); | ||
| if (unarchived) { | ||
| void notifyOnSubscriptionChangedByUserId(user._id); | ||
| } | ||
| }; | ||
|
|
||
| callbacks.add('afterDeactivateUser', handleDeactivateUser, callbacks.priority.LOW, 'subscription-archive-on-deactivate'); | ||
|
|
||
| callbacks.add('afterActivateUser', handleActivateUser, callbacks.priority.LOW, 'subscription-unarchive-on-activate'); |
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
119 changes: 119 additions & 0 deletions
119
apps/meteor/tests/e2e/read-receipts-deactivated-users.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,119 @@ | ||
| import type { Page } from '@playwright/test'; | ||
|
|
||
| import { IS_EE } from './config/constants'; | ||
| import { createAuxContext } from './fixtures/createAuxContext'; | ||
| import type { IUserState } from './fixtures/userStates'; | ||
| import { Users } from './fixtures/userStates'; | ||
| import { HomeChannel } from './page-objects'; | ||
| import { createTargetChannel, deleteChannel, setSettingValueById } from './utils'; | ||
| import { expect, test } from './utils/test'; | ||
| import type { ITestUser } from './utils/user-helpers'; | ||
| import { createTestUser, loginTestUser } from './utils/user-helpers'; | ||
|
|
||
| test.use({ storageState: Users.admin.state }); | ||
|
|
||
| test.describe.serial('read-receipts-deactivated-users', () => { | ||
| let poHomeChannel: HomeChannel; | ||
| let targetChannel: string; | ||
| let user1Context: { page: Page; poHomeChannel: HomeChannel } | undefined; | ||
| let user2Context: { page: Page; poHomeChannel: HomeChannel } | undefined; | ||
| let testUser1: ITestUser; | ||
| let testUser2: ITestUser; | ||
| let testUser1State: IUserState; | ||
| let testUser2State: IUserState; | ||
|
|
||
| test.skip(!IS_EE, 'Enterprise Only'); | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| [testUser1, testUser2] = await Promise.all([createTestUser(api), createTestUser(api)]); | ||
|
|
||
| [testUser1State, testUser2State] = await Promise.all([loginTestUser(api, testUser1), loginTestUser(api, testUser2)]); | ||
|
|
||
| targetChannel = await createTargetChannel(api, { members: [testUser1.data.username, testUser2.data.username] }); | ||
| await Promise.all([ | ||
| setSettingValueById(api, 'Message_Read_Receipt_Enabled', true), | ||
| setSettingValueById(api, 'Message_Read_Receipt_Store_Users', true), | ||
| ]); | ||
| }); | ||
|
|
||
| test.afterAll(async ({ api }) => { | ||
| await Promise.all([ | ||
| setSettingValueById(api, 'Message_Read_Receipt_Enabled', false), | ||
| setSettingValueById(api, 'Message_Read_Receipt_Store_Users', false), | ||
| ]); | ||
|
|
||
| await deleteChannel(api, targetChannel); | ||
| await Promise.all([testUser1?.delete(), testUser2?.delete()]); | ||
| }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| poHomeChannel = new HomeChannel(page); | ||
| await page.goto('/home'); | ||
| }); | ||
|
|
||
| test.afterEach(async () => { | ||
| await Promise.all([user1Context?.page.close(), user2Context?.page.close()]); | ||
| user1Context = undefined; | ||
| user2Context = undefined; | ||
| }); | ||
|
|
||
| test('should correctly handle read receipts as users are deactivated', async ({ browser, api, page }) => { | ||
| const { page: page1 } = await createAuxContext(browser, testUser1State); | ||
| const user1Ctx = { page: page1, poHomeChannel: new HomeChannel(page1) }; | ||
| user1Context = user1Ctx; | ||
|
|
||
| const { page: page2 } = await createAuxContext(browser, testUser2State); | ||
| const user2Ctx = { page: page2, poHomeChannel: new HomeChannel(page2) }; | ||
| user2Context = user2Ctx; | ||
|
|
||
| await Promise.all([ | ||
| poHomeChannel.navbar.openChat(targetChannel), | ||
| user1Ctx.poHomeChannel.navbar.openChat(targetChannel), | ||
| user2Ctx.poHomeChannel.navbar.openChat(targetChannel), | ||
| ]); | ||
|
|
||
| await test.step('when all users are active', async () => { | ||
| await poHomeChannel.content.sendMessage('Message 1: All three users active'); | ||
|
|
||
| await Promise.all([ | ||
| expect(user1Ctx.poHomeChannel.content.lastUserMessage).toBeVisible(), | ||
| expect(user2Ctx.poHomeChannel.content.lastUserMessage).toBeVisible(), | ||
| ]); | ||
|
|
||
| await expect(poHomeChannel.content.lastUserMessage.getByRole('status', { name: 'Message viewed' })).toBeVisible(); | ||
|
|
||
| await poHomeChannel.content.openLastMessageMenu(); | ||
| await page.locator('role=menuitem[name="Read receipts"]').click(); | ||
| await expect(page.getByRole('dialog').getByRole('listitem')).toHaveCount(3); | ||
| await page.getByRole('button', { name: 'Close' }).click(); | ||
| }); | ||
|
|
||
| await test.step('when some users are deactivated', async () => { | ||
| await api.post('/users.setActiveStatus', { userId: testUser1.data._id, activeStatus: false }); | ||
|
|
||
| await poHomeChannel.content.sendMessage('Message 2: User1 deactivated, two active users'); | ||
|
|
||
| await expect(user2Ctx.poHomeChannel.content.lastUserMessage).toBeVisible(); | ||
|
|
||
| await expect(poHomeChannel.content.lastUserMessage.getByRole('status', { name: 'Message viewed' })).toBeVisible(); | ||
|
|
||
| await poHomeChannel.content.openLastMessageMenu(); | ||
| await page.locator('role=menuitem[name="Read receipts"]').click(); | ||
| await expect(page.getByRole('dialog').getByRole('listitem')).toHaveCount(2); | ||
| await page.getByRole('button', { name: 'Close' }).click(); | ||
| }); | ||
|
|
||
| await test.step('when only one user remains active (user alone in room)', async () => { | ||
| await api.post('/users.setActiveStatus', { userId: testUser2.data._id, activeStatus: false }); | ||
|
|
||
| await poHomeChannel.content.sendMessage('Message 3: Only admin active'); | ||
|
|
||
| await expect(poHomeChannel.content.lastUserMessage.getByRole('status', { name: 'Message viewed' })).toBeVisible(); | ||
|
|
||
| await poHomeChannel.content.openLastMessageMenu(); | ||
| await page.locator('role=menuitem[name="Read receipts"]').click(); | ||
| await expect(page.getByRole('dialog').getByRole('listitem')).toHaveCount(1); | ||
| await page.getByRole('button', { name: 'Close' }).click(); | ||
| }); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.