1- import type { IMessage , IRoom , ISubscription } from '@rocket.chat/core-typings' ;
1+ import type { IMessage } 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' ;
4+ import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts' ;
45import { useLayout } from '@rocket.chat/ui-contexts' ;
56import DOMPurify from 'dompurify' ;
67import type { TFunction } from 'i18next' ;
@@ -13,10 +14,11 @@ import { roomCoordinator } from '../../lib/rooms/roomCoordinator';
1314import { isIOsDevice } from '../../lib/utils/isIOsDevice' ;
1415import { useOmnichannelPriorities } from '../../views/omnichannel/hooks/useOmnichannelPriorities' ;
1516import RoomMenu from '../RoomMenu' ;
16- import { OmnichannelBadges } from '../badges/OmnichannelBadges ' ;
17+ import SidebarItemBadges from '../badges/SidebarItemBadges ' ;
1718import type { useAvatarTemplate } from '../hooks/useAvatarTemplate' ;
19+ import { useUnreadDisplay } from '../hooks/useUnreadDisplay' ;
1820
19- const getMessage = ( room : IRoom , lastMessage : IMessage | undefined , t : TFunction ) : string | undefined => {
21+ const getMessage = ( room : SubscriptionWithRoom , lastMessage : IMessage | undefined , t : TFunction ) : string | undefined => {
2022 if ( ! lastMessage ) {
2123 return t ( 'No_messages_yet' ) ;
2224 }
@@ -35,24 +37,6 @@ const getMessage = (room: IRoom, lastMessage: IMessage | undefined, t: TFunction
3537 return `${ lastMessage . u . name || lastMessage . u . username } : ${ normalizeSidebarMessage ( lastMessage , t ) } ` ;
3638} ;
3739
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-
5640type RoomListRowProps = {
5741 extended : boolean ;
5842 t : TFunction ;
@@ -80,7 +64,7 @@ type RoomListRowProps = {
8064 // sidebarViewMode: 'extended';
8165 isAnonymous ?: boolean ;
8266
83- room : ISubscription & IRoom ;
67+ room : SubscriptionWithRoom ;
8468 id ?: string ;
8569 /* @deprecated */
8670 style ?: AllHTMLAttributes < HTMLElement > [ 'style' ] ;
@@ -110,22 +94,10 @@ function SideBarItemTemplateWithData({
11094 const href = roomCoordinator . getRouteLink ( room . t , room ) || '' ;
11195 const title = roomCoordinator . getRoomName ( room . t , room ) || '' ;
11296
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 ;
97+ const { lastMessage, unread = 0 , alert, rid, t : type , cl } = room ;
98+
99+ const { unreadCount, unreadTitle, showUnread, highlightUnread : highlighted } = useUnreadDisplay ( room ) ;
127100
128- const highlighted = Boolean ( ! hideUnreadStatus && ( alert || unread ) ) ;
129101 const icon = (
130102 // TODO: Remove icon='at'
131103 < Sidebar . Item . Icon highlighted = { highlighted } icon = 'at' >
@@ -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