@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
package/src/types/chat.ts
CHANGED
|
@@ -160,6 +160,12 @@ export interface DConversationQueryParams {
|
|
|
160
160
|
pageSize: number;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
export interface ISerializedMentionEx {
|
|
164
|
+
userID: string;
|
|
165
|
+
offset: number;
|
|
166
|
+
length: number;
|
|
167
|
+
}
|
|
168
|
+
|
|
163
169
|
export interface IMessageItemEx {
|
|
164
170
|
applicationType: DChatApplicationType;
|
|
165
171
|
sessionId?: string;
|
|
@@ -171,6 +177,22 @@ export interface IMessageItemEx {
|
|
|
171
177
|
urlMetadata?: IUrlMetadata;
|
|
172
178
|
flow?: IRunConversationFlowPayload;
|
|
173
179
|
stickerId?: string;
|
|
180
|
+
/**
|
|
181
|
+
* @mention ranges, riding in this app-defined `ex` channel because
|
|
182
|
+
* OpenIM's own AtTextElem/AtMsgParams carry no per-mention offset/length
|
|
183
|
+
* — just a flat atUserIDList/atUsersInfo. Render logic prefers this
|
|
184
|
+
* (exact) and falls back to searching AtTextElem.text for
|
|
185
|
+
* "@{groupNickname}" per atUsersInfo entry when absent (interop safety
|
|
186
|
+
* net — see mentionSerializer.ts deserializeMentionRanges).
|
|
187
|
+
*
|
|
188
|
+
* Wrapped under `offsets` (not a bare array) to match the wire shape
|
|
189
|
+
* already sent by other Droppii clients (confirmed against a real
|
|
190
|
+
* message from the web/CRM client, `applicationType: "OBEFE"`:
|
|
191
|
+
* `ex.mentions = { offsets: [{userID, offset, length}, ...] }`). Offset
|
|
192
|
+
* units matched too (UTF-16 code units) — verified against a real
|
|
193
|
+
* Vietnamese-diacritic payload, no cross-client encoding mismatch.
|
|
194
|
+
*/
|
|
195
|
+
mentions?: { offsets: ISerializedMentionEx[] };
|
|
174
196
|
}
|
|
175
197
|
|
|
176
198
|
export interface IGetMessagesParams {
|
|
@@ -341,3 +363,33 @@ export interface ISearchMessageItem {
|
|
|
341
363
|
chatLog: MessageItem;
|
|
342
364
|
conversation: ConversationItem;
|
|
343
365
|
}
|
|
366
|
+
|
|
367
|
+
export enum ContactCategory {
|
|
368
|
+
Customer = 'CUSTOMER',
|
|
369
|
+
Pdp = 'PDP_BOT',
|
|
370
|
+
Group = 'GROUP',
|
|
371
|
+
Seller = 'USER',
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export type IContactSearchRequest = {
|
|
375
|
+
applicationType: DChatApplicationType;
|
|
376
|
+
searchTerm: string;
|
|
377
|
+
page: number;
|
|
378
|
+
pageSize: number;
|
|
379
|
+
type?: ContactCategory;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export interface IContactSearchItem {
|
|
383
|
+
id: string;
|
|
384
|
+
type: ContactCategory;
|
|
385
|
+
targetUserId?: string;
|
|
386
|
+
targetCustomerId?: string;
|
|
387
|
+
targetGroupId?: string;
|
|
388
|
+
targetBotId?: string;
|
|
389
|
+
targetName: string;
|
|
390
|
+
targetAvatar?: string;
|
|
391
|
+
applicationType: DChatApplicationType;
|
|
392
|
+
lastOnlineTime?: string;
|
|
393
|
+
memberCount?: number;
|
|
394
|
+
description?: string;
|
|
395
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mention composer types.
|
|
3
|
+
*
|
|
4
|
+
* All offsets throughout this module are raw JS string indices (UTF-16 code
|
|
5
|
+
* units) — the same unit RN's TextInput selection/cursor API uses on both
|
|
6
|
+
* platforms. This is a deliberate choice, not a default: it means offsets
|
|
7
|
+
* never need conversion at the RN boundary, at the cost of requiring
|
|
8
|
+
* surrogate-pair-aware handling wherever text is diffed (see mentionDiff.ts).
|
|
9
|
+
* AT Protocol-style byte offsets are unnecessary here because this data
|
|
10
|
+
* never crosses a non-JS boundary — see mentionSerializer.ts.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface Selection {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A committed mention: created only by explicit picker selection
|
|
20
|
+
* (insertMention), never inferred from text content. [start, end) excludes
|
|
21
|
+
* the trailing separator space inserted after the display name — see
|
|
22
|
+
* insertMention's doc comment for why.
|
|
23
|
+
*/
|
|
24
|
+
export interface Mention {
|
|
25
|
+
id: string;
|
|
26
|
+
userId: string;
|
|
27
|
+
displayName: string;
|
|
28
|
+
start: number;
|
|
29
|
+
end: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The in-progress, uncommitted "@query" at the cursor. Freely editable
|
|
34
|
+
* character-by-character — never atomic, never promoted to a Mention except
|
|
35
|
+
* through explicit selection from the suggestion list.
|
|
36
|
+
*/
|
|
37
|
+
export interface ActiveMention {
|
|
38
|
+
trigger: '@';
|
|
39
|
+
start: number;
|
|
40
|
+
end: number;
|
|
41
|
+
keyword: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface MentionSuggestion {
|
|
45
|
+
userId: string;
|
|
46
|
+
displayName: string;
|
|
47
|
+
avatar?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The boundary between Part A (composer, no concrete OpenIM dependency) and
|
|
52
|
+
* Part B (OpenIM SDK integration). Part A depends only on this type,
|
|
53
|
+
* injected; Part B's `openIMMentionSearchSource` (src/services/mentionSearch.ts)
|
|
54
|
+
* implements it against the real SDK. Defined here, in Part A's own types
|
|
55
|
+
* file, rather than in the Part B service file, so the dependency direction
|
|
56
|
+
* stays correct: Part A defines the contract, Part B implements it.
|
|
57
|
+
*/
|
|
58
|
+
export interface MentionSearchResult {
|
|
59
|
+
items: MentionSuggestion[];
|
|
60
|
+
/** True when `items.length === limit` — a same-size next page may exist. */
|
|
61
|
+
hasMore: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface MentionSearchSource {
|
|
65
|
+
search(params: {
|
|
66
|
+
keyword: string;
|
|
67
|
+
limit: number;
|
|
68
|
+
offset: number;
|
|
69
|
+
}): Promise<MentionSearchResult>;
|
|
70
|
+
}
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
* Date and time formatting utilities
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
7
|
+
import 'dayjs/locale/vi';
|
|
8
|
+
|
|
9
|
+
dayjs.extend(relativeTime);
|
|
10
|
+
|
|
5
11
|
export const formatDuration = (durationMs: number): string => {
|
|
6
12
|
// Convert milliseconds to seconds
|
|
7
13
|
const totalSeconds = Math.floor(durationMs / 1000);
|
|
@@ -46,3 +52,12 @@ export const formatTimestamp = (ts: number | string | null): string => {
|
|
|
46
52
|
return '';
|
|
47
53
|
}
|
|
48
54
|
};
|
|
55
|
+
|
|
56
|
+
export const formatLastOnlineTime = (ts: number | string | null): string => {
|
|
57
|
+
if (!ts) return '';
|
|
58
|
+
|
|
59
|
+
const date = dayjs(ts).locale('vi');
|
|
60
|
+
if (!date.isValid()) return '';
|
|
61
|
+
|
|
62
|
+
return date.fromNow();
|
|
63
|
+
};
|
|
@@ -4,6 +4,16 @@ export interface HighlightResult {
|
|
|
4
4
|
after: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
// Strips Vietnamese diacritics one base-character-at-a-time (NFD decomposition +
|
|
8
|
+
// combining-mark removal, plus đ/Đ which NFD doesn't decompose) so the result stays
|
|
9
|
+
// the same length and index-aligned with the input
|
|
10
|
+
const stripDiacritics = (input: string): string =>
|
|
11
|
+
input
|
|
12
|
+
.normalize('NFD')
|
|
13
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
14
|
+
.replace(/đ/g, 'd')
|
|
15
|
+
.replace(/Đ/g, 'D');
|
|
16
|
+
|
|
7
17
|
export const highlightSearch = (
|
|
8
18
|
text: string,
|
|
9
19
|
keyword: string,
|
|
@@ -11,8 +21,8 @@ export const highlightSearch = (
|
|
|
11
21
|
): HighlightResult | null => {
|
|
12
22
|
if (!keyword) return null;
|
|
13
23
|
|
|
14
|
-
const lowerText = text.toLowerCase();
|
|
15
|
-
const lowerKeyword = keyword.toLowerCase();
|
|
24
|
+
const lowerText = stripDiacritics(text.toLowerCase());
|
|
25
|
+
const lowerKeyword = stripDiacritics(keyword.toLowerCase());
|
|
16
26
|
const index = lowerText.indexOf(lowerKeyword);
|
|
17
27
|
|
|
18
28
|
if (index === -1) return null;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { AtUsersInfoItem } from '@droppii/openim-rn-client-sdk';
|
|
2
|
+
import type { ISerializedMentionEx } from '../types/chat';
|
|
3
|
+
import type { Mention } from '../types/mention';
|
|
4
|
+
|
|
5
|
+
/** Composer-internal marker for the "Tất cả" suggestion row / a committed
|
|
6
|
+
* "tag everyone" Mention — never sent on the wire, see AT_ALL_TAG below. */
|
|
7
|
+
export const ALL_MEMBERS_USER_ID = 'ALL';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* OpenIM's own protocol sentinel for "everyone in the group", used inside
|
|
11
|
+
* atUserIDList in place of enumerating every member. Confirmed against
|
|
12
|
+
* openimsdk-core (pkg/constant/constant.go:242 — `AtAllString = "AtAllTag"`,
|
|
13
|
+
* exposed client-side as `GetAtAllTag()`) and openim-server's group-message
|
|
14
|
+
* send path (internal/rpc/msg/send.go's `setConversationAtInfo`), which
|
|
15
|
+
* special-cases exactly this string and does the "who is everyone right
|
|
16
|
+
* now" resolution itself, server-side.
|
|
17
|
+
*
|
|
18
|
+
* This is why "Tất cả" must serialize to this one token instead of
|
|
19
|
+
* expanding to every resolved member's userID client-side (the previous
|
|
20
|
+
* approach): the Go core's CreateTextAtMessage hard-rejects any
|
|
21
|
+
* atUserIDList longer than 10 entries regardless of group size
|
|
22
|
+
* (openimsdk-core/internal/conversation_msg/create_message.go:80-82) — a
|
|
23
|
+
* >10-member group's "Tất cả" silently failed to send at all. Sending just
|
|
24
|
+
* `[AT_ALL_TAG]` keeps atUserIDList small no matter the group size, and is
|
|
25
|
+
* also the behavior the protocol actually expects.
|
|
26
|
+
*/
|
|
27
|
+
export const AT_ALL_TAG = 'AtAllTag';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* OpenIM's Go core hard-rejects any AtMsgParams.atUserIDList longer than
|
|
31
|
+
* this (openimsdk-core/internal/conversation_msg/create_message.go:80-82,
|
|
32
|
+
* `if len(userIDList) > 10 { return nil, sdkerrs.ErrArgs }`) — not
|
|
33
|
+
* adjustable client-side. "Tất cả" no longer risks this (see AT_ALL_TAG),
|
|
34
|
+
* but tagging more than 10 *individual* members in one message still
|
|
35
|
+
* would, so serializeMentionsForSend caps atUserIDList/atUsersInfo at this
|
|
36
|
+
* count (keeping the first MAX_AT_USER_COUNT, in mention order) rather
|
|
37
|
+
* than letting the send fail outright the way "Tất cả" used to.
|
|
38
|
+
*/
|
|
39
|
+
export const MAX_AT_USER_COUNT = 10;
|
|
40
|
+
|
|
41
|
+
export interface SerializedMentions {
|
|
42
|
+
atUserIDList: string[];
|
|
43
|
+
atUsersInfo: AtUsersInfoItem[];
|
|
44
|
+
exMentions: ISerializedMentionEx[];
|
|
45
|
+
/**
|
|
46
|
+
* True when more than MAX_AT_USER_COUNT distinct users were mentioned —
|
|
47
|
+
* atUserIDList/atUsersInfo were capped to the first MAX_AT_USER_COUNT (in
|
|
48
|
+
* mention order) so the send doesn't hit the Go core's hard rejection.
|
|
49
|
+
* `exMentions` is deliberately NOT capped: every mention still renders
|
|
50
|
+
* highlighted in the sent text (the sender sees what they typed), only
|
|
51
|
+
* native tag/notify is limited to the first MAX_AT_USER_COUNT. Callers
|
|
52
|
+
* use this flag to warn the user, not to block the send.
|
|
53
|
+
*/
|
|
54
|
+
truncated: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Translates the composer's Mention[] (client-side ranges) into OpenIM's
|
|
59
|
+
* wire shapes for createTextAtMessage, plus our own ex.mentions channel. No
|
|
60
|
+
* group-member resolution needed here (or by the caller) any more — see
|
|
61
|
+
* AT_ALL_TAG's doc comment for why a "Tất cả" mention maps to that single
|
|
62
|
+
* sentinel rather than a per-member list.
|
|
63
|
+
*/
|
|
64
|
+
export function serializeMentionsForSend(
|
|
65
|
+
mentions: Mention[]
|
|
66
|
+
): SerializedMentions {
|
|
67
|
+
const wireUserId = (m: Mention) =>
|
|
68
|
+
m.userId === ALL_MEMBERS_USER_ID ? AT_ALL_TAG : m.userId;
|
|
69
|
+
|
|
70
|
+
const exMentions: ISerializedMentionEx[] = mentions.map((m) => ({
|
|
71
|
+
userID: wireUserId(m),
|
|
72
|
+
offset: m.start,
|
|
73
|
+
length: m.end - m.start,
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
// Map dedupes by userID — e.g. "Tất cả" and an individually-tagged member
|
|
77
|
+
// both present in the same message only produce one atUserIDList entry
|
|
78
|
+
// each, not duplicates. Insertion order == mention order, which is what
|
|
79
|
+
// makes "keep the first MAX_AT_USER_COUNT" below well-defined.
|
|
80
|
+
const nicknameByUserId = new Map<string, string>();
|
|
81
|
+
for (const m of mentions) {
|
|
82
|
+
nicknameByUserId.set(wireUserId(m), m.displayName);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const allEntries = [...nicknameByUserId.entries()];
|
|
86
|
+
const truncated = allEntries.length > MAX_AT_USER_COUNT;
|
|
87
|
+
const cappedEntries = truncated
|
|
88
|
+
? allEntries.slice(0, MAX_AT_USER_COUNT)
|
|
89
|
+
: allEntries;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
atUserIDList: cappedEntries.map(([atUserID]) => atUserID),
|
|
93
|
+
atUsersInfo: cappedEntries.map(([atUserID, groupNickname]) => ({
|
|
94
|
+
atUserID,
|
|
95
|
+
groupNickname,
|
|
96
|
+
})),
|
|
97
|
+
exMentions,
|
|
98
|
+
truncated,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface ReceivedAtTextElem {
|
|
103
|
+
text: string;
|
|
104
|
+
atUserList: string[];
|
|
105
|
+
atUsersInfo?: AtUsersInfoItem[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Reverse of serializeMentionsForSend, for rendering a received/sent
|
|
110
|
+
* AtTextMessage (Phase B3). Prefers `exMentions` (exact, our own channel);
|
|
111
|
+
* falls back to searching `atTextElem.text` for "@{groupNickname}" per
|
|
112
|
+
* atUsersInfo entry when ex is absent — an interop safety net, not the
|
|
113
|
+
* primary path. The fallback is inherently ambiguous if a member's
|
|
114
|
+
* nickname coincidentally appears elsewhere in the message as plain text;
|
|
115
|
+
* accepted as a known, documented limitation (see the mention plan's
|
|
116
|
+
* finding #3) rather than something client code can fully resolve without
|
|
117
|
+
* position data from the protocol.
|
|
118
|
+
*/
|
|
119
|
+
export function deserializeMentionRanges(
|
|
120
|
+
atTextElem: ReceivedAtTextElem,
|
|
121
|
+
exMentions?: ISerializedMentionEx[]
|
|
122
|
+
): Mention[] {
|
|
123
|
+
if (exMentions && exMentions.length > 0) {
|
|
124
|
+
return exMentions.map((e, index) => ({
|
|
125
|
+
id: `${e.userID}-${e.offset}-${index}`,
|
|
126
|
+
userId: e.userID,
|
|
127
|
+
displayName: atTextElem.text
|
|
128
|
+
.slice(e.offset, e.offset + e.length)
|
|
129
|
+
.replace(/^@/, ''),
|
|
130
|
+
start: e.offset,
|
|
131
|
+
end: e.offset + e.length,
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const nicknameByUserId = new Map(
|
|
136
|
+
(atTextElem.atUsersInfo ?? []).map((i) => [i.atUserID, i.groupNickname])
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const mentions: Mention[] = [];
|
|
140
|
+
for (const userId of atTextElem.atUserList) {
|
|
141
|
+
const nickname = nicknameByUserId.get(userId);
|
|
142
|
+
if (!nickname) continue;
|
|
143
|
+
const needle = `@${nickname}`;
|
|
144
|
+
const start = atTextElem.text.indexOf(needle);
|
|
145
|
+
if (start === -1) continue;
|
|
146
|
+
mentions.push({
|
|
147
|
+
id: `${userId}-${start}`,
|
|
148
|
+
userId,
|
|
149
|
+
displayName: nickname,
|
|
150
|
+
start,
|
|
151
|
+
end: start + needle.length,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return mentions;
|
|
155
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { findActiveMention } from './mentionDetector';
|
|
2
|
+
export {
|
|
3
|
+
diffTextChange,
|
|
4
|
+
snapBoundary,
|
|
5
|
+
type TextChangeDiff,
|
|
6
|
+
} from './mentionDiff';
|
|
7
|
+
export {
|
|
8
|
+
insertMention,
|
|
9
|
+
reconcileMentions,
|
|
10
|
+
normalizeDeleteRange,
|
|
11
|
+
applyTextChange,
|
|
12
|
+
type InsertMentionResult,
|
|
13
|
+
type ReconcileMentionsResult,
|
|
14
|
+
type ApplyTextChangeResult,
|
|
15
|
+
} from './mentionRange';
|
|
16
|
+
export { tokenize, type Segment } from './mentionTokenize';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ActiveMention } from '../../types/mention';
|
|
2
|
+
|
|
3
|
+
// No realistic @query is longer than this — caps the backward scan so the
|
|
4
|
+
// common case (cursor nowhere near an '@') bails in O(word length), not
|
|
5
|
+
// O(text length).
|
|
6
|
+
const MAX_ACTIVE_MENTION_SCAN = 64;
|
|
7
|
+
|
|
8
|
+
const isBoundaryChar = (ch: string) => /\s/.test(ch);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Scans backward from `cursor` for an unclosed "@query" — the in-progress
|
|
12
|
+
* trigger that drives the suggestion list, not a committed mention.
|
|
13
|
+
*
|
|
14
|
+
* Only called for a collapsed cursor (selection.start === selection.end);
|
|
15
|
+
* the caller must resolve a range selection to `null` before calling this —
|
|
16
|
+
* a live "@query" only makes sense at a single insertion point.
|
|
17
|
+
*
|
|
18
|
+
* "@" itself counts as a boundary: the scan stops there whether or not it's
|
|
19
|
+
* a valid trigger, which is what prevents re-scanning back through an
|
|
20
|
+
* already-committed mention's "@Name " when the user starts typing a second
|
|
21
|
+
* "@" right after it (insertMention always appends a trailing space, a
|
|
22
|
+
* boundary char, so the previous mention's "@" is never reachable from the
|
|
23
|
+
* new query).
|
|
24
|
+
*/
|
|
25
|
+
export function findActiveMention(
|
|
26
|
+
text: string,
|
|
27
|
+
cursor: number
|
|
28
|
+
): ActiveMention | null {
|
|
29
|
+
if (cursor <= 0 || cursor > text.length) return null;
|
|
30
|
+
|
|
31
|
+
let i = cursor;
|
|
32
|
+
let scanned = 0;
|
|
33
|
+
|
|
34
|
+
while (i > 0 && scanned < MAX_ACTIVE_MENTION_SCAN) {
|
|
35
|
+
const ch = text[i - 1] as string;
|
|
36
|
+
|
|
37
|
+
if (ch === '@') {
|
|
38
|
+
const before = i - 2 >= 0 ? text[i - 2] : undefined;
|
|
39
|
+
if (before === undefined || isBoundaryChar(before)) {
|
|
40
|
+
return {
|
|
41
|
+
trigger: '@',
|
|
42
|
+
start: i - 1,
|
|
43
|
+
end: cursor,
|
|
44
|
+
keyword: text.slice(i, cursor),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// '@' present but not at a valid boundary (e.g. "user@domain") — not a trigger.
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (isBoundaryChar(ch)) return null;
|
|
52
|
+
|
|
53
|
+
i--;
|
|
54
|
+
scanned++;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// RN's onChangeText hands over only the new full string — no delta, no
|
|
2
|
+
// info about what was inserted/deleted/replaced. A common-prefix +
|
|
3
|
+
// common-suffix scan is the only viable way to localize the changed region,
|
|
4
|
+
// and it's IME-safe for free: a Vietnamese diacritic recomposition (e.g.
|
|
5
|
+
// "tie" + accent key -> "tiế") is just "two different strings" to this
|
|
6
|
+
// algorithm, not a keystroke sequence it has to track.
|
|
7
|
+
//
|
|
8
|
+
// Assumes exactly one contiguous edit happened between the two strings —
|
|
9
|
+
// true for every realistic single-field mutation (typing, backspace,
|
|
10
|
+
// paste, autocorrect, IME composition). If that assumption is ever wrong
|
|
11
|
+
// (some exotic keyboard rewriting two disjoint spans in one event), the
|
|
12
|
+
// failure mode is safe-by-default: the computed region is a superset of
|
|
13
|
+
// the true edits, so callers may over-invalidate mention ranges but never
|
|
14
|
+
// corrupt them.
|
|
15
|
+
|
|
16
|
+
const isHighSurrogate = (code: number) => code >= 0xd800 && code <= 0xdbff;
|
|
17
|
+
const isLowSurrogate = (code: number) => code >= 0xdc00 && code <= 0xdfff;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Snaps `index` so it never sits between a surrogate pair in `str` —
|
|
21
|
+
* without this, diffing e.g. "😀" vs "😁" (which differ only in their low
|
|
22
|
+
* surrogate) would compute a boundary that bisects the emoji. Snapping
|
|
23
|
+
* always shrinks the "common" region (treats one more code point as
|
|
24
|
+
* "changed"), which is always safe: being more conservative about what
|
|
25
|
+
* counts as touched only ever produces more mention-invalidation upstream,
|
|
26
|
+
* never corruption.
|
|
27
|
+
*/
|
|
28
|
+
export function snapBoundary(
|
|
29
|
+
str: string,
|
|
30
|
+
index: number,
|
|
31
|
+
direction: 1 | -1
|
|
32
|
+
): number {
|
|
33
|
+
if (
|
|
34
|
+
index > 0 &&
|
|
35
|
+
index < str.length &&
|
|
36
|
+
isHighSurrogate(str.charCodeAt(index - 1)) &&
|
|
37
|
+
isLowSurrogate(str.charCodeAt(index))
|
|
38
|
+
) {
|
|
39
|
+
return index + direction;
|
|
40
|
+
}
|
|
41
|
+
return index;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface TextChangeDiff {
|
|
45
|
+
/** [removedStart, removedEnd) in previousText coords — what was deleted. */
|
|
46
|
+
removedStart: number;
|
|
47
|
+
removedEnd: number;
|
|
48
|
+
/** [insertedStart, insertedEnd) in nextText coords — what was inserted. insertedStart === removedStart. */
|
|
49
|
+
insertedStart: number;
|
|
50
|
+
insertedEnd: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function diffTextChange(
|
|
54
|
+
previousText: string,
|
|
55
|
+
nextText: string
|
|
56
|
+
): TextChangeDiff {
|
|
57
|
+
const prevLen = previousText.length;
|
|
58
|
+
const nextLen = nextText.length;
|
|
59
|
+
const maxCommon = Math.min(prevLen, nextLen);
|
|
60
|
+
|
|
61
|
+
let prefixLen = 0;
|
|
62
|
+
while (
|
|
63
|
+
prefixLen < maxCommon &&
|
|
64
|
+
previousText.charCodeAt(prefixLen) === nextText.charCodeAt(prefixLen)
|
|
65
|
+
) {
|
|
66
|
+
prefixLen++;
|
|
67
|
+
}
|
|
68
|
+
prefixLen = snapBoundary(previousText, prefixLen, -1);
|
|
69
|
+
|
|
70
|
+
// Clamp the suffix scan budget against what's left after the prefix —
|
|
71
|
+
// without this, a naive independent prefix+suffix scan can overlap on
|
|
72
|
+
// repeated-character edits (e.g. "aaa" -> "aaaa") and produce a
|
|
73
|
+
// negative-length "changed" region.
|
|
74
|
+
const maxSuffix = maxCommon - prefixLen;
|
|
75
|
+
let suffixLen = 0;
|
|
76
|
+
while (
|
|
77
|
+
suffixLen < maxSuffix &&
|
|
78
|
+
previousText.charCodeAt(prevLen - 1 - suffixLen) ===
|
|
79
|
+
nextText.charCodeAt(nextLen - 1 - suffixLen)
|
|
80
|
+
) {
|
|
81
|
+
suffixLen++;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let removedEnd = prevLen - suffixLen;
|
|
85
|
+
let insertedEnd = nextLen - suffixLen;
|
|
86
|
+
removedEnd = snapBoundary(previousText, removedEnd, 1);
|
|
87
|
+
insertedEnd = snapBoundary(nextText, insertedEnd, 1);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
removedStart: prefixLen,
|
|
91
|
+
removedEnd,
|
|
92
|
+
insertedStart: prefixLen,
|
|
93
|
+
insertedEnd,
|
|
94
|
+
};
|
|
95
|
+
}
|