@pubuduth-aplicy/chat-ui 2.2.6 → 2.2.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubuduth-aplicy/chat-ui",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -17,7 +17,7 @@ export const Chat = () => {
17
17
  const parsed = JSON.parse(event.data);
18
18
 
19
19
  if (parsed.event === "newMessage") {
20
- const message = parsed.data.data;
20
+ const message = parsed.data;
21
21
  // Send delivery confirmation
22
22
  // Update UI immediately
23
23
  setMessages((prev) => [...prev, message]);
@@ -35,6 +35,22 @@ export const Chat = () => {
35
35
 
36
36
  // Optional: update UI
37
37
  updateMessageStatus(message._id, "delivered");
38
+
39
+ // Send read receipt if user is viewing this conversation
40
+ // This ensures messages are marked as "read" immediately when both users are in the same chat
41
+ if (message.conversationId === selectedConversation?._id) {
42
+ sendMessage({
43
+ event: "messageRead",
44
+ data: {
45
+ messageIds: [message._id],
46
+ chatId: message.conversationId,
47
+ senderId: message.senderId,
48
+ receiverId: message.receiverId,
49
+ receiverRole: message.receiverRole,
50
+ senderRole: message.senderRole,
51
+ },
52
+ });
53
+ }
38
54
  }
39
55
  } catch (error) {
40
56
  console.error("WebSocket message parse error:", error);
@@ -546,7 +546,18 @@ const Message = ({ message }: MessageProps) => {
546
546
  };
547
547
 
548
548
  const formatLastMessageTime = (dateString: string) => {
549
+ // Validate date input
550
+ if (!dateString) {
551
+ return "";
552
+ }
553
+
549
554
  const date = new Date(dateString);
555
+
556
+ // Check if date is valid
557
+ if (isNaN(date.getTime())) {
558
+ return "";
559
+ }
560
+
550
561
  const now = new Date();
551
562
 
552
563
  const isToday = date.toDateString() === now.toDateString();
@@ -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:any)
29
29
  const unreadMessageIds = conversation.unreadMessageIds || [];
30
30
  if (unreadMessageIds.length > 0 && socket?.readyState === WebSocket.OPEN) {
31
31
  // console.log("unread messages", unreadMessageIds);
@@ -172,4 +172,4 @@ const Conversation = ({ conversation }: ConversationProps) => {
172
172
  );
173
173
  };
174
174
 
175
- export default memo(Conversation);
175
+ export default memo(Conversation);
@@ -360,4 +360,4 @@ const Conversations = () => {
360
360
  );
361
361
  };
362
362
 
363
- export default Conversations;
363
+ export default Conversations;