@droppii-org/chat-sdk 0.0.4 → 0.0.6
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/dist/assets/droppiiFontSelection.json +14521 -0
- package/dist/components/ChatBubble.d.ts +9 -1
- package/dist/components/ChatBubble.d.ts.map +1 -1
- package/dist/components/ChatBubble.js +23 -15
- package/dist/components/chat-bubble/ChatBubble.d.ts +9 -0
- package/dist/components/chat-bubble/ChatBubble.d.ts.map +1 -0
- package/dist/components/chat-bubble/ChatBubble.js +27 -0
- package/dist/components/conversation/DeskConversationList.d.ts +8 -0
- package/dist/components/conversation/DeskConversationList.d.ts.map +1 -0
- package/dist/components/conversation/DeskConversationList.js +168 -0
- package/dist/components/icon/index.d.ts +11 -0
- package/dist/components/icon/index.d.ts.map +1 -0
- package/dist/components/icon/index.js +18 -0
- package/dist/components/message/MessageList.d.ts +10 -0
- package/dist/components/message/MessageList.d.ts.map +1 -0
- package/dist/components/message/MessageList.js +91 -0
- package/dist/components/session/AssignedSessionFilter.d.ts +7 -0
- package/dist/components/session/AssignedSessionFilter.d.ts.map +1 -0
- package/dist/components/session/AssignedSessionFilter.js +90 -0
- package/dist/context/ChatContext.d.ts +4 -71
- package/dist/context/ChatContext.d.ts.map +1 -1
- package/dist/context/ChatContext.js +33 -344
- package/dist/hooks/conversation/useConversation.d.ts +11 -0
- package/dist/hooks/conversation/useConversation.d.ts.map +1 -0
- package/dist/hooks/conversation/useConversation.js +51 -0
- package/dist/hooks/message/useMessage.d.ts +9 -0
- package/dist/hooks/message/useMessage.d.ts.map +1 -0
- package/dist/hooks/message/useMessage.js +46 -0
- package/dist/hooks/message/useSendMessage.d.ts +10 -0
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -0
- package/dist/hooks/message/useSendMessage.js +42 -0
- package/dist/index.d.ts +9 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -27
- package/dist/screens/desk-message/index.d.ts +3 -0
- package/dist/screens/desk-message/index.d.ts.map +1 -0
- package/dist/screens/desk-message/index.js +14 -0
- package/dist/types/chat.d.ts +6 -36
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -85
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/sdk.d.ts +1 -0
- package/dist/types/sdk.d.ts.map +1 -0
- package/dist/types/sdk.js +1 -0
- package/package.json +19 -3
- package/dist/components/AutoScrollAnchor.d.ts +0 -2
- package/dist/components/AutoScrollAnchor.d.ts.map +0 -1
- package/dist/components/AutoScrollAnchor.js +0 -12
- package/dist/components/AutoScrollAnchor.jsx +0 -11
- package/dist/components/ChatBubble.jsx +0 -80
- package/dist/components/ChatHeader.d.ts +0 -8
- package/dist/components/ChatHeader.d.ts.map +0 -1
- package/dist/components/ChatHeader.js +0 -32
- package/dist/components/ChatHeader.jsx +0 -72
- package/dist/components/ChatInput.d.ts +0 -3
- package/dist/components/ChatInput.d.ts.map +0 -1
- package/dist/components/ChatInput.js +0 -379
- package/dist/components/ChatInput.jsx +0 -444
- package/dist/components/ChatInputDemo.d.ts +0 -2
- package/dist/components/ChatInputDemo.d.ts.map +0 -1
- package/dist/components/ChatInputDemo.js +0 -38
- package/dist/components/ChatInputDemo.jsx +0 -53
- package/dist/components/ChatInputWithCustomIcon.d.ts +0 -16
- package/dist/components/ChatInputWithCustomIcon.d.ts.map +0 -1
- package/dist/components/ChatInputWithCustomIcon.js +0 -85
- package/dist/components/ChatInputWithCustomIcon.jsx +0 -167
- package/dist/components/ChatLayout.d.ts +0 -6
- package/dist/components/ChatLayout.d.ts.map +0 -1
- package/dist/components/ChatLayout.js +0 -48
- package/dist/components/ChatLayout.jsx +0 -122
- package/dist/components/ConversationItem.d.ts +0 -9
- package/dist/components/ConversationItem.d.ts.map +0 -1
- package/dist/components/ConversationItem.js +0 -27
- package/dist/components/ConversationItem.jsx +0 -51
- package/dist/components/ConversationList.d.ts +0 -8
- package/dist/components/ConversationList.d.ts.map +0 -1
- package/dist/components/ConversationList.js +0 -11
- package/dist/components/ConversationList.jsx +0 -22
- package/dist/components/DateDivider.d.ts +0 -7
- package/dist/components/DateDivider.d.ts.map +0 -1
- package/dist/components/DateDivider.js +0 -27
- package/dist/components/DateDivider.jsx +0 -28
- package/dist/components/EmojiPicker.d.ts +0 -4
- package/dist/components/EmojiPicker.d.ts.map +0 -1
- package/dist/components/EmojiPicker.js +0 -191
- package/dist/components/EmojiPicker.jsx +0 -229
- package/dist/components/ImageLightbox.d.ts +0 -8
- package/dist/components/ImageLightbox.d.ts.map +0 -1
- package/dist/components/ImageLightbox.js +0 -8
- package/dist/components/ImageLightbox.jsx +0 -16
- package/dist/components/ImagePreviewModal.d.ts +0 -12
- package/dist/components/ImagePreviewModal.d.ts.map +0 -1
- package/dist/components/ImagePreviewModal.js +0 -55
- package/dist/components/ImagePreviewModal.jsx +0 -84
- package/dist/components/MessageItem.d.ts +0 -3
- package/dist/components/MessageItem.d.ts.map +0 -1
- package/dist/components/MessageItem.js +0 -38
- package/dist/components/MessageItem.jsx +0 -99
- package/dist/components/MessageItemDemo.d.ts +0 -2
- package/dist/components/MessageItemDemo.d.ts.map +0 -1
- package/dist/components/MessageItemDemo.js +0 -166
- package/dist/components/MessageItemDemo.jsx +0 -179
- package/dist/components/MessageList.d.ts +0 -15
- package/dist/components/MessageList.d.ts.map +0 -1
- package/dist/components/MessageList.js +0 -243
- package/dist/components/MessageList.jsx +0 -306
- package/dist/components/MessageListDemo.d.ts +0 -2
- package/dist/components/MessageListDemo.d.ts.map +0 -1
- package/dist/components/MessageListDemo.js +0 -165
- package/dist/components/MessageListDemo.jsx +0 -183
- package/dist/components/StickerPicker.d.ts +0 -4
- package/dist/components/StickerPicker.d.ts.map +0 -1
- package/dist/components/StickerPicker.js +0 -68
- package/dist/components/StickerPicker.jsx +0 -106
- package/dist/components/SwipeIndicator.d.ts +0 -9
- package/dist/components/SwipeIndicator.d.ts.map +0 -1
- package/dist/components/SwipeIndicator.js +0 -24
- package/dist/components/SwipeIndicator.jsx +0 -28
- package/dist/components/TextFormattingToolbar.d.ts +0 -4
- package/dist/components/TextFormattingToolbar.d.ts.map +0 -1
- package/dist/components/TextFormattingToolbar.js +0 -29
- package/dist/components/TextFormattingToolbar.jsx +0 -52
- package/dist/components/TypingIndicator.d.ts +0 -6
- package/dist/components/TypingIndicator.d.ts.map +0 -1
- package/dist/components/TypingIndicator.js +0 -21
- package/dist/components/TypingIndicator.jsx +0 -27
- package/dist/components/VoiceWaveIcon.d.ts +0 -7
- package/dist/components/VoiceWaveIcon.d.ts.map +0 -1
- package/dist/components/VoiceWaveIcon.js +0 -5
- package/dist/components/VoiceWaveIcon.jsx +0 -11
- package/dist/context/ChatContext.jsx +0 -346
- package/dist/hooks/useChat.d.ts +0 -5
- package/dist/hooks/useChat.d.ts.map +0 -1
- package/dist/hooks/useChat.js +0 -73
- package/dist/hooks/useConversationList.d.ts +0 -5
- package/dist/hooks/useConversationList.d.ts.map +0 -1
- package/dist/hooks/useConversationList.js +0 -9
- package/dist/hooks/useMessages.d.ts +0 -5
- package/dist/hooks/useMessages.d.ts.map +0 -1
- package/dist/hooks/useMessages.js +0 -192
- package/dist/hooks/useSocket.d.ts +0 -7
- package/dist/hooks/useSocket.d.ts.map +0 -1
- package/dist/hooks/useSocket.js +0 -120
- package/dist/hooks/useSwipeGesture.d.ts +0 -11
- package/dist/hooks/useSwipeGesture.d.ts.map +0 -1
- package/dist/hooks/useSwipeGesture.js +0 -54
- package/dist/hooks/useTextSelection.d.ts +0 -13
- package/dist/hooks/useTextSelection.d.ts.map +0 -1
- package/dist/hooks/useTextSelection.js +0 -132
- package/dist/hooks/useTyping.d.ts +0 -7
- package/dist/hooks/useTyping.d.ts.map +0 -1
- package/dist/hooks/useTyping.js +0 -64
|
@@ -1,347 +1,36 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
case "UPDATE_CONVERSATION":
|
|
22
|
-
return Object.assign(Object.assign({}, state), { conversations: state.conversations.map((conv) => (conv.id === action.payload.id ? action.payload : conv)) });
|
|
23
|
-
case "SET_MESSAGES":
|
|
24
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: action.payload.messages }) });
|
|
25
|
-
case "ADD_MESSAGE":
|
|
26
|
-
const conversationId = action.payload.conversationId;
|
|
27
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [conversationId]: [...(state.messages[conversationId] || []), action.payload] }) });
|
|
28
|
-
case "UPDATE_MESSAGE":
|
|
29
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: (state.messages[action.payload.conversationId] || []).map((msg) => msg.id === action.payload.id ? action.payload : msg) }) });
|
|
30
|
-
case "SET_USERS":
|
|
31
|
-
return Object.assign(Object.assign({}, state), { users: action.payload });
|
|
32
|
-
case "UPDATE_USER":
|
|
33
|
-
return Object.assign(Object.assign({}, state), { users: Object.assign(Object.assign({}, state.users), { [action.payload.id]: action.payload }) });
|
|
34
|
-
case "SET_TYPING":
|
|
35
|
-
return Object.assign(Object.assign({}, state), { typingStatuses: [
|
|
36
|
-
...state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)),
|
|
37
|
-
action.payload,
|
|
38
|
-
] });
|
|
39
|
-
case "REMOVE_TYPING":
|
|
40
|
-
return Object.assign(Object.assign({}, state), { typingStatuses: state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)) });
|
|
41
|
-
case "SET_CONNECTION_STATUS":
|
|
42
|
-
return Object.assign(Object.assign({}, state), { isConnected: action.payload });
|
|
43
|
-
default:
|
|
44
|
-
return state;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const ChatContext = createContext(null);
|
|
48
|
-
export function useChatContext() {
|
|
49
|
-
const context = useContext(ChatContext);
|
|
50
|
-
if (!context) {
|
|
51
|
-
throw new Error("useChatContext must be used within a ChatProvider");
|
|
52
|
-
}
|
|
53
|
-
return context;
|
|
54
|
-
}
|
|
55
|
-
export function ChatProvider({ children, userId, token, onTokenRefresh, websocketUrl = "demo", // Use "demo" as default to disable WebSocket
|
|
56
|
-
enableWebSocket = false, // Disabled by default for demo
|
|
57
|
-
}) {
|
|
58
|
-
const [state, dispatch] = useReducer(chatReducer, initialState);
|
|
59
|
-
// Initialize config
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
const config = {
|
|
62
|
-
userId,
|
|
63
|
-
token,
|
|
64
|
-
wsUrl: enableWebSocket ? websocketUrl : "demo",
|
|
65
|
-
onTokenRefresh,
|
|
66
|
-
};
|
|
67
|
-
dispatch({ type: "SET_CONFIG", payload: config });
|
|
68
|
-
// Initialize current user
|
|
69
|
-
const currentUser = {
|
|
70
|
-
id: userId,
|
|
71
|
-
name: "You",
|
|
72
|
-
status: "online",
|
|
73
|
-
};
|
|
74
|
-
dispatch({ type: "UPDATE_USER", payload: currentUser });
|
|
75
|
-
}, [userId, token, websocketUrl, onTokenRefresh, enableWebSocket]);
|
|
76
|
-
// Initialize with mock data for demo - MORE CONVERSATIONS
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!state.config)
|
|
79
|
-
return;
|
|
80
|
-
const mockUsers = {
|
|
81
|
-
[userId]: {
|
|
82
|
-
id: userId,
|
|
83
|
-
name: "You",
|
|
84
|
-
status: "online",
|
|
85
|
-
},
|
|
86
|
-
"user-2": {
|
|
87
|
-
id: "user-2",
|
|
88
|
-
name: "Alice Johnson",
|
|
89
|
-
status: "online",
|
|
90
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
91
|
-
},
|
|
92
|
-
"user-3": {
|
|
93
|
-
id: "user-3",
|
|
94
|
-
name: "Bob Smith",
|
|
95
|
-
status: "offline",
|
|
96
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
97
|
-
lastSeen: new Date(Date.now() - 7200000),
|
|
98
|
-
},
|
|
99
|
-
"user-4": {
|
|
100
|
-
id: "user-4",
|
|
101
|
-
name: "Carol Davis",
|
|
102
|
-
status: "online",
|
|
103
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
104
|
-
},
|
|
105
|
-
"user-5": {
|
|
106
|
-
id: "user-5",
|
|
107
|
-
name: "David Wilson",
|
|
108
|
-
status: "away",
|
|
109
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
110
|
-
lastSeen: new Date(Date.now() - 1800000),
|
|
111
|
-
},
|
|
112
|
-
"user-6": {
|
|
113
|
-
id: "user-6",
|
|
114
|
-
name: "Emma Brown",
|
|
115
|
-
status: "online",
|
|
116
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
117
|
-
},
|
|
118
|
-
"user-7": {
|
|
119
|
-
id: "user-7",
|
|
120
|
-
name: "Frank Miller",
|
|
121
|
-
status: "offline",
|
|
122
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
123
|
-
lastSeen: new Date(Date.now() - 86400000),
|
|
124
|
-
},
|
|
125
|
-
"user-8": {
|
|
126
|
-
id: "user-8",
|
|
127
|
-
name: "Grace Lee",
|
|
128
|
-
status: "online",
|
|
129
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
130
|
-
},
|
|
131
|
-
"user-9": {
|
|
132
|
-
id: "user-9",
|
|
133
|
-
name: "Henry Taylor",
|
|
134
|
-
status: "away",
|
|
135
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
136
|
-
lastSeen: new Date(Date.now() - 3600000),
|
|
137
|
-
},
|
|
138
|
-
"user-10": {
|
|
139
|
-
id: "user-10",
|
|
140
|
-
name: "Ivy Chen",
|
|
141
|
-
status: "online",
|
|
142
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
143
|
-
},
|
|
144
|
-
"group-1": {
|
|
145
|
-
id: "group-1",
|
|
146
|
-
name: "Team Project",
|
|
147
|
-
status: "online",
|
|
148
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
149
|
-
},
|
|
150
|
-
"group-2": {
|
|
151
|
-
id: "group-2",
|
|
152
|
-
name: "Family Chat",
|
|
153
|
-
status: "online",
|
|
154
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
const mockConversations = [
|
|
158
|
-
{
|
|
159
|
-
id: "conv-1",
|
|
160
|
-
participants: [mockUsers["user-2"], mockUsers[userId]],
|
|
161
|
-
unreadCount: 2,
|
|
162
|
-
updatedAt: new Date(Date.now() - 300000), // 5 minutes ago
|
|
163
|
-
type: "direct",
|
|
164
|
-
lastMessage: {
|
|
165
|
-
id: "msg-1",
|
|
166
|
-
conversationId: "conv-1",
|
|
167
|
-
senderId: "user-2",
|
|
168
|
-
content: "Hey there! How are you doing? 😊",
|
|
169
|
-
type: "text",
|
|
170
|
-
timestamp: new Date(Date.now() - 300000),
|
|
171
|
-
status: "delivered",
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
id: "conv-2",
|
|
176
|
-
participants: [mockUsers["user-3"], mockUsers[userId]],
|
|
177
|
-
unreadCount: 0,
|
|
178
|
-
updatedAt: new Date(Date.now() - 1800000), // 30 minutes ago
|
|
179
|
-
type: "direct",
|
|
180
|
-
lastMessage: {
|
|
181
|
-
id: "msg-2",
|
|
182
|
-
conversationId: "conv-2",
|
|
183
|
-
senderId: userId,
|
|
184
|
-
content: "Thanks for the help earlier!",
|
|
185
|
-
type: "text",
|
|
186
|
-
timestamp: new Date(Date.now() - 1800000),
|
|
187
|
-
status: "read",
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
id: "conv-3",
|
|
192
|
-
participants: [mockUsers["user-4"], mockUsers[userId]],
|
|
193
|
-
unreadCount: 1,
|
|
194
|
-
updatedAt: new Date(Date.now() - 3600000), // 1 hour ago
|
|
195
|
-
type: "direct",
|
|
196
|
-
lastMessage: {
|
|
197
|
-
id: "msg-3",
|
|
198
|
-
conversationId: "conv-3",
|
|
199
|
-
senderId: "user-4",
|
|
200
|
-
content: "Can you review this document?",
|
|
201
|
-
type: "file",
|
|
202
|
-
timestamp: new Date(Date.now() - 3600000),
|
|
203
|
-
status: "delivered",
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
id: "conv-4",
|
|
208
|
-
participants: [mockUsers["user-5"], mockUsers[userId]],
|
|
209
|
-
unreadCount: 0,
|
|
210
|
-
updatedAt: new Date(Date.now() - 7200000), // 2 hours ago
|
|
211
|
-
type: "direct",
|
|
212
|
-
lastMessage: {
|
|
213
|
-
id: "msg-4",
|
|
214
|
-
conversationId: "conv-4",
|
|
215
|
-
senderId: userId,
|
|
216
|
-
content: "See you tomorrow!",
|
|
217
|
-
type: "text",
|
|
218
|
-
timestamp: new Date(Date.now() - 7200000),
|
|
219
|
-
status: "read",
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
id: "conv-5",
|
|
224
|
-
participants: [mockUsers["user-6"], mockUsers[userId]],
|
|
225
|
-
unreadCount: 3,
|
|
226
|
-
updatedAt: new Date(Date.now() - 10800000), // 3 hours ago
|
|
227
|
-
type: "direct",
|
|
228
|
-
lastMessage: {
|
|
229
|
-
id: "msg-5",
|
|
230
|
-
conversationId: "conv-5",
|
|
231
|
-
senderId: "user-6",
|
|
232
|
-
content: "Check out these photos from the event!",
|
|
233
|
-
type: "image",
|
|
234
|
-
timestamp: new Date(Date.now() - 10800000),
|
|
235
|
-
status: "delivered",
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
id: "conv-6",
|
|
240
|
-
participants: [mockUsers["user-7"], mockUsers[userId]],
|
|
241
|
-
unreadCount: 0,
|
|
242
|
-
updatedAt: new Date(Date.now() - 86400000), // 1 day ago
|
|
243
|
-
type: "direct",
|
|
244
|
-
lastMessage: {
|
|
245
|
-
id: "msg-6",
|
|
246
|
-
conversationId: "conv-6",
|
|
247
|
-
senderId: "user-7",
|
|
248
|
-
content: "Happy birthday! 🎉",
|
|
249
|
-
type: "text",
|
|
250
|
-
timestamp: new Date(Date.now() - 86400000),
|
|
251
|
-
status: "read",
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
id: "conv-7",
|
|
256
|
-
participants: [mockUsers["user-8"], mockUsers[userId]],
|
|
257
|
-
unreadCount: 0,
|
|
258
|
-
updatedAt: new Date(Date.now() - 172800000), // 2 days ago
|
|
259
|
-
type: "direct",
|
|
260
|
-
lastMessage: {
|
|
261
|
-
id: "msg-7",
|
|
262
|
-
conversationId: "conv-7",
|
|
263
|
-
senderId: userId,
|
|
264
|
-
content: "Thanks for the coffee recommendation!",
|
|
265
|
-
type: "text",
|
|
266
|
-
timestamp: new Date(Date.now() - 172800000),
|
|
267
|
-
status: "read",
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
id: "conv-8",
|
|
272
|
-
participants: [mockUsers["user-9"], mockUsers[userId]],
|
|
273
|
-
unreadCount: 1,
|
|
274
|
-
updatedAt: new Date(Date.now() - 259200000), // 3 days ago
|
|
275
|
-
type: "direct",
|
|
276
|
-
lastMessage: {
|
|
277
|
-
id: "msg-8",
|
|
278
|
-
conversationId: "conv-8",
|
|
279
|
-
senderId: "user-9",
|
|
280
|
-
content: "Let's schedule a meeting next week",
|
|
281
|
-
type: "text",
|
|
282
|
-
timestamp: new Date(Date.now() - 259200000),
|
|
283
|
-
status: "delivered",
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
id: "conv-9",
|
|
288
|
-
participants: [mockUsers["user-10"], mockUsers[userId]],
|
|
289
|
-
unreadCount: 0,
|
|
290
|
-
updatedAt: new Date(Date.now() - 345600000), // 4 days ago
|
|
291
|
-
type: "direct",
|
|
292
|
-
lastMessage: {
|
|
293
|
-
id: "msg-9",
|
|
294
|
-
conversationId: "conv-9",
|
|
295
|
-
senderId: userId,
|
|
296
|
-
content: "Great presentation today!",
|
|
297
|
-
type: "text",
|
|
298
|
-
timestamp: new Date(Date.now() - 345600000),
|
|
299
|
-
status: "read",
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
id: "group-conv-1",
|
|
304
|
-
participants: [mockUsers["group-1"], mockUsers[userId], mockUsers["user-2"], mockUsers["user-4"]],
|
|
305
|
-
unreadCount: 5,
|
|
306
|
-
updatedAt: new Date(Date.now() - 600000), // 10 minutes ago
|
|
307
|
-
type: "group",
|
|
308
|
-
name: "Team Project",
|
|
309
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
310
|
-
lastMessage: {
|
|
311
|
-
id: "msg-group-1",
|
|
312
|
-
conversationId: "group-conv-1",
|
|
313
|
-
senderId: "user-4",
|
|
314
|
-
content: "The deadline has been moved to Friday",
|
|
315
|
-
type: "text",
|
|
316
|
-
timestamp: new Date(Date.now() - 600000),
|
|
317
|
-
status: "delivered",
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
id: "group-conv-2",
|
|
322
|
-
participants: [mockUsers["group-2"], mockUsers[userId], mockUsers["user-6"], mockUsers["user-8"]],
|
|
323
|
-
unreadCount: 0,
|
|
324
|
-
updatedAt: new Date(Date.now() - 432000000), // 5 days ago
|
|
325
|
-
type: "group",
|
|
326
|
-
name: "Family Chat",
|
|
327
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
328
|
-
lastMessage: {
|
|
329
|
-
id: "msg-group-2",
|
|
330
|
-
conversationId: "group-conv-2",
|
|
331
|
-
senderId: "user-6",
|
|
332
|
-
content: "Looking forward to the reunion!",
|
|
333
|
-
type: "text",
|
|
334
|
-
timestamp: new Date(Date.now() - 432000000),
|
|
335
|
-
status: "read",
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
];
|
|
339
|
-
dispatch({ type: "SET_USERS", payload: mockUsers });
|
|
340
|
-
dispatch({ type: "SET_CONVERSATIONS", payload: mockConversations });
|
|
341
|
-
}, [state.config, userId]);
|
|
342
|
-
const value = {
|
|
343
|
-
state,
|
|
344
|
-
dispatch,
|
|
3
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { getSDK, } from "@openim/wasm-client-sdk";
|
|
5
|
+
const DChatSDK = getSDK();
|
|
6
|
+
export const ChatContext = createContext({
|
|
7
|
+
user: null,
|
|
8
|
+
});
|
|
9
|
+
export const useChatContext = () => useContext(ChatContext);
|
|
10
|
+
export const ChatProvider = ({ children, config }) => {
|
|
11
|
+
const [loading, setLoading] = useState(true);
|
|
12
|
+
const [user, setUser] = useState(null);
|
|
13
|
+
const getUserInfo = () => {
|
|
14
|
+
DChatSDK.getSelfUserInfo()
|
|
15
|
+
.then(({ data }) => {
|
|
16
|
+
setUser(data);
|
|
17
|
+
})
|
|
18
|
+
.catch(({ errCode, errMsg }) => {
|
|
19
|
+
console.log("getSelfUserInfo", errCode, errMsg);
|
|
20
|
+
});
|
|
345
21
|
};
|
|
346
|
-
|
|
347
|
-
|
|
22
|
+
const handleLogin = () => {
|
|
23
|
+
DChatSDK.login(config)
|
|
24
|
+
.then((res) => {
|
|
25
|
+
getUserInfo();
|
|
26
|
+
setLoading(false);
|
|
27
|
+
})
|
|
28
|
+
.catch(({ errCode, errMsg }) => {
|
|
29
|
+
console.log("login", errCode, errMsg);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
handleLogin();
|
|
34
|
+
}, [config]);
|
|
35
|
+
return (_jsx(ChatContext.Provider, { value: { user }, children: !loading ? children : null }));
|
|
36
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConversationItem, SessionType } from '@openim/wasm-client-sdk';
|
|
2
|
+
export declare const useConversationList: () => {
|
|
3
|
+
conversationList: ConversationItem[];
|
|
4
|
+
};
|
|
5
|
+
export declare const useConversationDetail: ({ sourceID, sessionType }: {
|
|
6
|
+
sourceID: string;
|
|
7
|
+
sessionType: SessionType;
|
|
8
|
+
}) => {
|
|
9
|
+
conversationDetail: ConversationItem | null;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useConversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useConversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAIhF,eAAO,MAAM,mBAAmB;;CA8B/B,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,2BAAyB;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAC;;CAqB1G,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getSDK } from '@openim/wasm-client-sdk';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
const DChatSDK = getSDK();
|
|
4
|
+
export const useConversationList = () => {
|
|
5
|
+
const [conversationList, setConversationList] = useState([]);
|
|
6
|
+
const getAllConversationList = useCallback(async () => {
|
|
7
|
+
DChatSDK.getAllConversationList().then(({ data }) => {
|
|
8
|
+
console.log('getAllConversationList', data);
|
|
9
|
+
setConversationList(data);
|
|
10
|
+
}).catch((err) => {
|
|
11
|
+
console.log('getAllConversationList', err);
|
|
12
|
+
});
|
|
13
|
+
}, []);
|
|
14
|
+
const getOneConversation = useCallback(async () => {
|
|
15
|
+
DChatSDK.getOneConversation({
|
|
16
|
+
sourceID: '3408237279',
|
|
17
|
+
sessionType: 3
|
|
18
|
+
}).then(({ data }) => {
|
|
19
|
+
console.log('getOneConversation', data);
|
|
20
|
+
}).catch((err) => {
|
|
21
|
+
console.log('getOneConversation', err);
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
getAllConversationList();
|
|
26
|
+
getOneConversation();
|
|
27
|
+
}, [getAllConversationList]);
|
|
28
|
+
return {
|
|
29
|
+
conversationList,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const useConversationDetail = ({ sourceID, sessionType }) => {
|
|
33
|
+
const [conversationDetail, setConversationDetail] = useState(null);
|
|
34
|
+
const getConversationDetail = useCallback(async () => {
|
|
35
|
+
DChatSDK.getOneConversation({
|
|
36
|
+
sourceID,
|
|
37
|
+
sessionType
|
|
38
|
+
}).then(({ data }) => {
|
|
39
|
+
console.log('getOneConversation', data);
|
|
40
|
+
setConversationDetail(data);
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
console.log('getOneConversation', err);
|
|
43
|
+
});
|
|
44
|
+
}, [sourceID, sessionType]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
getConversationDetail();
|
|
47
|
+
}, [getConversationDetail]);
|
|
48
|
+
return {
|
|
49
|
+
conversationDetail,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MessageItem } from "@openim/wasm-client-sdk";
|
|
2
|
+
export declare const useMessage: (conversationId?: string) => {
|
|
3
|
+
refetch: () => void;
|
|
4
|
+
isEnd?: boolean | undefined;
|
|
5
|
+
errCode?: number | undefined;
|
|
6
|
+
errMsg?: string | undefined;
|
|
7
|
+
messageList?: MessageItem[] | undefined;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=useMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAGjC,eAAO,MAAM,UAAU,GAAI,iBAAiB,MAAM;;;;;;CAqDjD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { getSDK, ViewType, CbEvents, } from "@openim/wasm-client-sdk";
|
|
3
|
+
const DChatSDK = getSDK();
|
|
4
|
+
export const useMessage = (conversationId) => {
|
|
5
|
+
const [dataMessages, setDataMessages] = useState(null);
|
|
6
|
+
const getAdvancedHistoryMessageList = useCallback(() => {
|
|
7
|
+
if (!conversationId)
|
|
8
|
+
return;
|
|
9
|
+
DChatSDK.getSelfUserInfo()
|
|
10
|
+
.then(({ data }) => {
|
|
11
|
+
console.log("getSelfUserInfo", data);
|
|
12
|
+
})
|
|
13
|
+
.catch(({ errCode, errMsg }) => {
|
|
14
|
+
console.log("getSelfUserInfo", errCode, errMsg);
|
|
15
|
+
});
|
|
16
|
+
DChatSDK.getAdvancedHistoryMessageList({
|
|
17
|
+
conversationID: conversationId,
|
|
18
|
+
count: 1000,
|
|
19
|
+
startClientMsgID: "",
|
|
20
|
+
viewType: ViewType.History,
|
|
21
|
+
})
|
|
22
|
+
.then(({ data }) => {
|
|
23
|
+
console.log("getAdvancedHistoryMessageList", data);
|
|
24
|
+
setDataMessages(data);
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
console.log("getAdvancedHistoryMessageList", err);
|
|
28
|
+
});
|
|
29
|
+
}, [conversationId]);
|
|
30
|
+
const onRecvNewMessages = useCallback((data) => {
|
|
31
|
+
getAdvancedHistoryMessageList();
|
|
32
|
+
}, [getAdvancedHistoryMessageList]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
getAdvancedHistoryMessageList();
|
|
35
|
+
}, [getAdvancedHistoryMessageList]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
DChatSDK.on(CbEvents.OnRecvNewMessages, ({ data }) => {
|
|
38
|
+
console.log("OnRecvNewMessages123", data);
|
|
39
|
+
onRecvNewMessages(data);
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
DChatSDK.off(CbEvents.OnRecvNewMessages, () => { });
|
|
43
|
+
};
|
|
44
|
+
}, [onRecvNewMessages]);
|
|
45
|
+
return Object.assign(Object.assign({}, dataMessages), { refetch: getAdvancedHistoryMessageList });
|
|
46
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface SendMessageProps {
|
|
2
|
+
recvID: string;
|
|
3
|
+
groupID: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const createTextMessage: (text: string) => Promise<import("@openim/wasm-client-sdk").MessageItem | null>;
|
|
6
|
+
export declare const useSendMessage: (props: SendMessageProps) => {
|
|
7
|
+
sendTextMessage: (text: string) => Promise<boolean>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=useSendMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAIA,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,kEAUnD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,gBAAgB;4BAIf,MAAM;CAsB5C,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getSDK } from "@openim/wasm-client-sdk";
|
|
2
|
+
import { useChatContext } from "src/context/ChatContext";
|
|
3
|
+
const DChatSDK = getSDK();
|
|
4
|
+
export const createTextMessage = async (text) => {
|
|
5
|
+
let textMessage = await DChatSDK.createTextMessage(text)
|
|
6
|
+
.then(({ data }) => {
|
|
7
|
+
return data;
|
|
8
|
+
})
|
|
9
|
+
.catch(({ errCode, errMsg }) => {
|
|
10
|
+
console.log("createTextMessage", errCode, errMsg);
|
|
11
|
+
return null;
|
|
12
|
+
});
|
|
13
|
+
return textMessage;
|
|
14
|
+
};
|
|
15
|
+
export const useSendMessage = (props) => {
|
|
16
|
+
const { user } = useChatContext();
|
|
17
|
+
const { recvID, groupID } = props;
|
|
18
|
+
const sendTextMessage = async (text) => {
|
|
19
|
+
let result = false;
|
|
20
|
+
if (!recvID && !groupID)
|
|
21
|
+
return false;
|
|
22
|
+
const textMessage = await createTextMessage(text);
|
|
23
|
+
console.log("textMessage", textMessage);
|
|
24
|
+
if (!textMessage)
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
await DChatSDK.sendMessage({
|
|
28
|
+
recvID,
|
|
29
|
+
groupID,
|
|
30
|
+
message: textMessage,
|
|
31
|
+
});
|
|
32
|
+
result = true;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.log("sendMessage", error);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
sendTextMessage,
|
|
41
|
+
};
|
|
42
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
+
import DChatDeskMessage from "./screens/desk-message";
|
|
2
|
+
import { Platform, LogLevel, SessionType, InitAndLoginConfig } from "@openim/wasm-client-sdk";
|
|
3
|
+
import { Icon } from "./components/icon";
|
|
4
|
+
import ChatBubble from "./components/ChatBubble";
|
|
1
5
|
export { ChatProvider, useChatContext } from "./context/ChatContext";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { useSwipeGesture } from "./hooks/useSwipeGesture";
|
|
8
|
-
export { ChatLayout } from "./components/ChatLayout";
|
|
9
|
-
export { ChatHeader } from "./components/ChatHeader";
|
|
10
|
-
export { MessageList } from "./components/MessageList";
|
|
11
|
-
export { MessageItem } from "./components/MessageItem";
|
|
12
|
-
export { ChatInput } from "./components/ChatInput";
|
|
13
|
-
export { ConversationList } from "./components/ConversationList";
|
|
14
|
-
export { ConversationItem } from "./components/ConversationItem";
|
|
15
|
-
export { DateDivider } from "./components/DateDivider";
|
|
16
|
-
export { MessageItemDemo } from "./components/MessageItemDemo";
|
|
17
|
-
export { ChatBubble } from "./components/ChatBubble";
|
|
18
|
-
export { TypingIndicator } from "./components/TypingIndicator";
|
|
19
|
-
export { VoiceWaveIcon } from "./components/VoiceWaveIcon";
|
|
20
|
-
export { TextFormattingToolbar } from "./components/TextFormattingToolbar";
|
|
21
|
-
export { SwipeIndicator } from "./components/SwipeIndicator";
|
|
22
|
-
export { ImagePreviewModal } from "./components/ImagePreviewModal";
|
|
23
|
-
export { ChatInputWithCustomIcon } from "./components/ChatInputWithCustomIcon";
|
|
24
|
-
export { EmojiPicker } from "./components/EmojiPicker";
|
|
25
|
-
export { ChatInputDemo } from "./components/ChatInputDemo";
|
|
26
|
-
export { ImageLightbox } from "./components/ImageLightbox";
|
|
27
|
-
export type { User, Message, Conversation, TypingStatus, ChatConfig, MessageItemProps, } from "./types";
|
|
6
|
+
export { DChatDeskMessage };
|
|
7
|
+
export { Icon };
|
|
8
|
+
export { ChatBubble };
|
|
9
|
+
export { Platform as DChatPlatform, LogLevel as DChatLogLevel, SessionType as DChatSessionType, };
|
|
10
|
+
export type { InitAndLoginConfig as DChatInitAndLoginConfig };
|
|
28
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGrE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,CAAC;AAItB,OAAO,EACL,QAAQ,IAAI,aAAa,EACzB,QAAQ,IAAI,aAAa,EACzB,WAAW,IAAI,gBAAgB,GAChC,CAAC;AAEF,YAAY,EAAE,kBAAkB,IAAI,uBAAuB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
+
import DChatDeskMessage from "./screens/desk-message";
|
|
2
|
+
import { Platform, LogLevel, SessionType, } from "@openim/wasm-client-sdk";
|
|
3
|
+
import { Icon } from "./components/icon";
|
|
4
|
+
import ChatBubble from "./components/ChatBubble";
|
|
1
5
|
// Main exports for the SDK
|
|
2
6
|
export { ChatProvider, useChatContext } from "./context/ChatContext";
|
|
3
|
-
//
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
export { useSwipeGesture } from "./hooks/useSwipeGesture";
|
|
10
|
-
// Components
|
|
11
|
-
export { ChatLayout } from "./components/ChatLayout";
|
|
12
|
-
export { ChatHeader } from "./components/ChatHeader";
|
|
13
|
-
export { MessageList } from "./components/MessageList";
|
|
14
|
-
export { MessageItem } from "./components/MessageItem";
|
|
15
|
-
export { ChatInput } from "./components/ChatInput";
|
|
16
|
-
export { ConversationList } from "./components/ConversationList";
|
|
17
|
-
export { ConversationItem } from "./components/ConversationItem";
|
|
18
|
-
export { DateDivider } from "./components/DateDivider";
|
|
19
|
-
export { MessageItemDemo } from "./components/MessageItemDemo";
|
|
20
|
-
export { ChatBubble } from "./components/ChatBubble";
|
|
21
|
-
export { TypingIndicator } from "./components/TypingIndicator";
|
|
22
|
-
export { VoiceWaveIcon } from "./components/VoiceWaveIcon";
|
|
23
|
-
export { TextFormattingToolbar } from "./components/TextFormattingToolbar";
|
|
24
|
-
export { SwipeIndicator } from "./components/SwipeIndicator";
|
|
25
|
-
export { ImagePreviewModal } from "./components/ImagePreviewModal";
|
|
26
|
-
export { ChatInputWithCustomIcon } from "./components/ChatInputWithCustomIcon";
|
|
27
|
-
export { EmojiPicker } from "./components/EmojiPicker";
|
|
28
|
-
export { ChatInputDemo } from "./components/ChatInputDemo";
|
|
29
|
-
export { ImageLightbox } from "./components/ImageLightbox";
|
|
7
|
+
//Screens
|
|
8
|
+
export { DChatDeskMessage };
|
|
9
|
+
export { Icon };
|
|
10
|
+
export { ChatBubble };
|
|
11
|
+
// export * from "./types/sdk";
|
|
12
|
+
export { Platform as DChatPlatform, LogLevel as DChatLogLevel, SessionType as DChatSessionType, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screens/desk-message/index.tsx"],"names":[],"mappings":"AAQA,QAAA,MAAM,gBAAgB,+CAcrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|