@droppii-org/chat-mobile 0.2.4 → 0.2.7
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/AvatarSection.js +4 -4
- package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -1
- package/lib/module/components/ThreadCard/NamePrefixIcon.js +13 -16
- package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -1
- package/lib/module/components/ThreadCard/ThreadCard.js +13 -33
- package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -1
- package/lib/module/config/feature-flags.js +38 -0
- package/lib/module/config/feature-flags.js.map +1 -0
- package/lib/module/context/ChatContext.js +7 -6
- package/lib/module/context/ChatContext.js.map +1 -1
- package/lib/module/hooks/message/useSendMessage.js +101 -0
- package/lib/module/hooks/message/useSendMessage.js.map +1 -0
- package/lib/module/hooks/query-keys.js +4 -0
- package/lib/module/hooks/query-keys.js.map +1 -1
- package/lib/module/hooks/useChatMessages.js +54 -91
- package/lib/module/hooks/useChatMessages.js.map +1 -1
- package/lib/module/hooks/useConversationList.js +29 -17
- package/lib/module/hooks/useConversationList.js.map +1 -1
- package/lib/module/hooks/useLinkPreview/useFetchUrlMetadata.js +17 -0
- package/lib/module/hooks/useLinkPreview/useFetchUrlMetadata.js.map +1 -0
- package/lib/module/hooks/useLinkPreview/useLinkPreview.js +35 -0
- package/lib/module/hooks/useLinkPreview/useLinkPreview.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatComposer.js +20 -4
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetail.js +116 -22
- package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatDetailHeader.js +5 -8
- package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatLinkPreview.js +79 -0
- package/lib/module/screens/chat-detail/ChatLinkPreview.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatList.js +2 -0
- package/lib/module/screens/chat-detail/ChatList.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatListLegend.js +350 -0
- package/lib/module/screens/chat-detail/ChatListLegend.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatQuickActions.js +12 -2
- package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -1
- package/lib/module/screens/chat-detail/conversationHeader.utils.js +29 -0
- package/lib/module/screens/chat-detail/conversationHeader.utils.js.map +1 -0
- package/lib/module/screens/chat-detail/index.js +1 -0
- package/lib/module/screens/chat-detail/index.js.map +1 -1
- package/lib/module/screens/chat-detail/legend/LegendChatDay.js +57 -0
- package/lib/module/screens/chat-detail/legend/LegendChatDay.js.map +1 -0
- package/lib/module/screens/chat-detail/legend/LegendChatLoadEarlier.js +21 -0
- package/lib/module/screens/chat-detail/legend/LegendChatLoadEarlier.js.map +1 -0
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js +34 -0
- package/lib/module/screens/chat-detail/legend/LegendChatMessage.js.map +1 -0
- package/lib/module/screens/chat-detail/legend/LegendChatScrollToBottom.js +58 -0
- package/lib/module/screens/chat-detail/legend/LegendChatScrollToBottom.js.map +1 -0
- package/lib/module/screens/chat-detail/legend/message-types.js +244 -0
- package/lib/module/screens/chat-detail/legend/message-types.js.map +1 -0
- package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js.map +1 -1
- package/lib/module/services/apis.js +1 -1
- package/lib/module/services/apis.js.map +1 -1
- package/lib/module/services/endpoints.js +8 -0
- package/lib/module/services/endpoints.js.map +1 -0
- package/lib/module/store/conversation.js +1 -1
- package/lib/module/store/conversation.js.map +1 -1
- package/lib/module/store/message.js +45 -0
- package/lib/module/store/message.js.map +1 -0
- package/lib/module/translation/resources/i18n.js +7 -1
- package/lib/module/translation/resources/i18n.js.map +1 -1
- package/lib/module/types/chat.js +2 -7
- package/lib/module/types/chat.js.map +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/utils/conversation.js +34 -13
- package/lib/module/utils/conversation.js.map +1 -1
- package/lib/module/utils/legendListMessage.js +77 -0
- package/lib/module/utils/legendListMessage.js.map +1 -0
- package/lib/module/utils/message.js +5 -8
- package/lib/module/utils/message.js.map +1 -1
- package/lib/module/utils/url.js +7 -0
- package/lib/module/utils/url.js.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.d.ts +1 -1
- package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts +1 -1
- package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts.map +1 -1
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts +1 -1
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -1
- package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts +1 -1
- package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +2 -2
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +3 -4
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts +1 -1
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -1
- package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts +1 -1
- package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts.map +1 -1
- package/lib/typescript/src/config/feature-flags.d.ts +12 -0
- package/lib/typescript/src/config/feature-flags.d.ts.map +1 -0
- package/lib/typescript/src/context/ChatContext.d.ts +1 -1
- package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts +12 -0
- package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -0
- package/lib/typescript/src/hooks/query-keys.d.ts +4 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useChatMessages.d.ts +3 -1
- package/lib/typescript/src/hooks/useChatMessages.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useConversationList.d.ts +2 -1
- package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useLinkPreview/useFetchUrlMetadata.d.ts +3 -0
- package/lib/typescript/src/hooks/useLinkPreview/useFetchUrlMetadata.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useLinkPreview/useLinkPreview.d.ts +7 -0
- package/lib/typescript/src/hooks/useLinkPreview/useLinkPreview.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatLinkPreview.d.ts +9 -0
- package/lib/typescript/src/screens/chat-detail/ChatLinkPreview.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatList.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatList.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/conversationHeader.utils.d.ts +6 -0
- package/lib/typescript/src/screens/chat-detail/conversationHeader.utils.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/index.d.ts +2 -1
- package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatDay.d.ts +6 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatDay.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatLoadEarlier.d.ts +6 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatLoadEarlier.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts +13 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatMessage.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatScrollToBottom.d.ts +6 -0
- package/lib/typescript/src/screens/chat-detail/legend/LegendChatScrollToBottom.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/legend/message-types.d.ts +13 -0
- package/lib/typescript/src/screens/chat-detail/legend/message-types.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts +1 -1
- package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/types.d.ts +33 -7
- package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -1
- package/lib/typescript/src/screens/inbox/Inbox.d.ts +1 -1
- package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -1
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts +1 -1
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -1
- package/lib/typescript/src/services/apis.d.ts +1 -0
- package/lib/typescript/src/services/apis.d.ts.map +1 -1
- package/lib/typescript/src/services/endpoints.d.ts +6 -0
- package/lib/typescript/src/services/endpoints.d.ts.map +1 -0
- package/lib/typescript/src/store/message.d.ts +3 -0
- package/lib/typescript/src/store/message.d.ts.map +1 -0
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
- package/lib/typescript/src/types/chat.d.ts +28 -27
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +7 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/utils/conversation.d.ts +3 -2
- package/lib/typescript/src/utils/conversation.d.ts.map +1 -1
- package/lib/typescript/src/utils/legendListMessage.d.ts +23 -0
- package/lib/typescript/src/utils/legendListMessage.d.ts.map +1 -0
- package/lib/typescript/src/utils/message.d.ts.map +1 -1
- package/lib/typescript/src/utils/url.d.ts +2 -0
- package/lib/typescript/src/utils/url.d.ts.map +1 -0
- package/package.json +5 -3
- package/src/components/ThreadCard/AvatarSection.tsx +5 -8
- package/src/components/ThreadCard/NamePrefixIcon.tsx +27 -38
- package/src/components/ThreadCard/ThreadCard.tsx +16 -30
- package/src/config/feature-flags.ts +49 -0
- package/src/context/ChatContext.tsx +12 -4
- package/src/hooks/message/useSendMessage.ts +136 -0
- package/src/hooks/query-keys.ts +5 -0
- package/src/hooks/useChatMessages.ts +90 -118
- package/src/hooks/useConversationList.ts +34 -16
- package/src/hooks/useLinkPreview/useFetchUrlMetadata.ts +18 -0
- package/src/hooks/useLinkPreview/useLinkPreview.ts +31 -0
- package/src/index.tsx +1 -0
- package/src/screens/chat-detail/ChatComposer.tsx +23 -2
- package/src/screens/chat-detail/ChatDetail.tsx +163 -30
- package/src/screens/chat-detail/ChatDetailHeader.tsx +4 -10
- package/src/screens/chat-detail/ChatLinkPreview.tsx +86 -0
- package/src/screens/chat-detail/ChatList.tsx +3 -0
- package/src/screens/chat-detail/ChatListLegend.tsx +403 -0
- package/src/screens/chat-detail/ChatQuickActions.tsx +19 -2
- package/src/screens/chat-detail/conversationHeader.utils.ts +49 -0
- package/src/screens/chat-detail/index.ts +7 -0
- package/src/screens/chat-detail/legend/LegendChatDay.tsx +70 -0
- package/src/screens/chat-detail/legend/LegendChatLoadEarlier.tsx +21 -0
- package/src/screens/chat-detail/legend/LegendChatMessage.tsx +48 -0
- package/src/screens/chat-detail/legend/LegendChatScrollToBottom.tsx +56 -0
- package/src/screens/chat-detail/legend/message-types.tsx +304 -0
- package/src/screens/chat-detail/messages/ChatMessageBubble.tsx +0 -1
- package/src/screens/chat-detail/types.ts +45 -7
- package/src/services/apis.ts +1 -1
- package/src/services/endpoints.ts +5 -0
- package/src/store/conversation.ts +1 -1
- package/src/store/message.ts +44 -0
- package/src/translation/resources/i18n.ts +6 -0
- package/src/types/chat.ts +31 -30
- package/src/types/common.ts +6 -0
- package/src/utils/conversation.ts +44 -17
- package/src/utils/legendListMessage.ts +97 -0
- package/src/utils/message.ts +10 -12
- package/src/utils/url.ts +5 -0
|
@@ -7,11 +7,10 @@ import { ChatMessageAPI } from '../services/message';
|
|
|
7
7
|
import type { DMessageItem } from '../types/chat';
|
|
8
8
|
import {
|
|
9
9
|
belongsToConversation,
|
|
10
|
-
getHistoryPaginationAnchor,
|
|
11
10
|
hasNewHistoryMessages,
|
|
12
11
|
mergeMessages,
|
|
13
|
-
type HistoryPaginationAnchor,
|
|
14
12
|
} from '../utils/message';
|
|
13
|
+
import { useMessageStore } from '../store/message';
|
|
15
14
|
|
|
16
15
|
type UseChatMessagesOptions = {
|
|
17
16
|
conversationId: string;
|
|
@@ -24,35 +23,24 @@ export function useChatMessages({
|
|
|
24
23
|
enabled = true,
|
|
25
24
|
pageSize = 20,
|
|
26
25
|
}: UseChatMessagesOptions) {
|
|
27
|
-
const
|
|
26
|
+
const messages = useMessageStore((s) => s.messages);
|
|
27
|
+
const hasMoreEarlier = useMessageStore((s) => s.hasMoreEarlier);
|
|
28
|
+
const hasMoreNewer = useMessageStore((s) => s.hasMoreNewer);
|
|
29
|
+
const setMessages = useMessageStore((s) => s.setMessages);
|
|
30
|
+
const pushNewMessage = useMessageStore((s) => s.pushNewMessage);
|
|
31
|
+
const reset = useMessageStore((s) => s.reset);
|
|
32
|
+
|
|
28
33
|
const [currentUserId, setCurrentUserId] = useState<string>();
|
|
29
34
|
const [isLoading, setIsLoading] = useState(false);
|
|
30
35
|
const [isLoadingEarlier, setIsLoadingEarlier] = useState(false);
|
|
31
|
-
const [
|
|
36
|
+
const [isLoadingNewer, setIsLoadingNewer] = useState(false);
|
|
32
37
|
const [error, setError] = useState<Error | null>(null);
|
|
33
38
|
|
|
34
39
|
const conversationIdRef = useRef(conversationId);
|
|
35
40
|
conversationIdRef.current = conversationId;
|
|
36
41
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const hasMoreEarlierRef = useRef(hasMoreEarlier);
|
|
40
|
-
const historyAnchorRef = useRef<HistoryPaginationAnchor | null>(null);
|
|
41
|
-
messagesRef.current = messages;
|
|
42
|
-
hasMoreEarlierRef.current = hasMoreEarlier;
|
|
43
|
-
|
|
44
|
-
const resetState = useCallback(() => {
|
|
45
|
-
setMessages([]);
|
|
46
|
-
setHasMoreEarlier(false);
|
|
47
|
-
setError(null);
|
|
48
|
-
isLoadingEarlierRef.current = false;
|
|
49
|
-
historyAnchorRef.current = null;
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
const loadInitialMessages = useCallback(async () => {
|
|
53
|
-
if (!conversationId) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
42
|
+
const fetchInitial = useCallback(async () => {
|
|
43
|
+
if (!conversationId) return;
|
|
56
44
|
|
|
57
45
|
setIsLoading(true);
|
|
58
46
|
setError(null);
|
|
@@ -66,22 +54,9 @@ export function useChatMessages({
|
|
|
66
54
|
]);
|
|
67
55
|
|
|
68
56
|
const initialMessages = history.messageList as DMessageItem[];
|
|
69
|
-
const oldestAnchor = getHistoryPaginationAnchor(initialMessages);
|
|
70
57
|
|
|
71
58
|
setCurrentUserId(userId);
|
|
72
|
-
setMessages(mergeMessages([], initialMessages));
|
|
73
|
-
historyAnchorRef.current = oldestAnchor
|
|
74
|
-
? {
|
|
75
|
-
clientMsgID: oldestAnchor.clientMsgID,
|
|
76
|
-
// lastMinSeq: resolveHistoryLastMinSeq(
|
|
77
|
-
// history,
|
|
78
|
-
// initialMessages.find(
|
|
79
|
-
// (message) => message.clientMsgID === oldestAnchor.clientMsgID
|
|
80
|
-
// )
|
|
81
|
-
// ),
|
|
82
|
-
}
|
|
83
|
-
: null;
|
|
84
|
-
setHasMoreEarlier(!history.isEnd && !!oldestAnchor);
|
|
59
|
+
setMessages(mergeMessages([], initialMessages), !history.isEnd);
|
|
85
60
|
|
|
86
61
|
ChatMessageAPI.markConversationAsRead(conversationId).catch(
|
|
87
62
|
() => undefined
|
|
@@ -91,122 +66,117 @@ export function useChatMessages({
|
|
|
91
66
|
} finally {
|
|
92
67
|
setIsLoading(false);
|
|
93
68
|
}
|
|
94
|
-
}, [conversationId, pageSize]);
|
|
69
|
+
}, [conversationId, pageSize, setMessages]);
|
|
95
70
|
|
|
96
71
|
const onLoadEarlier = useCallback(async () => {
|
|
97
|
-
if (
|
|
98
|
-
!conversationId ||
|
|
99
|
-
isLoadingEarlierRef.current ||
|
|
100
|
-
!hasMoreEarlierRef.current ||
|
|
101
|
-
!messagesRef.current.length
|
|
102
|
-
) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
72
|
+
if (isLoadingEarlier || !hasMoreEarlier || !messages.length) return;
|
|
105
73
|
|
|
106
|
-
isLoadingEarlierRef.current = true;
|
|
107
74
|
setIsLoadingEarlier(true);
|
|
108
75
|
setError(null);
|
|
109
76
|
|
|
110
|
-
const anchor = historyAnchorRef.current;
|
|
111
|
-
if (!anchor?.clientMsgID) {
|
|
112
|
-
isLoadingEarlierRef.current = false;
|
|
113
|
-
setIsLoadingEarlier(false);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
77
|
try {
|
|
118
78
|
const history = await ChatMessageAPI.fetchHistoryMessages(
|
|
119
79
|
conversationId,
|
|
120
80
|
{
|
|
121
81
|
count: pageSize,
|
|
122
|
-
startClientMsgID:
|
|
82
|
+
startClientMsgID: messages[0]!.clientMsgID,
|
|
123
83
|
}
|
|
124
84
|
);
|
|
125
|
-
const incoming = history.messageList as DMessageItem[];
|
|
126
|
-
const hasNewMessages = hasNewHistoryMessages(
|
|
127
|
-
messagesRef.current,
|
|
128
|
-
incoming
|
|
129
|
-
);
|
|
130
85
|
|
|
131
|
-
|
|
132
|
-
|
|
86
|
+
const incoming = history.messageList as DMessageItem[];
|
|
87
|
+
const hasNew = hasNewHistoryMessages(messages, incoming);
|
|
88
|
+
|
|
89
|
+
if (hasNew) {
|
|
90
|
+
setMessages(
|
|
91
|
+
mergeMessages(messages, incoming),
|
|
92
|
+
!history.isEnd && hasNew
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
setMessages(messages, false);
|
|
133
96
|
}
|
|
134
|
-
|
|
135
|
-
const nextAnchor = getHistoryPaginationAnchor(incoming);
|
|
136
|
-
historyAnchorRef.current = nextAnchor
|
|
137
|
-
? {
|
|
138
|
-
clientMsgID: nextAnchor.clientMsgID,
|
|
139
|
-
// lastMinSeq: resolveHistoryLastMinSeq(
|
|
140
|
-
// history,
|
|
141
|
-
// incoming.find(
|
|
142
|
-
// (message) => message.clientMsgID === nextAnchor.clientMsgID
|
|
143
|
-
// )
|
|
144
|
-
// ),
|
|
145
|
-
}
|
|
146
|
-
: null;
|
|
147
|
-
|
|
148
|
-
setHasMoreEarlier(!history.isEnd && hasNewMessages && !!nextAnchor);
|
|
149
97
|
} catch (err) {
|
|
150
98
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
151
99
|
} finally {
|
|
152
|
-
isLoadingEarlierRef.current = false;
|
|
153
100
|
setIsLoadingEarlier(false);
|
|
154
101
|
}
|
|
155
|
-
}, [
|
|
102
|
+
}, [
|
|
103
|
+
conversationId,
|
|
104
|
+
hasMoreEarlier,
|
|
105
|
+
isLoadingEarlier,
|
|
106
|
+
messages,
|
|
107
|
+
pageSize,
|
|
108
|
+
setMessages,
|
|
109
|
+
]);
|
|
156
110
|
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
if (!trimmed) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
111
|
+
const onLoadNewer = useCallback(async () => {
|
|
112
|
+
if (isLoadingNewer || !hasMoreNewer || !messages.length) return;
|
|
162
113
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
});
|
|
114
|
+
setIsLoadingNewer(true);
|
|
115
|
+
setError(null);
|
|
166
116
|
|
|
167
|
-
|
|
168
|
-
|
|
117
|
+
try {
|
|
118
|
+
const history = await ChatMessageAPI.fetchHistoryMessages(
|
|
119
|
+
conversationId,
|
|
120
|
+
{
|
|
121
|
+
count: pageSize,
|
|
122
|
+
startClientMsgID: messages[messages.length - 1]!.clientMsgID,
|
|
123
|
+
}
|
|
124
|
+
);
|
|
169
125
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
belongsToConversation(message, conversationIdRef.current)
|
|
173
|
-
);
|
|
126
|
+
const incoming = history.messageList as DMessageItem[];
|
|
127
|
+
const hasNew = incoming.length > 0;
|
|
174
128
|
|
|
175
|
-
|
|
176
|
-
|
|
129
|
+
if (hasNew) {
|
|
130
|
+
setMessages(
|
|
131
|
+
mergeMessages(messages, incoming),
|
|
132
|
+
!history.isEnd && hasNew
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
137
|
+
} finally {
|
|
138
|
+
setIsLoadingNewer(false);
|
|
177
139
|
}
|
|
140
|
+
}, [
|
|
141
|
+
conversationId,
|
|
142
|
+
hasMoreNewer,
|
|
143
|
+
isLoadingNewer,
|
|
144
|
+
messages,
|
|
145
|
+
pageSize,
|
|
146
|
+
setMessages,
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
const appendIncomingMessages = useCallback(
|
|
150
|
+
(incoming: MessageItem[]) => {
|
|
151
|
+
const relevant = incoming.filter((message) =>
|
|
152
|
+
belongsToConversation(message, conversationIdRef.current)
|
|
153
|
+
);
|
|
178
154
|
|
|
179
|
-
|
|
180
|
-
mergeMessages(current, relevant as DMessageItem[])
|
|
181
|
-
);
|
|
155
|
+
if (!relevant.length) return;
|
|
182
156
|
|
|
183
|
-
|
|
184
|
-
()
|
|
185
|
-
|
|
186
|
-
|
|
157
|
+
relevant.forEach((msg) => pushNewMessage(msg));
|
|
158
|
+
ChatMessageAPI.markConversationAsRead(conversationIdRef.current).catch(
|
|
159
|
+
() => undefined
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
[pushNewMessage]
|
|
163
|
+
);
|
|
187
164
|
|
|
188
165
|
useEffect(() => {
|
|
189
|
-
|
|
166
|
+
reset();
|
|
190
167
|
|
|
191
|
-
if (!enabled || !conversationId)
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
168
|
+
if (!enabled || !conversationId) return;
|
|
194
169
|
|
|
195
|
-
|
|
196
|
-
}, [conversationId, enabled,
|
|
170
|
+
fetchInitial();
|
|
171
|
+
}, [conversationId, enabled, fetchInitial, reset]);
|
|
197
172
|
|
|
198
173
|
useEffect(() => {
|
|
199
|
-
if (!enabled || !conversationId)
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
174
|
+
if (!enabled || !conversationId) return;
|
|
202
175
|
|
|
203
|
-
const handleNewMessages = (incoming: MessageItem[]) =>
|
|
176
|
+
const handleNewMessages = (incoming: MessageItem[]) =>
|
|
204
177
|
appendIncomingMessages(incoming);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const handleNewMessage = (incoming: MessageItem) => {
|
|
178
|
+
const handleNewMessage = (incoming: MessageItem) =>
|
|
208
179
|
appendIncomingMessages([incoming]);
|
|
209
|
-
};
|
|
210
180
|
|
|
211
181
|
OpenIMSDK.on(OpenIMEvent.OnRecvNewMessages, handleNewMessages);
|
|
212
182
|
OpenIMSDK.on(OpenIMEvent.OnRecvNewMessage, handleNewMessage);
|
|
@@ -223,9 +193,11 @@ export function useChatMessages({
|
|
|
223
193
|
isLoading,
|
|
224
194
|
isLoadingEarlier,
|
|
225
195
|
hasMoreEarlier,
|
|
196
|
+
isLoadingNewer,
|
|
197
|
+
hasMoreNewer,
|
|
226
198
|
error,
|
|
227
199
|
onLoadEarlier,
|
|
228
|
-
|
|
229
|
-
refresh:
|
|
200
|
+
onLoadNewer,
|
|
201
|
+
refresh: fetchInitial,
|
|
230
202
|
};
|
|
231
203
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useQuery } from '@tanstack/react-query';
|
|
3
|
-
import OpenIMSDK
|
|
4
|
-
|
|
3
|
+
import OpenIMSDK, {
|
|
4
|
+
type ConversationItem,
|
|
5
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
5
6
|
import { conversationQueryKeys } from './query-keys';
|
|
6
7
|
import { useConversationStore } from '../store';
|
|
7
|
-
import {
|
|
8
|
+
import type { DConversationItem, DMessageItem } from '../types/chat';
|
|
8
9
|
|
|
9
10
|
type Params = {
|
|
10
11
|
applicationType: string;
|
|
@@ -12,6 +13,29 @@ type Params = {
|
|
|
12
13
|
enabled?: boolean;
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
function toConversationItem(raw: ConversationItem): DConversationItem {
|
|
17
|
+
let lastMessage: DMessageItem | undefined;
|
|
18
|
+
if (raw.latestMsg) {
|
|
19
|
+
try {
|
|
20
|
+
lastMessage = JSON.parse(raw.latestMsg) as DMessageItem;
|
|
21
|
+
} catch {
|
|
22
|
+
// leave undefined
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let applicationType: string | undefined;
|
|
27
|
+
if (raw.ex) {
|
|
28
|
+
try {
|
|
29
|
+
applicationType = (JSON.parse(raw.ex) as { applicationType?: string })
|
|
30
|
+
.applicationType;
|
|
31
|
+
} catch {
|
|
32
|
+
// leave undefined
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { ...(raw as DConversationItem), lastMessage, applicationType };
|
|
37
|
+
}
|
|
38
|
+
|
|
15
39
|
export function useConversationList({
|
|
16
40
|
applicationType,
|
|
17
41
|
page = 1,
|
|
@@ -26,21 +50,15 @@ export function useConversationList({
|
|
|
26
50
|
enabled: enabled !== false,
|
|
27
51
|
queryFn: async () => {
|
|
28
52
|
const offset = (page - 1) * 20;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const openimMap = new Map(openimList.map((c) => [c.conversationID, c]));
|
|
34
|
-
|
|
35
|
-
const merged = droppiiList.map((conv) => {
|
|
36
|
-
const openimConv = openimMap.get(conv.conversationId);
|
|
37
|
-
return openimConv
|
|
38
|
-
? mergeOpenIMIntoConversation(conv, openimConv)
|
|
39
|
-
: conv;
|
|
53
|
+
const rawList = await OpenIMSDK.getConversationListSplitApp({
|
|
54
|
+
offset,
|
|
55
|
+
count: 20,
|
|
56
|
+
applicationType,
|
|
40
57
|
});
|
|
41
58
|
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
const conversations = rawList.map(toConversationItem);
|
|
60
|
+
useConversationStore.getState().updateConversations(conversations);
|
|
61
|
+
return conversations;
|
|
44
62
|
},
|
|
45
63
|
});
|
|
46
64
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { keepPreviousData, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { commonQueryKeys } from '../query-keys';
|
|
3
|
+
import { apiInstance } from '../../services/apis';
|
|
4
|
+
import type { BaseResponse } from '../../types/auth';
|
|
5
|
+
import type { IUrlMetadata } from '../../types/common';
|
|
6
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
7
|
+
|
|
8
|
+
export const useFetchUrlMetadata = (url?: string) =>
|
|
9
|
+
useQuery({
|
|
10
|
+
queryKey: commonQueryKeys.urlMetadata(url || ''),
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const path = `${ENDPOINTS.chatService.urlMetadata}?url=${url}`;
|
|
13
|
+
const res = await apiInstance?.get<BaseResponse<IUrlMetadata>>(path);
|
|
14
|
+
return res?.data?.data;
|
|
15
|
+
},
|
|
16
|
+
enabled: !!url,
|
|
17
|
+
placeholderData: keepPreviousData,
|
|
18
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useFetchUrlMetadata } from './useFetchUrlMetadata';
|
|
3
|
+
import { extractUrls } from '../../utils/url';
|
|
4
|
+
|
|
5
|
+
export function useLinkPreview(value: string | undefined) {
|
|
6
|
+
const [detectedUrl, setDetectedUrl] = useState<string | undefined>(undefined);
|
|
7
|
+
const [isDismissed, setIsDismissed] = useState(false);
|
|
8
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
12
|
+
timerRef.current = setTimeout(() => {
|
|
13
|
+
const urls = value ? extractUrls(value) : [];
|
|
14
|
+
const url = urls.length === 1 ? urls[0] : undefined;
|
|
15
|
+
setDetectedUrl(url);
|
|
16
|
+
if (url) setIsDismissed(false);
|
|
17
|
+
}, 500);
|
|
18
|
+
return () => {
|
|
19
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
20
|
+
};
|
|
21
|
+
}, [value]);
|
|
22
|
+
|
|
23
|
+
const { data: metadata, isFetching: isLoading } =
|
|
24
|
+
useFetchUrlMetadata(detectedUrl);
|
|
25
|
+
|
|
26
|
+
const dismiss = useCallback(() => setIsDismissed(true), []);
|
|
27
|
+
|
|
28
|
+
const isVisible = !!detectedUrl && !isDismissed;
|
|
29
|
+
|
|
30
|
+
return { isVisible, metadata, isLoading, dismiss };
|
|
31
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -22,8 +22,10 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
22
22
|
import { KContainer, KImage, KColors, KSpacingValue } from '@droppii/libs';
|
|
23
23
|
import { ChatQuickActions } from './ChatQuickActions';
|
|
24
24
|
import { ChatAttachmentPanel } from './ChatAttachmentPanel';
|
|
25
|
+
import { ChatLinkPreview } from './ChatLinkPreview';
|
|
25
26
|
import { getAttachmentPanelHeight } from './constants';
|
|
26
27
|
import type { ChatComposerProps } from './types';
|
|
28
|
+
import { useLinkPreview } from '../../hooks/useLinkPreview/useLinkPreview';
|
|
27
29
|
|
|
28
30
|
const ACCESSORY_ANIMATION_MS = 250;
|
|
29
31
|
const ACCESSORY_SETTLE_MS = 150;
|
|
@@ -44,11 +46,13 @@ export const ChatComposer = memo(
|
|
|
44
46
|
onSend,
|
|
45
47
|
onPressAttach,
|
|
46
48
|
onPressEmoji,
|
|
49
|
+
showQuickActions = true,
|
|
47
50
|
quickActions,
|
|
48
51
|
attachmentActions,
|
|
49
52
|
onQuickActionPress,
|
|
50
53
|
onAttachmentAction,
|
|
51
54
|
renderQuickAction,
|
|
55
|
+
renderQuickActions,
|
|
52
56
|
renderAttachmentAction,
|
|
53
57
|
attachmentColumns,
|
|
54
58
|
}: ChatComposerProps) => {
|
|
@@ -60,6 +64,13 @@ export const ChatComposer = memo(
|
|
|
60
64
|
const [isInputWrapped, setIsInputWrapped] = useState(false);
|
|
61
65
|
const insets = useSafeAreaInsets();
|
|
62
66
|
|
|
67
|
+
const {
|
|
68
|
+
isVisible: showLinkPreview,
|
|
69
|
+
metadata: urlMetadata,
|
|
70
|
+
isLoading: isMetadataLoading,
|
|
71
|
+
dismiss: handleDismissPreview,
|
|
72
|
+
} = useLinkPreview(value);
|
|
73
|
+
|
|
63
74
|
const isKeyboardVisible = useKeyboardState((state) => state.isVisible);
|
|
64
75
|
const keyboardHeight = useKeyboardState((state) => state.height);
|
|
65
76
|
const { progress: keyboardProgress } = useReanimatedKeyboardAnimation();
|
|
@@ -170,8 +181,8 @@ export const ChatComposer = memo(
|
|
|
170
181
|
});
|
|
171
182
|
|
|
172
183
|
const handleSend = useCallback(() => {
|
|
173
|
-
onSend?.();
|
|
174
|
-
}, [onSend]);
|
|
184
|
+
onSend?.(showLinkPreview ? urlMetadata : undefined);
|
|
185
|
+
}, [onSend, urlMetadata, showLinkPreview]);
|
|
175
186
|
|
|
176
187
|
const handleToggleAttachment = useCallback(() => {
|
|
177
188
|
if (!hasAttachmentActions) {
|
|
@@ -268,11 +279,21 @@ export const ChatComposer = memo(
|
|
|
268
279
|
return (
|
|
269
280
|
<KContainer.View background={'rgba(131, 137, 157, 0.05)'}>
|
|
270
281
|
<ChatQuickActions
|
|
282
|
+
visible={showQuickActions}
|
|
271
283
|
actions={quickActions}
|
|
272
284
|
onActionPress={onQuickActionPress}
|
|
273
285
|
renderAction={renderQuickAction}
|
|
286
|
+
renderQuickActions={renderQuickActions}
|
|
274
287
|
/>
|
|
275
288
|
|
|
289
|
+
{showLinkPreview ? (
|
|
290
|
+
<ChatLinkPreview
|
|
291
|
+
metadata={urlMetadata}
|
|
292
|
+
isLoading={isMetadataLoading}
|
|
293
|
+
onDismiss={handleDismissPreview}
|
|
294
|
+
/>
|
|
295
|
+
) : null}
|
|
296
|
+
|
|
276
297
|
<KContainer.View
|
|
277
298
|
row
|
|
278
299
|
alignItems
|