@@ -12,6 +12,11 @@ import dispatcher from "../../../dispatcher/dispatcher";
12
12
import type { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload" ;
13
13
import { Action } from "../../../dispatcher/actions" ;
14
14
import { hasAccessToOptionsMenu } from "./utils" ;
15
+ import {
16
+ type NotificationDecorationViewState ,
17
+ useNotificationDecorationViewModel ,
18
+ } from "../notification_decoration/NotificationDecorationViewModel" ;
19
+ import { _t } from "../../../languageHandler" ;
15
20
16
21
export interface RoomListItemViewState {
17
22
/**
@@ -22,6 +27,14 @@ export interface RoomListItemViewState {
22
27
* Open the room having given roomId.
23
28
*/
24
29
openRoom : ( ) => void ;
30
+ /**
31
+ * The a11y label for the room list item.
32
+ */
33
+ a11yLabel : string ;
34
+ /**
35
+ * The notification state of the room.
36
+ */
37
+ notificationDecorationViewState : NotificationDecorationViewState ;
25
38
}
26
39
27
40
/**
@@ -31,6 +44,11 @@ export interface RoomListItemViewState {
31
44
export function useRoomListItemViewModel ( room : Room ) : RoomListItemViewState {
32
45
// incoming: Check notification menu rights
33
46
const showHoverMenu = hasAccessToOptionsMenu ( room ) ;
47
+ // Use the VM of the notification decoration because we need to put the a11y label on the room list item
48
+ // The VM is passed to the NotificationDecoration component by the RoomListItemView component
49
+ // This is a bit of a hack but it's the easiest way to avoid to put twice the same listeners to compute the same notification
50
+ const notificationDecorationViewState = useNotificationDecorationViewModel ( room ) ;
51
+ const a11yLabel = getA11yLabel ( room , notificationDecorationViewState ) ;
34
52
35
53
// Actions
36
54
@@ -43,7 +61,38 @@ export function useRoomListItemViewModel(room: Room): RoomListItemViewState {
43
61
} , [ room ] ) ;
44
62
45
63
return {
64
+ notificationDecorationViewState,
46
65
showHoverMenu,
47
66
openRoom,
67
+ a11yLabel,
48
68
} ;
49
69
}
70
+
71
+ /**
72
+ * Get the a11y label for the room list item
73
+ * @param room
74
+ * @param notificationDecorationViewState
75
+ */
76
+ function getA11yLabel ( room : Room , notificationDecorationViewState : NotificationDecorationViewState ) : string {
77
+ if ( notificationDecorationViewState . isMessageNotSent ) {
78
+ return _t ( "a11y|room_messsage_not_sent" , {
79
+ roomName : room . name ,
80
+ } ) ;
81
+ } else if ( notificationDecorationViewState . isInvite ) {
82
+ return _t ( "a11y|room_n_unread_invite" , {
83
+ roomName : room . name ,
84
+ } ) ;
85
+ } else if ( notificationDecorationViewState . isHighlighted ) {
86
+ return _t ( "a11y|room_n_unread_messages_mentions" , {
87
+ roomName : room . name ,
88
+ count : notificationDecorationViewState . rawUnreadCount ,
89
+ } ) ;
90
+ } else if ( notificationDecorationViewState . hasUnread ) {
91
+ return _t ( "a11y|room_n_unread_messages" , {
92
+ roomName : room . name ,
93
+ count : notificationDecorationViewState . rawUnreadCount ,
94
+ } ) ;
95
+ } else {
96
+ return _t ( "room_list|room|open_room" , { roomName : room . name } ) ;
97
+ }
98
+ }
0 commit comments