@messenger-box/platform-mobile 10.0.3-alpha.34 → 10.0.3-alpha.37

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/screens/inbox/components/CachedImage/index.js +125 -93
  3. package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
  4. package/lib/screens/inbox/components/DialogsListItem.js +80 -256
  5. package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
  6. package/lib/screens/inbox/components/ServiceDialogsListItem.js +222 -324
  7. package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +1 -1
  8. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +0 -2
  9. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
  10. package/lib/screens/inbox/containers/ConversationView.js +487 -888
  11. package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
  12. package/lib/screens/inbox/containers/Dialogs.js +243 -547
  13. package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
  14. package/lib/screens/inbox/containers/ThreadConversationView.js +409 -1364
  15. package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
  16. package/package.json +4 -4
  17. package/src/screens/inbox/components/CachedImage/index.tsx +191 -140
  18. package/src/screens/inbox/components/DialogsListItem.tsx +112 -345
  19. package/src/screens/inbox/components/ServiceDialogsListItem.tsx +316 -437
  20. package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +2 -4
  21. package/src/screens/inbox/containers/ConversationView.tsx +676 -993
  22. package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
  23. package/src/screens/inbox/containers/Dialogs.tsx +345 -636
  24. package/src/screens/inbox/containers/ThreadConversationView.tsx +661 -1887
  25. package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js +0 -175
  26. package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js.map +0 -1
  27. package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js +0 -191
  28. package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js.map +0 -1
  29. package/lib/screens/inbox/containers/workflow/conversation-xstate.js +0 -380
  30. package/lib/screens/inbox/containers/workflow/conversation-xstate.js.map +0 -1
  31. package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +0 -211
  32. package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +0 -1
  33. package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js +0 -438
  34. package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import React__default,{useState,useRef,useCallback,useEffect,useMemo}from'react';import {Box,Button,ButtonText,HStack,Avatar,AvatarFallbackText,AvatarImage,Text,Image,Spinner}from'@admin-layout/gluestack-ui-mobile';import {Platform,View,TouchableHighlight}from'react-native';import {useNavigation,useIsFocused,useFocusEffect}from'@react-navigation/native';import {navigationRef}from'@common-stack/client-react';import {useSelector}from'react-redux';import {uniqBy,orderBy,startCase}from'lodash-es';import*as ImagePicker from'expo-image-picker';import'base-64';import {MaterialCommunityIcons,Ionicons}from'@expo/vector-icons';import {Send,MessageText,InputToolbar,GiftedChat,Actions as Actions$1}from'react-native-gifted-chat';import {RoomType,PreDefinedRole}from'common';import {useAddDirectChannelMutation,useSendMessagesMutation,useSendExpoNotificationOnPostMutation,useMessagesQuery,OnChatMessageAddedDocument}from'common/graphql';import {useUploadFilesNative}from'@messenger-box/platform-client';import {objectId}from'@messenger-box/core';import {userSelector}from'@adminide-stack/user-auth0-client';import {isToday,isYesterday,format}from'date-fns';import Message from'../components/SlackMessageContainer/SlackMessage.js';import ImageViewerModal from'../components/SlackMessageContainer/ImageViewerModal.js';import CachedImage from'../components/CachedImage/index.js';import {config}from'../config/config.js';import {Actions,BaseState,MainState}from'./workflow/conversation-xstate.js';import colors from'tailwindcss/colors';var __defProp = Object.defineProperty;
1
+ import React__default,{useState,useRef,useMemo,useEffect,useCallback}from'react';import {Box,Button,ButtonText,HStack,Avatar,AvatarFallbackText,AvatarImage,Text,Image,Spinner,Skeleton}from'@admin-layout/gluestack-ui-mobile';import {Platform,View,TouchableHighlight}from'react-native';import {useNavigation,useIsFocused,useFocusEffect}from'@react-navigation/native';import {navigationRef}from'@common-stack/client-react';import {useSelector}from'react-redux';import {uniqBy,orderBy,startCase}from'lodash-es';import*as ImagePicker from'expo-image-picker';import {MaterialCommunityIcons,Ionicons}from'@expo/vector-icons';import {Send,MessageText,InputToolbar,GiftedChat,Actions}from'react-native-gifted-chat';import {FileRefType,RoomType,PreDefinedRole}from'common';import {useAddDirectChannelMutation,useSendMessagesMutation,useSendExpoNotificationOnPostMutation,useMessagesQuery,OnChatMessageAddedDocument}from'common/graphql';import {useUploadFilesNative}from'@messenger-box/platform-client';import {objectId}from'@messenger-box/core';import {userSelector}from'@adminide-stack/user-auth0-client';import {isToday,isYesterday,format}from'date-fns';import Message from'../components/SlackMessageContainer/SlackMessage.js';import ImageViewerModal from'../components/SlackMessageContainer/ImageViewerModal.js';import CachedImage from'../components/CachedImage/index.js';import {config}from'../config/config.js';import colors from'tailwindcss/colors';var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -46,189 +46,9 @@ const createdAtText = (value) => {
46
46
  return "Yesterday";
47
47
  return format(new Date(value), "MMM dd, yyyy");
48
48
  };
49
- function useSafeMachine(machine) {
50
- const [state, setState] = useState({
51
- context: {
52
- channelId: null,
53
- channelMessages: [],
54
- totalCount: 0,
55
- skip: 0,
56
- loading: false,
57
- loadingOldMessages: false,
58
- error: null,
59
- selectedImage: "",
60
- files: [],
61
- images: [],
62
- messageText: "",
63
- imageLoading: false
64
- },
65
- value: "idle"
66
- });
67
- const send = useCallback((event) => {
68
- try {
69
- console.log("Event received:", event.type);
70
- if (event.type === Actions.INITIAL_CONTEXT) {
71
- setState((prev) => {
72
- var _a;
73
- return __spreadProps(__spreadValues({}, prev), {
74
- context: __spreadProps(__spreadValues({}, prev.context), {
75
- channelId: ((_a = event.data) == null ? void 0 : _a.channelId) || null
76
- }),
77
- value: BaseState.FetchMessages
78
- });
79
- });
80
- } else if (event.type === Actions.SET_CHANNEL_MESSAGES) {
81
- setState((prev) => {
82
- var _a, _b;
83
- return __spreadProps(__spreadValues({}, prev), {
84
- context: __spreadProps(__spreadValues({}, prev.context), {
85
- channelMessages: ((_a = event.data) == null ? void 0 : _a.messages) || [],
86
- totalCount: ((_b = event.data) == null ? void 0 : _b.totalCount) || 0,
87
- loading: false,
88
- loadingOldMessages: false
89
- }),
90
- value: "active"
91
- });
92
- });
93
- } else if (event.type === Actions.CLEAR_MESSAGES) {
94
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
95
- context: __spreadProps(__spreadValues({}, prev.context), {
96
- channelMessages: [],
97
- totalCount: 0
98
- })
99
- }));
100
- } else if (event.type === Actions.SET_MESSAGE_TEXT) {
101
- setState((prev) => {
102
- var _a;
103
- return __spreadProps(__spreadValues({}, prev), {
104
- context: __spreadProps(__spreadValues({}, prev.context), {
105
- messageText: ((_a = event.data) == null ? void 0 : _a.messageText) || ""
106
- })
107
- });
108
- });
109
- } else if (event.type === Actions.FETCH_MORE_MESSAGES) {
110
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
111
- context: __spreadProps(__spreadValues({}, prev.context), {
112
- loadingOldMessages: true
113
- }),
114
- value: MainState.FetchMoreMessages
115
- }));
116
- } else if (event.type === Actions.SET_IMAGE) {
117
- setState((prev) => {
118
- var _a, _b;
119
- return __spreadProps(__spreadValues({}, prev), {
120
- context: __spreadProps(__spreadValues({}, prev.context), {
121
- selectedImage: ((_a = event.data) == null ? void 0 : _a.image) || "",
122
- images: ((_b = event.data) == null ? void 0 : _b.images) || [],
123
- imageLoading: false
124
- })
125
- });
126
- });
127
- } else if (event.type === Actions.CLEAR_IMAGE) {
128
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
129
- context: __spreadProps(__spreadValues({}, prev.context), {
130
- selectedImage: "",
131
- images: []
132
- })
133
- }));
134
- } else if (event.type === Actions.START_LOADING) {
135
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
136
- context: __spreadProps(__spreadValues({}, prev.context), {
137
- loading: true
138
- })
139
- }));
140
- } else if (event.type === Actions.STOP_LOADING) {
141
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
142
- context: __spreadProps(__spreadValues({}, prev.context), {
143
- loading: false
144
- })
145
- }));
146
- } else if (event.type === Actions.SEND_MESSAGE) {
147
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
148
- context: __spreadProps(__spreadValues({}, prev.context), {
149
- loading: true
150
- }),
151
- value: MainState.SendMessage
152
- }));
153
- } else if (event.type === Actions.SEND_MESSAGE_WITH_FILE) {
154
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
155
- context: __spreadProps(__spreadValues({}, prev.context), {
156
- loading: true
157
- }),
158
- value: MainState.SendMessageWithFile
159
- }));
160
- } else if (event.type === Actions.CREATE_DIRECT_CHANNEL) {
161
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
162
- context: __spreadProps(__spreadValues({}, prev.context), {
163
- loading: true
164
- }),
165
- value: MainState.CreateDirectChannel
166
- }));
167
- } else if (event.type === "SEND_MESSAGE_SUCCESS" || event.type === "SEND_MESSAGE_WITH_FILE_SUCCESS") {
168
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
169
- context: __spreadProps(__spreadValues({}, prev.context), {
170
- loading: false,
171
- messageText: "",
172
- images: [],
173
- selectedImage: ""
174
- }),
175
- value: "active"
176
- }));
177
- } else if (event.type === "CREATE_DIRECT_CHANNEL_SUCCESS") {
178
- setState((prev) => {
179
- var _a;
180
- return __spreadProps(__spreadValues({}, prev), {
181
- context: __spreadProps(__spreadValues({}, prev.context), {
182
- loading: false,
183
- channelId: ((_a = event.data) == null ? void 0 : _a.channelId) || prev.context.channelId,
184
- messageText: ""
185
- }),
186
- value: BaseState.FetchMessages
187
- });
188
- });
189
- } else if (event.type === "FETCH_MORE_MESSAGES_SUCCESS") {
190
- setState((prev) => {
191
- var _a;
192
- const newMessages = ((_a = event.data) == null ? void 0 : _a.messages) || [];
193
- return __spreadProps(__spreadValues({}, prev), {
194
- context: __spreadProps(__spreadValues({}, prev.context), {
195
- loadingOldMessages: false,
196
- channelMessages: uniqBy([...prev.context.channelMessages, ...newMessages], ({
197
- id
198
- }) => id)
199
- }),
200
- value: "active"
201
- });
202
- });
203
- } else if (event.type === "ERROR") {
204
- setState((prev) => {
205
- var _a;
206
- return __spreadProps(__spreadValues({}, prev), {
207
- context: __spreadProps(__spreadValues({}, prev.context), {
208
- loading: false,
209
- loadingOldMessages: false,
210
- error: ((_a = event.data) == null ? void 0 : _a.message) || "Unknown error"
211
- }),
212
- value: "error"
213
- });
214
- });
215
- }
216
- } catch (error) {
217
- console.error("Error in send function:", error);
218
- }
219
- }, []);
220
- const stateWithMatches = useMemo(() => {
221
- return __spreadProps(__spreadValues({}, state), {
222
- matches: (checkState) => {
223
- return state.value === checkState;
224
- }
225
- });
226
- }, [state]);
227
- return [stateWithMatches, send];
228
- }
229
49
  const ConversationViewComponent = (_a) => {
230
50
  var _b = _a, {
231
- channelId: ChannelId,
51
+ channelId: initialChannelId,
232
52
  role,
233
53
  isShowThreadMessage
234
54
  } = _b, rest = __objRest(_b, [
@@ -236,93 +56,23 @@ const ConversationViewComponent = (_a) => {
236
56
  "role",
237
57
  "isShowThreadMessage"
238
58
  ]);
239
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
240
- const [channelToTop, setChannelToTop] = useState(0);
241
- const isMountedRef = useRef(true);
242
- const [state, send] = useSafeMachine();
243
- useCallback(() => {
244
- try {
245
- return (state == null ? void 0 : state.context) || {};
246
- } catch (error) {
247
- console.error("Error accessing state.context:", error);
248
- return {};
249
- }
250
- }, [state]);
251
- const safeContextProperty = useCallback((property, defaultValue = null) => {
252
- var _a3, _b3;
253
- try {
254
- return (_b3 = (_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3[property]) != null ? _b3 : defaultValue;
255
- } catch (error) {
256
- console.error(`Error accessing state.context.${property}:`, error);
257
- return defaultValue;
258
- }
259
- }, [state]);
260
- useCallback((stateValue) => {
261
- var _a3;
262
- try {
263
- return ((_a3 = state == null ? void 0 : state.matches) == null ? void 0 : _a3.call(state, stateValue)) || false;
264
- } catch (error) {
265
- console.error(`Error calling state.matches with ${stateValue}:`, error);
266
- return false;
267
- }
268
- }, [state]);
269
- const safeSend = useCallback((event) => {
270
- try {
271
- send(event);
272
- } catch (error) {
273
- console.error("Error sending event to state machine:", error, event);
274
- }
275
- }, [send]);
276
- useEffect(() => {
277
- if (ChannelId) {
278
- console.log("Setting initial channel ID on mount:", ChannelId);
279
- try {
280
- send({
281
- type: Actions.INITIAL_CONTEXT,
282
- data: {
283
- channelId: ChannelId
284
- }
285
- });
286
- } catch (error) {
287
- console.error("Error sending initial context:", error);
288
- }
289
- }
290
- }, []);
291
- const stateRef = useRef(state);
292
- useEffect(() => {
293
- stateRef.current = state;
294
- }, [state]);
295
- const safeGetContext = useCallback(() => {
296
- if (stateRef.current && stateRef.current.context) {
297
- return stateRef.current.context;
298
- }
299
- return {
300
- channelId: null,
301
- channelMessages: [],
302
- totalCount: 0,
303
- skip: 0,
304
- loading: false,
305
- loadingOldMessages: false,
306
- error: null,
307
- selectedImage: "",
308
- files: [],
309
- images: [],
310
- messageText: "",
311
- imageLoading: false
312
- };
313
- }, []);
314
- useEffect(() => {
315
- return () => {
316
- isMountedRef.current = false;
317
- };
318
- }, []);
319
- const auth = useSelector(userSelector);
320
- const currentRoute = navigationRef.isReady() ? (_a2 = navigationRef) == null ? void 0 : _a2.getCurrentRoute() : null;
321
- const navigation = useNavigation();
322
- const [selectedImage, setImage] = useState("");
59
+ var _a2, _b2, _c, _d;
60
+ const [channelId, setChannelId] = useState(initialChannelId || null);
61
+ const [messageText, setMessageText] = useState("");
62
+ const [skip, setSkip] = useState(0);
63
+ const [loading, setLoading] = useState(false);
64
+ const [loadingOldMessages, setLoadingOldMessages] = useState(false);
65
+ const [error, setError] = useState(null);
66
+ const [selectedImage, setSelectedImage] = useState("");
67
+ const [images, setImages] = useState([]);
323
68
  const [isShowImageViewer, setImageViewer] = useState(false);
324
69
  const [imageObject, setImageObject] = useState({});
325
70
  const messageRootListRef = useRef(null);
71
+ const isMounted = useRef(true);
72
+ const fetchOldDebounceRef = useRef(false);
73
+ const auth = useSelector(userSelector);
74
+ const currentRoute = navigationRef.isReady() ? (_a2 = navigationRef) == null ? void 0 : _a2.getCurrentRoute() : null;
75
+ const navigation = useNavigation();
326
76
  const isFocused = useIsFocused();
327
77
  const [addDirectChannel] = useAddDirectChannelMutation();
328
78
  const {
@@ -338,89 +88,67 @@ const ConversationViewComponent = (_a) => {
338
88
  subscribeToMore
339
89
  } = useMessagesQuery({
340
90
  variables: {
341
- channelId: (_b2 = state.context.channelId) == null ? void 0 : _b2.toString(),
91
+ channelId: channelId == null ? void 0 : channelId.toString(),
342
92
  parentId: null,
343
93
  limit: MESSAGES_PER_PAGE,
344
- skip: state.context.skip
94
+ skip
345
95
  },
346
- skip: !state.context.channelId,
96
+ skip: !channelId,
347
97
  fetchPolicy: "cache-and-network",
348
98
  nextFetchPolicy: "cache-first",
349
99
  refetchWritePolicy: "merge",
100
+ notifyOnNetworkStatusChange: true,
350
101
  onCompleted: (queryData) => {
351
- var _a3;
352
- console.log("MESSAGE QUERY COMPLETED:", queryData);
353
- if ((_a3 = queryData == null ? void 0 : queryData.messages) == null ? void 0 : _a3.data) {
354
- console.log("Raw message data from query:", JSON.stringify(queryData.messages.data).substring(0, 100) + "...");
355
- console.log("Message count from query:", queryData.messages.data.length);
356
- console.log("Total count from query:", queryData.messages.totalCount);
357
- }
358
102
  },
359
- onError: (error) => {
360
- console.error("MESSAGE QUERY ERROR:", error);
103
+ onError: (error2) => {
104
+ setError(String(error2));
361
105
  }
362
106
  });
363
- const fetchMessagesDirectly = useCallback(async () => {
107
+ const channelMessages = useMemo(() => {
364
108
  var _a3;
365
- const channelId = safeGetContext().channelId;
366
- if (!channelId) {
367
- console.warn("Cannot fetch messages: No channel ID");
368
- return;
109
+ return ((_a3 = data == null ? void 0 : data.messages) == null ? void 0 : _a3.data) || [];
110
+ }, [(_b2 = data == null ? void 0 : data.messages) == null ? void 0 : _b2.data]);
111
+ const totalCount = useMemo(() => {
112
+ var _a3;
113
+ return ((_a3 = data == null ? void 0 : data.messages) == null ? void 0 : _a3.totalCount) || 0;
114
+ }, [(_c = data == null ? void 0 : data.messages) == null ? void 0 : _c.totalCount]);
115
+ useEffect(() => {
116
+ return () => {
117
+ isMounted.current = false;
118
+ };
119
+ }, []);
120
+ useEffect(() => {
121
+ var _a3;
122
+ const currentChannelId = initialChannelId || ((_a3 = currentRoute == null ? void 0 : currentRoute.params) == null ? void 0 : _a3.channelId);
123
+ if (currentChannelId) {
124
+ setChannelId(currentChannelId);
369
125
  }
370
- try {
371
- console.log("\u{1F4AB} FETCHING messages for channel:", channelId);
372
- send({
373
- type: Actions.START_LOADING
374
- });
375
- const response = await refetch({
376
- channelId: channelId.toString(),
377
- parentId: null,
378
- limit: MESSAGES_PER_PAGE,
379
- skip: 0
380
- });
381
- if ((_a3 = response == null ? void 0 : response.data) == null ? void 0 : _a3.messages) {
382
- const {
383
- data: messages,
384
- totalCount
385
- } = response.data.messages;
386
- if (messages && messages.length > 0) {
387
- safeSend({
388
- type: Actions.SET_CHANNEL_MESSAGES,
389
- data: {
390
- messages,
391
- totalCount
392
- }
393
- });
394
- } else {
395
- console.warn("No messages found for channel", channelId);
396
- send({
397
- type: Actions.STOP_LOADING
398
- });
399
- }
400
- } else {
401
- console.warn("Query returned no messages data");
402
- send({
403
- type: Actions.STOP_LOADING
404
- });
405
- }
406
- } catch (error) {
407
- console.error("ERROR fetching messages:", error);
408
- send({
409
- type: Actions.STOP_LOADING
410
- });
126
+ }, [initialChannelId, currentRoute]);
127
+ useFocusEffect(React__default.useCallback(() => {
128
+ if (channelId) {
129
+ refetch();
411
130
  }
412
- }, [safeGetContext, refetch, safeSend]);
131
+ return () => {
132
+ };
133
+ }, [channelId, isFocused, refetch]));
134
+ useEffect(() => {
135
+ if (selectedImage) {
136
+ setLoading(false);
137
+ }
138
+ }, [selectedImage]);
413
139
  const fetchMoreMessagesImpl = useCallback(async () => {
414
- var _a3, _b3, _c2;
140
+ var _a3, _b3;
415
141
  try {
142
+ setLoadingOldMessages(true);
416
143
  const response = await fetchMoreMessages({
417
144
  variables: {
418
- channelId: (_a3 = state.context.channelId) == null ? void 0 : _a3.toString(),
145
+ channelId: channelId == null ? void 0 : channelId.toString(),
419
146
  parentId: null,
420
- skip: state.context.channelMessages.length
147
+ skip: channelMessages.length
421
148
  }
422
149
  });
423
- if (!((_c2 = (_b3 = response == null ? void 0 : response.data) == null ? void 0 : _b3.messages) == null ? void 0 : _c2.data)) {
150
+ setLoadingOldMessages(false);
151
+ if (!((_b3 = (_a3 = response == null ? void 0 : response.data) == null ? void 0 : _a3.messages) == null ? void 0 : _b3.data)) {
424
152
  return {
425
153
  error: "No messages returned"
426
154
  };
@@ -428,19 +156,23 @@ const ConversationViewComponent = (_a) => {
428
156
  return {
429
157
  messages: response.data.messages.data
430
158
  };
431
- } catch (error) {
159
+ } catch (error2) {
160
+ setLoadingOldMessages(false);
161
+ setError(String(error2));
432
162
  return {
433
- error: String(error)
163
+ error: String(error2)
434
164
  };
435
165
  }
436
- }, [state.context.channelId, state.context.channelMessages.length, fetchMoreMessages]);
166
+ }, [channelId, channelMessages.length, fetchMoreMessages]);
437
167
  const sendMessageImpl = useCallback(async () => {
438
168
  var _a3;
439
169
  try {
170
+ const currentMessageText = messageText;
171
+ setMessageText("");
440
172
  const notificationData = {
441
173
  url: config.INBOX_MESSEGE_PATH,
442
174
  params: {
443
- channelId: state.context.channelId,
175
+ channelId,
444
176
  hideTabBar: true
445
177
  },
446
178
  screen: "DialogMessages",
@@ -448,29 +180,75 @@ const ConversationViewComponent = (_a) => {
448
180
  sound: Platform.OS === "android" ? void 0 : "default"
449
181
  }
450
182
  };
183
+ const messageId = objectId();
184
+ const optimisticMessage = {
185
+ __typename: "Post",
186
+ id: messageId,
187
+ message: currentMessageText,
188
+ createdAt: new Date().toISOString(),
189
+ updatedAt: new Date().toISOString(),
190
+ author: {
191
+ __typename: "UserAccount",
192
+ id: auth == null ? void 0 : auth.id,
193
+ givenName: (auth == null ? void 0 : auth.givenName) || "",
194
+ familyName: (auth == null ? void 0 : auth.familyName) || "",
195
+ picture: (auth == null ? void 0 : auth.picture) || "",
196
+ username: (auth == null ? void 0 : auth.username) || "",
197
+ email: (auth == null ? void 0 : auth.email) || "",
198
+ alias: [],
199
+ tokens: []
200
+ },
201
+ isDelivered: true,
202
+ isRead: false,
203
+ type: "TEXT",
204
+ parentId: null,
205
+ fromServer: false,
206
+ channel: {
207
+ __typename: "Channel",
208
+ id: channelId
209
+ },
210
+ propsConfiguration: {
211
+ __typename: "MachineConfiguration",
212
+ resource: ""
213
+ },
214
+ props: {},
215
+ files: {
216
+ __typename: "FilesInfo",
217
+ data: [],
218
+ totalCount: 0
219
+ },
220
+ replies: {
221
+ __typename: "Messages",
222
+ data: [],
223
+ totalCount: 0
224
+ }
225
+ };
451
226
  const response = await sendMsg({
452
227
  variables: {
453
- channelId: state.context.channelId,
454
- content: state.context.messageText,
228
+ channelId,
229
+ content: currentMessageText,
455
230
  notificationParams: notificationData
231
+ },
232
+ optimisticResponse: {
233
+ __typename: "Mutation",
234
+ sendMessage: optimisticMessage
456
235
  }
457
236
  });
458
237
  return {
459
238
  message: (_a3 = response.data) == null ? void 0 : _a3.sendMessage
460
239
  };
461
- } catch (error) {
240
+ } catch (error2) {
241
+ setLoading(false);
242
+ setError(String(error2));
462
243
  return {
463
- error: String(error)
244
+ error: String(error2)
464
245
  };
465
246
  }
466
- }, [state.context.channelId, state.context.messageText, sendMsg]);
247
+ }, [channelId, messageText, sendMsg, auth]);
467
248
  const onSelectImages = async () => {
468
- var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
469
- safeSend({
470
- type: Actions.START_LOADING
471
- });
249
+ var _a3;
250
+ setLoading(true);
472
251
  try {
473
- console.log("Starting image picker...");
474
252
  let imageSource = await ImagePicker.launchImageLibraryAsync({
475
253
  mediaTypes: ImagePicker.MediaTypeOptions.Images,
476
254
  allowsEditing: true,
@@ -480,19 +258,9 @@ const ConversationViewComponent = (_a) => {
480
258
  exif: false
481
259
  });
482
260
  if (!(imageSource == null ? void 0 : imageSource.canceled)) {
483
- console.log("Image selected. Asset details:", JSON.stringify({
484
- uri: ((_c2 = (_b3 = (_a3 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _a3[0]) == null ? void 0 : _b3.uri) == null ? void 0 : _c2.substring(0, 30)) + "...",
485
- width: (_e2 = (_d2 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _d2[0]) == null ? void 0 : _e2.width,
486
- height: (_g2 = (_f2 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _f2[0]) == null ? void 0 : _g2.height,
487
- hasBase64: !!((_i2 = (_h2 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _h2[0]) == null ? void 0 : _i2.base64),
488
- hasUri: !!((_k2 = (_j2 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _j2[0]) == null ? void 0 : _k2.uri)
489
- }));
490
- const selectedAsset = (_l2 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _l2[0];
261
+ const selectedAsset = (_a3 = imageSource == null ? void 0 : imageSource.assets) == null ? void 0 : _a3[0];
491
262
  if (!selectedAsset) {
492
- console.error("No asset found in selected image");
493
- safeSend({
494
- type: Actions.STOP_LOADING
495
- });
263
+ setLoading(false);
496
264
  return;
497
265
  }
498
266
  const base64Data = selectedAsset.base64;
@@ -502,43 +270,26 @@ const ConversationViewComponent = (_a) => {
502
270
  fileName: selectedAsset.fileName || `image_${Date.now()}.jpg`,
503
271
  mimeType: "image/jpeg"
504
272
  });
505
- console.log("Prepared image asset for upload:", {
506
- hasUrl: !!asset.url,
507
- hasFileName: !!asset.fileName,
508
- hasMimeType: !!asset.mimeType,
509
- previewAvailable: !!previewImage
510
- });
511
- safeSend({
512
- type: Actions.SET_IMAGE,
513
- data: {
514
- image: previewImage,
515
- images: [asset]
516
- }
517
- });
518
- console.log("Image state updated successfully");
273
+ setSelectedImage(previewImage);
274
+ setImages([asset]);
519
275
  } else {
520
- console.log("Image selection cancelled");
521
- safeSend({
522
- type: Actions.STOP_LOADING
523
- });
276
+ setLoading(false);
524
277
  }
525
- } catch (error) {
526
- console.error("Error selecting image:", error);
527
- safeSend({
528
- type: Actions.STOP_LOADING
529
- });
278
+ } catch (error2) {
279
+ setLoading(false);
530
280
  }
531
281
  };
282
+ const [uploadingMessageId, setUploadingMessageId] = useState(null);
532
283
  const sendMessageWithFileImpl = useCallback(async () => {
533
- var _a3, _b3, _c2, _d2, _e2, _f2;
284
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h, _i;
534
285
  try {
535
- console.log("Executing sendMessageWithFileImpl");
286
+ setLoading(true);
536
287
  const postId = objectId();
537
- console.log("Generated postId for file upload:", postId);
288
+ setUploadingMessageId(postId);
538
289
  const notificationData = {
539
290
  url: config.INBOX_MESSEGE_PATH,
540
291
  params: {
541
- channelId: state.context.channelId,
292
+ channelId,
542
293
  hideTabBar: true
543
294
  },
544
295
  screen: "DialogMessages",
@@ -546,31 +297,87 @@ const ConversationViewComponent = (_a) => {
546
297
  sound: Platform.OS === "android" ? void 0 : "default"
547
298
  }
548
299
  };
549
- if (!state.context.images || state.context.images.length === 0) {
550
- console.error("No images found in state");
300
+ if (!images || images.length === 0) {
301
+ setLoading(false);
302
+ setUploadingMessageId(null);
551
303
  return {
552
304
  error: "No images available to upload"
553
305
  };
554
306
  }
555
- const imagesToUpload = state.context.images.map((img) => {
307
+ const imagesToUpload = images.map((img) => {
556
308
  return __spreadProps(__spreadValues({}, img), {
557
309
  uri: img.uri || img.url,
558
310
  type: "image/jpeg",
559
311
  name: img.fileName || `image_${Date.now()}.jpg`
560
312
  });
561
313
  });
562
- console.log("Formatted images for upload:", imagesToUpload.map((img) => {
563
- var _a4;
564
- return {
565
- hasUri: !!img.uri,
566
- hasUrl: !!img.url,
567
- hasName: !!img.name,
568
- hasType: !!img.type,
569
- hasFileName: !!img.fileName,
570
- uri: ((_a4 = img.uri) == null ? void 0 : _a4.substring(0, 30)) + "..."
571
- };
572
- }));
573
- console.log("Starting file upload...");
314
+ const currentMessageText = messageText;
315
+ setMessageText("");
316
+ const optimisticFileInfo = {
317
+ __typename: "FileInfo",
318
+ id: objectId(),
319
+ url: selectedImage,
320
+ name: ((_a3 = imagesToUpload[0]) == null ? void 0 : _a3.name) || "image.jpg",
321
+ extension: "jpg",
322
+ mimeType: "image/jpeg",
323
+ size: 0,
324
+ refType: FileRefType.Post,
325
+ height: ((_b3 = imagesToUpload[0]) == null ? void 0 : _b3.height) || 0,
326
+ width: ((_c2 = imagesToUpload[0]) == null ? void 0 : _c2.width) || 0
327
+ };
328
+ const optimisticMessage = {
329
+ __typename: "Post",
330
+ id: postId,
331
+ message: currentMessageText || " ",
332
+ createdAt: new Date().toISOString(),
333
+ updatedAt: new Date().toISOString(),
334
+ author: {
335
+ __typename: "UserAccount",
336
+ id: auth == null ? void 0 : auth.id,
337
+ givenName: (auth == null ? void 0 : auth.givenName) || "",
338
+ familyName: (auth == null ? void 0 : auth.familyName) || "",
339
+ picture: (auth == null ? void 0 : auth.picture) || "",
340
+ username: (auth == null ? void 0 : auth.username) || "",
341
+ email: (auth == null ? void 0 : auth.email) || "",
342
+ alias: [],
343
+ tokens: []
344
+ },
345
+ isDelivered: true,
346
+ isRead: false,
347
+ type: "TEXT",
348
+ parentId: null,
349
+ fromServer: false,
350
+ channel: {
351
+ __typename: "Channel",
352
+ id: channelId
353
+ },
354
+ propsConfiguration: {
355
+ __typename: "MachineConfiguration",
356
+ resource: ""
357
+ },
358
+ props: {},
359
+ files: {
360
+ __typename: "FilesInfo",
361
+ data: [{
362
+ __typename: "FileInfo",
363
+ id: objectId(),
364
+ url: selectedImage,
365
+ name: ((_d2 = imagesToUpload[0]) == null ? void 0 : _d2.name) || "image.jpg",
366
+ extension: "jpg",
367
+ mimeType: "image/jpeg",
368
+ size: 0,
369
+ refType: FileRefType.Post,
370
+ height: ((_e = imagesToUpload[0]) == null ? void 0 : _e.height) || 0,
371
+ width: ((_f = imagesToUpload[0]) == null ? void 0 : _f.width) || 0
372
+ }],
373
+ totalCount: 1
374
+ },
375
+ replies: {
376
+ __typename: "Messages",
377
+ data: [],
378
+ totalCount: 0
379
+ }
380
+ };
574
381
  const uploadResponse = await startUpload({
575
382
  file: imagesToUpload,
576
383
  saveUploadedFile: {
@@ -584,85 +391,72 @@ const ConversationViewComponent = (_a) => {
584
391
  }
585
392
  }
586
393
  });
587
- console.log("Upload response received:", (uploadResponse == null ? void 0 : uploadResponse.data) ? "Has data" : "No data", "Error:", (uploadResponse == null ? void 0 : uploadResponse.error) ? uploadResponse.error : "None");
588
394
  if (uploadResponse == null ? void 0 : uploadResponse.error) {
589
- console.error("Upload error:", uploadResponse.error);
395
+ setLoading(false);
396
+ setUploadingMessageId(null);
590
397
  return {
591
398
  error: String(uploadResponse.error)
592
399
  };
593
400
  }
594
401
  const uploadedFiles = uploadResponse.data;
595
- console.log("Uploaded files:", uploadedFiles ? JSON.stringify(uploadedFiles.map((f) => {
596
- var _a4;
597
- return {
598
- id: f.id,
599
- url: ((_a4 = f.url) == null ? void 0 : _a4.substring(0, 30)) + "..."
600
- };
601
- })) : "null");
602
- const files = (_a3 = uploadedFiles == null ? void 0 : uploadedFiles.map((f) => f.id)) != null ? _a3 : null;
603
- console.log("Files uploaded successfully. File IDs:", files);
604
- console.log("Sending message with files:", {
605
- postId,
606
- channelId: state.context.channelId,
607
- content: state.context.messageText || " ",
608
- hasFiles: !!files,
609
- fileCount: (files == null ? void 0 : files.length) || 0
610
- });
402
+ const files = (_g = uploadedFiles == null ? void 0 : uploadedFiles.map((f) => f.id)) != null ? _g : null;
611
403
  const response = await sendMsg({
612
404
  variables: {
613
405
  postId,
614
- channelId: state.context.channelId,
615
- content: state.context.messageText || " ",
406
+ channelId,
407
+ content: currentMessageText || " ",
616
408
  files,
617
409
  notificationParams: notificationData
410
+ },
411
+ optimisticResponse: {
412
+ __typename: "Mutation",
413
+ sendMessage: optimisticMessage
618
414
  }
619
415
  });
620
- if ((_b3 = response == null ? void 0 : response.data) == null ? void 0 : _b3.sendMessage) {
621
- console.log("Message with file sent successfully:", response.data.sendMessage.id);
622
- if ((_c2 = response.data.sendMessage.files) == null ? void 0 : _c2.data) {
623
- console.log("\u{1F4F7} Message response file data:", JSON.stringify({
624
- fileCount: response.data.sendMessage.files.data.length,
625
- fileUrl: ((_e2 = (_d2 = response.data.sendMessage.files.data[0]) == null ? void 0 : _d2.url) == null ? void 0 : _e2.substring(0, 30)) + "..."
626
- }));
627
- }
628
- setTimeout(() => {
629
- safeSend({
630
- type: Actions.CLEAR_IMAGE
631
- });
632
- }, 100);
633
- } else {
634
- console.error("Failed to send message with file:", response == null ? void 0 : response.errors);
416
+ if ((_h = response == null ? void 0 : response.data) == null ? void 0 : _h.sendMessage) {
417
+ setSelectedImage("");
418
+ setImages([]);
635
419
  }
420
+ setLoading(false);
421
+ setUploadingMessageId(null);
636
422
  return {
637
- message: (_f2 = response.data) == null ? void 0 : _f2.sendMessage
423
+ message: (_i = response.data) == null ? void 0 : _i.sendMessage
638
424
  };
639
- } catch (error) {
640
- console.error("Error in sendMessageWithFileImpl:", error);
425
+ } catch (error2) {
426
+ setLoading(false);
427
+ setUploadingMessageId(null);
428
+ setError(String(error2));
641
429
  return {
642
- error: String(error)
430
+ error: String(error2)
643
431
  };
644
432
  }
645
- }, [state.context.channelId, state.context.messageText, state.context.images, startUpload, sendMsg, safeSend]);
433
+ }, [channelId, messageText, images, selectedImage, startUpload, sendMsg, auth]);
646
434
  const createDirectChannelImpl = useCallback(async () => {
647
- var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2;
435
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h;
648
436
  try {
437
+ setLoading(true);
649
438
  if (!(rest == null ? void 0 : rest.isCreateNewChannel) || ((_a3 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _a3.type) !== ((_b3 = RoomType) == null ? void 0 : _b3.Direct) || !((_d2 = (_c2 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _c2.userIds) == null ? void 0 : _d2.length)) {
439
+ setLoading(false);
650
440
  return {
651
441
  error: "Invalid channel data"
652
442
  };
653
443
  }
444
+ const currentMessageText = messageText;
445
+ setMessageText("");
654
446
  const response = await addDirectChannel({
655
447
  variables: {
656
- receiver: [...(_f2 = (_e2 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _e2.userIds) != null ? _f2 : []],
448
+ receiver: [...(_f = (_e = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _e.userIds) != null ? _f : []],
657
449
  displayName: "DIRECT CHANNEL"
658
450
  }
659
451
  });
660
- if (!((_h2 = (_g2 = response == null ? void 0 : response.data) == null ? void 0 : _g2.createDirectChannel) == null ? void 0 : _h2.id)) {
452
+ if (!((_h = (_g = response == null ? void 0 : response.data) == null ? void 0 : _g.createDirectChannel) == null ? void 0 : _h.id)) {
453
+ setLoading(false);
661
454
  return {
662
455
  error: "Failed to create channel"
663
456
  };
664
457
  }
665
458
  const newChannelId = response.data.createDirectChannel.id;
459
+ setChannelId(newChannelId);
666
460
  const notificationData = {
667
461
  url: config.INBOX_MESSEGE_PATH,
668
462
  params: {
@@ -674,121 +468,83 @@ const ConversationViewComponent = (_a) => {
674
468
  sound: Platform.OS === "android" ? void 0 : "default"
675
469
  }
676
470
  };
471
+ const messageId = objectId();
472
+ const optimisticMessage = {
473
+ __typename: "Post",
474
+ id: messageId,
475
+ message: currentMessageText,
476
+ createdAt: new Date().toISOString(),
477
+ updatedAt: new Date().toISOString(),
478
+ author: {
479
+ __typename: "UserAccount",
480
+ id: auth == null ? void 0 : auth.id,
481
+ givenName: (auth == null ? void 0 : auth.givenName) || "",
482
+ familyName: (auth == null ? void 0 : auth.familyName) || "",
483
+ picture: (auth == null ? void 0 : auth.picture) || "",
484
+ username: (auth == null ? void 0 : auth.username) || "",
485
+ email: (auth == null ? void 0 : auth.email) || "",
486
+ alias: [],
487
+ tokens: []
488
+ },
489
+ isDelivered: true,
490
+ isRead: false,
491
+ type: "TEXT",
492
+ parentId: null,
493
+ fromServer: false,
494
+ channel: {
495
+ __typename: "Channel",
496
+ id: newChannelId
497
+ },
498
+ propsConfiguration: {
499
+ __typename: "MachineConfiguration",
500
+ resource: ""
501
+ },
502
+ props: {},
503
+ files: {
504
+ __typename: "FilesInfo",
505
+ data: [],
506
+ totalCount: 0
507
+ },
508
+ replies: {
509
+ __typename: "Messages",
510
+ data: [],
511
+ totalCount: 0
512
+ }
513
+ };
677
514
  await sendMsg({
678
515
  variables: {
679
516
  channelId: newChannelId,
680
- content: state.context.messageText,
517
+ content: currentMessageText,
681
518
  notificationParams: notificationData
519
+ },
520
+ optimisticResponse: {
521
+ __typename: "Mutation",
522
+ sendMessage: optimisticMessage
682
523
  }
683
524
  });
525
+ setLoading(false);
684
526
  return {
685
527
  channelId: newChannelId
686
528
  };
687
- } catch (error) {
529
+ } catch (error2) {
530
+ setLoading(false);
531
+ setError(String(error2));
688
532
  return {
689
- error: String(error)
533
+ error: String(error2)
690
534
  };
691
535
  }
692
- }, [rest, state.context.messageText, addDirectChannel, sendMsg]);
693
- useEffect(() => {
694
- }, [state.value, sendMsg, refetch, fetchMoreMessages, addDirectChannel, startUpload, rest, state.context]);
695
- React__default.useEffect(() => {
696
- return () => {
697
- send({
698
- type: Actions.CLEAR_MESSAGES
699
- });
700
- };
701
- }, []);
702
- useFocusEffect(React__default.useCallback(() => {
703
- if (state.context.channelId) {
704
- send({
705
- type: Actions.INITIAL_CONTEXT,
706
- data: {
707
- channelId: state.context.channelId
708
- }
709
- });
710
- }
711
- return () => {
712
- send({
713
- type: Actions.CLEAR_MESSAGES
714
- });
715
- };
716
- }, [state.context.channelId, isFocused]));
717
- React__default.useEffect(() => {
718
- var _a3;
719
- const currentChannelId = ChannelId || ((_a3 = currentRoute == null ? void 0 : currentRoute.params) == null ? void 0 : _a3.channelId);
720
- if (currentChannelId) {
721
- console.log("Setting initial channel ID:", currentChannelId);
722
- send({
723
- type: Actions.INITIAL_CONTEXT,
724
- data: {
725
- channelId: currentChannelId
726
- }
727
- });
728
- }
729
- }, [ChannelId, currentRoute]);
730
- React__default.useEffect(() => {
731
- if (state.context.selectedImage) {
732
- send({
733
- type: Actions.STOP_LOADING
734
- });
735
- }
736
- }, [state.context.selectedImage]);
737
- useEffect(() => {
738
- var _a3, _b3, _c2, _d2;
739
- if ((_a3 = data == null ? void 0 : data.messages) == null ? void 0 : _a3.data) {
740
- console.log("\u{1F4E9} QUERY DATA CHANGED - Messages received:", data.messages.data.length);
741
- const {
742
- data: messages,
743
- totalCount: messageTotalCount
744
- } = data.messages;
745
- if (messages && messages.length > 0) {
746
- console.log("\u{1F4E9} QUERY DATA - Setting channel messages, count:", messages.length);
747
- send({
748
- type: Actions.SET_CHANNEL_MESSAGES,
749
- data: {
750
- messages: uniqBy([...messages, ...state.context.channelMessages], ({
751
- id
752
- }) => id),
753
- totalCount: messageTotalCount
754
- }
755
- });
756
- if (messages[0]) {
757
- const sample = messages[0];
758
- console.log("\u{1F4E9} SAMPLE MESSAGE:", JSON.stringify({
759
- id: sample.id,
760
- message: sample.message,
761
- author: {
762
- id: (_b3 = sample.author) == null ? void 0 : _b3.id,
763
- name: `${(_c2 = sample.author) == null ? void 0 : _c2.givenName} ${(_d2 = sample.author) == null ? void 0 : _d2.familyName}`
764
- },
765
- createdAt: sample.createdAt
766
- }));
767
- }
768
- setTimeout(() => {
769
- var _a4;
770
- if (((_a4 = state.context.channelMessages) == null ? void 0 : _a4.length) === 0) {
771
- console.warn("\u26A0\uFE0F STATE NOT UPDATED after message data received - may need fallback");
772
- }
773
- }, 500);
774
- }
775
- }
776
- }, [data]);
536
+ }, [rest, messageText, addDirectChannel, sendMsg, auth]);
777
537
  const onFetchOld = useCallback(() => {
778
- var _a3, _b3, _c2, _d2;
779
538
  if (fetchOldDebounceRef.current)
780
539
  return;
781
- if (((_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.totalCount) > ((_c2 = (_b3 = state == null ? void 0 : state.context) == null ? void 0 : _b3.channelMessages) == null ? void 0 : _c2.length) && !((_d2 = state == null ? void 0 : state.context) == null ? void 0 : _d2.loadingOldMessages)) {
540
+ if (totalCount > channelMessages.length && !loadingOldMessages) {
782
541
  fetchOldDebounceRef.current = true;
783
- send({
784
- type: Actions.FETCH_MORE_MESSAGES
785
- });
542
+ fetchMoreMessagesImpl();
786
543
  setTimeout(() => {
787
544
  fetchOldDebounceRef.current = false;
788
545
  }, 1e3);
789
546
  }
790
- }, [(_c = state == null ? void 0 : state.context) == null ? void 0 : _c.totalCount, (_d = state == null ? void 0 : state.context) == null ? void 0 : _d.channelMessages, (_e = state == null ? void 0 : state.context) == null ? void 0 : _e.loadingOldMessages]);
791
- const fetchOldDebounceRef = useRef(false);
547
+ }, [totalCount, channelMessages.length, loadingOldMessages, fetchMoreMessagesImpl]);
792
548
  const isCloseToTop = ({
793
549
  layoutMeasurement,
794
550
  contentOffset,
@@ -797,121 +553,21 @@ const ConversationViewComponent = (_a) => {
797
553
  const paddingToTop = 60;
798
554
  return contentSize.height - layoutMeasurement.height - paddingToTop <= contentOffset.y;
799
555
  };
800
- const renderSend = useCallback((props) => {
801
- var _a3, _b3, _c2;
802
- const hasContent = !!props.text || ((_b3 = (_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.images) == null ? void 0 : _b3.length) > 0;
803
- const canSend = (((_c2 = state == null ? void 0 : state.context) == null ? void 0 : _c2.channelId) || (rest == null ? void 0 : rest.isCreateNewChannel)) && hasContent;
804
- return /* @__PURE__ */ React__default.createElement(Send, __spreadProps(__spreadValues({}, props), { disabled: !canSend, containerStyle: {
805
- justifyContent: "center",
806
- alignItems: "center",
807
- height: 40,
808
- width: 44,
809
- marginRight: 4,
810
- marginBottom: 0,
811
- marginLeft: 4
812
- } }), /* @__PURE__ */ React__default.createElement(View, { style: {
813
- padding: 4
814
- } }, /* @__PURE__ */ React__default.createElement(MaterialCommunityIcons, { name: "send-circle", size: 32, color: canSend ? colors.blue[500] : colors.gray[400] })));
815
- }, [(_f = state == null ? void 0 : state.context) == null ? void 0 : _f.channelId, (_g = state == null ? void 0 : state.context) == null ? void 0 : _g.images, rest == null ? void 0 : rest.isCreateNewChannel]);
816
- const handleSend = useCallback(async (messages) => {
817
- var _a3, _b3, _c2, _d2;
818
- const messageText = messages && messages.length > 0 ? ((_a3 = messages[0]) == null ? void 0 : _a3.text) || " " : " ";
819
- console.log("Sending message:", messageText);
820
- console.log("Images:", (_b3 = state.context.images) == null ? void 0 : _b3.length);
821
- if (!state.context.channelId && !(rest == null ? void 0 : rest.isCreateNewChannel)) {
822
- console.log("Cannot send - no channel");
823
- return;
824
- }
825
- const hasText = !!messageText && messageText !== " ";
826
- const hasImages = state.context.images && state.context.images.length > 0;
827
- if (!hasText && !hasImages) {
828
- console.log("Nothing to send - no text or images");
829
- return;
830
- }
831
- safeSend({
832
- type: Actions.SET_MESSAGE_TEXT,
833
- data: {
834
- messageText
835
- }
836
- });
837
- if ((rest == null ? void 0 : rest.isCreateNewChannel) && !state.context.channelId) {
838
- if (((_c2 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _c2.type) === ((_d2 = RoomType) == null ? void 0 : _d2.Direct)) {
839
- safeSend({
840
- type: Actions.CREATE_DIRECT_CHANNEL
841
- });
842
- }
843
- return;
844
- }
845
- if (hasImages) {
846
- console.log("Sending message with file");
847
- safeSend({
848
- type: Actions.SEND_MESSAGE_WITH_FILE
849
- });
850
- } else {
851
- console.log("Sending text-only message");
852
- safeSend({
853
- type: Actions.SEND_MESSAGE
854
- });
855
- }
856
- }, [state.context.channelId, state.context.images, rest == null ? void 0 : rest.isCreateNewChannel, (_h = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _h.type, safeSend]);
857
- const fetchMessagesWithFallback = useCallback(async () => {
858
- var _a3, _b3, _c2;
859
- if (!state.context.channelId)
860
- return;
861
- try {
862
- console.log("\u{1F504} DIRECT FETCH: Using direct approach for channel:", state.context.channelId);
863
- const response = await refetch({
864
- channelId: (_a3 = state.context.channelId) == null ? void 0 : _a3.toString(),
865
- parentId: null,
866
- limit: MESSAGES_PER_PAGE,
867
- skip: 0
868
- });
869
- if ((_c2 = (_b3 = response == null ? void 0 : response.data) == null ? void 0 : _b3.messages) == null ? void 0 : _c2.data) {
870
- const messages = response.data.messages.data;
871
- console.log("\u2705 DIRECT FETCH: Got messages:", messages.length);
872
- send({
873
- type: Actions.SET_CHANNEL_MESSAGES,
874
- data: {
875
- messages,
876
- totalCount: response.data.messages.totalCount
877
- }
878
- });
879
- }
880
- } catch (error) {
881
- console.error("\u274C DIRECT FETCH ERROR:", error);
882
- }
883
- }, [state.context.channelId, refetch]);
884
- useEffect(() => {
885
- let timeoutId;
886
- if (state.context.channelId && state.context.channelMessages.length === 0) {
887
- timeoutId = setTimeout(() => {
888
- console.log("\u26A0\uFE0F ACTIVATING FALLBACK - XState not updating after timeout");
889
- fetchMessagesWithFallback();
890
- }, 3e3);
891
- }
892
- return () => {
893
- if (timeoutId)
894
- clearTimeout(timeoutId);
895
- };
896
- }, [state.context.channelId, state.context.channelMessages, fetchMessagesWithFallback]);
897
556
  const messageList = useMemo(() => {
898
- var _a3;
899
- console.log("\u{1F504} CALCULATING MESSAGE LIST - Optimized version");
900
- if (!((_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.channelMessages) || state.context.channelMessages.length === 0) {
901
- console.log("No messages to process");
557
+ if (!channelMessages || channelMessages.length === 0) {
902
558
  return [];
903
559
  }
904
- const filteredMessages = uniqBy(state.context.channelMessages, ({
560
+ const filteredMessages = uniqBy(channelMessages, ({
905
561
  id
906
562
  }) => id);
907
563
  if (filteredMessages.length === 0) {
908
564
  return [];
909
565
  }
910
566
  return orderBy(filteredMessages, ["createdAt"], ["desc"]).map((msg) => {
911
- var _a4, _b3, _c2, _d2, _e2, _f2;
567
+ var _a3, _b3, _c2, _d2, _e, _f;
912
568
  const date = new Date(msg.createdAt);
913
569
  let imageUrl = null;
914
- if (((_a4 = msg.files) == null ? void 0 : _a4.data) && msg.files.data.length > 0) {
570
+ if (((_a3 = msg.files) == null ? void 0 : _a3.data) && msg.files.data.length > 0) {
915
571
  const fileData = msg.files.data[0];
916
572
  if (fileData && fileData.url) {
917
573
  imageUrl = fileData.url;
@@ -924,40 +580,79 @@ const ConversationViewComponent = (_a) => {
924
580
  user: {
925
581
  _id: ((_b3 = msg.author) == null ? void 0 : _b3.id) || "",
926
582
  name: `${((_c2 = msg.author) == null ? void 0 : _c2.givenName) || ""} ${((_d2 = msg.author) == null ? void 0 : _d2.familyName) || ""}`,
927
- avatar: ((_e2 = msg.author) == null ? void 0 : _e2.picture) || ""
583
+ avatar: ((_e = msg.author) == null ? void 0 : _e.picture) || ""
928
584
  },
929
585
  image: imageUrl,
930
586
  sent: msg == null ? void 0 : msg.isDelivered,
931
587
  received: msg == null ? void 0 : msg.isRead,
932
588
  type: msg == null ? void 0 : msg.type,
933
589
  propsConfiguration: msg == null ? void 0 : msg.propsConfiguration,
934
- replies: (_f2 = msg == null ? void 0 : msg.replies) != null ? _f2 : [],
590
+ replies: (_f = msg == null ? void 0 : msg.replies) != null ? _f : [],
935
591
  isShowThreadMessage
936
592
  };
937
593
  });
938
- }, [(_i = state == null ? void 0 : state.context) == null ? void 0 : _i.channelMessages, isShowThreadMessage]);
594
+ }, [channelMessages, isShowThreadMessage]);
595
+ const renderSend = useCallback((props) => {
596
+ const hasContent = !!props.text || (images == null ? void 0 : images.length) > 0;
597
+ const canSend = (channelId || (rest == null ? void 0 : rest.isCreateNewChannel)) && hasContent;
598
+ return /* @__PURE__ */ React__default.createElement(Send, __spreadProps(__spreadValues({}, props), { disabled: !canSend, containerStyle: {
599
+ justifyContent: "center",
600
+ alignItems: "center",
601
+ height: 40,
602
+ width: 44,
603
+ marginRight: 4,
604
+ marginBottom: 0,
605
+ marginLeft: 4
606
+ } }), /* @__PURE__ */ React__default.createElement(View, { style: {
607
+ padding: 4
608
+ } }, /* @__PURE__ */ React__default.createElement(MaterialCommunityIcons, { name: "send-circle", size: 32, color: canSend ? colors.blue[500] : colors.gray[400] })));
609
+ }, [channelId, images, rest == null ? void 0 : rest.isCreateNewChannel]);
610
+ const handleSend = useCallback(async (messages) => {
611
+ var _a3, _b3, _c2;
612
+ const newMessageText = messages && messages.length > 0 ? ((_a3 = messages[0]) == null ? void 0 : _a3.text) || " " : " ";
613
+ if (!channelId && !(rest == null ? void 0 : rest.isCreateNewChannel)) {
614
+ return;
615
+ }
616
+ const hasText = !!newMessageText && newMessageText !== " ";
617
+ const hasImages = images && images.length > 0;
618
+ if (!hasText && !hasImages) {
619
+ return;
620
+ }
621
+ setMessageText(newMessageText);
622
+ if ((rest == null ? void 0 : rest.isCreateNewChannel) && !channelId) {
623
+ if (((_b3 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _b3.type) === ((_c2 = RoomType) == null ? void 0 : _c2.Direct)) {
624
+ createDirectChannelImpl();
625
+ }
626
+ return;
627
+ }
628
+ if (hasImages) {
629
+ sendMessageWithFileImpl();
630
+ } else {
631
+ sendMessageImpl();
632
+ }
633
+ }, [channelId, images, rest == null ? void 0 : rest.isCreateNewChannel, (_d = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _d.type, createDirectChannelImpl, sendMessageWithFileImpl, sendMessageImpl]);
939
634
  const renderMessageText = useCallback((props) => {
940
- var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2, _q2, _r2, _s2, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U;
635
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U;
941
636
  const {
942
637
  currentMessage
943
638
  } = props;
944
639
  const lastReply = ((_b3 = (_a3 = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _a3.data) == null ? void 0 : _b3.length) > 0 ? (_d2 = (_c2 = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _c2.data) == null ? void 0 : _d2[0] : null;
945
640
  if (currentMessage.type === "ALERT") {
946
- const attachment = (_f2 = (_e2 = currentMessage == null ? void 0 : currentMessage.propsConfiguration) == null ? void 0 : _e2.contents) == null ? void 0 : _f2.attachment;
641
+ const attachment = (_f = (_e = currentMessage == null ? void 0 : currentMessage.propsConfiguration) == null ? void 0 : _e.contents) == null ? void 0 : _f.attachment;
947
642
  let action = "";
948
643
  let actionId = "";
949
644
  let params = {};
950
- if ((_g2 = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _g2.extraParams) {
951
- const extraParams = (_h2 = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _h2.extraParams;
952
- const route = (_i2 = extraParams == null ? void 0 : extraParams.route) != null ? _i2 : null;
645
+ if ((_g = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _g.extraParams) {
646
+ const extraParams = (_h = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _h.extraParams;
647
+ const route = (_i = extraParams == null ? void 0 : extraParams.route) != null ? _i : null;
953
648
  let path = null;
954
649
  let param = null;
955
650
  if (role && role == PreDefinedRole.Guest) {
956
- path = ((_j2 = route == null ? void 0 : route.guest) == null ? void 0 : _j2.name) ? (_l2 = (_k2 = route == null ? void 0 : route.guest) == null ? void 0 : _k2.name) != null ? _l2 : null : null;
957
- param = ((_m2 = route == null ? void 0 : route.guest) == null ? void 0 : _m2.params) ? (_o2 = (_n2 = route == null ? void 0 : route.guest) == null ? void 0 : _n2.params) != null ? _o2 : null : null;
651
+ path = ((_j = route == null ? void 0 : route.guest) == null ? void 0 : _j.name) ? (_l = (_k = route == null ? void 0 : route.guest) == null ? void 0 : _k.name) != null ? _l : null : null;
652
+ param = ((_m = route == null ? void 0 : route.guest) == null ? void 0 : _m.params) ? (_o = (_n = route == null ? void 0 : route.guest) == null ? void 0 : _n.params) != null ? _o : null : null;
958
653
  } else if (role && role == PreDefinedRole.Owner) {
959
- path = ((_p2 = route == null ? void 0 : route.host) == null ? void 0 : _p2.name) ? (_r2 = (_q2 = route == null ? void 0 : route.host) == null ? void 0 : _q2.name) != null ? _r2 : null : null;
960
- param = ((_s2 = route == null ? void 0 : route.host) == null ? void 0 : _s2.params) ? (_u = (_t = route == null ? void 0 : route.host) == null ? void 0 : _t.params) != null ? _u : null : null;
654
+ path = ((_p = route == null ? void 0 : route.host) == null ? void 0 : _p.name) ? (_r = (_q = route == null ? void 0 : route.host) == null ? void 0 : _q.name) != null ? _r : null : null;
655
+ param = ((_s = route == null ? void 0 : route.host) == null ? void 0 : _s.params) ? (_u = (_t = route == null ? void 0 : route.host) == null ? void 0 : _t.params) != null ? _u : null : null;
961
656
  } else {
962
657
  path = ((_v = route == null ? void 0 : route.host) == null ? void 0 : _v.name) ? (_x = (_w = route == null ? void 0 : route.host) == null ? void 0 : _w.name) != null ? _x : null : null;
963
658
  param = ((_y = route == null ? void 0 : route.host) == null ? void 0 : _y.params) ? (_A = (_z = route == null ? void 0 : route.host) == null ? void 0 : _z.params) != null ? _A : null : null;
@@ -980,10 +675,9 @@ const ConversationViewComponent = (_a) => {
980
675
  } }))) : /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#c0c0c0", style: {
981
676
  width: "100%"
982
677
  }, onPress: () => {
983
- var _a4;
984
678
  if (currentMessage == null ? void 0 : currentMessage.isShowThreadMessage)
985
679
  navigation.navigate(config.THREAD_MESSEGE_PATH, {
986
- channelId: (_a4 = state == null ? void 0 : state.context) == null ? void 0 : _a4.channelId,
680
+ channelId,
987
681
  title: "Message",
988
682
  postParentId: currentMessage == null ? void 0 : currentMessage._id,
989
683
  isPostParentIdThread: true
@@ -1013,10 +707,9 @@ const ConversationViewComponent = (_a) => {
1013
707
  return /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#c0c0c0", style: {
1014
708
  width: "100%"
1015
709
  }, onPress: () => {
1016
- var _a4;
1017
710
  if (currentMessage == null ? void 0 : currentMessage.isShowThreadMessage)
1018
711
  navigation.navigate(config.THREAD_MESSEGE_PATH, {
1019
- channelId: (_a4 = state == null ? void 0 : state.context) == null ? void 0 : _a4.channelId,
712
+ channelId,
1020
713
  title: "Message",
1021
714
  postParentId: currentMessage == null ? void 0 : currentMessage._id,
1022
715
  isPostParentIdThread: true
@@ -1043,10 +736,10 @@ const ConversationViewComponent = (_a) => {
1043
736
  fontSize: 12
1044
737
  }, className: "font-bold color-gray-500" }, lastReply ? createdAtText(lastReply == null ? void 0 : lastReply.createdAt) : ""))));
1045
738
  }
1046
- }, [navigation, (_j = state == null ? void 0 : state.context) == null ? void 0 : _j.channelId, role]);
739
+ }, [navigation, channelId, role]);
1047
740
  const renderActions = (props) => {
1048
741
  return /* @__PURE__ */ React__default.createElement(
1049
- Actions$1,
742
+ Actions,
1050
743
  __spreadProps(__spreadValues({}, props), {
1051
744
  options: {
1052
745
  ["Choose from Library"]: onSelectImages,
@@ -1070,68 +763,93 @@ const ConversationViewComponent = (_a) => {
1070
763
  })
1071
764
  );
1072
765
  };
1073
- const renderAccessory = useCallback((props) => {
1074
- var _a3, _b3;
1075
- const selectedImage2 = safeContextProperty("selectedImage", "");
1076
- if (!selectedImage2) {
766
+ const renderAccessory = useCallback(() => {
767
+ var _a3;
768
+ if (!selectedImage) {
1077
769
  return null;
1078
770
  }
1079
771
  return /* @__PURE__ */ React__default.createElement(View, { style: {
1080
- height: 50,
1081
- padding: 3,
772
+ height: 70,
1082
773
  backgroundColor: "white",
1083
774
  borderTopWidth: 1,
1084
775
  borderTopColor: "#e0e0e0",
1085
776
  flexDirection: "row",
1086
777
  alignItems: "center",
1087
778
  margin: 0,
1088
- paddingBottom: 0,
1089
- paddingTop: 5,
779
+ padding: 0,
780
+ paddingVertical: 0,
1090
781
  position: "absolute",
1091
- bottom: 0,
782
+ bottom: Platform.OS === "ios" ? 105 : 95,
1092
783
  left: 0,
1093
784
  right: 0,
1094
- zIndex: 999
1095
- } }, /* @__PURE__ */ React__default.createElement(View, { style: {
1096
- flex: 1,
1097
- flexDirection: "row",
1098
- alignItems: "center",
1099
- paddingHorizontal: 15
1100
- } }, /* @__PURE__ */ React__default.createElement(Image, { key: (_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.selectedImage, alt: "selected image", source: {
1101
- uri: (_b3 = state == null ? void 0 : state.context) == null ? void 0 : _b3.selectedImage
1102
- }, style: {
1103
- width: 36,
1104
- height: 36,
1105
- borderRadius: 5,
1106
- marginRight: 15
1107
- }, size: "xs" }), /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#dddddd", onPress: () => safeSend({
1108
- type: Actions.CLEAR_IMAGE
1109
- }), style: {
1110
- backgroundColor: "#f44336",
1111
- paddingVertical: 2,
1112
- paddingHorizontal: 5,
1113
- borderRadius: 5,
1114
- marginLeft: 10,
785
+ zIndex: 1,
1115
786
  elevation: 3,
1116
787
  shadowColor: "#000",
1117
788
  shadowOffset: {
1118
789
  width: 0,
1119
- height: 1
790
+ height: -1
1120
791
  },
1121
- shadowOpacity: 0.3,
792
+ shadowOpacity: 0.05,
1122
793
  shadowRadius: 2
794
+ } }, /* @__PURE__ */ React__default.createElement(View, { style: {
795
+ flex: 1,
796
+ flexDirection: "row",
797
+ alignItems: "center",
798
+ paddingLeft: 15,
799
+ paddingRight: 5
800
+ } }, /* @__PURE__ */ React__default.createElement(View, { style: {
801
+ width: 56,
802
+ height: 56,
803
+ marginRight: 15,
804
+ borderRadius: 4,
805
+ backgroundColor: colors.gray[200],
806
+ overflow: "hidden",
807
+ borderWidth: 1,
808
+ borderColor: "#e0e0e0"
809
+ } }, /* @__PURE__ */ React__default.createElement(Image, { key: selectedImage, alt: "selected image", source: {
810
+ uri: selectedImage
811
+ }, style: {
812
+ width: "100%",
813
+ height: "100%"
814
+ }, size: "md" }), loading && /* @__PURE__ */ React__default.createElement(View, { style: {
815
+ position: "absolute",
816
+ top: 0,
817
+ left: 0,
818
+ right: 0,
819
+ bottom: 0,
820
+ backgroundColor: "rgba(255, 255, 255, 0.7)",
821
+ justifyContent: "center",
822
+ alignItems: "center"
823
+ } }, /* @__PURE__ */ React__default.createElement(Spinner, { size: "small", color: colors.blue[500] }))), /* @__PURE__ */ React__default.createElement(View, { style: {
824
+ flex: 1
1123
825
  } }, /* @__PURE__ */ React__default.createElement(Text, { style: {
1124
- color: "white",
1125
- fontWeight: "bold"
1126
- } }, "X"))));
1127
- }, [(_k = state == null ? void 0 : state.context) == null ? void 0 : _k.selectedImage, safeSend]);
826
+ fontSize: 14,
827
+ fontWeight: "400",
828
+ color: colors.gray[800]
829
+ } }, ((_a3 = images[0]) == null ? void 0 : _a3.fileName) || "image_" + new Date().getTime() + ".jpg"), /* @__PURE__ */ React__default.createElement(Text, { style: {
830
+ fontSize: 12,
831
+ color: colors.gray[500],
832
+ marginTop: 2
833
+ } }, loading ? "Preparing..." : "Ready to send")), /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "rgba(0,0,0,0.1)", onPress: () => {
834
+ setSelectedImage("");
835
+ setImages([]);
836
+ }, style: {
837
+ backgroundColor: colors.red[500],
838
+ borderRadius: 24,
839
+ width: 36,
840
+ height: 36,
841
+ alignItems: "center",
842
+ justifyContent: "center",
843
+ marginRight: 10
844
+ } }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size: 20, color: "white" }))));
845
+ }, [selectedImage, loading, images]);
1128
846
  const setImageViewerObject = (obj, v) => {
1129
847
  setImageObject(obj);
1130
848
  setImageViewer(v);
1131
849
  };
1132
850
  const modalContent = React__default.useMemo(() => {
1133
- if (!imageObject)
1134
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
851
+ if (!imageObject || !imageObject.image)
852
+ return null;
1135
853
  const {
1136
854
  image,
1137
855
  _id
@@ -1139,14 +857,42 @@ const ConversationViewComponent = (_a) => {
1139
857
  return /* @__PURE__ */ React__default.createElement(CachedImage, { style: {
1140
858
  width: "100%",
1141
859
  height: "100%"
1142
- }, resizeMode: "cover", cacheKey: `${_id}-slack-bubble-imageKey`, source: {
860
+ }, resizeMode: "cover", cacheKey: `${_id}-modal-imageKey`, source: {
1143
861
  uri: image,
1144
862
  expiresIn: 86400
1145
863
  }, alt: "image" });
1146
864
  }, [imageObject]);
1147
865
  const renderMessage = useCallback((props) => {
866
+ const isUploading = props.currentMessage._id === uploadingMessageId && loading;
867
+ if (isUploading && props.currentMessage.image) {
868
+ return /* @__PURE__ */ React__default.createElement(View, { style: {
869
+ padding: 10,
870
+ marginBottom: 10,
871
+ marginRight: 10,
872
+ alignSelf: "flex-end",
873
+ borderRadius: 15,
874
+ backgroundColor: colors.gray[100],
875
+ maxWidth: "80%"
876
+ } }, props.currentMessage.text && props.currentMessage.text.trim() !== "" && /* @__PURE__ */ React__default.createElement(Box, { style: {
877
+ height: 15,
878
+ borderRadius: 4,
879
+ backgroundColor: colors.gray[200],
880
+ overflow: "hidden",
881
+ marginBottom: 8
882
+ } }, /* @__PURE__ */ React__default.createElement(Skeleton, { variant: "rounded", style: {
883
+ flex: 1
884
+ } })), /* @__PURE__ */ React__default.createElement(Box, { style: {
885
+ height: 150,
886
+ width: 150,
887
+ borderRadius: 10,
888
+ backgroundColor: colors.gray[200],
889
+ overflow: "hidden"
890
+ } }, /* @__PURE__ */ React__default.createElement(Skeleton, { variant: "rounded", style: {
891
+ flex: 1
892
+ } })));
893
+ }
1148
894
  return /* @__PURE__ */ React__default.createElement(Message, __spreadProps(__spreadValues({}, props), { isShowImageViewer, setImageViewer: setImageViewerObject }));
1149
- }, [isShowImageViewer]);
895
+ }, [isShowImageViewer, uploadingMessageId, loading]);
1150
896
  let onScroll = false;
1151
897
  const onMomentumScrollBegin = async ({
1152
898
  nativeEvent
@@ -1157,185 +903,18 @@ const ConversationViewComponent = (_a) => {
1157
903
  }
1158
904
  };
1159
905
  const onEndReached = () => {
1160
- console.log("on end reached");
1161
906
  if (!onScroll)
1162
907
  return;
1163
908
  onScroll = false;
1164
909
  };
1165
- useEffect(() => {
1166
- console.log("Current channel ID:", state.context.channelId);
1167
- console.log("Current state:", state.value);
1168
- console.log("Channel messages count:", state.context.channelMessages.length);
1169
- }, [state.context.channelId, state.value, state.context.channelMessages]);
1170
- useEffect(() => {
1171
- if (state && typeof state.matches === "function") {
1172
- if (state.matches(BaseState.FetchMessages)) {
1173
- console.log("In FetchMessages state, attempting to fetch messages");
1174
- if (!fetchInProgressRef.current) {
1175
- fetchInProgressRef.current = true;
1176
- fetchMessagesDirectly().finally(() => {
1177
- fetchInProgressRef.current = false;
1178
- });
1179
- }
1180
- } else if (state.matches(MainState.FetchMoreMessages)) {
1181
- if (!fetchMoreInProgressRef.current) {
1182
- fetchMoreInProgressRef.current = true;
1183
- fetchMoreMessagesImpl().then((result) => {
1184
- if (result.error) {
1185
- console.error("Error fetching more messages:", result.error);
1186
- safeSend({
1187
- type: "ERROR",
1188
- data: {
1189
- message: result.error
1190
- }
1191
- });
1192
- } else {
1193
- safeSend({
1194
- type: "FETCH_MORE_MESSAGES_SUCCESS",
1195
- data: result
1196
- });
1197
- }
1198
- fetchMoreInProgressRef.current = false;
1199
- });
1200
- }
1201
- } else if (state.matches(MainState.SendMessage)) {
1202
- if (!sendInProgressRef.current) {
1203
- sendInProgressRef.current = true;
1204
- sendMessageImpl().then((result) => {
1205
- if (result.error) {
1206
- console.error("Error sending message:", result.error);
1207
- safeSend({
1208
- type: "ERROR",
1209
- data: {
1210
- message: result.error
1211
- }
1212
- });
1213
- } else {
1214
- safeSend({
1215
- type: "SEND_MESSAGE_SUCCESS",
1216
- data: result
1217
- });
1218
- }
1219
- sendInProgressRef.current = false;
1220
- });
1221
- }
1222
- } else if (state.matches(MainState.SendMessageWithFile)) {
1223
- if (!sendFileInProgressRef.current) {
1224
- sendFileInProgressRef.current = true;
1225
- sendMessageWithFileImpl().then((result) => {
1226
- if (result.error) {
1227
- console.error("Error sending message with file:", result.error);
1228
- safeSend({
1229
- type: "ERROR",
1230
- data: {
1231
- message: result.error
1232
- }
1233
- });
1234
- } else {
1235
- safeSend({
1236
- type: "SEND_MESSAGE_WITH_FILE_SUCCESS",
1237
- data: result
1238
- });
1239
- }
1240
- sendFileInProgressRef.current = false;
1241
- });
1242
- }
1243
- } else if (state.matches(MainState.CreateDirectChannel)) {
1244
- if (!createChannelInProgressRef.current) {
1245
- createChannelInProgressRef.current = true;
1246
- createDirectChannelImpl().then((result) => {
1247
- if (result.error) {
1248
- console.error("Error creating direct channel:", result.error);
1249
- safeSend({
1250
- type: "ERROR",
1251
- data: {
1252
- message: result.error
1253
- }
1254
- });
1255
- } else {
1256
- safeSend({
1257
- type: "CREATE_DIRECT_CHANNEL_SUCCESS",
1258
- data: result
1259
- });
1260
- }
1261
- createChannelInProgressRef.current = false;
1262
- });
1263
- }
1264
- }
1265
- }
1266
- }, [state == null ? void 0 : state.value, fetchMessagesDirectly, fetchMoreMessagesImpl, sendMessageImpl, sendMessageWithFileImpl, createDirectChannelImpl, safeSend]);
1267
- const fetchInProgressRef = useRef(false);
1268
- const fetchMoreInProgressRef = useRef(false);
1269
- const sendInProgressRef = useRef(false);
1270
- const sendFileInProgressRef = useRef(false);
1271
- const createChannelInProgressRef = useRef(false);
1272
- const renderChatFooter = useCallback(() => {
1273
- var _a3, _b3;
1274
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent }), /* @__PURE__ */ React__default.createElement(SubscriptionHandler, { channelId: (_b3 = (_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.channelId) == null ? void 0 : _b3.toString(), subscribeToNewMessages: () => {
1275
- var _a4, _b4;
1276
- return subscribeToMore({
1277
- document: OnChatMessageAddedDocument,
1278
- variables: {
1279
- channelId: (_b4 = (_a4 = state == null ? void 0 : state.context) == null ? void 0 : _a4.channelId) == null ? void 0 : _b4.toString()
1280
- },
1281
- updateQuery: (prev, {
1282
- subscriptionData
1283
- }) => {
1284
- var _a5, _b5, _c2;
1285
- if (!((_a5 = subscriptionData == null ? void 0 : subscriptionData.data) == null ? void 0 : _a5.chatMessageAdded))
1286
- return prev;
1287
- const newMessage = subscriptionData.data.chatMessageAdded;
1288
- const currentMessages = ((_b5 = prev == null ? void 0 : prev.messages) == null ? void 0 : _b5.data) || [];
1289
- if (currentMessages.some((msg) => msg.id === newMessage.id)) {
1290
- return prev;
1291
- }
1292
- if (lastProcessedMessageRef.current === newMessage.id) {
1293
- return prev;
1294
- }
1295
- lastProcessedMessageRef.current = newMessage.id;
1296
- queueMicrotask(() => {
1297
- var _a6;
1298
- safeSend({
1299
- type: Actions.SET_CHANNEL_MESSAGES,
1300
- data: {
1301
- messages: uniqBy([...state.context.channelMessages, newMessage], ({
1302
- id
1303
- }) => id),
1304
- totalCount: (((_a6 = prev == null ? void 0 : prev.messages) == null ? void 0 : _a6.totalCount) || 0) + 1
1305
- }
1306
- });
1307
- });
1308
- return __spreadProps(__spreadValues({}, prev), {
1309
- messages: __spreadProps(__spreadValues({}, prev == null ? void 0 : prev.messages), {
1310
- data: [...currentMessages, newMessage],
1311
- totalCount: (((_c2 = prev == null ? void 0 : prev.messages) == null ? void 0 : _c2.totalCount) || 0) + 1
1312
- })
1313
- });
1314
- }
1315
- });
1316
- } }));
1317
- }, [isShowImageViewer, modalContent, (_l = state == null ? void 0 : state.context) == null ? void 0 : _l.channelId, (_m = state == null ? void 0 : state.context) == null ? void 0 : _m.channelMessages, subscribeToMore, safeSend]);
1318
- const lastProcessedMessageRef = useRef(null);
1319
- const listViewProps = useMemo(() => ({
1320
- onEndReached,
1321
- onEndReachedThreshold: 0.5,
1322
- onMomentumScrollBegin,
1323
- removeClippedSubviews: true,
1324
- initialNumToRender: 10,
1325
- maxToRenderPerBatch: 7,
1326
- windowSize: 7,
1327
- updateCellsBatchingPeriod: 50,
1328
- keyExtractor: (item) => item._id
1329
- }), [onEndReached, onMomentumScrollBegin]);
1330
910
  const renderLoadEarlier = useCallback(() => {
1331
- var _a3;
1332
- return ((_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.loadingOldMessages) ? /* @__PURE__ */ React__default.createElement(View, { style: {
911
+ return loadingOldMessages ? /* @__PURE__ */ React__default.createElement(View, { style: {
1333
912
  padding: 10,
1334
913
  backgroundColor: "rgba(255,255,255,0.8)",
1335
914
  borderRadius: 10,
1336
915
  marginTop: 10
1337
916
  } }, /* @__PURE__ */ React__default.createElement(Spinner, { size: "small", color: "#3b82f6" })) : null;
1338
- }, [(_n = state == null ? void 0 : state.context) == null ? void 0 : _n.loadingOldMessages]);
917
+ }, [loadingOldMessages]);
1339
918
  const renderInputToolbar = useCallback((props) => {
1340
919
  return /* @__PURE__ */ React__default.createElement(InputToolbar, __spreadProps(__spreadValues({}, props), { containerStyle: {
1341
920
  backgroundColor: "white",
@@ -1350,10 +929,32 @@ const ConversationViewComponent = (_a) => {
1350
929
  alignItems: "center"
1351
930
  } }));
1352
931
  }, []);
932
+ const imageViewerModal = useMemo(() => /* @__PURE__ */ React__default.createElement(ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent }), [isShowImageViewer, modalContent]);
933
+ const subscriptionHandler = useMemo(() => /* @__PURE__ */ React__default.createElement(SubscriptionHandler, { channelId: channelId == null ? void 0 : channelId.toString(), subscribeToNewMessages: () => subscribeToMore({
934
+ document: OnChatMessageAddedDocument,
935
+ variables: {
936
+ channelId: channelId == null ? void 0 : channelId.toString()
937
+ }
938
+ }) }), [channelId, subscribeToMore, auth == null ? void 0 : auth.id]);
939
+ const renderChatFooter = useCallback(() => {
940
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, imageViewerModal, subscriptionHandler);
941
+ }, [imageViewerModal, subscriptionHandler]);
942
+ const listViewProps = useMemo(() => ({
943
+ onEndReached,
944
+ onEndReachedThreshold: 0.5,
945
+ onMomentumScrollBegin,
946
+ removeClippedSubviews: true,
947
+ initialNumToRender: 10,
948
+ maxToRenderPerBatch: 7,
949
+ windowSize: 7,
950
+ updateCellsBatchingPeriod: 50,
951
+ keyExtractor: (item) => item._id
952
+ }), [onEndReached, onMomentumScrollBegin]);
1353
953
  return /* @__PURE__ */ React__default.createElement(View, { style: {
1354
954
  flex: 1,
1355
- backgroundColor: "white"
1356
- } }, (state == null ? void 0 : state.matches) && state.matches(BaseState.FetchMessages) && /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }), /* @__PURE__ */ React__default.createElement(
955
+ backgroundColor: "white",
956
+ position: "relative"
957
+ } }, messageLoading && /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }), selectedImage ? renderAccessory() : null, /* @__PURE__ */ React__default.createElement(
1357
958
  GiftedChat,
1358
959
  {
1359
960
  ref: messageRootListRef,
@@ -1362,19 +963,13 @@ const ConversationViewComponent = (_a) => {
1362
963
  messages: messageList,
1363
964
  listViewProps: __spreadProps(__spreadValues({}, listViewProps), {
1364
965
  contentContainerStyle: {
1365
- paddingBottom: 10
1366
- },
1367
- keyboardShouldPersistTaps: "handled"
1368
- }),
1369
- onSend: handleSend,
1370
- text: safeContextProperty("messageText", " ") || " ",
1371
- onInputTextChanged: (text) => safeSend({
1372
- type: Actions.SET_MESSAGE_TEXT,
1373
- data: {
1374
- messageText: text
966
+ paddingBottom: selectedImage ? 90 : 0
1375
967
  }
1376
968
  }),
1377
- renderFooter: () => safeContextProperty("loading") || safeContextProperty("imageLoading") ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : null,
969
+ onSend: handleSend,
970
+ text: messageText || " ",
971
+ onInputTextChanged: (text) => setMessageText(text),
972
+ renderFooter: () => loading && !images.length ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : null,
1378
973
  scrollToBottom: true,
1379
974
  user: {
1380
975
  _id: (auth == null ? void 0 : auth.id) || ""
@@ -1385,14 +980,13 @@ const ConversationViewComponent = (_a) => {
1385
980
  renderMessageText,
1386
981
  renderInputToolbar,
1387
982
  minInputToolbarHeight: 50,
1388
- renderActions: safeContextProperty("channelId") && renderActions,
1389
- renderAccessory: !!((_o = state == null ? void 0 : state.context) == null ? void 0 : _o.selectedImage) ? renderAccessory : void 0,
983
+ renderActions: channelId && renderActions,
1390
984
  renderMessage,
1391
985
  renderChatFooter,
1392
986
  renderLoadEarlier,
1393
- loadEarlier: ((_p = state == null ? void 0 : state.context) == null ? void 0 : _p.totalCount) > ((_r = (_q = state == null ? void 0 : state.context) == null ? void 0 : _q.channelMessages) == null ? void 0 : _r.length),
1394
- isLoadingEarlier: (_s = state == null ? void 0 : state.context) == null ? void 0 : _s.loadingOldMessages,
1395
- bottomOffset: Platform.OS === "ios" ? 10 : 0,
987
+ loadEarlier: totalCount > channelMessages.length,
988
+ isLoadingEarlier: loadingOldMessages,
989
+ bottomOffset: Platform.OS === "ios" ? selectedImage ? 90 : 10 : 0,
1396
990
  textInputProps: {
1397
991
  style: {
1398
992
  borderWidth: 1,
@@ -1436,11 +1030,16 @@ const SubscriptionHandler = ({
1436
1030
  }) => {
1437
1031
  const channelIdRef = useRef(channelId);
1438
1032
  useEffect(() => {
1439
- if (channelId && channelId !== channelIdRef.current) {
1440
- channelIdRef.current = channelId;
1441
- console.log("Setting up subscription for channel:", channelId);
1442
- return subscribeToNewMessages();
1033
+ if (!channelId) {
1034
+ return;
1443
1035
  }
1036
+ const unsubscribe = subscribeToNewMessages();
1037
+ channelIdRef.current = channelId;
1038
+ return () => {
1039
+ if (unsubscribe && typeof unsubscribe === "function") {
1040
+ unsubscribe();
1041
+ }
1042
+ };
1444
1043
  }, [channelId, subscribeToNewMessages]);
1445
1044
  return null;
1446
1045
  };