@vserifsaglam/chat-react-client 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -154,7 +154,13 @@ const MessagePanel = ({ conversationId, receiverId }) => {
154
154
  const handleSend = async () => {
155
155
  if (!messageText.trim()) return;
156
156
 
157
- const success = await handleSendMessage(messageText, receiverId);
157
+ // Optional metadata as a javascript object
158
+ const metadata = {
159
+ source: 'web-client',
160
+ priority: 'high'
161
+ };
162
+
163
+ const success = await handleSendMessage(messageText, receiverId, false, metadata);
158
164
  if (success) {
159
165
  setMessageText('');
160
166
  }
@@ -168,7 +174,9 @@ const MessagePanel = ({ conversationId, receiverId }) => {
168
174
  const fileId = await uploadFile(selectedFile);
169
175
 
170
176
  if (fileId) {
171
- await handleSendFileMessage(`Sent a file: ${selectedFile.name}`, fileId, receiverId);
177
+ // Optional metadata for file messages too
178
+ const metadata = { file_type: selectedFile.type };
179
+ await handleSendFileMessage(`Sent a file: ${selectedFile.name}`, fileId, receiverId, selectedFile.name, '', false, metadata);
172
180
  setFile(null);
173
181
  }
174
182
  };
@@ -554,8 +562,8 @@ Returns:
554
562
  - `fileLoading` (boolean): Loading state for file uploads
555
563
  - `uploadProgress` (number): Upload progress percentage (0-100)
556
564
  - `uploadFile(file: File)`: Function to upload a file
557
- - `handleSendMessage(content: string, receiverId: string)`: Function to send a text message
558
- - `handleSendFileMessage(content: string, fileId: number, receiverId: string)`: Function to send a message with a file attachment
565
+ - `handleSendMessage(content: string, receiverId: string, isAppointment?: boolean, metadata?: Record<string, any>)`: Function to send a text message
566
+ - `handleSendFileMessage(content: string, fileId: number, receiverId: string, filename?: string, url?: string, isAppointment?: boolean, metadata?: Record<string, any>)`: Function to send a message with a file attachment
559
567
  - `getMessages(conversationId?: string, page?: number)`: Function to get messages for a conversation
560
568
  - `loadMoreMessages()`: Function to load more messages (pagination)
561
569
  - `hasMore` (boolean): Whether there are more messages to load
@@ -6,8 +6,8 @@ export declare function useMessageManagement(selectedConversationId: string): {
6
6
  fileLoading: boolean;
7
7
  uploadProgress: number;
8
8
  uploadFile: (file: File) => Promise<import("..").FileUploadResponse | null>;
9
- handleSendMessage: (content: string, receiver: SenderReceiverUser, isAppointment?: boolean | undefined) => Promise<any>;
10
- handleSendFileMessage: (content: string, fileId: number, receiver: SenderReceiverUser, filename?: string | undefined, url?: string | undefined, isAppointment?: boolean | undefined) => Promise<boolean | undefined>;
9
+ handleSendMessage: (content: string, receiver: SenderReceiverUser, isAppointment?: boolean | undefined, metadata?: Record<string, any> | undefined) => Promise<any>;
10
+ handleSendFileMessage: (content: string, fileId: number, receiver: SenderReceiverUser, filename?: string | undefined, url?: string | undefined, isAppointment?: boolean | undefined, metadata?: Record<string, any> | undefined) => Promise<boolean | undefined>;
11
11
  deleteMessage: (messageId: number) => Promise<import("..").DeleteMessageResponse | null>;
12
12
  updateMessage: (messageId: number, update: import("..").UpdateMessageRequest) => Promise<import("..").UpdateMessageResponse | null>;
13
13
  getMessages: (conversationId?: any, page?: any, pageSize?: any) => Promise<import("..").MessagesResponse | null>;
package/dist/index.js CHANGED
@@ -191,6 +191,26 @@ function _finallyRethrows(body, finalizer) {
191
191
  return finalizer(false, result);
192
192
  }
193
193
 
194
+ function _extends() {
195
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
196
+ for (var e = 1; e < arguments.length; e++) {
197
+ var t = arguments[e];
198
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
199
+ }
200
+ return n;
201
+ }, _extends.apply(null, arguments);
202
+ }
203
+ function _objectWithoutPropertiesLoose(r, e) {
204
+ if (null == r) return {};
205
+ var t = {};
206
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
207
+ if (-1 !== e.indexOf(n)) continue;
208
+ t[n] = r[n];
209
+ }
210
+ return t;
211
+ }
212
+
213
+ var _excluded = ["isAppointment"];
194
214
  var ChatApi = /*#__PURE__*/function () {
195
215
  function ChatApi(config) {
196
216
  this.client = axios.create({
@@ -332,7 +352,9 @@ var ChatApi = /*#__PURE__*/function () {
332
352
  'x-disable-limit': true
333
353
  };
334
354
  }
335
- return Promise.resolve(_this1.client.post('/api/messages/send-message', message, config)).then(function (response) {
355
+ var isAppointment = message.isAppointment,
356
+ messageToSend = _objectWithoutPropertiesLoose(message, _excluded);
357
+ return Promise.resolve(_this1.client.post('/api/messages/send-message', messageToSend, config)).then(function (response) {
336
358
  return response.data;
337
359
  });
338
360
  } catch (e) {
@@ -485,16 +507,6 @@ var ChatApi = /*#__PURE__*/function () {
485
507
  return ChatApi;
486
508
  }();
487
509
 
488
- function _extends() {
489
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
490
- for (var e = 1; e < arguments.length; e++) {
491
- var t = arguments[e];
492
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
493
- }
494
- return n;
495
- }, _extends.apply(null, arguments);
496
- }
497
-
498
510
  (function (ConnectionType) {
499
511
  ConnectionType["WebSocket"] = "websocket";
500
512
  ConnectionType["LongPolling"] = "longpolling";
@@ -2821,7 +2833,7 @@ function useMessageManagement(selectedConversationId) {
2821
2833
  return Promise.reject(e);
2822
2834
  }
2823
2835
  }, [messagesLoading, hasMore, getMessages, page, selectedConversationId]);
2824
- var handleSendMessage = React.useCallback(function (content, receiver, isAppointment) {
2836
+ var handleSendMessage = React.useCallback(function (content, receiver, isAppointment, metadata) {
2825
2837
  try {
2826
2838
  if (!content.trim() || !selectedConversationId || !profile) return Promise.resolve();
2827
2839
  var tempMessageId = "temp-" + Date.now();
@@ -2834,7 +2846,8 @@ function useMessageManagement(selectedConversationId) {
2834
2846
  sender: profile,
2835
2847
  receiver: receiver,
2836
2848
  is_read: false,
2837
- status: 'sending'
2849
+ status: 'sending',
2850
+ metadata: metadata
2838
2851
  };
2839
2852
  setMessages(function (prevMessages) {
2840
2853
  var prevMessageArray = (prevMessages === null || prevMessages === void 0 ? void 0 : prevMessages.messages) || [];
@@ -2847,7 +2860,8 @@ function useMessageManagement(selectedConversationId) {
2847
2860
  receiver_client_id: receiver.id,
2848
2861
  content: content,
2849
2862
  conversation_uid: selectedConversationId,
2850
- isAppointment: isAppointment
2863
+ isAppointment: isAppointment,
2864
+ metadata: metadata
2851
2865
  })).then(function (success) {
2852
2866
  if (!success) {
2853
2867
  setMessages(function (prevMessages) {
@@ -2892,7 +2906,7 @@ function useMessageManagement(selectedConversationId) {
2892
2906
  return Promise.reject(e);
2893
2907
  }
2894
2908
  }, [sendMessage, selectedConversationId, profile === null || profile === void 0 ? void 0 : profile.id, setMessages]);
2895
- var handleSendFileMessage = React.useCallback(function (content, fileId, receiver, filename, url, isAppointment) {
2909
+ var handleSendFileMessage = React.useCallback(function (content, fileId, receiver, filename, url, isAppointment, metadata) {
2896
2910
  try {
2897
2911
  if (!selectedConversationId) return Promise.resolve();
2898
2912
  var tempMessageId = "temp-file-" + Date.now();
@@ -2909,7 +2923,8 @@ function useMessageManagement(selectedConversationId) {
2909
2923
  sender: profile,
2910
2924
  receiver: receiver,
2911
2925
  is_read: false,
2912
- status: 'sending'
2926
+ status: 'sending',
2927
+ metadata: metadata
2913
2928
  };
2914
2929
  setMessages(function (prevMessages) {
2915
2930
  var prevMessageArray = (prevMessages === null || prevMessages === void 0 ? void 0 : prevMessages.messages) || [];
@@ -2923,7 +2938,8 @@ function useMessageManagement(selectedConversationId) {
2923
2938
  content: content,
2924
2939
  attachments: [fileId],
2925
2940
  conversation_uid: selectedConversationId,
2926
- isAppointment: isAppointment
2941
+ isAppointment: isAppointment,
2942
+ metadata: metadata
2927
2943
  })).then(function (success) {
2928
2944
  if (success) {
2929
2945
  setMessages(function (prevMessages) {