@pubuduth-aplicy/chat-ui 2.1.78 → 2.1.79
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
package/src/Chat.config.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { FilePreview, FileType } from "../common/FilePreview";
|
|
|
7
7
|
import { getApiClient } from "../../lib/api/apiClient";
|
|
8
8
|
import { MessageStatus } from "../../types/type";
|
|
9
9
|
import { Path } from "../../lib/api/endpoint";
|
|
10
|
+
import { getChatConfig } from "../../Chat.config";
|
|
10
11
|
|
|
11
12
|
const MAX_FILE_SIZE_MB = 5;
|
|
12
13
|
const MAX_FILE_COUNT = 5;
|
|
@@ -37,6 +38,7 @@ interface Attachment {
|
|
|
37
38
|
|
|
38
39
|
const MessageInput = () => {
|
|
39
40
|
const apiClient = getApiClient();
|
|
41
|
+
const {role} = getChatConfig();
|
|
40
42
|
const { socket, sendMessage, userId } = useChatContext();
|
|
41
43
|
const { selectedConversation, setMessages } = useChatUIStore();
|
|
42
44
|
const [message, setMessage] = useState("");
|
|
@@ -349,6 +351,8 @@ const MessageInput = () => {
|
|
|
349
351
|
selectedConversation?.type === "service"
|
|
350
352
|
? selectedConversation?.serviceId
|
|
351
353
|
: undefined,
|
|
354
|
+
senderRole: role,
|
|
355
|
+
receiverRole: role === 'customer' ? 'provider' : 'customer',
|
|
352
356
|
},
|
|
353
357
|
{
|
|
354
358
|
onSuccess: (data) => {
|
|
@@ -41,7 +41,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
41
41
|
const reconnectAttempts = useRef(0);
|
|
42
42
|
const maxReconnectAttempts = 5;
|
|
43
43
|
const reconnectInterval = 5000; // 5 seconds
|
|
44
|
-
const { webSocketUrl } = getChatConfig();
|
|
44
|
+
const { webSocketUrl,role } = getChatConfig();
|
|
45
45
|
|
|
46
46
|
const connectWebSocket = useCallback(() => {
|
|
47
47
|
// console.log("🔌 Creating new WebSocket connection...");
|
|
@@ -49,7 +49,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
49
49
|
// Convert HTTP URL to WebSocket URL
|
|
50
50
|
const wsUrl = webSocketUrl.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
51
51
|
const socketInstance = new WebSocket(
|
|
52
|
-
`${wsUrl}?userId=${encodeURIComponent(userId)}`
|
|
52
|
+
`${wsUrl}?userId=${encodeURIComponent(userId)}&role=${encodeURIComponent(role)}`
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
socketInstance.onopen = () => {
|
|
@@ -62,6 +62,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
62
62
|
JSON.stringify({
|
|
63
63
|
event: "handshake",
|
|
64
64
|
userId: userId,
|
|
65
|
+
role: role,
|
|
65
66
|
})
|
|
66
67
|
);
|
|
67
68
|
};
|
|
@@ -12,6 +12,8 @@ export const sendMessage = async (params: {
|
|
|
12
12
|
serviceTitle?: string;
|
|
13
13
|
type?: "personal" | "service";
|
|
14
14
|
serviceId?: string;
|
|
15
|
+
senderRole?: string;
|
|
16
|
+
receiverRole?: string;
|
|
15
17
|
}) => {
|
|
16
18
|
const {
|
|
17
19
|
receiverId,
|
|
@@ -22,6 +24,8 @@ export const sendMessage = async (params: {
|
|
|
22
24
|
serviceTitle,
|
|
23
25
|
type,
|
|
24
26
|
serviceId,
|
|
27
|
+
senderRole,
|
|
28
|
+
receiverRole,
|
|
25
29
|
} = params;
|
|
26
30
|
const apiClient = getApiClient();
|
|
27
31
|
|
|
@@ -34,7 +38,9 @@ export const sendMessage = async (params: {
|
|
|
34
38
|
serviceTitle,
|
|
35
39
|
type,
|
|
36
40
|
serviceId,
|
|
37
|
-
messageType: "user"
|
|
41
|
+
messageType: "user",
|
|
42
|
+
senderRole,
|
|
43
|
+
receiverRole
|
|
38
44
|
}
|
|
39
45
|
);
|
|
40
46
|
return response.data;
|
|
@@ -12,7 +12,7 @@ export const getAllConversationData = async (userid: string) => {
|
|
|
12
12
|
|
|
13
13
|
const endpoint = role === 'admin'
|
|
14
14
|
? `${Path.getConversationListByAdmin}`
|
|
15
|
-
: `${Path.getconversation}/${userid}`;
|
|
15
|
+
: `${Path.getconversation}/${userid}/${role}`;
|
|
16
16
|
|
|
17
17
|
const res = await apiClient.get<ApiResponse>(endpoint);
|
|
18
18
|
if (res.data) {
|