@pubuduth-aplicy/chat-ui 2.1.85 → 2.1.87

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.1.85",
3
+ "version": "2.1.87",
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": "",
@@ -8,7 +8,7 @@ const SystemNotice = () => (
8
8
  fontSize: "14px",
9
9
  }}>
10
10
  <strong style={{ display: "block", marginBottom: "0.5rem", textAlign:"center", fontSize:"smaller" }}>🛡 WE HAVE YOUR BACK</strong>
11
- <p style={{fontSize:"x-small"}}>For added safety and your protection, keep payments and communications within Gigmosaic.
11
+ <p style={{fontSize:"x-small"}}>For added safety and your protection, keep payments and communications within Hirepanther.
12
12
  {/* <a href="#">Learn more</a> */}
13
13
  </p>
14
14
  </div>
@@ -24,6 +24,7 @@ const MessageContainer = () => {
24
24
  data: {
25
25
  chatId: selectedConversation._id,
26
26
  userId: userId,
27
+ role: role,
27
28
  },
28
29
  })
29
30
  );
@@ -4,17 +4,19 @@ import { useEffect } from "react";
4
4
  import { useChatContext } from "../../providers/ChatProvider";
5
5
  import useChatUIStore from "../../stores/Zustant";
6
6
  import { ConversationProps } from "../../types/type";
7
+ import { getChatConfig } from "../../Chat.config";
7
8
 
8
9
  const Conversation = ({ conversation }: ConversationProps) => {
9
10
  const {
10
11
  setSelectedConversation,
11
12
  setOnlineUsers,
12
13
  } = useChatUIStore();
13
- const { socket, isUserOnline } = useChatContext();
14
+ const { socket, isUserOnline, } = useChatContext();
14
15
  const selectedConversation = useChatUIStore(
15
16
  (state) => state.selectedConversation
16
17
  );
17
18
  const { userId } = useChatContext();
19
+ const { role } = getChatConfig();
18
20
 
19
21
  const participant = conversation.participantDetails?.find(
20
22
  (p:any) => p._id !== userId
@@ -36,6 +38,7 @@ const Conversation = ({ conversation }: ConversationProps) => {
36
38
  messageIds: unreadMessageIds,
37
39
  senderId: participant?._id,
38
40
  receiverId: userId,
41
+ receiverRole: role,
39
42
  chatId: conversation._id,
40
43
  },
41
44
  };
@@ -77,7 +80,7 @@ const Conversation = ({ conversation }: ConversationProps) => {
77
80
  : participant?.name || "Conversation";
78
81
 
79
82
  const lastMessageTimestamp = new Date(
80
- conversation.lastMessage?.updatedAt || conversation.lastMessage?.createdAt
83
+ conversation.lastMessage?.updatedAt || conversation.lastMessage?.createdAt || conversation.createdAt
81
84
  ).toLocaleTimeString([], {
82
85
  hour: "2-digit",
83
86
  minute: "2-digit",
@@ -114,17 +114,38 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
114
114
  }
115
115
  }, []);
116
116
 
117
+ // useEffect(() => {
118
+ // connectWebSocket();
119
+
120
+ // return () => {
121
+ // // console.log("❌ Closing WebSocket connection...");
122
+ // if (socketRef.current) {
123
+ // socketRef.current.close(1000, "Component unmounted");
124
+ // socketRef.current = null;
125
+ // }
126
+ // };
127
+ // }, [connectWebSocket]);
128
+
129
+
117
130
  useEffect(() => {
118
131
  connectWebSocket();
119
-
132
+
120
133
  return () => {
121
- // console.log("❌ Closing WebSocket connection...");
122
- if (socketRef.current) {
134
+ // Gracefully notify backend before closing
135
+ if (socketRef.current && socketRef.current.readyState === WebSocket.OPEN) {
136
+ socketRef.current.send(
137
+ JSON.stringify({
138
+ event: "disconnect",
139
+ userId,
140
+ role,
141
+ })
142
+ );
123
143
  socketRef.current.close(1000, "Component unmounted");
124
- socketRef.current = null;
125
144
  }
145
+ socketRef.current = null;
126
146
  };
127
147
  }, [connectWebSocket]);
148
+
128
149
 
129
150
  const isUserOnline = useCallback(
130
151
  (userId: string) => {