This repository was archived by the owner on Oct 30, 2025. It is now read-only.
forked from signalapp/Signal-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathHeaderItem.tsx
More file actions
202 lines (178 loc) · 5.79 KB
/
Copy pathHeaderItem.tsx
File metadata and controls
202 lines (178 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import classNames from 'classnames';
import React, { useCallback, useContext } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { Data } from '../../../data/data';
import { useConversationPropsById, useIsPinned } from '../../../hooks/useParamSelector';
import { getUsBlindedInThatServer } from '../../../session/apis/open_group_api/sogsv3/knownBlindedkeys';
import { UserUtils } from '../../../session/utils';
import {
openConversationToSpecificMessage,
openConversationWithMessages,
} from '../../../state/ducks/conversations';
import { SectionType } from '../../../state/ducks/section';
import { isSearching } from '../../../state/selectors/search';
import { getFocusedSection } from '../../../state/selectors/section';
import { Timestamp } from '../../conversation/Timestamp';
import { SessionIcon } from '../../icon';
import { ContextConversationId } from './ConversationListItem';
import { UserItem } from './UserItem';
const NotificationSettingIcon = (props: { isMessagesSection: boolean }) => {
const convoId = useContext(ContextConversationId);
const convoSetting = useConversationPropsById(convoId)?.currentNotificationSetting;
if (!props.isMessagesSection) {
return null;
}
switch (convoSetting) {
case 'all':
return null;
case 'disabled':
return (
<SessionIcon
iconType="mute"
iconColor={'var(--conversation-tab-text-color)'}
iconSize="small"
/>
);
case 'mentions_only':
default:
return (
<SessionIcon
iconType="bell"
iconColor={'var(--conversation-tab-text-color)'}
iconSize="small"
/>
);
}
};
const StyledConversationListItemIconWrapper = styled.div`
svg {
margin: 0px 2px;
}
display: flex;
flex-direction: row;
`;
function useHeaderItemProps(conversationId: string) {
const convoProps = useConversationPropsById(conversationId);
if (!convoProps) {
return null;
}
return {
isPinned: !!convoProps.isPinned,
mentionedUs: convoProps.mentionedUs || false,
unreadCount: convoProps.unreadCount || 0,
activeAt: convoProps.activeAt,
};
}
const ListItemIcons = () => {
const isMessagesSection = useSelector(getFocusedSection) === SectionType.Message;
const conversationId = useContext(ContextConversationId);
const isPinned = useIsPinned(conversationId);
const pinIcon =
isMessagesSection && isPinned ? (
<SessionIcon
iconType="pin"
iconColor={'var(--conversation-tab-text-color)'}
iconSize="small"
/>
) : null;
return (
<StyledConversationListItemIconWrapper>
{pinIcon}
<NotificationSettingIcon isMessagesSection={isMessagesSection} />
</StyledConversationListItemIconWrapper>
);
};
const MentionAtSymbol = styled.span`
background: var(--unread-messages-alert-background-color);
color: var(--unread-messages-alert-text-color);
text-align: center;
margin-top: 0px;
margin-bottom: 0px;
padding-inline-start: 3px;
padding-inline-end: 3px;
position: static;
margin-inline-start: 5px;
font-weight: 700;
font-size: var(--font-size-xs);
letter-spacing: 0.25px;
height: 16px;
min-width: 16px;
border-radius: 8px;
cursor: pointer;
:hover {
filter: grayscale(0.7);
}
`;
export const ConversationListItemHeaderItem = () => {
const conversationId = useContext(ContextConversationId);
const isSearchingMode = useSelector(isSearching);
const convoProps = useHeaderItemProps(conversationId);
const openConvoToLastMention = useCallback(
async (e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
e.preventDefault();
// mousedown is invoked sooner than onClick, but for both right and left click
if (e.button === 0) {
const usInThatConversation =
getUsBlindedInThatServer(conversationId) || UserUtils.getOurPubKeyStrFromCache();
const oldestMessageUnreadWithMention =
(await Data.getFirstUnreadMessageWithMention(conversationId, usInThatConversation)) ||
null;
if (oldestMessageUnreadWithMention) {
await openConversationToSpecificMessage({
conversationKey: conversationId,
messageIdToNavigateTo: oldestMessageUnreadWithMention,
shouldHighlightMessage: true,
});
} else {
window.log.info('cannot open to latest mention as no unread mention are found');
await openConversationWithMessages({
conversationKey: conversationId,
messageId: null,
});
}
}
},
[conversationId]
);
if (!convoProps) {
return null;
}
const { unreadCount, mentionedUs, activeAt } = convoProps;
let atSymbol = null;
let unreadCountDiv = null;
if (unreadCount > 0) {
atSymbol = mentionedUs ? (
<MentionAtSymbol title="Open to latest mention" onMouseDown={openConvoToLastMention}>
@
</MentionAtSymbol>
) : null;
unreadCountDiv = <p className="module-conversation-list-item__unread-count">{unreadCount}</p>;
}
return (
<div className="module-conversation-list-item__header">
<div
className={classNames(
'module-conversation-list-item__header__name',
unreadCount > 0 ? 'module-conversation-list-item__header__name--with-unread' : null
)}
>
<UserItem />
</div>
<ListItemIcons />
{unreadCountDiv}
{atSymbol}
{!isSearchingMode && (
<div
className={classNames(
'module-conversation-list-item__header__date',
unreadCount > 0 ? 'module-conversation-list-item__header__date--has-unread' : null
)}
>
<Timestamp timestamp={activeAt} isConversationListItem={true} momentFromNow={true} />
</div>
)}
</div>
);
};