@pubuduth-aplicy/chat-ui 2.2.7 → 2.2.9
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/package.json
CHANGED
|
@@ -25,7 +25,7 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
25
25
|
// "Selected Conversation Data:",
|
|
26
26
|
// JSON.stringify(conversation, null, 2)
|
|
27
27
|
// );
|
|
28
|
-
setSelectedConversation(conversation)
|
|
28
|
+
setSelectedConversation(conversation as any)
|
|
29
29
|
const unreadMessageIds = conversation.unreadMessageIds || [];
|
|
30
30
|
if (unreadMessageIds.length > 0 && socket?.readyState === WebSocket.OPEN) {
|
|
31
31
|
// console.log("unread messages", unreadMessageIds);
|
|
@@ -79,18 +79,7 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
79
79
|
: participant?.name || "Conversation";
|
|
80
80
|
|
|
81
81
|
const formatLastMessageTime = (dateString: string) => {
|
|
82
|
-
// Validate date input
|
|
83
|
-
if (!dateString) {
|
|
84
|
-
return "";
|
|
85
|
-
}
|
|
86
|
-
|
|
87
82
|
const date = new Date(dateString);
|
|
88
|
-
|
|
89
|
-
// Check if date is valid
|
|
90
|
-
if (isNaN(date.getTime())) {
|
|
91
|
-
return "";
|
|
92
|
-
}
|
|
93
|
-
|
|
94
83
|
const now = new Date();
|
|
95
84
|
|
|
96
85
|
const isToday = date.toDateString() === now.toDateString();
|
|
@@ -141,8 +130,8 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
141
130
|
<img
|
|
142
131
|
className="w-10 h-10 rounded-full"
|
|
143
132
|
src={
|
|
144
|
-
participant?.
|
|
145
|
-
? participant?.
|
|
133
|
+
participant?.profilePicture
|
|
134
|
+
? participant?.profilePicture
|
|
146
135
|
: defaultProfilePicture
|
|
147
136
|
}
|
|
148
137
|
alt="User Avatar"
|
|
@@ -183,4 +172,4 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
183
172
|
);
|
|
184
173
|
};
|
|
185
174
|
|
|
186
|
-
export default memo(Conversation);
|
|
175
|
+
export default memo(Conversation);
|
|
@@ -134,18 +134,7 @@ const Conversations = () => {
|
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
const handleNewMessage = (newMessage: any) => {
|
|
137
|
-
|
|
138
|
-
const conversationId = newMessage?.conversationId || newMessage?.chatId;
|
|
139
|
-
|
|
140
|
-
if (!conversationId) return;
|
|
141
|
-
|
|
142
|
-
// Ensure we have a valid message object
|
|
143
|
-
const messageData = {
|
|
144
|
-
...newMessage,
|
|
145
|
-
conversationId: conversationId, // Normalize to conversationId
|
|
146
|
-
createdAt: newMessage.createdAt || new Date().toISOString(),
|
|
147
|
-
updatedAt: newMessage.updatedAt || new Date().toISOString()
|
|
148
|
-
};
|
|
137
|
+
if (!newMessage?.conversationId) return;
|
|
149
138
|
|
|
150
139
|
setConversations((prev) => {
|
|
151
140
|
const personalChats = [...prev.personalChats];
|
|
@@ -153,20 +142,20 @@ const Conversations = () => {
|
|
|
153
142
|
|
|
154
143
|
const updateConversation = (convo: ConversationType) => ({
|
|
155
144
|
...convo,
|
|
156
|
-
lastMessage:
|
|
145
|
+
lastMessage: newMessage,
|
|
157
146
|
updatedAt: new Date().toISOString(),
|
|
158
147
|
unreadMessageIds:
|
|
159
|
-
userId !==
|
|
160
|
-
? [...(convo.unreadMessageIds || []),
|
|
148
|
+
userId !== newMessage.senderId
|
|
149
|
+
? [...(convo.unreadMessageIds || []), newMessage._id]
|
|
161
150
|
: convo.unreadMessageIds || [],
|
|
162
151
|
unreadMessageCount:
|
|
163
|
-
userId !==
|
|
152
|
+
userId !== newMessage.senderId
|
|
164
153
|
? (convo.unreadMessageCount || 0) + 1
|
|
165
154
|
: convo.unreadMessageCount || 0,
|
|
166
155
|
});
|
|
167
156
|
|
|
168
157
|
const personalIndex = personalChats.findIndex(
|
|
169
|
-
(c) => c._id === conversationId
|
|
158
|
+
(c) => c._id === newMessage.conversationId
|
|
170
159
|
);
|
|
171
160
|
if (personalIndex >= 0) {
|
|
172
161
|
personalChats[personalIndex] = updateConversation(
|
|
@@ -178,7 +167,7 @@ const Conversations = () => {
|
|
|
178
167
|
for (const serviceId in groupedServiceChats) {
|
|
179
168
|
const serviceIndex = groupedServiceChats[
|
|
180
169
|
serviceId
|
|
181
|
-
].conversations.findIndex((c) => c._id === conversationId);
|
|
170
|
+
].conversations.findIndex((c) => c._id === newMessage.conversationId);
|
|
182
171
|
if (serviceIndex >= 0) {
|
|
183
172
|
const updatedConversations = [
|
|
184
173
|
...groupedServiceChats[serviceId].conversations,
|
|
@@ -194,14 +183,10 @@ const Conversations = () => {
|
|
|
194
183
|
}
|
|
195
184
|
}
|
|
196
185
|
|
|
197
|
-
// Only add new conversation if we have enough info
|
|
198
|
-
// This part usually requires fetching full conversation details if it doesn't exist
|
|
199
|
-
// For now we just skip if not found to avoid ghost chats
|
|
200
|
-
/*
|
|
201
186
|
personalChats.push({
|
|
202
|
-
_id: conversationId,
|
|
187
|
+
_id: newMessage.conversationId,
|
|
203
188
|
participants: [newMessage.senderId, newMessage.receiverId],
|
|
204
|
-
lastMessage:
|
|
189
|
+
lastMessage: newMessage,
|
|
205
190
|
updatedAt: new Date().toISOString(),
|
|
206
191
|
unreadMessageIds:
|
|
207
192
|
userId !== newMessage.senderId ? [newMessage._id] : [],
|
|
@@ -209,9 +194,7 @@ const Conversations = () => {
|
|
|
209
194
|
type: "personal",
|
|
210
195
|
readReceipts: [],
|
|
211
196
|
createdAt: new Date().toISOString(),
|
|
212
|
-
participantDetails: [] // Missing details
|
|
213
197
|
});
|
|
214
|
-
*/
|
|
215
198
|
|
|
216
199
|
return { personalChats, groupedServiceChats };
|
|
217
200
|
});
|
|
@@ -221,7 +204,6 @@ const Conversations = () => {
|
|
|
221
204
|
try {
|
|
222
205
|
const data = JSON.parse(event.data);
|
|
223
206
|
if (data.event === "newMessage") {
|
|
224
|
-
// data.data is the message object
|
|
225
207
|
handleNewMessage(data.data);
|
|
226
208
|
} else if (
|
|
227
209
|
data.event === "messageStatusUpdated" &&
|
|
@@ -293,8 +275,8 @@ const Conversations = () => {
|
|
|
293
275
|
);
|
|
294
276
|
|
|
295
277
|
const serviceUnreadCount = Object.values(conversations.groupedServiceChats)
|
|
296
|
-
.flatMap((group
|
|
297
|
-
.reduce((total
|
|
278
|
+
.flatMap((group) => group.conversations)
|
|
279
|
+
.reduce((total, convo) => total + (convo.unreadMessageCount || 0), 0);
|
|
298
280
|
|
|
299
281
|
return (
|
|
300
282
|
<div className="chatSidebarConversations">
|
|
@@ -378,4 +360,4 @@ const Conversations = () => {
|
|
|
378
360
|
);
|
|
379
361
|
};
|
|
380
362
|
|
|
381
|
-
export default Conversations;
|
|
363
|
+
export default Conversations;
|
package/src/stores/Zustant.ts
CHANGED
package/src/types/type.ts
CHANGED
|
@@ -6,19 +6,16 @@ export interface ChatWindowProps {
|
|
|
6
6
|
export interface ParticipantDetails {
|
|
7
7
|
_id: string;
|
|
8
8
|
username: string;
|
|
9
|
-
password
|
|
10
|
-
acctype
|
|
11
|
-
contactno
|
|
12
|
-
country
|
|
13
|
-
email
|
|
14
|
-
verified
|
|
15
|
-
profilePic
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
createdAt?: string;
|
|
20
|
-
updatedAt?: string;
|
|
21
|
-
__v?: number;
|
|
9
|
+
password: string;
|
|
10
|
+
acctype: string;
|
|
11
|
+
contactno: string;
|
|
12
|
+
country: string;
|
|
13
|
+
email: string;
|
|
14
|
+
verified: string;
|
|
15
|
+
profilePic: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
__v: number;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
export interface Conversation {
|
|
@@ -35,15 +32,14 @@ export interface Conversation {
|
|
|
35
32
|
createdAt: string;
|
|
36
33
|
updatedAt: string;
|
|
37
34
|
__v: number;
|
|
38
|
-
conversationId?: string;
|
|
39
35
|
};
|
|
40
36
|
updatedAt: string;
|
|
41
37
|
__v: number;
|
|
42
|
-
participantDetails: ParticipantDetails
|
|
38
|
+
participantDetails: ParticipantDetails;
|
|
43
39
|
participants?: string[];
|
|
44
40
|
// readReceipts?: string[] | [];
|
|
45
41
|
unreadMessageIds: string[];
|
|
46
|
-
type?:
|
|
42
|
+
type?: string | undefined;
|
|
47
43
|
bookingId?: string;
|
|
48
44
|
serviceId?: string;
|
|
49
45
|
unreadMessageCount?: number
|