Skip to content
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

fix: Mark as unread not working #32939

Merged
merged 30 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ec9e093
fix: Mark as unread not working
MartinSchoeler Jul 30, 2024
f8c672f
Create hot-balloons-travel.md
MartinSchoeler Jul 30, 2024
e1edd84
test: Mark as unread not working
MartinSchoeler Jul 31, 2024
1500314
Fix order
MartinSchoeler Aug 1, 2024
3022a8d
Merge branch 'develop' into fix/mark-unread
MartinSchoeler Aug 1, 2024
39655aa
revert package removal
MartinSchoeler Aug 2, 2024
6036d88
revert rerouting
MartinSchoeler Aug 2, 2024
d974788
more tests
MartinSchoeler Aug 2, 2024
68b55c3
Update hot-balloons-travel.md
MartinSchoeler Aug 2, 2024
44f6da6
Update mark-unread.spec.ts
MartinSchoeler Aug 2, 2024
617d0aa
reviews
MartinSchoeler Aug 5, 2024
612f9a7
Merge branch 'develop' into fix/mark-unread
MartinSchoeler Aug 12, 2024
83aa653
Merge branch 'develop' into fix/mark-unread
MartinSchoeler Aug 12, 2024
5b2a504
Merge branch 'develop' into fix/mark-unread
MartinSchoeler Aug 13, 2024
3b73135
Merge branch 'develop' into fix/mark-unread
MartinSchoeler Aug 15, 2024
088c967
invalidate sidebar query
MartinSchoeler Aug 29, 2024
2821609
test
MartinSchoeler Aug 29, 2024
6450e28
reveiew
MartinSchoeler Aug 29, 2024
ab63c92
Merge branch 'develop' into fix/mark-unread
MartinSchoeler Aug 29, 2024
e5c54db
fix: review
dougfabris Sep 2, 2024
34060e0
fix: action button
MartinSchoeler Sep 3, 2024
2675fa5
Merge branch 'fix/mark-unread' of https://github.com/RocketChat/Rocke…
MartinSchoeler Sep 3, 2024
809a8a8
fix: e2e test
dougfabris Sep 3, 2024
e406ac6
fix: [gazzo: Gazzo]
MartinSchoeler Sep 3, 2024
f07fcc5
Update hot-balloons-travel.md
MartinSchoeler Sep 3, 2024
4a44af7
Merge remote-tracking branch 'origin/develop' into fix/mark-unread
MartinSchoeler Sep 17, 2024
728ddff
Merge branch 'develop' into fix/mark-unread
scuciatto Sep 17, 2024
a0a1cbb
Merge branch 'develop' into fix/mark-unread
kodiakhq[bot] Sep 18, 2024
c74d20b
Merge branch 'develop' into fix/mark-unread
kodiakhq[bot] Sep 18, 2024
f3db577
Merge branch 'develop' into fix/mark-unread
kodiakhq[bot] Sep 18, 2024
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/hot-balloons-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue where when you marked a room as read and you were part of it, sometimes it would mark it as read right after
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function SideBarItemTemplateWithData({
threadUnread={threadUnread}
rid={rid}
unread={!!unread}
roomOpen={false}
roomOpen={selected}
type={type}
cl={cl}
name={title}
Expand Down
14 changes: 11 additions & 3 deletions apps/meteor/client/sidebar/RoomMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RoomType } from '@rocket.chat/core-typings';
import { Option, Menu } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useEffectEvent, useMutableCallback } from '@rocket.chat/fuselage-hooks';
import type { TranslationKey, Fields } from '@rocket.chat/ui-contexts';
import {
useRouter,
Expand All @@ -13,6 +13,7 @@ import {
useTranslation,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React, { memo, useMemo } from 'react';

Expand Down Expand Up @@ -100,6 +101,8 @@ const RoomMenu = ({
const isOmnichannelRoom = type === 'l';
const prioritiesMenu = useOmnichannelPrioritiesMenu(rid);

const queryClient = useQueryClient();

const canLeave = ((): boolean => {
if (type === 'c' && !canLeaveChannel) {
return false;
Expand Down Expand Up @@ -171,19 +174,24 @@ const RoomMenu = ({
);
});

const handleToggleRead = useMutableCallback(async () => {
const handleToggleRead = useEffectEvent(async () => {
try {
queryClient.invalidateQueries(['sidebar/search/spotlight']);

if (isUnread) {
await readMessages({ rid, readThreads: true });
return;
}
await unreadMessages(undefined, rid);

if (subscription == null) {
return;
}

LegacyRoomManager.close(subscription.t + subscription.name);

router.navigate('/home');

await unreadMessages(undefined, rid);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const SideBarItemTemplateWithData = ({
threadUnread={threadUnread}
rid={rid}
unread={!!unread}
roomOpen={false}
roomOpen={selected}
type={type}
cl={cl}
name={title}
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/client/sidebarv2/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useTranslation,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React, { memo, useMemo } from 'react';

Expand Down Expand Up @@ -100,6 +101,8 @@ const RoomMenu = ({
const isOmnichannelRoom = type === 'l';
const prioritiesMenu = useOmnichannelPrioritiesMenu(rid);

const queryClient = useQueryClient();

const canLeave = ((): boolean => {
if (type === 'c' && !canLeaveChannel) {
return false;
Expand Down Expand Up @@ -173,17 +176,22 @@ const RoomMenu = ({

const handleToggleRead = useEffectEvent(async () => {
try {
queryClient.invalidateQueries(['sidebar/search/spotlight']);

if (isUnread) {
await readMessages({ rid, readThreads: true });
return;
}
await unreadMessages(undefined, rid);

if (subscription == null) {
return;
}

LegacyRoomManager.close(subscription.t + subscription.name);

router.navigate('/home');

await unreadMessages(undefined, rid);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
72 changes: 72 additions & 0 deletions apps/meteor/tests/e2e/mark-unread.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { createAuxContext } from './fixtures/createAuxContext';
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetChannel } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });

test.describe('Mark Unread - Sidebar Action', () => {
let poHomeChannel: HomeChannel;
let targetChannel: string;

test.beforeEach(async ({ page, api }) => {
poHomeChannel = new HomeChannel(page);
await page.emulateMedia({ reducedMotion: 'reduce' });

targetChannel = await createTargetChannel(api, { members: ['user2'] });

await page.goto('/home');
});

test.afterEach(async ({ api }) => {
await api.post('/channels.delete', { roomName: targetChannel });
});

test('should not mark empty room as unread', async () => {
const sidebarItem = poHomeChannel.sidenav.getSidebarItemByName(targetChannel);
await poHomeChannel.sidenav.selectMarkAsUnread(targetChannel);
await expect(poHomeChannel.sidenav.getChannelBadge(sidebarItem)).not.toBeVisible();
});

test('should mark a populated room as unread', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.content.sendMessage('this is a message for reply');
const sidebarItem = poHomeChannel.sidenav.getSidebarItemByName(targetChannel);
await poHomeChannel.sidenav.selectMarkAsUnread(targetChannel);
await expect(poHomeChannel.sidenav.getChannelBadge(sidebarItem)).toBeVisible();
});

test('should mark a populated room as unread - search', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.content.sendMessage('this is a message for reply');
await poHomeChannel.sidenav.selectMarkAsUnread(targetChannel);
await poHomeChannel.sidenav.searchChat(targetChannel);
await expect(poHomeChannel.sidenav.getSearchChannelBadge(targetChannel)).toBeVisible();
});

test.describe('Mark Unread - Message Action', () => {
let poHomeChannelUser2: HomeChannel;

test.beforeEach(async ({ browser }) => {
const { page: user2Page } = await createAuxContext(browser, Users.user2);
poHomeChannelUser2 = new HomeChannel(user2Page);

await poHomeChannelUser2.sidenav.openChat(targetChannel);
await poHomeChannelUser2.content.sendMessage('this is a message for reply');
});

test('should mark a populated room as unread', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);

await poHomeChannel.content.openLastMessageMenu();
await poHomeChannel.markUnread.click();
const sidebarItem = poHomeChannel.sidenav.getSidebarItemByName(targetChannel);
await expect(poHomeChannel.sidenav.getChannelBadge(sidebarItem)).toBeVisible();
});

test.afterEach(async () => {
await poHomeChannelUser2.page.close();
});
});
});
21 changes: 21 additions & 0 deletions apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export class HomeSidenav {
return this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`);
}

async selectMarkAsUnread(name: string) {
const sidebarItem = this.getSidebarItemByName(name);
await sidebarItem.focus();
await sidebarItem.locator('.rcx-sidebar-item__menu').click();
await this.page.getByRole('option', { name: 'Mark Unread' }).click();
}

async selectPriority(name: string, priority: string) {
const sidebarItem = this.getSidebarItemByName(name);
await sidebarItem.focus();
Expand Down Expand Up @@ -123,6 +130,12 @@ export class HomeSidenav {
await this.waitForChannel();
}

async searchChat(name: string): Promise<void> {
await this.page.locator('role=navigation >> role=button[name=Search]').click();
await this.page.locator('role=search >> role=searchbox').fill(name);
await expect(this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`).first()).toBeVisible();
}

async waitForChannel(): Promise<void> {
await this.page.locator('role=main').waitFor();
await this.page.locator('role=main >> role=heading[level=1]').waitFor();
Expand Down Expand Up @@ -170,4 +183,12 @@ export class HomeSidenav {
await this.checkboxEncryption.click();
await this.btnCreate.click();
}

getChannelBadge(sidebarItem: Locator): Locator {
return sidebarItem.locator('.rcx-badge');
}

getSearchChannelBadge(name: string): Locator {
return this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`).first().locator('.rcx-badge');
}
}
4 changes: 4 additions & 0 deletions apps/meteor/tests/e2e/page-objects/home-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ export class HomeChannel {
get roomHeaderToolbar(): Locator {
return this.page.locator('[role=toolbar][aria-label="Primary Room actions"]');
}

get markUnread(): Locator {
return this.page.locator('role=menuitem[name="Mark Unread"]');
}
}
Loading