@droppii-org/chat-sdk 0.0.4 → 0.0.5
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/tsconfig.tsbuildinfo +1 -0
- package/package.json +11 -4
- 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.d.ts +0 -2
- package/dist/components/ChatBubble.d.ts.map +0 -1
- package/dist/components/ChatBubble.js +0 -18
- 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.d.ts +0 -72
- package/dist/context/ChatContext.d.ts.map +0 -1
- package/dist/context/ChatContext.js +0 -347
- 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
- package/dist/index.d.ts +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -29
- package/dist/types/chat.d.ts +0 -39
- package/dist/types/chat.d.ts.map +0 -1
- package/dist/types/chat.js +0 -1
- package/dist/types/index.d.ts +0 -86
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { createContext, useContext, useReducer, useEffect } from "react";
|
|
3
|
-
const initialState = {
|
|
4
|
-
config: null,
|
|
5
|
-
conversations: [],
|
|
6
|
-
messages: {},
|
|
7
|
-
users: {},
|
|
8
|
-
typingStatuses: [],
|
|
9
|
-
currentUser: null,
|
|
10
|
-
isConnected: false,
|
|
11
|
-
};
|
|
12
|
-
function chatReducer(state, action) {
|
|
13
|
-
switch (action.type) {
|
|
14
|
-
case "SET_CONFIG":
|
|
15
|
-
return Object.assign(Object.assign({}, state), { config: action.payload });
|
|
16
|
-
case "SET_CONVERSATIONS":
|
|
17
|
-
return Object.assign(Object.assign({}, state), { conversations: action.payload });
|
|
18
|
-
case "ADD_CONVERSATION":
|
|
19
|
-
return Object.assign(Object.assign({}, state), { conversations: [action.payload, ...state.conversations] });
|
|
20
|
-
case "UPDATE_CONVERSATION":
|
|
21
|
-
return Object.assign(Object.assign({}, state), { conversations: state.conversations.map((conv) => (conv.id === action.payload.id ? action.payload : conv)) });
|
|
22
|
-
case "SET_MESSAGES":
|
|
23
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: action.payload.messages }) });
|
|
24
|
-
case "ADD_MESSAGE":
|
|
25
|
-
const conversationId = action.payload.conversationId;
|
|
26
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [conversationId]: [...(state.messages[conversationId] || []), action.payload] }) });
|
|
27
|
-
case "UPDATE_MESSAGE":
|
|
28
|
-
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) }) });
|
|
29
|
-
case "SET_USERS":
|
|
30
|
-
return Object.assign(Object.assign({}, state), { users: action.payload });
|
|
31
|
-
case "UPDATE_USER":
|
|
32
|
-
return Object.assign(Object.assign({}, state), { users: Object.assign(Object.assign({}, state.users), { [action.payload.id]: action.payload }) });
|
|
33
|
-
case "SET_TYPING":
|
|
34
|
-
return Object.assign(Object.assign({}, state), { typingStatuses: [
|
|
35
|
-
...state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)),
|
|
36
|
-
action.payload,
|
|
37
|
-
] });
|
|
38
|
-
case "REMOVE_TYPING":
|
|
39
|
-
return Object.assign(Object.assign({}, state), { typingStatuses: state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)) });
|
|
40
|
-
case "SET_CONNECTION_STATUS":
|
|
41
|
-
return Object.assign(Object.assign({}, state), { isConnected: action.payload });
|
|
42
|
-
default:
|
|
43
|
-
return state;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const ChatContext = createContext(null);
|
|
47
|
-
export function useChatContext() {
|
|
48
|
-
const context = useContext(ChatContext);
|
|
49
|
-
if (!context) {
|
|
50
|
-
throw new Error("useChatContext must be used within a ChatProvider");
|
|
51
|
-
}
|
|
52
|
-
return context;
|
|
53
|
-
}
|
|
54
|
-
export function ChatProvider({ children, userId, token, onTokenRefresh, websocketUrl = "demo", // Use "demo" as default to disable WebSocket
|
|
55
|
-
enableWebSocket = false, // Disabled by default for demo
|
|
56
|
-
}) {
|
|
57
|
-
const [state, dispatch] = useReducer(chatReducer, initialState);
|
|
58
|
-
// Initialize config
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
const config = {
|
|
61
|
-
userId,
|
|
62
|
-
token,
|
|
63
|
-
wsUrl: enableWebSocket ? websocketUrl : "demo",
|
|
64
|
-
onTokenRefresh,
|
|
65
|
-
};
|
|
66
|
-
dispatch({ type: "SET_CONFIG", payload: config });
|
|
67
|
-
// Initialize current user
|
|
68
|
-
const currentUser = {
|
|
69
|
-
id: userId,
|
|
70
|
-
name: "You",
|
|
71
|
-
status: "online",
|
|
72
|
-
};
|
|
73
|
-
dispatch({ type: "UPDATE_USER", payload: currentUser });
|
|
74
|
-
}, [userId, token, websocketUrl, onTokenRefresh, enableWebSocket]);
|
|
75
|
-
// Initialize with mock data for demo - MORE CONVERSATIONS
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
if (!state.config)
|
|
78
|
-
return;
|
|
79
|
-
const mockUsers = {
|
|
80
|
-
[userId]: {
|
|
81
|
-
id: userId,
|
|
82
|
-
name: "You",
|
|
83
|
-
status: "online",
|
|
84
|
-
},
|
|
85
|
-
"user-2": {
|
|
86
|
-
id: "user-2",
|
|
87
|
-
name: "Alice Johnson",
|
|
88
|
-
status: "online",
|
|
89
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
90
|
-
},
|
|
91
|
-
"user-3": {
|
|
92
|
-
id: "user-3",
|
|
93
|
-
name: "Bob Smith",
|
|
94
|
-
status: "offline",
|
|
95
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
96
|
-
lastSeen: new Date(Date.now() - 7200000),
|
|
97
|
-
},
|
|
98
|
-
"user-4": {
|
|
99
|
-
id: "user-4",
|
|
100
|
-
name: "Carol Davis",
|
|
101
|
-
status: "online",
|
|
102
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
103
|
-
},
|
|
104
|
-
"user-5": {
|
|
105
|
-
id: "user-5",
|
|
106
|
-
name: "David Wilson",
|
|
107
|
-
status: "away",
|
|
108
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
109
|
-
lastSeen: new Date(Date.now() - 1800000),
|
|
110
|
-
},
|
|
111
|
-
"user-6": {
|
|
112
|
-
id: "user-6",
|
|
113
|
-
name: "Emma Brown",
|
|
114
|
-
status: "online",
|
|
115
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
116
|
-
},
|
|
117
|
-
"user-7": {
|
|
118
|
-
id: "user-7",
|
|
119
|
-
name: "Frank Miller",
|
|
120
|
-
status: "offline",
|
|
121
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
122
|
-
lastSeen: new Date(Date.now() - 86400000),
|
|
123
|
-
},
|
|
124
|
-
"user-8": {
|
|
125
|
-
id: "user-8",
|
|
126
|
-
name: "Grace Lee",
|
|
127
|
-
status: "online",
|
|
128
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
129
|
-
},
|
|
130
|
-
"user-9": {
|
|
131
|
-
id: "user-9",
|
|
132
|
-
name: "Henry Taylor",
|
|
133
|
-
status: "away",
|
|
134
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
135
|
-
lastSeen: new Date(Date.now() - 3600000),
|
|
136
|
-
},
|
|
137
|
-
"user-10": {
|
|
138
|
-
id: "user-10",
|
|
139
|
-
name: "Ivy Chen",
|
|
140
|
-
status: "online",
|
|
141
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
142
|
-
},
|
|
143
|
-
"group-1": {
|
|
144
|
-
id: "group-1",
|
|
145
|
-
name: "Team Project",
|
|
146
|
-
status: "online",
|
|
147
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
148
|
-
},
|
|
149
|
-
"group-2": {
|
|
150
|
-
id: "group-2",
|
|
151
|
-
name: "Family Chat",
|
|
152
|
-
status: "online",
|
|
153
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
const mockConversations = [
|
|
157
|
-
{
|
|
158
|
-
id: "conv-1",
|
|
159
|
-
participants: [mockUsers["user-2"], mockUsers[userId]],
|
|
160
|
-
unreadCount: 2,
|
|
161
|
-
updatedAt: new Date(Date.now() - 300000), // 5 minutes ago
|
|
162
|
-
type: "direct",
|
|
163
|
-
lastMessage: {
|
|
164
|
-
id: "msg-1",
|
|
165
|
-
conversationId: "conv-1",
|
|
166
|
-
senderId: "user-2",
|
|
167
|
-
content: "Hey there! How are you doing? 😊",
|
|
168
|
-
type: "text",
|
|
169
|
-
timestamp: new Date(Date.now() - 300000),
|
|
170
|
-
status: "delivered",
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
id: "conv-2",
|
|
175
|
-
participants: [mockUsers["user-3"], mockUsers[userId]],
|
|
176
|
-
unreadCount: 0,
|
|
177
|
-
updatedAt: new Date(Date.now() - 1800000), // 30 minutes ago
|
|
178
|
-
type: "direct",
|
|
179
|
-
lastMessage: {
|
|
180
|
-
id: "msg-2",
|
|
181
|
-
conversationId: "conv-2",
|
|
182
|
-
senderId: userId,
|
|
183
|
-
content: "Thanks for the help earlier!",
|
|
184
|
-
type: "text",
|
|
185
|
-
timestamp: new Date(Date.now() - 1800000),
|
|
186
|
-
status: "read",
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
id: "conv-3",
|
|
191
|
-
participants: [mockUsers["user-4"], mockUsers[userId]],
|
|
192
|
-
unreadCount: 1,
|
|
193
|
-
updatedAt: new Date(Date.now() - 3600000), // 1 hour ago
|
|
194
|
-
type: "direct",
|
|
195
|
-
lastMessage: {
|
|
196
|
-
id: "msg-3",
|
|
197
|
-
conversationId: "conv-3",
|
|
198
|
-
senderId: "user-4",
|
|
199
|
-
content: "Can you review this document?",
|
|
200
|
-
type: "file",
|
|
201
|
-
timestamp: new Date(Date.now() - 3600000),
|
|
202
|
-
status: "delivered",
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
id: "conv-4",
|
|
207
|
-
participants: [mockUsers["user-5"], mockUsers[userId]],
|
|
208
|
-
unreadCount: 0,
|
|
209
|
-
updatedAt: new Date(Date.now() - 7200000), // 2 hours ago
|
|
210
|
-
type: "direct",
|
|
211
|
-
lastMessage: {
|
|
212
|
-
id: "msg-4",
|
|
213
|
-
conversationId: "conv-4",
|
|
214
|
-
senderId: userId,
|
|
215
|
-
content: "See you tomorrow!",
|
|
216
|
-
type: "text",
|
|
217
|
-
timestamp: new Date(Date.now() - 7200000),
|
|
218
|
-
status: "read",
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
id: "conv-5",
|
|
223
|
-
participants: [mockUsers["user-6"], mockUsers[userId]],
|
|
224
|
-
unreadCount: 3,
|
|
225
|
-
updatedAt: new Date(Date.now() - 10800000), // 3 hours ago
|
|
226
|
-
type: "direct",
|
|
227
|
-
lastMessage: {
|
|
228
|
-
id: "msg-5",
|
|
229
|
-
conversationId: "conv-5",
|
|
230
|
-
senderId: "user-6",
|
|
231
|
-
content: "Check out these photos from the event!",
|
|
232
|
-
type: "image",
|
|
233
|
-
timestamp: new Date(Date.now() - 10800000),
|
|
234
|
-
status: "delivered",
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
id: "conv-6",
|
|
239
|
-
participants: [mockUsers["user-7"], mockUsers[userId]],
|
|
240
|
-
unreadCount: 0,
|
|
241
|
-
updatedAt: new Date(Date.now() - 86400000), // 1 day ago
|
|
242
|
-
type: "direct",
|
|
243
|
-
lastMessage: {
|
|
244
|
-
id: "msg-6",
|
|
245
|
-
conversationId: "conv-6",
|
|
246
|
-
senderId: "user-7",
|
|
247
|
-
content: "Happy birthday! 🎉",
|
|
248
|
-
type: "text",
|
|
249
|
-
timestamp: new Date(Date.now() - 86400000),
|
|
250
|
-
status: "read",
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
id: "conv-7",
|
|
255
|
-
participants: [mockUsers["user-8"], mockUsers[userId]],
|
|
256
|
-
unreadCount: 0,
|
|
257
|
-
updatedAt: new Date(Date.now() - 172800000), // 2 days ago
|
|
258
|
-
type: "direct",
|
|
259
|
-
lastMessage: {
|
|
260
|
-
id: "msg-7",
|
|
261
|
-
conversationId: "conv-7",
|
|
262
|
-
senderId: userId,
|
|
263
|
-
content: "Thanks for the coffee recommendation!",
|
|
264
|
-
type: "text",
|
|
265
|
-
timestamp: new Date(Date.now() - 172800000),
|
|
266
|
-
status: "read",
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
id: "conv-8",
|
|
271
|
-
participants: [mockUsers["user-9"], mockUsers[userId]],
|
|
272
|
-
unreadCount: 1,
|
|
273
|
-
updatedAt: new Date(Date.now() - 259200000), // 3 days ago
|
|
274
|
-
type: "direct",
|
|
275
|
-
lastMessage: {
|
|
276
|
-
id: "msg-8",
|
|
277
|
-
conversationId: "conv-8",
|
|
278
|
-
senderId: "user-9",
|
|
279
|
-
content: "Let's schedule a meeting next week",
|
|
280
|
-
type: "text",
|
|
281
|
-
timestamp: new Date(Date.now() - 259200000),
|
|
282
|
-
status: "delivered",
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
id: "conv-9",
|
|
287
|
-
participants: [mockUsers["user-10"], mockUsers[userId]],
|
|
288
|
-
unreadCount: 0,
|
|
289
|
-
updatedAt: new Date(Date.now() - 345600000), // 4 days ago
|
|
290
|
-
type: "direct",
|
|
291
|
-
lastMessage: {
|
|
292
|
-
id: "msg-9",
|
|
293
|
-
conversationId: "conv-9",
|
|
294
|
-
senderId: userId,
|
|
295
|
-
content: "Great presentation today!",
|
|
296
|
-
type: "text",
|
|
297
|
-
timestamp: new Date(Date.now() - 345600000),
|
|
298
|
-
status: "read",
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
id: "group-conv-1",
|
|
303
|
-
participants: [mockUsers["group-1"], mockUsers[userId], mockUsers["user-2"], mockUsers["user-4"]],
|
|
304
|
-
unreadCount: 5,
|
|
305
|
-
updatedAt: new Date(Date.now() - 600000), // 10 minutes ago
|
|
306
|
-
type: "group",
|
|
307
|
-
name: "Team Project",
|
|
308
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
309
|
-
lastMessage: {
|
|
310
|
-
id: "msg-group-1",
|
|
311
|
-
conversationId: "group-conv-1",
|
|
312
|
-
senderId: "user-4",
|
|
313
|
-
content: "The deadline has been moved to Friday",
|
|
314
|
-
type: "text",
|
|
315
|
-
timestamp: new Date(Date.now() - 600000),
|
|
316
|
-
status: "delivered",
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
id: "group-conv-2",
|
|
321
|
-
participants: [mockUsers["group-2"], mockUsers[userId], mockUsers["user-6"], mockUsers["user-8"]],
|
|
322
|
-
unreadCount: 0,
|
|
323
|
-
updatedAt: new Date(Date.now() - 432000000), // 5 days ago
|
|
324
|
-
type: "group",
|
|
325
|
-
name: "Family Chat",
|
|
326
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
327
|
-
lastMessage: {
|
|
328
|
-
id: "msg-group-2",
|
|
329
|
-
conversationId: "group-conv-2",
|
|
330
|
-
senderId: "user-6",
|
|
331
|
-
content: "Looking forward to the reunion!",
|
|
332
|
-
type: "text",
|
|
333
|
-
timestamp: new Date(Date.now() - 432000000),
|
|
334
|
-
status: "read",
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
];
|
|
338
|
-
dispatch({ type: "SET_USERS", payload: mockUsers });
|
|
339
|
-
dispatch({ type: "SET_CONVERSATIONS", payload: mockConversations });
|
|
340
|
-
}, [state.config, userId]);
|
|
341
|
-
const value = {
|
|
342
|
-
state,
|
|
343
|
-
dispatch,
|
|
344
|
-
};
|
|
345
|
-
return <ChatContext.Provider value={value}>{children}</ChatContext.Provider>;
|
|
346
|
-
}
|
package/dist/hooks/useChat.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useChat.ts"],"names":[],"mappings":"AAOA,wBAAgB,OAAO,CAAC,cAAc,EAAE,MAAM;2BAK1B,MAAM,SAAQ,MAAM,GAAG,OAAO,GAAG,MAAM;4BA6DrC,MAAM;EAmB3B"}
|
package/dist/hooks/useChat.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback } from "react";
|
|
3
|
-
import { useChatContext } from "../context/ChatContext";
|
|
4
|
-
import { useSocket } from "./useSocket";
|
|
5
|
-
export function useChat(conversationId) {
|
|
6
|
-
const { state, dispatch } = useChatContext();
|
|
7
|
-
const { sendMessage: sendSocketMessage, isConnected } = useSocket();
|
|
8
|
-
const sendMessage = useCallback(async (content, type = "text") => {
|
|
9
|
-
var _a;
|
|
10
|
-
if (!((_a = state.config) === null || _a === void 0 ? void 0 : _a.userId) || !conversationId)
|
|
11
|
-
return;
|
|
12
|
-
const message = {
|
|
13
|
-
id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
14
|
-
conversationId,
|
|
15
|
-
senderId: state.config.userId,
|
|
16
|
-
content,
|
|
17
|
-
type,
|
|
18
|
-
timestamp: new Date(),
|
|
19
|
-
status: "sending",
|
|
20
|
-
};
|
|
21
|
-
// Add message optimistically
|
|
22
|
-
dispatch({ type: "ADD_MESSAGE", payload: message });
|
|
23
|
-
try {
|
|
24
|
-
// Try to send via WebSocket if connected
|
|
25
|
-
const socketSent = sendSocketMessage({
|
|
26
|
-
type: "message",
|
|
27
|
-
data: message,
|
|
28
|
-
});
|
|
29
|
-
// Update message status
|
|
30
|
-
const updatedMessage = Object.assign(Object.assign({}, message), { status: (socketSent && isConnected ? "sent" : "delivered") });
|
|
31
|
-
// Simulate a small delay for better UX
|
|
32
|
-
setTimeout(() => {
|
|
33
|
-
dispatch({
|
|
34
|
-
type: "UPDATE_MESSAGE",
|
|
35
|
-
payload: updatedMessage,
|
|
36
|
-
});
|
|
37
|
-
}, 100);
|
|
38
|
-
// Update conversation's last message
|
|
39
|
-
const conversation = state.conversations.find((c) => c.id === conversationId);
|
|
40
|
-
if (conversation) {
|
|
41
|
-
dispatch({
|
|
42
|
-
type: "UPDATE_CONVERSATION",
|
|
43
|
-
payload: Object.assign(Object.assign({}, conversation), { lastMessage: updatedMessage, updatedAt: new Date() }),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error("Failed to send message:", error);
|
|
49
|
-
dispatch({
|
|
50
|
-
type: "UPDATE_MESSAGE",
|
|
51
|
-
payload: Object.assign(Object.assign({}, message), { status: "delivered" }), // Still mark as delivered for demo
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}, [state.config, conversationId, dispatch, sendSocketMessage, isConnected, state.conversations]);
|
|
55
|
-
const markAsRead = useCallback(async (messageId) => {
|
|
56
|
-
var _a;
|
|
57
|
-
if (!((_a = state.config) === null || _a === void 0 ? void 0 : _a.token))
|
|
58
|
-
return;
|
|
59
|
-
try {
|
|
60
|
-
sendSocketMessage({
|
|
61
|
-
type: "read",
|
|
62
|
-
data: { messageId, conversationId },
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error("Failed to mark message as read:", error);
|
|
67
|
-
}
|
|
68
|
-
}, [state.config, conversationId, sendSocketMessage]);
|
|
69
|
-
return {
|
|
70
|
-
sendMessage,
|
|
71
|
-
markAsRead,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useConversationList.d.ts","sourceRoot":"","sources":["../../src/hooks/useConversationList.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB;;;EAOlC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.d.ts","sourceRoot":"","sources":["../../src/hooks/useMessages.ts"],"names":[],"mappings":"AAKA,wBAAgB,WAAW,CAAC,cAAc,EAAE,MAAM;;;EA+LjD"}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { useChatContext } from "../context/ChatContext";
|
|
4
|
-
export function useMessages(conversationId) {
|
|
5
|
-
const { state, dispatch } = useChatContext();
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
var _a;
|
|
8
|
-
// Load messages for conversation if not already loaded
|
|
9
|
-
if (conversationId && !state.messages[conversationId] && ((_a = state.config) === null || _a === void 0 ? void 0 : _a.token)) {
|
|
10
|
-
// For demo, add some mock messages with different types
|
|
11
|
-
const mockMessages = [
|
|
12
|
-
// Older messages (yesterday)
|
|
13
|
-
{
|
|
14
|
-
id: "old-1",
|
|
15
|
-
conversationId,
|
|
16
|
-
senderId: "user-2",
|
|
17
|
-
content: "Hey! How was your weekend?",
|
|
18
|
-
type: "text",
|
|
19
|
-
timestamp: new Date(Date.now() - 86400000 - 3600000), // Yesterday, 1 hour earlier
|
|
20
|
-
status: "read",
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: "old-2",
|
|
24
|
-
conversationId,
|
|
25
|
-
senderId: state.config.userId,
|
|
26
|
-
content: "It was great! Went hiking with friends 🏔️",
|
|
27
|
-
type: "text",
|
|
28
|
-
timestamp: new Date(Date.now() - 86400000 - 3000000), // Yesterday, 50 minutes earlier
|
|
29
|
-
status: "read",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: "old-3",
|
|
33
|
-
conversationId,
|
|
34
|
-
senderId: state.config.userId,
|
|
35
|
-
content: "Here are some photos from the trip!",
|
|
36
|
-
type: "image",
|
|
37
|
-
timestamp: new Date(Date.now() - 86400000 - 2700000), // Yesterday, 45 minutes earlier
|
|
38
|
-
status: "read",
|
|
39
|
-
attachments: [
|
|
40
|
-
{
|
|
41
|
-
id: "att-old-1",
|
|
42
|
-
name: "mountain1.jpg",
|
|
43
|
-
url: "/placeholder.svg?height=300&width=400",
|
|
44
|
-
type: "image/jpeg",
|
|
45
|
-
size: 245760,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: "att-old-2",
|
|
49
|
-
name: "mountain2.jpg",
|
|
50
|
-
url: "/placeholder.svg?height=300&width=400",
|
|
51
|
-
type: "image/jpeg",
|
|
52
|
-
size: 198432,
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
id: "old-4",
|
|
58
|
-
conversationId,
|
|
59
|
-
senderId: "user-2",
|
|
60
|
-
content: "Wow, those are amazing! 😍 The view is incredible!",
|
|
61
|
-
type: "text",
|
|
62
|
-
timestamp: new Date(Date.now() - 86400000 - 2400000), // Yesterday, 40 minutes earlier
|
|
63
|
-
status: "read",
|
|
64
|
-
},
|
|
65
|
-
// Today's messages
|
|
66
|
-
{
|
|
67
|
-
id: "1",
|
|
68
|
-
conversationId,
|
|
69
|
-
senderId: "user-2",
|
|
70
|
-
content: "Hey there! How are you doing today? 😊",
|
|
71
|
-
type: "text",
|
|
72
|
-
timestamp: new Date(Date.now() - 3600000), // 1 hour ago
|
|
73
|
-
status: "read",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
id: "2",
|
|
77
|
-
conversationId,
|
|
78
|
-
senderId: state.config.userId,
|
|
79
|
-
content: "I'm doing great! Thanks for asking. How about you?",
|
|
80
|
-
type: "text",
|
|
81
|
-
timestamp: new Date(Date.now() - 3000000), // 50 minutes ago
|
|
82
|
-
status: "read",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: "3",
|
|
86
|
-
conversationId,
|
|
87
|
-
senderId: "user-2",
|
|
88
|
-
content: "I'm good too! By the way, check out this cool website: https://example.com",
|
|
89
|
-
type: "text",
|
|
90
|
-
timestamp: new Date(Date.now() - 2700000), // 45 minutes ago
|
|
91
|
-
status: "read",
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "4",
|
|
95
|
-
conversationId,
|
|
96
|
-
senderId: state.config.userId,
|
|
97
|
-
content: "Look at this beautiful sunset!",
|
|
98
|
-
type: "image",
|
|
99
|
-
timestamp: new Date(Date.now() - 2400000), // 40 minutes ago
|
|
100
|
-
status: "read",
|
|
101
|
-
attachments: [
|
|
102
|
-
{
|
|
103
|
-
id: "att-1",
|
|
104
|
-
name: "sunset.jpg",
|
|
105
|
-
url: "/placeholder.svg?height=300&width=400",
|
|
106
|
-
type: "image/jpeg",
|
|
107
|
-
size: 245760,
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
id: "5",
|
|
113
|
-
conversationId,
|
|
114
|
-
senderId: "user-2",
|
|
115
|
-
content: "Here's the document you requested",
|
|
116
|
-
type: "file",
|
|
117
|
-
timestamp: new Date(Date.now() - 1800000), // 30 minutes ago
|
|
118
|
-
status: "read",
|
|
119
|
-
attachments: [
|
|
120
|
-
{
|
|
121
|
-
id: "att-2",
|
|
122
|
-
name: "project-proposal.pdf",
|
|
123
|
-
url: "/placeholder.svg?height=200&width=200",
|
|
124
|
-
type: "application/pdf",
|
|
125
|
-
size: 1024000,
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: "6",
|
|
131
|
-
conversationId,
|
|
132
|
-
senderId: state.config.userId,
|
|
133
|
-
content: "Photos from my vacation 📸",
|
|
134
|
-
type: "image",
|
|
135
|
-
timestamp: new Date(Date.now() - 1200000), // 20 minutes ago
|
|
136
|
-
status: "read",
|
|
137
|
-
attachments: [
|
|
138
|
-
{
|
|
139
|
-
id: "att-3",
|
|
140
|
-
name: "beach1.jpg",
|
|
141
|
-
url: "/placeholder.svg?height=200&width=300",
|
|
142
|
-
type: "image/jpeg",
|
|
143
|
-
size: 180000,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
id: "att-4",
|
|
147
|
-
name: "beach2.jpg",
|
|
148
|
-
url: "/placeholder.svg?height=200&width=300",
|
|
149
|
-
type: "image/jpeg",
|
|
150
|
-
size: 195000,
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
id: "7",
|
|
156
|
-
conversationId,
|
|
157
|
-
senderId: "user-2",
|
|
158
|
-
content: "Wow, those photos are amazing! 🏖️",
|
|
159
|
-
type: "text",
|
|
160
|
-
timestamp: new Date(Date.now() - 600000), // 10 minutes ago
|
|
161
|
-
status: "read",
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
id: "8",
|
|
165
|
-
conversationId,
|
|
166
|
-
senderId: state.config.userId,
|
|
167
|
-
content: "Thanks! The weather was perfect 🌞",
|
|
168
|
-
type: "text",
|
|
169
|
-
timestamp: new Date(Date.now() - 300000), // 5 minutes ago
|
|
170
|
-
status: "read",
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
id: "9",
|
|
174
|
-
conversationId,
|
|
175
|
-
senderId: "user-2",
|
|
176
|
-
content: "I'm so jealous! I need a vacation too 😅",
|
|
177
|
-
type: "text",
|
|
178
|
-
timestamp: new Date(Date.now() - 60000), // 1 minute ago
|
|
179
|
-
status: "delivered",
|
|
180
|
-
},
|
|
181
|
-
];
|
|
182
|
-
dispatch({
|
|
183
|
-
type: "SET_MESSAGES",
|
|
184
|
-
payload: { conversationId, messages: mockMessages },
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}, [conversationId, state.messages, state.config, dispatch]);
|
|
188
|
-
return {
|
|
189
|
-
messages: state.messages[conversationId] || [], // Ensure always returns array
|
|
190
|
-
isLoading: false,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSocket.d.ts","sourceRoot":"","sources":["../../src/hooks/useSocket.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS;;2BAgGmB,GAAG;;;EA+B9C"}
|