11import type { IMessage , IRoom , ISubscription } from '@rocket.chat/core-typings' ;
22import { isDirectMessageRoom , isMultipleDirectMessageRoom , isOmnichannelRoom , isVideoConfMessage } from '@rocket.chat/core-typings' ;
3- import { Badge , Sidebar , SidebarItemAction , SidebarItemActions , Margins } from '@rocket.chat/fuselage' ;
3+ import { Sidebar , SidebarItemAction , SidebarItemActions } from '@rocket.chat/fuselage' ;
44import { useLayout } from '@rocket.chat/ui-contexts' ;
55import DOMPurify from 'dompurify' ;
66import type { TFunction } from 'i18next' ;
@@ -13,8 +13,9 @@ import { roomCoordinator } from '../../lib/rooms/roomCoordinator';
1313import { isIOsDevice } from '../../lib/utils/isIOsDevice' ;
1414import { useOmnichannelPriorities } from '../../views/omnichannel/hooks/useOmnichannelPriorities' ;
1515import RoomMenu from '../RoomMenu' ;
16- import { OmnichannelBadges } from '../badges/OmnichannelBadges ' ;
16+ import SidebarItemBadges from '../badges/SidebarItemBadges ' ;
1717import type { useAvatarTemplate } from '../hooks/useAvatarTemplate' ;
18+ import { useUnreadDisplay } from '../hooks/useUnreadDisplay' ;
1819
1920const getMessage = ( room : IRoom , lastMessage : IMessage | undefined , t : TFunction ) : string | undefined => {
2021 if ( ! lastMessage ) {
@@ -35,24 +36,6 @@ const getMessage = (room: IRoom, lastMessage: IMessage | undefined, t: TFunction
3536 return `${ lastMessage . u . name || lastMessage . u . username } : ${ normalizeSidebarMessage ( lastMessage , t ) } ` ;
3637} ;
3738
38- const getBadgeTitle = ( userMentions : number , threadUnread : number , groupMentions : number , unread : number , t : TFunction ) => {
39- const title = [ ] as string [ ] ;
40- if ( userMentions ) {
41- title . push ( t ( 'mentions_counter' , { count : userMentions } ) ) ;
42- }
43- if ( threadUnread ) {
44- title . push ( t ( 'threads_counter' , { count : threadUnread } ) ) ;
45- }
46- if ( groupMentions ) {
47- title . push ( t ( 'group_mentions_counter' , { count : groupMentions } ) ) ;
48- }
49- const count = unread - userMentions - groupMentions ;
50- if ( count > 0 ) {
51- title . push ( t ( 'unread_messages_counter' , { count } ) ) ;
52- }
53- return title . join ( ', ' ) ;
54- } ;
55-
5639type RoomListRowProps = {
5740 extended : boolean ;
5841 t : TFunction ;
@@ -110,20 +93,9 @@ function SideBarItemTemplateWithData({
11093 const href = roomCoordinator . getRouteLink ( room . t , room ) || '' ;
11194 const title = roomCoordinator . getRoomName ( room . t , room ) || '' ;
11295
113- const {
114- lastMessage,
115- hideUnreadStatus,
116- hideMentionStatus,
117- unread = 0 ,
118- alert,
119- userMentions,
120- groupMentions,
121- tunread = [ ] ,
122- tunreadUser = [ ] ,
123- rid,
124- t : type ,
125- cl,
126- } = room ;
96+ const { lastMessage, hideUnreadStatus, unread = 0 , alert, rid, t : type , cl } = room ;
97+
98+ const { unreadCount, unreadTitle, showUnread } = useUnreadDisplay ( room ) ;
12799
128100 const highlighted = Boolean ( ! hideUnreadStatus && ( alert || unread ) ) ;
129101 const icon = (
@@ -152,32 +124,6 @@ function SideBarItemTemplateWithData({
152124 < span className = 'message-body--unstyled' dangerouslySetInnerHTML = { { __html : DOMPurify . sanitize ( message ) } } />
153125 ) : null ;
154126
155- const threadUnread = tunread . length > 0 ;
156- const variant =
157- ( ( userMentions || tunreadUser . length ) && 'danger' ) || ( threadUnread && 'primary' ) || ( groupMentions && 'warning' ) || 'secondary' ;
158-
159- const isUnread = unread > 0 || threadUnread ;
160- const showBadge = ! hideUnreadStatus || ( ! hideMentionStatus && ( Boolean ( userMentions ) || tunreadUser . length > 0 ) ) ;
161-
162- const badgeTitle = getBadgeTitle ( userMentions , tunread . length , groupMentions , unread , t ) ;
163-
164- const badges = (
165- < Margins inlineStart = { 8 } >
166- { showBadge && isUnread && (
167- < Badge
168- role = 'status'
169- { ...( { style : { display : 'inline-flex' , flexShrink : 0 } } as any ) }
170- variant = { variant }
171- title = { badgeTitle }
172- aria-label = { t ( '__unreadTitle__from__roomTitle__' , { unreadTitle : badgeTitle , roomTitle : title } ) }
173- >
174- < span aria-hidden > { unread + tunread ?. length } </ span >
175- </ Badge >
176- ) }
177- { isOmnichannelRoom ( room ) && < OmnichannelBadges room = { room } /> }
178- </ Margins >
179- ) ;
180-
181127 return (
182128 < SideBarItemTemplate
183129 is = 'a'
@@ -190,21 +136,21 @@ function SideBarItemTemplateWithData({
190136 onClick = { ( ) : void => {
191137 ! selected && sidebar . toggle ( ) ;
192138 } }
193- aria-label = { showBadge && isUnread ? t ( '__unreadTitle__from__roomTitle__' , { unreadTitle : badgeTitle , roomTitle : title } ) : title }
139+ aria-label = { showUnread ? t ( '__unreadTitle__from__roomTitle__' , { unreadTitle, roomTitle : title } ) : title }
194140 title = { title }
195141 time = { lastMessage ?. ts }
196142 subtitle = { subtitle }
197143 icon = { icon }
198144 style = { style }
199- badges = { badges }
145+ badges = { < SidebarItemBadges room = { room } roomTitle = { title } /> }
200146 avatar = { AvatarTemplate && < AvatarTemplate { ...room } /> }
201147 actions = { actions }
202148 menu = {
203149 ! isIOsDevice && ! isAnonymous && ( ! isQueued || ( isQueued && isPriorityEnabled ) )
204150 ? ( ) : ReactElement => (
205151 < RoomMenu
206152 alert = { alert }
207- threadUnread = { threadUnread }
153+ threadUnread = { unreadCount . threads > 0 }
208154 rid = { rid }
209155 unread = { ! ! unread }
210156 roomOpen = { selected }
0 commit comments