Skip to content

Commit

Permalink
feat: Display total and room unread messages in room title.
Browse files Browse the repository at this point in the history
Room title: `[total unread] (room unread) Room Name`
    [total unread] - this is total number of unread messages - it is hidden when value is zero
    (room unread) - this is number of room unread messages - it is hidden when value is zero
  • Loading branch information
MichalFoksa committed Apr 24, 2024
1 parent 3680573 commit 57a049d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/meteor/client/views/room/Header/RoomTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@ import type { KeyboardEvent, ReactElement } from 'react';
import React from 'react';

import { useRoomToolbox } from '../contexts/RoomToolboxContext';
import { useSession } from '@rocket.chat/ui-contexts';
import HeaderIconWithRoom from './HeaderIconWithRoom';

const RoomTitle = ({ room }: { room: IRoom }): ReactElement => {
useDocumentTitle(room.name, false);

const getTotalUnreaddMessages = (): number => {
const unreadMessages = useSession('unread') as number | '' | '999+' | '•';
if (typeof unreadMessages !== 'number') {
return 0;
}
return unreadMessages;
};

const totalUnread = getTotalUnreaddMessages();
const roomUnread = room.unread === undefined ? 0 : room.unread;
useDocumentTitle(
// [total unread] (room unread) Room Name
(totalUnread > 0 ? '[' + totalUnread + '] ' : '') + (roomUnread > 0 ? '(' + roomUnread + ') ' : '') + room.name, false);

const { openTab } = useRoomToolbox();

const handleOpenRoomInfo = useEffectEvent(() => {
Expand Down

0 comments on commit 57a049d

Please sign in to comment.