@droppii-org/chat-mobile 0.2.80 → 0.2.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/components/ThreadCard/MentionBadge.js +24 -0
- package/lib/module/components/ThreadCard/MentionBadge.js.map +1 -0
- package/lib/module/components/ThreadCard/ThreadCard.js +5 -1
- package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -1
- package/lib/module/components/messages/linkMessage/LinkPreviewCard.js +67 -0
- package/lib/module/components/messages/linkMessage/LinkPreviewCard.js.map +1 -0
- package/lib/module/components/messages/linkMessage/index.js +21 -68
- package/lib/module/components/messages/linkMessage/index.js.map +1 -1
- package/lib/module/components/messages/quotedMessage/QuotedMessagePreviewStrip.js +152 -0
- package/lib/module/components/messages/quotedMessage/QuotedMessagePreviewStrip.js.map +1 -0
- package/lib/module/components/messages/textMessage/index.js +102 -8
- package/lib/module/components/messages/textMessage/index.js.map +1 -1
- package/lib/module/config/api-endpoints.js +2 -1
- package/lib/module/config/api-endpoints.js.map +1 -1
- package/lib/module/core/useChatListener.js +1 -1
- package/lib/module/core/useChatListener.js.map +1 -1
- package/lib/module/hooks/contacts/useSearchContacts.js +50 -0
- package/lib/module/hooks/contacts/useSearchContacts.js.map +1 -0
- package/lib/module/hooks/message/useSendMessage.js +64 -3
- package/lib/module/hooks/message/useSendMessage.js.map +1 -1
- package/lib/module/hooks/query-keys.js +8 -0
- package/lib/module/hooks/query-keys.js.map +1 -1
- package/lib/module/hooks/useChatCompose.js +3 -2
- package/lib/module/hooks/useChatCompose.js.map +1 -1
- package/lib/module/screens/SearchConversation/ContactResultItem.js +119 -0
- package/lib/module/screens/SearchConversation/ContactResultItem.js.map +1 -0
- package/lib/module/screens/SearchConversation/SearchAllResult.js +26 -20
- package/lib/module/screens/SearchConversation/SearchAllResult.js.map +1 -1
- package/lib/module/screens/SearchConversation/SearchCommunityResult.js +79 -0
- package/lib/module/screens/SearchConversation/SearchCommunityResult.js.map +1 -0
- package/lib/module/screens/SearchConversation/SearchContactsResult.js +117 -0
- package/lib/module/screens/SearchConversation/SearchContactsResult.js.map +1 -0
- package/lib/module/screens/SearchConversation/SearchEmpty.js +2 -0
- package/lib/module/screens/SearchConversation/SearchEmpty.js.map +1 -1
- package/lib/module/screens/SearchConversation/SearchMessagesResult.js +1 -8
- package/lib/module/screens/SearchConversation/SearchMessagesResult.js.map +1 -1
- package/lib/module/screens/SearchConversation/SearchResultItem.js +2 -0
- package/lib/module/screens/SearchConversation/SearchResultItem.js.map +1 -1
- package/lib/module/screens/SearchConversation/TabResult.js +24 -7
- package/lib/module/screens/SearchConversation/TabResult.js.map +1 -1
- package/lib/module/screens/SearchConversation/index.js +6 -2
- package/lib/module/screens/SearchConversation/index.js.map +1 -1
- package/lib/module/screens/SearchConversation/types.js +1 -0
- package/lib/module/screens/SearchConversation/types.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatComposer.js +170 -48
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatListLegend.js +1 -0
- package/lib/module/screens/chat-detail/ChatListLegend.js.map +1 -1
- package/lib/module/screens/chat-detail/components/ChatMessageInput.js +23 -2
- package/lib/module/screens/chat-detail/components/ChatMessageInput.js.map +1 -1
- package/lib/module/screens/chat-detail/components/MentionHighlightAdapter.js +51 -0
- package/lib/module/screens/chat-detail/components/MentionHighlightAdapter.js.map +1 -0
- package/lib/module/screens/chat-detail/components/MentionSuggestionItem.js +49 -0
- package/lib/module/screens/chat-detail/components/MentionSuggestionItem.js.map +1 -0
- package/lib/module/screens/chat-detail/components/MentionSuggestionList.js +114 -0
- package/lib/module/screens/chat-detail/components/MentionSuggestionList.js.map +1 -0
- package/lib/module/screens/chat-detail/hooks/useChatComposerState.js +8 -0
- package/lib/module/screens/chat-detail/hooks/useChatComposerState.js.map +1 -1
- package/lib/module/screens/chat-detail/hooks/useMentionComposer.js +251 -0
- package/lib/module/screens/chat-detail/hooks/useMentionComposer.js.map +1 -0
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js +5 -1
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js.map +1 -1
- package/lib/module/screens/chat-detail/messageToolbox/MessageToolboxWrapper.js +11 -1
- package/lib/module/screens/chat-detail/messageToolbox/MessageToolboxWrapper.js.map +1 -1
- package/lib/module/services/endpoints.js +2 -1
- package/lib/module/services/endpoints.js.map +1 -1
- package/lib/module/services/mentionSearch.js +49 -0
- package/lib/module/services/mentionSearch.js.map +1 -0
- package/lib/module/services/message.js +6 -1
- package/lib/module/services/message.js.map +1 -1
- package/lib/module/translation/resources/i18n.js +11 -0
- package/lib/module/translation/resources/i18n.js.map +1 -1
- package/lib/module/types/chat.js +8 -0
- package/lib/module/types/chat.js.map +1 -1
- package/lib/module/types/mention.js +2 -0
- package/lib/module/types/mention.js.map +1 -0
- package/lib/module/utils/dateTimeUtils.js +10 -0
- package/lib/module/utils/dateTimeUtils.js.map +1 -1
- package/lib/module/utils/highlightSearch.js +6 -2
- package/lib/module/utils/highlightSearch.js.map +1 -1
- package/lib/module/utils/mentionSerializer.js +113 -0
- package/lib/module/utils/mentionSerializer.js.map +1 -0
- package/lib/module/utils/mentions/index.js +7 -0
- package/lib/module/utils/mentions/index.js.map +1 -0
- package/lib/module/utils/mentions/mentionDetector.js +49 -0
- package/lib/module/utils/mentions/mentionDetector.js.map +1 -0
- package/lib/module/utils/mentions/mentionDiff.js +66 -0
- package/lib/module/utils/mentions/mentionDiff.js.map +1 -0
- package/lib/module/utils/mentions/mentionRange.js +188 -0
- package/lib/module/utils/mentions/mentionRange.js.map +1 -0
- package/lib/module/utils/mentions/mentionTokenize.js +50 -0
- package/lib/module/utils/mentions/mentionTokenize.js.map +1 -0
- package/lib/module/utils/messageUtils.js +16 -3
- package/lib/module/utils/messageUtils.js.map +1 -1
- package/lib/module/utils/url.js +33 -0
- package/lib/module/utils/url.js.map +1 -1
- package/lib/typescript/src/components/ThreadCard/MentionBadge.d.ts +7 -0
- package/lib/typescript/src/components/ThreadCard/MentionBadge.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -1
- package/lib/typescript/src/components/messages/linkMessage/LinkPreviewCard.d.ts +16 -0
- package/lib/typescript/src/components/messages/linkMessage/LinkPreviewCard.d.ts.map +1 -0
- package/lib/typescript/src/components/messages/linkMessage/index.d.ts.map +1 -1
- package/lib/typescript/src/components/messages/quotedMessage/QuotedMessagePreviewStrip.d.ts +13 -0
- package/lib/typescript/src/components/messages/quotedMessage/QuotedMessagePreviewStrip.d.ts.map +1 -0
- package/lib/typescript/src/components/messages/textMessage/index.d.ts +3 -1
- package/lib/typescript/src/components/messages/textMessage/index.d.ts.map +1 -1
- package/lib/typescript/src/config/api-endpoints.d.ts +1 -0
- package/lib/typescript/src/config/api-endpoints.d.ts.map +1 -1
- package/lib/typescript/src/hooks/contacts/useSearchContacts.d.ts +221 -0
- package/lib/typescript/src/hooks/contacts/useSearchContacts.d.ts.map +1 -0
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts +5 -2
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/query-keys.d.ts +8 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useChatCompose.d.ts +2 -1
- package/lib/typescript/src/hooks/useChatCompose.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/ContactResultItem.d.ts +9 -0
- package/lib/typescript/src/screens/SearchConversation/ContactResultItem.d.ts.map +1 -0
- package/lib/typescript/src/screens/SearchConversation/SearchAllResult.d.ts +3 -2
- package/lib/typescript/src/screens/SearchConversation/SearchAllResult.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/SearchCommunityResult.d.ts +7 -0
- package/lib/typescript/src/screens/SearchConversation/SearchCommunityResult.d.ts.map +1 -0
- package/lib/typescript/src/screens/SearchConversation/SearchContactsResult.d.ts +8 -0
- package/lib/typescript/src/screens/SearchConversation/SearchContactsResult.d.ts.map +1 -0
- package/lib/typescript/src/screens/SearchConversation/SearchEmpty.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/SearchMessagesResult.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/SearchResultItem.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/TabResult.d.ts +4 -2
- package/lib/typescript/src/screens/SearchConversation/TabResult.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/index.d.ts +4 -2
- package/lib/typescript/src/screens/SearchConversation/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/SearchConversation/types.d.ts +2 -1
- package/lib/typescript/src/screens/SearchConversation/types.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/components/ChatMessageInput.d.ts +10 -2
- package/lib/typescript/src/screens/chat-detail/components/ChatMessageInput.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/components/MentionHighlightAdapter.d.ts +29 -0
- package/lib/typescript/src/screens/chat-detail/components/MentionHighlightAdapter.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/components/MentionSuggestionItem.d.ts +8 -0
- package/lib/typescript/src/screens/chat-detail/components/MentionSuggestionItem.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/components/MentionSuggestionList.d.ts +12 -0
- package/lib/typescript/src/screens/chat-detail/components/MentionSuggestionList.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/hooks/useChatComposerState.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/hooks/useChatComposerState.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/hooks/useMentionComposer.d.ts +48 -0
- package/lib/typescript/src/screens/chat-detail/hooks/useMentionComposer.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/messageToolbox/MessageToolboxWrapper.d.ts.map +1 -1
- package/lib/typescript/src/services/endpoints.d.ts +1 -0
- package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
- package/lib/typescript/src/services/mentionSearch.d.ts +15 -0
- package/lib/typescript/src/services/mentionSearch.d.ts.map +1 -0
- package/lib/typescript/src/services/message.d.ts +1 -1
- package/lib/typescript/src/services/message.d.ts.map +1 -1
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
- package/lib/typescript/src/types/chat.d.ts +50 -0
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/lib/typescript/src/types/mention.d.ts +65 -0
- package/lib/typescript/src/types/mention.d.ts.map +1 -0
- package/lib/typescript/src/utils/dateTimeUtils.d.ts +2 -0
- package/lib/typescript/src/utils/dateTimeUtils.d.ts.map +1 -1
- package/lib/typescript/src/utils/highlightSearch.d.ts.map +1 -1
- package/lib/typescript/src/utils/mentionSerializer.d.ts +78 -0
- package/lib/typescript/src/utils/mentionSerializer.d.ts.map +1 -0
- package/lib/typescript/src/utils/mentions/index.d.ts +5 -0
- package/lib/typescript/src/utils/mentions/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/mentions/mentionDetector.d.ts +18 -0
- package/lib/typescript/src/utils/mentions/mentionDetector.d.ts.map +1 -0
- package/lib/typescript/src/utils/mentions/mentionDiff.d.ts +20 -0
- package/lib/typescript/src/utils/mentions/mentionDiff.d.ts.map +1 -0
- package/lib/typescript/src/utils/mentions/mentionRange.d.ts +86 -0
- package/lib/typescript/src/utils/mentions/mentionRange.d.ts.map +1 -0
- package/lib/typescript/src/utils/mentions/mentionTokenize.d.ts +29 -0
- package/lib/typescript/src/utils/mentions/mentionTokenize.d.ts.map +1 -0
- package/lib/typescript/src/utils/messageUtils.d.ts.map +1 -1
- package/lib/typescript/src/utils/url.d.ts +12 -0
- package/lib/typescript/src/utils/url.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/build-ignore.d.ts +2 -0
- package/src/components/ThreadCard/MentionBadge.tsx +28 -0
- package/src/components/ThreadCard/ThreadCard.tsx +3 -0
- package/src/components/messages/linkMessage/LinkPreviewCard.tsx +92 -0
- package/src/components/messages/linkMessage/index.tsx +25 -89
- package/src/components/messages/quotedMessage/QuotedMessagePreviewStrip.tsx +168 -0
- package/src/components/messages/textMessage/index.tsx +124 -4
- package/src/config/api-endpoints.ts +2 -0
- package/src/core/useChatListener.ts +1 -1
- package/src/hooks/contacts/useSearchContacts.ts +66 -0
- package/src/hooks/message/useSendMessage.ts +60 -1
- package/src/hooks/query-keys.ts +12 -0
- package/src/hooks/useChatCompose.ts +115 -107
- package/src/screens/SearchConversation/ContactResultItem.tsx +128 -0
- package/src/screens/SearchConversation/SearchAllResult.tsx +38 -24
- package/src/screens/SearchConversation/SearchCommunityResult.tsx +96 -0
- package/src/screens/SearchConversation/SearchContactsResult.tsx +155 -0
- package/src/screens/SearchConversation/SearchEmpty.tsx +2 -0
- package/src/screens/SearchConversation/SearchMessagesResult.tsx +1 -6
- package/src/screens/SearchConversation/SearchResultItem.tsx +6 -1
- package/src/screens/SearchConversation/TabResult.tsx +40 -5
- package/src/screens/SearchConversation/index.tsx +10 -2
- package/src/screens/SearchConversation/types.tsx +1 -0
- package/src/screens/chat-detail/ChatComposer.tsx +201 -67
- package/src/screens/chat-detail/ChatListLegend.tsx +1 -0
- package/src/screens/chat-detail/components/ChatMessageInput.tsx +35 -2
- package/src/screens/chat-detail/components/MentionHighlightAdapter.tsx +57 -0
- package/src/screens/chat-detail/components/MentionSuggestionItem.tsx +53 -0
- package/src/screens/chat-detail/components/MentionSuggestionList.tsx +133 -0
- package/src/screens/chat-detail/hooks/useChatComposerState.ts +7 -1
- package/src/screens/chat-detail/hooks/useMentionComposer.ts +344 -0
- package/src/screens/chat-detail/legend/LegendChatMessage.tsx +7 -1
- package/src/screens/chat-detail/messageToolbox/MessageToolboxWrapper.tsx +22 -4
- package/src/services/endpoints.ts +1 -0
- package/src/services/mentionSearch.ts +57 -0
- package/src/services/message.ts +9 -1
- package/src/translation/resources/i18n.ts +12 -0
- package/src/types/chat.ts +52 -0
- package/src/types/mention.ts +70 -0
- package/src/utils/dateTimeUtils.ts +15 -0
- package/src/utils/highlightSearch.ts +12 -2
- package/src/utils/mentionSerializer.ts +155 -0
- package/src/utils/mentions/index.ts +16 -0
- package/src/utils/mentions/mentionDetector.ts +58 -0
- package/src/utils/mentions/mentionDiff.ts +95 -0
- package/src/utils/mentions/mentionRange.ts +207 -0
- package/src/utils/mentions/mentionTokenize.ts +53 -0
- package/src/utils/messageUtils.ts +21 -10
- package/src/utils/url.ts +30 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { memo, useCallback } from 'react';
|
|
2
|
+
import { ActivityIndicator, StyleSheet } from 'react-native';
|
|
3
|
+
import { LegendList } from '@legendapp/list/react-native';
|
|
4
|
+
import { KContainer, KLabel, KColors, KSpacingValue } from '@droppii/libs';
|
|
5
|
+
import { MentionSuggestionItem } from './MentionSuggestionItem';
|
|
6
|
+
import { trans } from '../../../translation';
|
|
7
|
+
import type { MentionSuggestion } from '../../../types/mention';
|
|
8
|
+
|
|
9
|
+
// Figma (node 15066-319156): regular rows are 40px (single line, avatar
|
|
10
|
+
// height defines it), the "Tất cả" row is 45px (title + subtitle) — 40 is
|
|
11
|
+
// used as the shared estimate since most rows are the single-line kind.
|
|
12
|
+
const ROW_HEIGHT = 40;
|
|
13
|
+
const ROW_GAP = 8;
|
|
14
|
+
const MAX_VISIBLE_ROWS = 6;
|
|
15
|
+
const MAX_PANEL_HEIGHT =
|
|
16
|
+
ROW_HEIGHT * MAX_VISIBLE_ROWS + ROW_GAP * (MAX_VISIBLE_ROWS - 1);
|
|
17
|
+
|
|
18
|
+
interface MentionSuggestionListProps {
|
|
19
|
+
suggestions: MentionSuggestion[];
|
|
20
|
+
isSearching: boolean;
|
|
21
|
+
isLoadingMore?: boolean;
|
|
22
|
+
hasMore?: boolean;
|
|
23
|
+
onLoadMore?: () => void;
|
|
24
|
+
onSelect: (item: MentionSuggestion) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const MentionSuggestionList = memo(
|
|
28
|
+
({
|
|
29
|
+
suggestions,
|
|
30
|
+
isSearching,
|
|
31
|
+
isLoadingMore,
|
|
32
|
+
hasMore,
|
|
33
|
+
onLoadMore,
|
|
34
|
+
onSelect,
|
|
35
|
+
}: MentionSuggestionListProps) => {
|
|
36
|
+
const renderItem = useCallback(
|
|
37
|
+
({ item }: { item: MentionSuggestion }) => (
|
|
38
|
+
<MentionSuggestionItem item={item} onPress={onSelect} />
|
|
39
|
+
),
|
|
40
|
+
[onSelect]
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const keyExtractor = useCallback(
|
|
44
|
+
(item: MentionSuggestion) => item.userId,
|
|
45
|
+
[]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const renderFooter = useCallback(() => {
|
|
49
|
+
if (!isLoadingMore) return null;
|
|
50
|
+
return (
|
|
51
|
+
<KContainer.View paddingV="0.5rem" center>
|
|
52
|
+
<ActivityIndicator color={KColors.palette.primary.w400} />
|
|
53
|
+
</KContainer.View>
|
|
54
|
+
);
|
|
55
|
+
}, [isLoadingMore]);
|
|
56
|
+
|
|
57
|
+
const renderSeparator = useCallback(
|
|
58
|
+
() => <KContainer.View style={styles.separator} />,
|
|
59
|
+
[]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<KContainer.View style={styles.shadowWrapper}>
|
|
64
|
+
<KContainer.View background={KColors.white} style={styles.container}>
|
|
65
|
+
<KLabel.Text
|
|
66
|
+
typo="TextNmBold"
|
|
67
|
+
color={KColors.palette.gray.w600}
|
|
68
|
+
paddingH="0.75rem"
|
|
69
|
+
paddingV="0.5rem"
|
|
70
|
+
>
|
|
71
|
+
{trans('group:tag_title')}
|
|
72
|
+
</KLabel.Text>
|
|
73
|
+
|
|
74
|
+
{suggestions.length === 0 && !isSearching ? (
|
|
75
|
+
<KLabel.Text
|
|
76
|
+
typo="TextSmNormal"
|
|
77
|
+
color={KColors.palette.gray.w600}
|
|
78
|
+
paddingH="0.75rem"
|
|
79
|
+
paddingB="0.75rem"
|
|
80
|
+
>
|
|
81
|
+
{trans('group:tag_no_member_found')}
|
|
82
|
+
</KLabel.Text>
|
|
83
|
+
) : suggestions.length === 0 && isSearching ? (
|
|
84
|
+
<KContainer.View paddingV="0.75rem" center>
|
|
85
|
+
<ActivityIndicator color={KColors.palette.primary.w400} />
|
|
86
|
+
</KContainer.View>
|
|
87
|
+
) : (
|
|
88
|
+
<KContainer.View style={styles.listWrapper} padding="0.5rem">
|
|
89
|
+
<LegendList
|
|
90
|
+
data={suggestions}
|
|
91
|
+
renderItem={renderItem}
|
|
92
|
+
keyExtractor={keyExtractor}
|
|
93
|
+
estimatedItemSize={ROW_HEIGHT}
|
|
94
|
+
keyboardShouldPersistTaps="handled"
|
|
95
|
+
onEndReached={hasMore ? onLoadMore : undefined}
|
|
96
|
+
onEndReachedThreshold={0.5}
|
|
97
|
+
ListFooterComponent={renderFooter}
|
|
98
|
+
ItemSeparatorComponent={renderSeparator}
|
|
99
|
+
/>
|
|
100
|
+
</KContainer.View>
|
|
101
|
+
)}
|
|
102
|
+
</KContainer.View>
|
|
103
|
+
</KContainer.View>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
MentionSuggestionList.displayName = 'MentionSuggestionList';
|
|
109
|
+
|
|
110
|
+
const styles = StyleSheet.create({
|
|
111
|
+
// Shadow lives on its own, non-clipping wrapper — a single view can't
|
|
112
|
+
// both clip to a rounded corner (overflow:'hidden', required below) and
|
|
113
|
+
// cast a shadow, since the clip cuts the shadow off too.
|
|
114
|
+
shadowWrapper: {
|
|
115
|
+
shadowColor: KColors.black,
|
|
116
|
+
shadowOffset: { width: 0, height: -8 },
|
|
117
|
+
shadowOpacity: 0.08,
|
|
118
|
+
shadowRadius: 16,
|
|
119
|
+
elevation: 4,
|
|
120
|
+
},
|
|
121
|
+
container: {
|
|
122
|
+
borderRadius: KSpacingValue['0.75rem'],
|
|
123
|
+
borderTopLeftRadius: KSpacingValue['0.75rem'],
|
|
124
|
+
borderTopRightRadius: KSpacingValue['0.75rem'],
|
|
125
|
+
overflow: 'hidden',
|
|
126
|
+
},
|
|
127
|
+
listWrapper: {
|
|
128
|
+
maxHeight: MAX_PANEL_HEIGHT,
|
|
129
|
+
},
|
|
130
|
+
separator: {
|
|
131
|
+
height: ROW_GAP,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { useState, useMemo, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// 'mention' is used only for mutual-exclusion (closing attachment/sticker
|
|
4
|
+
// when the mention picker opens) — the mention picker itself renders as its
|
|
5
|
+
// own absolutely-positioned sibling in ChatComposer, not through this
|
|
6
|
+
// state's render slot, since it must float above the input while the
|
|
7
|
+
// keyboard stays open (attachment/sticker intentionally take over the
|
|
8
|
+
// keyboard area, which the mention picker must not do).
|
|
9
|
+
export type ActivePanelType = 'attachment' | 'sticker' | 'mention' | null;
|
|
4
10
|
|
|
5
11
|
interface UseChatComposerStateReturn {
|
|
6
12
|
activePanelType: ActivePanelType;
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { TextInput, NativeSyntheticEvent } from 'react-native';
|
|
3
|
+
import type { TextInputSelectionChangeEventData } from 'react-native';
|
|
4
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
5
|
+
import debounce from 'lodash/debounce';
|
|
6
|
+
import {
|
|
7
|
+
applyTextChange,
|
|
8
|
+
findActiveMention,
|
|
9
|
+
insertMention,
|
|
10
|
+
} from '../../../utils/mentions';
|
|
11
|
+
import { trans } from '../../../translation';
|
|
12
|
+
import { mentionQueryKeys } from '../../../hooks/query-keys';
|
|
13
|
+
import type {
|
|
14
|
+
ActiveMention,
|
|
15
|
+
Mention,
|
|
16
|
+
MentionSearchSource,
|
|
17
|
+
MentionSuggestion,
|
|
18
|
+
} from '../../../types/mention';
|
|
19
|
+
|
|
20
|
+
const SEARCH_DEBOUNCE_MS = 200;
|
|
21
|
+
// Matches MentionSuggestionList's MAX_VISIBLE_ROWS — one page fills exactly
|
|
22
|
+
// one screenful of the panel, so scrolling further triggers loadMore instead
|
|
23
|
+
// of over-fetching members the user hasn't scrolled to yet.
|
|
24
|
+
const SEARCH_LIMIT = 4;
|
|
25
|
+
const ALL_MEMBERS_USER_ID = 'ALL';
|
|
26
|
+
|
|
27
|
+
const allMembersSuggestion = (): MentionSuggestion => ({
|
|
28
|
+
userId: ALL_MEMBERS_USER_ID,
|
|
29
|
+
displayName: trans('group:tag_all'),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
interface UseMentionComposerParams {
|
|
33
|
+
text: string;
|
|
34
|
+
setText: (text: string) => void;
|
|
35
|
+
searchSource: MentionSearchSource;
|
|
36
|
+
/** Namespaces the react-query cache per conversation — see the query
|
|
37
|
+
* itself for why this matters even though the hook is expected to remount
|
|
38
|
+
* per chat-detail screen. */
|
|
39
|
+
groupID?: string;
|
|
40
|
+
/** Mention only makes sense in group conversations (tagging a specific
|
|
41
|
+
* other member) — false for 1-1/bot/customer threads disables "@"
|
|
42
|
+
* detection entirely, not just the search results. Without this, typing
|
|
43
|
+
* "@" in a non-group chat would still open the picker (empty, since
|
|
44
|
+
* there's no real MentionSearchSource for it) instead of behaving as a
|
|
45
|
+
* plain character. Defaults to true so existing group-only callers don't
|
|
46
|
+
* need to pass it. */
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
inputRef: React.RefObject<TextInput | null>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface UseMentionComposerReturn {
|
|
52
|
+
mentions: Mention[];
|
|
53
|
+
activeMention: ActiveMention | null;
|
|
54
|
+
suggestions: MentionSuggestion[];
|
|
55
|
+
isSearching: boolean;
|
|
56
|
+
isLoadingMore: boolean;
|
|
57
|
+
hasMore: boolean;
|
|
58
|
+
loadMore: () => void;
|
|
59
|
+
isPanelOpen: boolean;
|
|
60
|
+
handleChangeText: (text?: string) => void;
|
|
61
|
+
handleSelectionChange: (
|
|
62
|
+
event: NativeSyntheticEvent<TextInputSelectionChangeEventData>
|
|
63
|
+
) => void;
|
|
64
|
+
selectSuggestion: (item: MentionSuggestion) => void;
|
|
65
|
+
closeMentionPanel: () => void;
|
|
66
|
+
clear: () => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Orchestrates the @mention composer: wires the pure Phase A1 logic
|
|
71
|
+
* (findActiveMention / applyTextChange / insertMention) and an injected
|
|
72
|
+
* MentionSearchSource into the live TextInput event loop.
|
|
73
|
+
*
|
|
74
|
+
* `text` stays owned by useChatCompose (the existing composer state) — this
|
|
75
|
+
* hook doesn't duplicate it, only mirrors it into a ref for synchronous
|
|
76
|
+
* access within its own event handlers (see textRef below).
|
|
77
|
+
*/
|
|
78
|
+
export function useMentionComposer({
|
|
79
|
+
text,
|
|
80
|
+
setText,
|
|
81
|
+
searchSource,
|
|
82
|
+
groupID,
|
|
83
|
+
enabled = true,
|
|
84
|
+
inputRef,
|
|
85
|
+
}: UseMentionComposerParams): UseMentionComposerReturn {
|
|
86
|
+
const [mentions, setMentions] = useState<Mention[]>([]);
|
|
87
|
+
const [activeMention, setActiveMention] = useState<ActiveMention | null>(
|
|
88
|
+
null
|
|
89
|
+
);
|
|
90
|
+
// The keyword actually being searched for — distinct from
|
|
91
|
+
// activeMention.keyword, which updates on every keystroke. This only
|
|
92
|
+
// changes 200ms after typing pauses (see debouncedSetKeywordRef below),
|
|
93
|
+
// and IS the react-query key: typing further characters within the debounce
|
|
94
|
+
// window never touches the query at all, so the previous page's results
|
|
95
|
+
// stay on screen with zero flicker until the debounce actually fires.
|
|
96
|
+
// null means "no active search" (panel closed) — distinct from '' (an
|
|
97
|
+
// active search for the empty keyword, which also lists all members).
|
|
98
|
+
const [debouncedKeyword, setDebouncedKeyword] = useState<string | null>(null);
|
|
99
|
+
|
|
100
|
+
// Synchronous mirrors of the externally-owned `text` and internally-owned
|
|
101
|
+
// `mentions` state. React state updates aren't visible until the next
|
|
102
|
+
// render, but applyTextChange needs the *actual* latest committed values
|
|
103
|
+
// within the same tick a keystroke is processed — these refs are updated
|
|
104
|
+
// in lockstep with every setText/setMentions call below so they never lag.
|
|
105
|
+
const textRef = useRef(text);
|
|
106
|
+
const mentionsRef = useRef<Mention[]>([]);
|
|
107
|
+
const activeMentionRef = useRef<ActiveMention | null>(null);
|
|
108
|
+
|
|
109
|
+
const searchSourceRef = useRef(searchSource);
|
|
110
|
+
searchSourceRef.current = searchSource;
|
|
111
|
+
|
|
112
|
+
const enabledRef = useRef(enabled);
|
|
113
|
+
enabledRef.current = enabled;
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
// External text changes not driven by this hook (e.g. clearing the
|
|
117
|
+
// composer after send) — keep the mirror and mention state in sync.
|
|
118
|
+
if (text !== textRef.current) {
|
|
119
|
+
textRef.current = text;
|
|
120
|
+
if (text === '') {
|
|
121
|
+
mentionsRef.current = [];
|
|
122
|
+
setMentions([]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, [text]);
|
|
126
|
+
|
|
127
|
+
const debouncedSetKeywordRef = useRef(
|
|
128
|
+
debounce(
|
|
129
|
+
(keyword: string) => setDebouncedKeyword(keyword),
|
|
130
|
+
SEARCH_DEBOUNCE_MS,
|
|
131
|
+
{ leading: false, trailing: true }
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
useEffect(() => () => debouncedSetKeywordRef.current.cancel(), []);
|
|
135
|
+
|
|
136
|
+
const isActiveSearch = debouncedKeyword !== null;
|
|
137
|
+
|
|
138
|
+
const { data, isFetching, isFetchingNextPage, hasNextPage, fetchNextPage } =
|
|
139
|
+
useInfiniteQuery({
|
|
140
|
+
queryKey: mentionQueryKeys.search(groupID ?? '', debouncedKeyword ?? ''),
|
|
141
|
+
queryFn: ({ pageParam }) =>
|
|
142
|
+
searchSourceRef.current.search({
|
|
143
|
+
keyword: debouncedKeyword ?? '',
|
|
144
|
+
limit: SEARCH_LIMIT,
|
|
145
|
+
offset: pageParam,
|
|
146
|
+
}),
|
|
147
|
+
// Neither getGroupMemberList nor searchGroupMembers returns a total, so
|
|
148
|
+
// "is there a next page" is inferred from page size (see
|
|
149
|
+
// MentionSearchResult.hasMore's doc comment) instead of an exact count.
|
|
150
|
+
getNextPageParam: (lastPage, allPages) =>
|
|
151
|
+
lastPage.hasMore
|
|
152
|
+
? allPages.reduce((sum, p) => sum + p.items.length, 0)
|
|
153
|
+
: undefined,
|
|
154
|
+
initialPageParam: 0,
|
|
155
|
+
enabled: isActiveSearch,
|
|
156
|
+
// Deliberately no maxPages cap — this is a scrolling picker, not a
|
|
157
|
+
// one-shot search; capping pages would drop already-loaded members as
|
|
158
|
+
// the user scrolls further, which is a worse experience than the memory
|
|
159
|
+
// cost of keeping them.
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const includeAll = debouncedKeyword === '';
|
|
163
|
+
const suggestions = useMemo(() => {
|
|
164
|
+
const items = data?.pages.flatMap((page) => page.items) ?? [];
|
|
165
|
+
return includeAll ? [allMembersSuggestion(), ...items] : items;
|
|
166
|
+
}, [data, includeAll]);
|
|
167
|
+
|
|
168
|
+
const loadMore = useCallback(() => {
|
|
169
|
+
if (!isActiveSearch || !hasNextPage || isFetchingNextPage) return;
|
|
170
|
+
fetchNextPage();
|
|
171
|
+
}, [isActiveSearch, hasNextPage, isFetchingNextPage, fetchNextPage]);
|
|
172
|
+
|
|
173
|
+
const updateActiveMentionAndSearch = useCallback(
|
|
174
|
+
(currentText: string, cursor: number) => {
|
|
175
|
+
// Non-group conversation — "@" is a plain character, never a trigger.
|
|
176
|
+
// Checked here (not just left to the search source returning empty)
|
|
177
|
+
// so the picker UI never opens at all in this case.
|
|
178
|
+
const active = enabledRef.current
|
|
179
|
+
? findActiveMention(currentText, cursor)
|
|
180
|
+
: null;
|
|
181
|
+
activeMentionRef.current = active;
|
|
182
|
+
setActiveMention(active);
|
|
183
|
+
|
|
184
|
+
if (!active) {
|
|
185
|
+
debouncedSetKeywordRef.current.cancel();
|
|
186
|
+
// Functional updater so an already-null value doesn't force a
|
|
187
|
+
// render on every ordinary keystroke (the common case).
|
|
188
|
+
setDebouncedKeyword((prev) => (prev === null ? prev : null));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
debouncedSetKeywordRef.current(active.keyword);
|
|
193
|
+
},
|
|
194
|
+
[]
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// Simplified from an earlier microtask-buffered design (see git history /
|
|
198
|
+
// plan doc for why that existed) after it caused a real, reproduced
|
|
199
|
+
// "Maximum update depth exceeded" loop in production testing. Root cause
|
|
200
|
+
// wasn't fully isolated without device logs, but the buffering added a
|
|
201
|
+
// second, redundant path (onSelectionChange re-running mention detection
|
|
202
|
+
// with native selection data that could be stale relative to the edit
|
|
203
|
+
// onChangeText had just processed) that could set state back and forth.
|
|
204
|
+
// applyTextChange already derives an authoritative cursor from the text
|
|
205
|
+
// diff itself — it never needed to wait for onSelectionChange for the
|
|
206
|
+
// edit case, so handling each event directly, synchronously, removes an
|
|
207
|
+
// entire dimension of timing uncertainty instead of trying to patch it.
|
|
208
|
+
const handleChangeText = useCallback(
|
|
209
|
+
(nextText?: string) => {
|
|
210
|
+
const nextTextRaw = nextText ?? '';
|
|
211
|
+
const previousText = textRef.current;
|
|
212
|
+
if (nextTextRaw === previousText) return;
|
|
213
|
+
|
|
214
|
+
const result = applyTextChange(
|
|
215
|
+
previousText,
|
|
216
|
+
mentionsRef.current,
|
|
217
|
+
nextTextRaw
|
|
218
|
+
);
|
|
219
|
+
textRef.current = result.text;
|
|
220
|
+
mentionsRef.current = result.mentions;
|
|
221
|
+
setText(result.text);
|
|
222
|
+
setMentions(result.mentions);
|
|
223
|
+
|
|
224
|
+
if (result.mentionRemoved) {
|
|
225
|
+
// The native buffer currently shows nextTextRaw, not our corrected
|
|
226
|
+
// result.text — force the cursor back to a position that's valid
|
|
227
|
+
// once React re-renders the controlled value.
|
|
228
|
+
requestAnimationFrame(() => {
|
|
229
|
+
inputRef.current?.setSelection(result.cursor, result.cursor);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
updateActiveMentionAndSearch(result.text, result.cursor);
|
|
234
|
+
},
|
|
235
|
+
[inputRef, setText, updateActiveMentionAndSearch]
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// Only meaningful for a pure cursor move with NO accompanying text change
|
|
239
|
+
// (tap elsewhere in the draft, arrow keys) — an edit's cursor is already
|
|
240
|
+
// handled authoritatively inside handleChangeText above. Deliberately
|
|
241
|
+
// does not re-run search/active-mention detection here to avoid the
|
|
242
|
+
// redundant double-handling that caused the loop this replaced.
|
|
243
|
+
const handleSelectionChange = useCallback(
|
|
244
|
+
(event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
|
|
245
|
+
const selection = event.nativeEvent.selection;
|
|
246
|
+
if (selection.start !== selection.end) return;
|
|
247
|
+
if (selection.start === textRef.current.length) return; // typical post-edit echo, already handled
|
|
248
|
+
|
|
249
|
+
updateActiveMentionAndSearch(textRef.current, selection.start);
|
|
250
|
+
},
|
|
251
|
+
[updateActiveMentionAndSearch]
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
const selectSuggestion = useCallback(
|
|
255
|
+
(item: MentionSuggestion) => {
|
|
256
|
+
const active = activeMentionRef.current;
|
|
257
|
+
if (!active) return;
|
|
258
|
+
|
|
259
|
+
const result = insertMention(
|
|
260
|
+
textRef.current,
|
|
261
|
+
mentionsRef.current,
|
|
262
|
+
active,
|
|
263
|
+
{
|
|
264
|
+
userId: item.userId,
|
|
265
|
+
displayName: item.displayName,
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
textRef.current = result.text;
|
|
270
|
+
mentionsRef.current = result.mentions;
|
|
271
|
+
setText(result.text);
|
|
272
|
+
setMentions(result.mentions);
|
|
273
|
+
activeMentionRef.current = null;
|
|
274
|
+
setActiveMention(null);
|
|
275
|
+
debouncedSetKeywordRef.current.cancel();
|
|
276
|
+
setDebouncedKeyword(null);
|
|
277
|
+
|
|
278
|
+
requestAnimationFrame(() => {
|
|
279
|
+
inputRef.current?.setSelection(result.cursor, result.cursor);
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
[inputRef, setText]
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Called by ChatComposer when the user explicitly opens the
|
|
286
|
+
// attachment/sticker panel while a mention query is active — the mutual
|
|
287
|
+
// exclusion works both directions: opening mention closes attachment/
|
|
288
|
+
// sticker (ChatComposer's own handlers already do that reactively, see
|
|
289
|
+
// the effect wired there), and this closes mention when the user
|
|
290
|
+
// deliberately switches to a different panel.
|
|
291
|
+
const closeMentionPanel = useCallback(() => {
|
|
292
|
+
activeMentionRef.current = null;
|
|
293
|
+
setActiveMention(null);
|
|
294
|
+
debouncedSetKeywordRef.current.cancel();
|
|
295
|
+
setDebouncedKeyword(null);
|
|
296
|
+
}, []);
|
|
297
|
+
|
|
298
|
+
// Defensive: if `enabled` ever flips false while a mention query happens
|
|
299
|
+
// to be open (e.g. conversation type resolves after mount), close it
|
|
300
|
+
// immediately rather than leaving a stale picker for a thread that
|
|
301
|
+
// shouldn't have one at all.
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
if (!enabled) closeMentionPanel();
|
|
304
|
+
// closeMentionPanel is stable ([] deps) — listing it here doesn't cause
|
|
305
|
+
// extra runs, it just keeps the deps array honest instead of suppressing
|
|
306
|
+
// the lint rule.
|
|
307
|
+
}, [enabled, closeMentionPanel]);
|
|
308
|
+
|
|
309
|
+
// Called explicitly by ChatComposer right when it clears the composer
|
|
310
|
+
// after send. The existing `useEffect` watching the `text` prop *would*
|
|
311
|
+
// eventually sync mentions to [] once `compose.setText('')` propagates
|
|
312
|
+
// down as a new `text` prop — but that's a render later, and in between
|
|
313
|
+
// there's a real transient bug: `value` is already '' while `mentions`
|
|
314
|
+
// still holds the old (now-stale) entries, and tokenize('', oldMentions)
|
|
315
|
+
// happily emits a mention segment anchored past the end of an empty
|
|
316
|
+
// string — a "ghost" mention with no surrounding text. Clearing
|
|
317
|
+
// synchronously here, in the same tick as setText(''), removes that
|
|
318
|
+
// window entirely instead of just shrinking it.
|
|
319
|
+
const clear = useCallback(() => {
|
|
320
|
+
textRef.current = '';
|
|
321
|
+
mentionsRef.current = [];
|
|
322
|
+
activeMentionRef.current = null;
|
|
323
|
+
setMentions([]);
|
|
324
|
+
setActiveMention(null);
|
|
325
|
+
debouncedSetKeywordRef.current.cancel();
|
|
326
|
+
setDebouncedKeyword(null);
|
|
327
|
+
}, []);
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
mentions,
|
|
331
|
+
activeMention,
|
|
332
|
+
suggestions,
|
|
333
|
+
isSearching: isActiveSearch && isFetching && !isFetchingNextPage,
|
|
334
|
+
isLoadingMore: isFetchingNextPage,
|
|
335
|
+
hasMore: !!hasNextPage,
|
|
336
|
+
loadMore,
|
|
337
|
+
isPanelOpen: activeMention !== null,
|
|
338
|
+
handleChangeText,
|
|
339
|
+
handleSelectionChange,
|
|
340
|
+
selectSuggestion,
|
|
341
|
+
closeMentionPanel,
|
|
342
|
+
clear,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
@@ -137,8 +137,14 @@ export const LegendChatMessage = memo(
|
|
|
137
137
|
|
|
138
138
|
const hasMediaPress =
|
|
139
139
|
MEDIA_TYPES.includes(message?.contentType) && onMediaPress;
|
|
140
|
+
// AtTextMessage included: mention+URL combo attaches its link-preview
|
|
141
|
+
// card via ex.urlMetadata on an AtTextMessage (see TextMessage's doc
|
|
142
|
+
// comment) instead of a dedicated UrlTextMessage — the card still needs
|
|
143
|
+
// a tap handler.
|
|
140
144
|
const hasUrlPress =
|
|
141
|
-
onPressUrl &&
|
|
145
|
+
onPressUrl &&
|
|
146
|
+
(message?.contentType === MessageType.UrlTextMessage ||
|
|
147
|
+
message?.contentType === MessageType.AtTextMessage);
|
|
142
148
|
|
|
143
149
|
return (
|
|
144
150
|
<KContainer.View style={messageStyles.wrapper} row alignItems>
|
|
@@ -35,11 +35,19 @@ export const MessageToolboxWrapper = memo(
|
|
|
35
35
|
toolbox,
|
|
36
36
|
}: MessageToolboxWrapperProps) => {
|
|
37
37
|
const insets = useSafeAreaInsets();
|
|
38
|
+
const messageHeight = useSharedValue(0);
|
|
38
39
|
const reactionHeight = useSharedValue(0);
|
|
39
40
|
const toolboxHeight = useSharedValue(0);
|
|
40
41
|
const topOffset = Platform.OS === 'android' ? insets.top : 0;
|
|
41
42
|
const { height: windowHeight } = useWindowDimensions();
|
|
42
43
|
|
|
44
|
+
const onMessageCloneLayout = useCallback(
|
|
45
|
+
({ nativeEvent }: LayoutChangeEvent) => {
|
|
46
|
+
messageHeight.value = nativeEvent.layout.height;
|
|
47
|
+
},
|
|
48
|
+
[messageHeight]
|
|
49
|
+
);
|
|
50
|
+
|
|
43
51
|
const onToolboxLayout = useCallback(
|
|
44
52
|
({ nativeEvent }: LayoutChangeEvent) => {
|
|
45
53
|
toolboxHeight.value = nativeEvent.layout.height;
|
|
@@ -62,7 +70,7 @@ export const MessageToolboxWrapper = memo(
|
|
|
62
70
|
const overflowBottom =
|
|
63
71
|
Math.max(rect.y, insets.top) +
|
|
64
72
|
topOffset +
|
|
65
|
-
|
|
73
|
+
messageHeight.value +
|
|
66
74
|
toolboxHeight.value +
|
|
67
75
|
(insets.bottom || 32) +
|
|
68
76
|
menuGap -
|
|
@@ -89,9 +97,19 @@ export const MessageToolboxWrapper = memo(
|
|
|
89
97
|
containerStyles,
|
|
90
98
|
]}
|
|
91
99
|
>
|
|
92
|
-
<View
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
<View
|
|
101
|
+
pointerEvents="none"
|
|
102
|
+
collapsable={false}
|
|
103
|
+
onLayout={onMessageCloneLayout}
|
|
104
|
+
>
|
|
105
|
+
{message}
|
|
106
|
+
</View>
|
|
107
|
+
<View collapsable={false} onLayout={onReactionLayout}>
|
|
108
|
+
{reaction}
|
|
109
|
+
</View>
|
|
110
|
+
<View collapsable={false} onLayout={onToolboxLayout}>
|
|
111
|
+
{toolbox}
|
|
112
|
+
</View>
|
|
95
113
|
</Animated.View>
|
|
96
114
|
);
|
|
97
115
|
}
|
|
@@ -39,6 +39,7 @@ export const ENDPOINTS = {
|
|
|
39
39
|
`${getApiEndpoint('stickersByCategory')}/${id}/stickers`,
|
|
40
40
|
stickerHistory: () => getApiEndpoint('stickerHistory'),
|
|
41
41
|
searchMessages: () => `${getApiEndpoint('messages')}/search`,
|
|
42
|
+
searchContacts: () => `${getApiEndpoint('contacts')}/search`,
|
|
42
43
|
},
|
|
43
44
|
uploaderService: {
|
|
44
45
|
get uploadImage() {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import OpenIMSDK, {
|
|
2
|
+
GroupMemberFilter,
|
|
3
|
+
type GroupMemberItem,
|
|
4
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
5
|
+
import type {
|
|
6
|
+
MentionSearchResult,
|
|
7
|
+
MentionSearchSource,
|
|
8
|
+
MentionSuggestion,
|
|
9
|
+
} from '../types/mention';
|
|
10
|
+
|
|
11
|
+
const toSuggestion = (member: GroupMemberItem): MentionSuggestion => ({
|
|
12
|
+
userId: member.userID,
|
|
13
|
+
displayName: member.nickname,
|
|
14
|
+
avatar: member.faceURL,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Concrete MentionSearchSource implementation for Part A's mention
|
|
19
|
+
* composer, wrapping the OpenIM SDK's group-member primitives — 0 call
|
|
20
|
+
* sites anywhere else in this repo before this feature. Empty keyword ->
|
|
21
|
+
* the full/initial member list (getGroupMemberList); non-empty keyword ->
|
|
22
|
+
* server-backed search (searchGroupMembers), purpose-built for this case.
|
|
23
|
+
*
|
|
24
|
+
* Neither SDK call returns a total count, so `hasMore` is inferred from
|
|
25
|
+
* page size (a full page *might* mean there's another one) — the same
|
|
26
|
+
* heuristic every offset/count-paginated list in this codebase already
|
|
27
|
+
* relies on, since OpenIM doesn't expose a cheaper alternative here.
|
|
28
|
+
*/
|
|
29
|
+
export function createOpenIMMentionSearchSource(
|
|
30
|
+
groupID: string
|
|
31
|
+
): MentionSearchSource {
|
|
32
|
+
return {
|
|
33
|
+
async search({ keyword, limit, offset }): Promise<MentionSearchResult> {
|
|
34
|
+
const members =
|
|
35
|
+
keyword === ''
|
|
36
|
+
? await OpenIMSDK.getGroupMemberList({
|
|
37
|
+
groupID,
|
|
38
|
+
filter: GroupMemberFilter.All,
|
|
39
|
+
offset,
|
|
40
|
+
count: limit,
|
|
41
|
+
})
|
|
42
|
+
: await OpenIMSDK.searchGroupMembers({
|
|
43
|
+
groupID,
|
|
44
|
+
keywordList: [keyword],
|
|
45
|
+
isSearchUserID: false,
|
|
46
|
+
isSearchMemberNickname: true,
|
|
47
|
+
offset,
|
|
48
|
+
count: limit,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
items: members.map(toSuggestion),
|
|
53
|
+
hasMore: members.length === limit,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
package/src/services/message.ts
CHANGED
|
@@ -67,7 +67,15 @@ export namespace ChatMessageAPI {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export async function markConversationAsRead(conversationID: string) {
|
|
70
|
-
|
|
70
|
+
// resetConversationGroupAtType clears the "@ mention" flag
|
|
71
|
+
// (ConversationItem.groupAtType) — the core SDK never resets it on its
|
|
72
|
+
// own (confirmed: markConversationMessageAsRead only zeroes
|
|
73
|
+
// unreadCount), so it has to be requested explicitly at the same
|
|
74
|
+
// "user is caught up on this conversation" moment as the read marker.
|
|
75
|
+
return Promise.all([
|
|
76
|
+
OpenIMSDK.markConversationMessageAsRead(conversationID),
|
|
77
|
+
OpenIMSDK.resetConversationGroupAtType(conversationID),
|
|
78
|
+
]);
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
export async function getCurrentUserId() {
|
|
@@ -188,7 +188,13 @@ const i18nKey: Record<string, string> = {
|
|
|
188
188
|
'Bạn có thể tìm kiếm theo liên hệ hoặc nội dung tin nhắn',
|
|
189
189
|
'search_message:empty_hint': 'Bạn có thể tìm kiếm theo nội dung tin nhắn',
|
|
190
190
|
'search_conversation:empty_hint': 'Bạn có thể tìm kiếm theo liên hệ',
|
|
191
|
+
'search_community:empty_hint': 'Bạn có thể tìm kiếm theo tên nhóm cộng đồng',
|
|
191
192
|
'view_all': 'Xem tất cả',
|
|
193
|
+
'contact_type:customer': 'Khách hàng',
|
|
194
|
+
'contact_type:pdp': 'PDP',
|
|
195
|
+
'contact_type:group': 'Nhóm',
|
|
196
|
+
'contact_type:seller': 'Người bán',
|
|
197
|
+
'group:no_description': 'Chưa có mô tả nhóm',
|
|
192
198
|
'search_message:revoked_message': 'Tin nhắn đã được thu hồi',
|
|
193
199
|
'chat:no_permission': 'Bạn không có quyền này',
|
|
194
200
|
'chat:no_send_permission': 'Bạn không có quyền gửi tin nhắn',
|
|
@@ -209,6 +215,12 @@ const i18nKey: Record<string, string> = {
|
|
|
209
215
|
'group:dismiss_confirm_primary': 'Giải tán',
|
|
210
216
|
'group:dismiss_confirm_secondary': 'Quay lại',
|
|
211
217
|
'group:dismiss_toast_success': 'Đã giải tán nhóm',
|
|
218
|
+
'group:tag_title': 'Nhắc đến',
|
|
219
|
+
'group:tag_all': 'Tất cả',
|
|
220
|
+
'group:tag_all_desc': 'Nhắc đến tất cả thành viên',
|
|
221
|
+
'group:tag_no_member_found': 'Không tìm thấy thành viên nào',
|
|
222
|
+
'group:tag_limit_exceeded':
|
|
223
|
+
'Chỉ {{max}} người được nhắc đến đầu tiên sẽ nhận được thông báo',
|
|
212
224
|
'group:access_blocked_title': 'Không thể xem cuộc trò chuyện này',
|
|
213
225
|
'group:access_blocked_desc':
|
|
214
226
|
'Bạn hiện không có quyền truy cập vào cuộc trò chuyện hoặc tin nhắn này.',
|