@messenger-box/platform-mobile 10.0.3-alpha.16 → 10.0.3-alpha.162

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 (95) hide show
  1. package/CHANGELOG.md +248 -0
  2. package/lib/compute.js +2 -3
  3. package/lib/compute.js.map +1 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/module.js.map +1 -1
  6. package/lib/queries/inboxQueries.js +65 -0
  7. package/lib/queries/inboxQueries.js.map +1 -0
  8. package/lib/routes.json +13 -1
  9. package/lib/screens/inbox/DialogMessages.js +5 -3
  10. package/lib/screens/inbox/DialogMessages.js.map +1 -1
  11. package/lib/screens/inbox/DialogThreadMessages.js +3 -7
  12. package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
  13. package/lib/screens/inbox/DialogThreads.js +57 -18
  14. package/lib/screens/inbox/DialogThreads.js.map +1 -1
  15. package/lib/screens/inbox/Inbox.js.map +1 -1
  16. package/lib/screens/inbox/components/CachedImage/consts.js +1 -1
  17. package/lib/screens/inbox/components/CachedImage/consts.js.map +1 -1
  18. package/lib/screens/inbox/components/CachedImage/index.js +168 -46
  19. package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
  20. package/lib/screens/inbox/components/DialogItem.js +169 -0
  21. package/lib/screens/inbox/components/DialogItem.js.map +1 -0
  22. package/lib/screens/inbox/components/GiftedChatInboxComponent.js +313 -0
  23. package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
  24. package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js.map +1 -1
  25. package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js +197 -0
  26. package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js.map +1 -0
  27. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +141 -31
  28. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
  29. package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
  30. package/lib/screens/inbox/components/SubscriptionHandler.js +24 -0
  31. package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
  32. package/lib/screens/inbox/components/ThreadsViewItem.js +66 -44
  33. package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
  34. package/lib/screens/inbox/config/config.js +2 -2
  35. package/lib/screens/inbox/config/config.js.map +1 -1
  36. package/lib/screens/inbox/containers/ConversationView.js +1205 -432
  37. package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
  38. package/lib/screens/inbox/containers/Dialogs.js +193 -80
  39. package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
  40. package/lib/screens/inbox/containers/ThreadConversationView.js +724 -207
  41. package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
  42. package/lib/screens/inbox/containers/ThreadsView.js +83 -50
  43. package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
  44. package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
  45. package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
  46. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
  47. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
  48. package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
  49. package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
  50. package/package.json +5 -5
  51. package/src/index.ts +2 -0
  52. package/src/queries/inboxQueries.ts +299 -0
  53. package/src/queries/index.d.ts +2 -0
  54. package/src/queries/index.ts +1 -0
  55. package/src/screens/inbox/DialogMessages.tsx +2 -1
  56. package/src/screens/inbox/DialogThreadMessages.tsx +3 -11
  57. package/src/screens/inbox/DialogThreads.tsx +53 -60
  58. package/src/screens/inbox/components/Actionsheet.tsx +30 -0
  59. package/src/screens/inbox/components/CachedImage/consts.ts +4 -3
  60. package/src/screens/inbox/components/CachedImage/index.tsx +232 -61
  61. package/src/screens/inbox/components/DialogItem.tsx +306 -0
  62. package/src/screens/inbox/components/DialogsListItem.tsx +230 -170
  63. package/src/screens/inbox/components/ExpandableInput.tsx +460 -0
  64. package/src/screens/inbox/components/ExpandableInputActionSheet.tsx +518 -0
  65. package/src/screens/inbox/components/GiftedChatInboxComponent.tsx +411 -0
  66. package/src/screens/inbox/components/ServiceDialogsListItem.tsx +330 -171
  67. package/src/screens/inbox/components/SlackInput.tsx +23 -0
  68. package/src/screens/inbox/components/SlackMessageContainer/PaymentMessage.tsx +199 -0
  69. package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +233 -23
  70. package/src/screens/inbox/components/SmartLoader.tsx +61 -0
  71. package/src/screens/inbox/components/SubscriptionHandler.tsx +41 -0
  72. package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +41 -24
  73. package/src/screens/inbox/components/ThreadsViewItem.tsx +177 -265
  74. package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +145 -0
  75. package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +159 -0
  76. package/src/screens/inbox/config/config.ts +2 -2
  77. package/src/screens/inbox/containers/ConversationView.tsx +2004 -698
  78. package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
  79. package/src/screens/inbox/containers/Dialogs.tsx +402 -196
  80. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +2 -2
  81. package/src/screens/inbox/containers/ThreadConversationView.tsx +1337 -301
  82. package/src/screens/inbox/containers/ThreadsView.tsx +105 -186
  83. package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +20 -0
  84. package/src/screens/inbox/containers/workflow/conversation-xstate.ts +313 -0
  85. package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +196 -0
  86. package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +401 -0
  87. package/src/screens/inbox/hooks/useInboxMessages.ts +34 -0
  88. package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +136 -0
  89. package/src/screens/inbox/index.ts +37 -0
  90. package/src/screens/inbox/machines/threadsMachine.ts +147 -0
  91. package/src/screens/inbox/workflow/dialog-threads-xstate.ts +163 -0
  92. package/lib/screens/inbox/components/DialogsListItem.js +0 -175
  93. package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
  94. package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -165
  95. package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import React__default,{useState,useRef,useEffect,useCallback,useMemo}from'react';import {Spinner,Box,HStack,Image,Button,ButtonText,Avatar,AvatarFallbackText,AvatarImage,Text}from'@admin-layout/gluestack-ui-mobile';import {Platform,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 {encode}from'base-64';import {Ionicons,MaterialCommunityIcons}from'@expo/vector-icons';import {GiftedChat,Actions,MessageText,Send}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';var __defProp = Object.defineProperty;
1
+ import React__default,{useState,useRef,useMemo,useEffect,useCallback}from'react';import {useToast,Box,Button,ButtonText,HStack,Avatar,AvatarFallbackText,AvatarImage,Text,ScrollView,Image,VStack,Spinner}from'@admin-layout/gluestack-ui-mobile';import {Platform,View,TouchableHighlight,TouchableOpacity,TextInput,KeyboardAvoidingView,Animated}from'react-native';import {useRoute,useNavigation,useIsFocused,useFocusEffect}from'@react-navigation/native';import {navigationRef}from'@common-stack/client-react';import {useSelector,shallowEqual}from'react-redux';import {uniqBy,orderBy,startCase}from'lodash-es';import*as ImagePicker from'expo-image-picker';import {MaterialCommunityIcons,Ionicons,MaterialIcons}from'@expo/vector-icons';import {Send,MessageText}from'react-native-gifted-chat';import {PostTypeEnum,FileRefType,RoomType,PreDefinedRole}from'common';import {useAddDirectChannel,useSendChannelMessage,useSendExpoNotification,MESSAGES_DOCUMENT,CHAT_MESSAGE_ADDED,useChannelMessagesQuery}from'../../../queries/inboxQueries.js';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';import {SubscriptionHandler}from'../components/SubscriptionHandler.js';import {useInboxMessages}from'../hooks/useInboxMessages.js';import'react-native-reanimated';import'expo-constants';import {GiftedChatInboxComponent}from'../components/GiftedChatInboxComponent.js';import PaymentMessage from'../components/SlackMessageContainer/PaymentMessage.js';var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -46,381 +46,949 @@ const createdAtText = (value) => {
46
46
  return "Yesterday";
47
47
  return format(new Date(value), "MMM dd, yyyy");
48
48
  };
49
+ const ErrorNotification = ({
50
+ message,
51
+ onClose,
52
+ type = "error"
53
+ }) => {
54
+ const opacity = useRef(new Animated.Value(0)).current;
55
+ const bgColor = type === "error" ? "#f44336" : "#ff9800";
56
+ const title = type === "error" ? "Error" : "Warning";
57
+ useEffect(() => {
58
+ Animated.timing(opacity, {
59
+ toValue: 1,
60
+ duration: 300,
61
+ useNativeDriver: true
62
+ }).start();
63
+ const timer = setTimeout(() => {
64
+ Animated.timing(opacity, {
65
+ toValue: 0,
66
+ duration: 300,
67
+ useNativeDriver: true
68
+ }).start(() => onClose && onClose());
69
+ }, 4e3);
70
+ return () => clearTimeout(timer);
71
+ }, []);
72
+ return /* @__PURE__ */ React__default.createElement(Animated.View, { style: {
73
+ position: "absolute",
74
+ top: 10,
75
+ left: 10,
76
+ right: 10,
77
+ backgroundColor: bgColor,
78
+ padding: 15,
79
+ borderRadius: 8,
80
+ shadowColor: "#000",
81
+ shadowOffset: {
82
+ width: 0,
83
+ height: 2
84
+ },
85
+ shadowOpacity: 0.25,
86
+ shadowRadius: 3.84,
87
+ elevation: 5,
88
+ zIndex: 1e3,
89
+ opacity
90
+ } }, /* @__PURE__ */ React__default.createElement(HStack, { className: "items-center justify-between" }, /* @__PURE__ */ React__default.createElement(Text, { style: {
91
+ color: "white",
92
+ fontWeight: "bold"
93
+ } }, title), /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: onClose }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size: 20, color: "white" }))), /* @__PURE__ */ React__default.createElement(Text, { style: {
94
+ color: "white",
95
+ marginTop: 5
96
+ } }, message));
97
+ };
98
+ Platform.OS === "ios" ? 20 : 0;
49
99
  const ConversationViewComponent = (_a) => {
50
100
  var _b = _a, {
51
- channelId: ChannelId,
101
+ channelId: initialChannelId,
52
102
  role,
53
- isShowThreadMessage
103
+ isShowThreadMessage,
104
+ isPaymentChatUI
54
105
  } = _b, rest = __objRest(_b, [
55
106
  "channelId",
56
107
  "role",
57
- "isShowThreadMessage"
108
+ "isShowThreadMessage",
109
+ "isPaymentChatUI"
58
110
  ]);
59
- var _a2;
60
- const [channelToTop, setChannelToTop] = useState(0);
61
- const [channelMessages, setChannelMessages] = useState([]);
62
- const auth = useSelector(userSelector);
63
- const [totalCount, setTotalCount] = useState(0);
64
- const [selectedImage, setImage] = useState("");
65
- const currentRoute = navigationRef.isReady() ? (_a2 = navigationRef) == null ? void 0 : _a2.getCurrentRoute() : null;
66
- const [channelId, setChannelId] = useState((rest == null ? void 0 : rest.isCreateNewChannel) ? null : ChannelId);
111
+ var _a2, _b2, _c, _d;
112
+ const {
113
+ params
114
+ } = useRoute();
115
+ const [channelId, setChannelId] = useState(initialChannelId || null);
116
+ const [messageText, setMessageText] = useState("");
117
+ const [loading, setLoading] = useState(false);
67
118
  const [loadingOldMessages, setLoadingOldMessages] = useState(false);
68
- const navigation = useNavigation();
69
- const [files, setFiles] = useState([]);
119
+ const [error, setError] = useState(null);
120
+ const [selectedImage, setSelectedImage] = useState("");
70
121
  const [images, setImages] = useState([]);
71
- const [msg, setMsg] = useState("");
72
- const [loading, setLoading] = useState(false);
73
- const [loadEarlierMsg, setLoadEarlierMsg] = useState(false);
74
- const [imageLoading, setImageLoading] = useState(false);
75
- const [expoTokens, setExpoTokens] = useState([]);
76
122
  const [isShowImageViewer, setImageViewer] = useState(false);
77
123
  const [imageObject, setImageObject] = useState({});
78
- const [skip, setSkip] = useState(0);
124
+ const [errorMessage, setErrorMessage] = useState("");
125
+ const [notificationType, setNotificationType] = useState("error");
126
+ const [isActionSheetVisible, setActionSheetVisible] = useState(false);
127
+ const [bottomMargin, setBottomMargin] = useState(0);
79
128
  const messageRootListRef = useRef(null);
129
+ const textInputRef = useRef(null);
130
+ const isMounted = useRef(true);
131
+ const fetchOldDebounceRef = useRef(false);
132
+ const auth = useSelector(userSelector, shallowEqual);
133
+ const currentRoute = navigationRef.isReady() ? (_a2 = navigationRef) == null ? void 0 : _a2.getCurrentRoute() : null;
134
+ const navigation = useNavigation();
80
135
  const isFocused = useIsFocused();
81
- const [addDirectChannel, {
82
- loading: addDirectChannaleLoading
83
- }] = useAddDirectChannelMutation();
136
+ const [addDirectChannel] = useAddDirectChannel();
84
137
  const {
85
138
  startUpload
86
139
  } = useUploadFilesNative();
87
- const [sendMsg] = useSendMessagesMutation();
88
- const [sendExpoNotificationOnPostMutation] = useSendExpoNotificationOnPostMutation();
140
+ const [sendMsg] = useSendChannelMessage();
141
+ const [sendExpoNotification] = useSendExpoNotification();
142
+ const [skip, setSkip] = useState(0);
89
143
  const {
90
144
  data,
91
145
  loading: messageLoading,
92
146
  refetch,
93
- fetchMore: fetchMoreMessages,
94
- subscribeToMore
95
- } = useMessagesQuery({
96
- variables: {
147
+ subscribe
148
+ } = useInboxMessages({
149
+ useQueryHook: useChannelMessagesQuery,
150
+ queryVariables: {
97
151
  channelId: channelId == null ? void 0 : channelId.toString(),
98
152
  parentId: null,
99
153
  limit: MESSAGES_PER_PAGE,
100
- skip
154
+ skip,
155
+ orgName: params == null ? void 0 : params.orgName
101
156
  },
102
- skip: !channelId,
103
- fetchPolicy: "cache-and-network",
104
- nextFetchPolicy: "cache-first",
105
- refetchWritePolicy: "merge"
157
+ subscriptionDocument: CHAT_MESSAGE_ADDED,
158
+ subscriptionVariables: {
159
+ channelId: channelId == null ? void 0 : channelId.toString()
160
+ },
161
+ updateQuery: void 0,
162
+ onError: (err) => setError(String(err))
106
163
  });
107
- React__default.useEffect(() => {
164
+ const channelMessages = useMemo(() => {
165
+ var _a3;
166
+ return ((_a3 = data == null ? void 0 : data.messages) == null ? void 0 : _a3.data) || [];
167
+ }, [(_b2 = data == null ? void 0 : data.messages) == null ? void 0 : _b2.data]);
168
+ const totalCount = useMemo(() => {
169
+ var _a3;
170
+ return ((_a3 = data == null ? void 0 : data.messages) == null ? void 0 : _a3.totalCount) || 0;
171
+ }, [(_c = data == null ? void 0 : data.messages) == null ? void 0 : _c.totalCount]);
172
+ useEffect(() => {
108
173
  return () => {
109
- setChannelMessages([]);
174
+ isMounted.current = false;
110
175
  };
111
176
  }, []);
177
+ useEffect(() => {
178
+ var _a3;
179
+ const currentChannelId = initialChannelId || ((_a3 = currentRoute == null ? void 0 : currentRoute.params) == null ? void 0 : _a3.channelId);
180
+ if (currentChannelId) {
181
+ setChannelId(currentChannelId);
182
+ }
183
+ }, [initialChannelId, currentRoute]);
112
184
  useFocusEffect(React__default.useCallback(() => {
113
- setSkip(0);
114
185
  if (channelId) {
115
- refetch({
186
+ refetch();
187
+ }
188
+ }, [isFocused, refetch]));
189
+ const fetchMoreMessagesImpl = useCallback(async () => {
190
+ var _a3, _b3;
191
+ try {
192
+ setLoadingOldMessages(true);
193
+ const response = await refetch({
116
194
  channelId: channelId == null ? void 0 : channelId.toString(),
117
195
  parentId: null,
118
196
  limit: MESSAGES_PER_PAGE,
119
- skip: 0
120
- }).then(({
121
- data: data2
122
- }) => {
123
- if (!(data2 == null ? void 0 : data2.messages)) {
124
- return;
125
- }
126
- const {
127
- data: messages,
128
- totalCount: totalCount2
129
- } = data2.messages;
130
- setTotalCount(totalCount2);
131
- setChannelMessages(messages);
197
+ skip: channelMessages.length
132
198
  });
133
- }
134
- return () => {
135
- setChannelId(null);
136
- setTotalCount(0);
137
- setSkip(0);
138
- };
139
- }, [channelId, isFocused]));
140
- React__default.useEffect(() => {
141
- var _a3;
142
- const currentChannelId = ChannelId || ((_a3 = currentRoute == null ? void 0 : currentRoute.params) == null ? void 0 : _a3.channelId);
143
- setChannelId(currentChannelId);
144
- }, [ChannelId, currentRoute]);
145
- React__default.useEffect(() => {
146
- if (selectedImage)
147
- setImageLoading(false);
148
- }, [selectedImage]);
149
- useEffect(() => {
150
- var _a3;
151
- if ((_a3 = data == null ? void 0 : data.messages) == null ? void 0 : _a3.data) {
152
- const {
153
- data: messages,
154
- totalCount: messeageTotalCount
155
- } = data.messages;
156
- console.log("messeageTotalCount", messeageTotalCount, " totalCount=", totalCount);
157
- if (messages && messages.length > 0 && messeageTotalCount > totalCount || messages && messages.length > 0 && (loadingOldMessages || channelMessages.length === 0)) {
158
- setChannelMessages((oldMessages) => uniqBy([...messages, ...oldMessages], ({
159
- id
160
- }) => id));
161
- setTotalCount(messeageTotalCount);
199
+ setSkip(channelMessages.length);
200
+ setLoadingOldMessages(false);
201
+ if (!((_b3 = (_a3 = response == null ? void 0 : response.data) == null ? void 0 : _a3.messages) == null ? void 0 : _b3.data)) {
202
+ return {
203
+ error: "No messages returned"
204
+ };
162
205
  }
163
- if (loadingOldMessages && channelMessages)
164
- setLoadingOldMessages(false);
206
+ return {
207
+ messages: response.data.messages.data
208
+ };
209
+ } catch (error2) {
210
+ setLoadingOldMessages(false);
211
+ setError(String(error2));
212
+ return {
213
+ error: String(error2)
214
+ };
165
215
  }
166
- }, [data, loadingOldMessages, channelMessages, totalCount]);
167
- const onFetchOld = useCallback(async () => {
168
- if (totalCount > channelMessages.length && !loadingOldMessages) {
169
- setLoadEarlierMsg(true);
170
- try {
171
- const response = await fetchMoreMessages({
172
- variables: {
173
- channelId: channelId == null ? void 0 : channelId.toString(),
174
- parentId: null,
175
- skip: channelMessages.length
216
+ }, [channelId, channelMessages.length, refetch]);
217
+ const sendMessageImpl = useCallback(async () => {
218
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h;
219
+ try {
220
+ const currentMessageText = messageText;
221
+ setMessageText("");
222
+ const notificationData = {
223
+ url: config.INBOX_MESSEGE_PATH,
224
+ params: {
225
+ channelId,
226
+ hideTabBar: true
227
+ },
228
+ screen: "DialogMessages",
229
+ other: {
230
+ sound: Platform.OS === "android" ? void 0 : "default"
231
+ }
232
+ };
233
+ const messageId = objectId();
234
+ const optimisticMessage = {
235
+ __typename: "Post",
236
+ id: messageId,
237
+ message: currentMessageText,
238
+ createdAt: new Date().toISOString(),
239
+ updatedAt: new Date().toISOString(),
240
+ author: {
241
+ __typename: "UserAccount",
242
+ id: auth == null ? void 0 : auth.id,
243
+ givenName: ((_a3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _a3.given_name) || "",
244
+ familyName: ((_b3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _b3.family_name) || "",
245
+ email: ((_c2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _c2.email) || "",
246
+ username: ((_d2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _d2.nickname) || "",
247
+ fullName: ((_e = auth == null ? void 0 : auth.profile) == null ? void 0 : _e.name) || "",
248
+ picture: ((_f = auth == null ? void 0 : auth.profile) == null ? void 0 : _f.picture) || "",
249
+ alias: [(_g = auth == null ? void 0 : auth.authUserId) != null ? _g : ""],
250
+ tokens: []
251
+ },
252
+ isDelivered: true,
253
+ isRead: false,
254
+ type: PostTypeEnum.Simple,
255
+ parentId: null,
256
+ fromServer: false,
257
+ channel: {
258
+ __typename: "Channel",
259
+ id: channelId
260
+ },
261
+ propsConfiguration: {
262
+ __typename: "MachineConfiguration",
263
+ id: null,
264
+ resource: "",
265
+ contents: null,
266
+ keys: null,
267
+ target: null,
268
+ overrides: null
269
+ },
270
+ props: {},
271
+ files: {
272
+ __typename: "FilesInfo",
273
+ data: [],
274
+ totalCount: 0
275
+ },
276
+ replies: {
277
+ __typename: "Messages",
278
+ data: [],
279
+ totalCount: 0
280
+ }
281
+ };
282
+ const response = await sendMsg({
283
+ variables: {
284
+ channelId,
285
+ content: currentMessageText,
286
+ notificationParams: notificationData
287
+ },
288
+ optimisticResponse: {
289
+ __typename: "Mutation",
290
+ sendMessage: optimisticMessage
291
+ },
292
+ update: (cache, {
293
+ data: data2
294
+ }) => {
295
+ if (!(data2 == null ? void 0 : data2.sendMessage))
296
+ return;
297
+ try {
298
+ cache.writeQuery({
299
+ query: MESSAGES_DOCUMENT,
300
+ variables: {
301
+ channelId: channelId == null ? void 0 : channelId.toString(),
302
+ parentId: null,
303
+ limit: MESSAGES_PER_PAGE,
304
+ skip: 0
305
+ },
306
+ data: {
307
+ messages: {
308
+ __typename: "Messages",
309
+ messagesRefId: channelId,
310
+ data: [data2.sendMessage],
311
+ totalCount: 1
312
+ }
313
+ }
314
+ });
315
+ } catch (error2) {
316
+ console.error("Error updating cache:", error2);
317
+ let errorMsg = "Failed to update message cache";
318
+ if (__DEV__ && error2) {
319
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Cache update failed";
320
+ }
321
+ setNotificationType("error");
322
+ setErrorMessage(errorMsg);
176
323
  }
324
+ }
325
+ });
326
+ setIsUploadingImage(false);
327
+ setLoading(false);
328
+ return {
329
+ message: (_h = response.data) == null ? void 0 : _h.sendMessage
330
+ };
331
+ } catch (error2) {
332
+ setLoading(false);
333
+ setIsUploadingImage(false);
334
+ let errorMsg = "Failed to send message";
335
+ if (__DEV__ && error2) {
336
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Message sending failed";
337
+ }
338
+ setNotificationType("error");
339
+ setErrorMessage(errorMsg);
340
+ setError(String(error2));
341
+ return {
342
+ error: String(error2)
343
+ };
344
+ }
345
+ }, [channelId, messageText, sendMsg, auth]);
346
+ const onSelectImages = async () => {
347
+ setLoading(true);
348
+ try {
349
+ let imageSource = await ImagePicker.launchImageLibraryAsync({
350
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
351
+ allowsEditing: false,
352
+ aspect: [4, 3],
353
+ quality: 0.8,
354
+ base64: true,
355
+ exif: false,
356
+ allowsMultipleSelection: true
357
+ });
358
+ if (!(imageSource == null ? void 0 : imageSource.canceled)) {
359
+ const selectedAssets = (imageSource == null ? void 0 : imageSource.assets) || [];
360
+ if (selectedAssets.length === 0) {
361
+ setLoading(false);
362
+ return;
363
+ }
364
+ const newImages = selectedAssets.map((selectedAsset) => {
365
+ const base64Data = selectedAsset.base64;
366
+ const previewImage = base64Data ? `data:image/jpeg;base64,${base64Data}` : selectedAsset.uri;
367
+ const asset = __spreadProps(__spreadValues({}, selectedAsset), {
368
+ url: selectedAsset.uri,
369
+ fileName: selectedAsset.fileName || `image_${Date.now()}.jpg`,
370
+ mimeType: "image/jpeg"
371
+ });
372
+ return asset;
177
373
  });
178
- if (response == null ? void 0 : response.data) {
179
- setSkip(channelMessages.length);
180
- setLoadEarlierMsg(false);
181
- setLoadingOldMessages(true);
374
+ if (newImages.length > 0) {
375
+ const base64Data = newImages[0].base64;
376
+ const previewImage = base64Data ? `data:image/jpeg;base64,${base64Data}` : newImages[0].uri;
377
+ setSelectedImage(previewImage);
182
378
  }
183
- } catch (error) {
184
- setLoadEarlierMsg(false);
379
+ setImages((currentImages) => [...currentImages, ...newImages]);
380
+ if (!isActionSheetVisible) {
381
+ setActionSheetVisible(true);
382
+ }
383
+ } else {
384
+ setLoading(false);
185
385
  }
386
+ } catch (error2) {
387
+ setLoading(false);
186
388
  }
187
- }, [totalCount, channelMessages]);
188
- const isCloseToTop = ({
189
- layoutMeasurement,
190
- contentOffset,
191
- contentSize
192
- }) => {
193
- const paddingToTop = 60;
194
- return contentSize.height - layoutMeasurement.height - paddingToTop <= contentOffset.y;
195
389
  };
196
- const dataURLtoFile = (dataurl, filename) => {
197
- var arr = dataurl.split(","), mime = arr[0].match(/:(.*?);/)[1], bstr = encode(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
198
- while (n--) {
199
- u8arr[n] = bstr.charCodeAt(n);
390
+ const [uploadingMessageId, setUploadingMessageId] = useState(null);
391
+ const [pendingUploads, setPendingUploads] = useState({});
392
+ const [uploadErrors, setUploadErrors] = useState({});
393
+ const [isUploadingImage, setIsUploadingImage] = useState(false);
394
+ useEffect(() => {
395
+ if (images.length === 0) {
396
+ setIsUploadingImage(false);
200
397
  }
201
- return new File([u8arr], filename, {
202
- type: mime
398
+ }, [images]);
399
+ useToast();
400
+ const removeMessageFromUI = useCallback((messageId) => {
401
+ setPendingUploads((prev) => {
402
+ const newPending = __spreadValues({}, prev);
403
+ delete newPending[messageId];
404
+ return newPending;
203
405
  });
204
- };
205
- const onSelectImages = async () => {
206
- var _a3;
207
- setImageLoading(true);
208
- let imageSource = await ImagePicker.launchImageLibraryAsync({
209
- mediaTypes: ImagePicker.MediaTypeOptions.Images,
210
- allowsEditing: true,
211
- aspect: [4, 3],
212
- quality: 1,
213
- base64: true
406
+ setUploadErrors((prev) => {
407
+ const newErrors = __spreadValues({}, prev);
408
+ delete newErrors[messageId];
409
+ return newErrors;
214
410
  });
215
- if (!imageSource.canceled) {
216
- const image = "data:image/jpeg;base64," + ((_a3 = imageSource == null ? void 0 : imageSource.assets[0]) == null ? void 0 : _a3.base64);
217
- setImage(image);
218
- const file = dataURLtoFile(image, "inputImage.jpg");
219
- setFiles((files2) => files2.concat(file));
220
- setImages((images2) => images2.concat(imageSource == null ? void 0 : imageSource.assets[0]));
221
- }
222
- if (imageSource.canceled)
411
+ setIsUploadingImage(false);
412
+ }, []);
413
+ const sendMessageWithFileImpl = useCallback(async () => {
414
+ var _a3, _b3, _c2, _d2, _e, _f, _g;
415
+ try {
416
+ const postId = objectId();
417
+ setIsUploadingImage(true);
223
418
  setLoading(false);
224
- };
225
- const createDirectChannel = useCallback((msg2) => {
226
- var _a3, _b2, _c, _d, _e, _f, _g, _h;
227
- if ((rest == null ? void 0 : rest.isCreateNewChannel) && ((_a3 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _a3.type) === ((_b2 = RoomType) == null ? void 0 : _b2.Direct) && ((_d = (_c = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _c.userIds) == null ? void 0 : _d.length) > 0) {
228
- (_h = (_g = addDirectChannel({
229
- variables: {
230
- receiver: [...(_f = (_e = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _e.userIds) != null ? _f : []],
231
- displayName: "DIRECT CHANNEL"
419
+ setUploadingMessageId(null);
420
+ if (!images || images.length === 0) {
421
+ setIsUploadingImage(false);
422
+ setLoading(false);
423
+ return {
424
+ error: "No images available to upload"
425
+ };
426
+ }
427
+ const currentMessageText = messageText;
428
+ const currentImages = [...images];
429
+ const imageUris = currentImages.map((img) => img.uri || img.url);
430
+ setMessageText("");
431
+ setSelectedImage("");
432
+ setImages([]);
433
+ const clientMessage = {
434
+ _id: postId,
435
+ text: currentMessageText || " ",
436
+ createdAt: new Date(),
437
+ user: {
438
+ _id: (auth == null ? void 0 : auth.id) || "",
439
+ name: `${(auth == null ? void 0 : auth.givenName) || ""} ${(auth == null ? void 0 : auth.familyName) || ""}`,
440
+ avatar: (auth == null ? void 0 : auth.picture) || ""
441
+ },
442
+ image: imageUris[0],
443
+ images: imageUris,
444
+ sent: true,
445
+ received: true,
446
+ pending: false,
447
+ type: "TEXT",
448
+ replies: {
449
+ data: [],
450
+ totalCount: 0
451
+ },
452
+ isShowThreadMessage: false
453
+ };
454
+ setPendingUploads((prev) => __spreadProps(__spreadValues({}, prev), {
455
+ [postId]: clientMessage
456
+ }));
457
+ const notificationData = {
458
+ url: config.INBOX_MESSEGE_PATH,
459
+ params: {
460
+ channelId,
461
+ hideTabBar: true
462
+ },
463
+ screen: "DialogMessages",
464
+ other: {
465
+ sound: Platform.OS === "android" ? void 0 : "default"
232
466
  }
233
- })) == null ? void 0 : _g.then(async (res) => {
234
- var _a4, _b3, _c2, _d2, _e2, _f2, _g2, _h2;
235
- if ((_b3 = (_a4 = res == null ? void 0 : res.data) == null ? void 0 : _a4.createDirectChannel) == null ? void 0 : _b3.id) {
236
- setChannelId((_d2 = (_c2 = res == null ? void 0 : res.data) == null ? void 0 : _c2.createDirectChannel) == null ? void 0 : _d2.id);
237
- const notificationData = {
238
- url: config.INBOX_MESSEGE_PATH,
239
- params: {
240
- channelId: (_f2 = (_e2 = res == null ? void 0 : res.data) == null ? void 0 : _e2.createDirectChannel) == null ? void 0 : _f2.id,
241
- hideTabBar: true
242
- },
243
- screen: "DialogMessages",
244
- other: {
245
- sound: Platform.OS === "android" ? void 0 : "default"
246
- }
247
- };
248
- setLoading(true);
249
- await sendMsg({
250
- variables: {
251
- channelId: (_h2 = (_g2 = res == null ? void 0 : res.data) == null ? void 0 : _g2.createDirectChannel) == null ? void 0 : _h2.id,
252
- content: msg2,
253
- notificationParams: notificationData
467
+ };
468
+ const optimisticMessage = {
469
+ __typename: "Post",
470
+ id: postId,
471
+ message: currentMessageText || " ",
472
+ createdAt: new Date().toISOString(),
473
+ updatedAt: new Date().toISOString(),
474
+ author: {
475
+ __typename: "UserAccount",
476
+ id: auth == null ? void 0 : auth.id,
477
+ givenName: ((_a3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _a3.given_name) || "",
478
+ familyName: ((_b3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _b3.family_name) || "",
479
+ email: ((_c2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _c2.email) || "",
480
+ username: ((_d2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _d2.nickname) || "",
481
+ fullName: ((_e = auth == null ? void 0 : auth.profile) == null ? void 0 : _e.name) || "",
482
+ picture: ((_f = auth == null ? void 0 : auth.profile) == null ? void 0 : _f.picture) || "",
483
+ alias: [(_g = auth == null ? void 0 : auth.authUserId) != null ? _g : ""],
484
+ tokens: []
485
+ },
486
+ isDelivered: true,
487
+ isRead: false,
488
+ type: PostTypeEnum.Simple,
489
+ parentId: null,
490
+ fromServer: false,
491
+ channel: {
492
+ __typename: "Channel",
493
+ id: channelId
494
+ },
495
+ propsConfiguration: {
496
+ __typename: "MachineConfiguration",
497
+ id: null,
498
+ resource: "",
499
+ contents: null,
500
+ keys: null,
501
+ target: null,
502
+ overrides: null
503
+ },
504
+ props: {},
505
+ files: {
506
+ __typename: "FilesInfo",
507
+ data: imageUris.map((uri, index) => ({
508
+ __typename: "FileInfo",
509
+ id: `temp-file-${index}-${postId}`,
510
+ url: uri,
511
+ name: `image-${index}.jpg`,
512
+ extension: "jpg",
513
+ mimeType: "image/jpeg",
514
+ size: 0,
515
+ height: 300,
516
+ width: 300,
517
+ channel: null,
518
+ post: null,
519
+ refType: FileRefType.Post
520
+ })),
521
+ totalCount: imageUris.length
522
+ },
523
+ replies: {
524
+ __typename: "Messages",
525
+ data: [],
526
+ totalCount: 0
527
+ }
528
+ };
529
+ setTimeout(async () => {
530
+ var _a4;
531
+ try {
532
+ const imagesToUpload = currentImages.map((img) => __spreadProps(__spreadValues({}, img), {
533
+ uri: img.uri || img.url,
534
+ type: img.mimeType || "image/jpeg",
535
+ name: img.fileName || `image_${Date.now()}.jpg`
536
+ }));
537
+ const uploadResponse = await startUpload({
538
+ file: imagesToUpload,
539
+ saveUploadedFile: {
540
+ variables: {
541
+ postId
542
+ }
254
543
  },
255
- update: (cache, {
256
- data: data2,
257
- errors
258
- }) => {
259
- if (!data2 || errors) {
260
- setLoading(false);
261
- return;
544
+ createUploadLink: {
545
+ variables: {
546
+ postId
262
547
  }
263
- setChannelToTop(channelToTop + 1);
264
- setLoading(false);
265
- setMsg("");
266
548
  }
267
549
  });
550
+ if (uploadResponse == null ? void 0 : uploadResponse.error) {
551
+ console.error("Upload error:", uploadResponse.error);
552
+ let errorMsg = "Failed to upload image. Please try again.";
553
+ if (__DEV__ && uploadResponse.error) {
554
+ errorMsg = typeof uploadResponse.error === "string" ? uploadResponse.error : uploadResponse.error.message || errorMsg;
555
+ }
556
+ setNotificationType("error");
557
+ setErrorMessage(errorMsg);
558
+ setUploadErrors((prev) => __spreadProps(__spreadValues({}, prev), {
559
+ [postId]: errorMsg
560
+ }));
561
+ removeMessageFromUI(postId);
562
+ setIsUploadingImage(false);
563
+ setLoading(false);
564
+ return;
565
+ }
566
+ const uploadedFiles = uploadResponse.data;
567
+ const fileIds = (_a4 = uploadedFiles == null ? void 0 : uploadedFiles.map((f) => f.id)) != null ? _a4 : null;
568
+ if ((fileIds == null ? void 0 : fileIds.length) > 0) {
569
+ await sendMsg({
570
+ variables: {
571
+ postId,
572
+ channelId,
573
+ content: currentMessageText || " ",
574
+ files: fileIds,
575
+ notificationParams: notificationData
576
+ },
577
+ optimisticResponse: {
578
+ __typename: "Mutation",
579
+ sendMessage: optimisticMessage
580
+ },
581
+ update: (cache, {
582
+ data: data2
583
+ }) => {
584
+ var _a5, _b4;
585
+ if (!(data2 == null ? void 0 : data2.sendMessage)) {
586
+ setIsUploadingImage(false);
587
+ setLoading(false);
588
+ return;
589
+ }
590
+ try {
591
+ cache.writeQuery({
592
+ query: MESSAGES_DOCUMENT,
593
+ variables: {
594
+ channelId: channelId == null ? void 0 : channelId.toString(),
595
+ parentId: null,
596
+ limit: MESSAGES_PER_PAGE,
597
+ skip: 0
598
+ },
599
+ data: {
600
+ messages: {
601
+ __typename: "Messages",
602
+ messagesRefId: channelId,
603
+ data: [data2.sendMessage],
604
+ totalCount: 1
605
+ }
606
+ }
607
+ });
608
+ const serverMessage = data2.sendMessage;
609
+ const hasServerImage = (_b4 = (_a5 = serverMessage == null ? void 0 : serverMessage.files) == null ? void 0 : _a5.data) == null ? void 0 : _b4.some((file) => file.url);
610
+ if (hasServerImage) {
611
+ removeMessageFromUI(postId);
612
+ }
613
+ setIsUploadingImage(false);
614
+ setLoading(false);
615
+ } catch (error2) {
616
+ console.error("Cache update error:", error2);
617
+ let errorMsg = "Failed to update message.";
618
+ if (__DEV__ && error2) {
619
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Cache update failed";
620
+ }
621
+ setNotificationType("error");
622
+ setErrorMessage(errorMsg);
623
+ setIsUploadingImage(false);
624
+ setLoading(false);
625
+ }
626
+ }
627
+ });
628
+ } else {
629
+ setIsUploadingImage(false);
630
+ setLoading(false);
631
+ }
632
+ } catch (error2) {
633
+ console.error("Background process error:", error2);
634
+ let errorMsg = "Failed to send image. Please try again.";
635
+ if (__DEV__ && error2) {
636
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Background process failed";
637
+ }
638
+ setNotificationType("error");
639
+ setErrorMessage(errorMsg);
640
+ removeMessageFromUI(postId);
641
+ setIsUploadingImage(false);
642
+ setLoading(false);
268
643
  }
269
- })) == null ? void 0 : _h.catch((e) => console.log("error", JSON.stringify(e)));
270
- }
271
- }, [rest]);
272
- const handleSend = useCallback(async (message) => {
273
- var _a3;
274
- if (!channelId)
275
- return;
276
- if (!message && message != " " && images.length == 0)
277
- return;
278
- const notificationData = {
279
- url: config.INBOX_MESSEGE_PATH,
280
- params: {
281
- channelId,
282
- hideTabBar: true
283
- },
284
- screen: "DialogMessages",
285
- other: {
286
- sound: Platform.OS === "android" ? void 0 : "default"
644
+ }, 0);
645
+ return {
646
+ success: true
647
+ };
648
+ } catch (error2) {
649
+ console.error("Send message error:", error2);
650
+ let errorMsg = "Failed to process image. Please try again.";
651
+ if (__DEV__ && error2) {
652
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Image processing failed";
287
653
  }
288
- };
289
- if (images && images.length > 0) {
290
- const postId = objectId();
654
+ setNotificationType("error");
655
+ setErrorMessage(errorMsg);
656
+ setError(String(error2));
657
+ setIsUploadingImage(false);
658
+ setLoading(false);
659
+ return {
660
+ error: String(error2)
661
+ };
662
+ }
663
+ }, [channelId, messageText, images, selectedImage, startUpload, sendMsg, auth, removeMessageFromUI]);
664
+ const createDirectChannelImpl = useCallback(async () => {
665
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h;
666
+ try {
291
667
  setLoading(true);
292
- const uploadResponse = await startUpload({
293
- file: images,
294
- saveUploadedFile: {
295
- variables: {
296
- postId
297
- }
298
- },
299
- createUploadLink: {
300
- variables: {
301
- postId
302
- }
668
+ 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)) {
669
+ setLoading(false);
670
+ setNotificationType("error");
671
+ setErrorMessage(__DEV__ ? "Invalid channel data" : "Unable to create conversation");
672
+ return {
673
+ error: "Invalid channel data"
674
+ };
675
+ }
676
+ const currentMessageText = messageText;
677
+ setMessageText("");
678
+ const response = await addDirectChannel({
679
+ variables: {
680
+ receiver: [...(_f = (_e = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _e.userIds) != null ? _f : []],
681
+ displayName: "DIRECT CHANNEL"
303
682
  }
304
683
  });
305
- if (uploadResponse == null ? void 0 : uploadResponse.error)
684
+ if (!((_h = (_g = response == null ? void 0 : response.data) == null ? void 0 : _g.createDirectChannel) == null ? void 0 : _h.id)) {
306
685
  setLoading(false);
307
- const uploadedFiles = uploadResponse.data;
308
- if (uploadResponse.data) {
309
- setImage("");
310
- setFiles([]);
311
- setImages([]);
312
- const files2 = (_a3 = uploadedFiles == null ? void 0 : uploadedFiles.map((f) => f.id)) != null ? _a3 : null;
313
- await sendMsg({
314
- variables: {
315
- postId,
316
- channelId,
317
- content: message,
318
- files: files2,
319
- notificationParams: notificationData
320
- },
321
- update: (cache, {
322
- data: data2,
323
- errors
324
- }) => {
325
- if (!data2 || errors) {
326
- setLoading(false);
327
- return;
328
- }
329
- const newMessage = data2 == null ? void 0 : data2.sendMessage;
330
- setChannelMessages((oldMessages) => uniqBy([...oldMessages, newMessage], ({
331
- id
332
- }) => id));
333
- setTotalCount((t) => t + 1);
334
- setChannelToTop(channelToTop + 1);
335
- setLoading(false);
336
- setMsg("");
337
- }
338
- });
686
+ setNotificationType("error");
687
+ setErrorMessage(__DEV__ ? "Failed to create channel" : "Unable to create conversation");
688
+ return {
689
+ error: "Failed to create channel"
690
+ };
339
691
  }
340
- } else {
341
- setLoading(true);
692
+ const newChannelId = response.data.createDirectChannel.id;
693
+ setChannelId(newChannelId);
694
+ const notificationData = {
695
+ url: config.INBOX_MESSEGE_PATH,
696
+ params: {
697
+ channelId: newChannelId,
698
+ hideTabBar: true
699
+ },
700
+ screen: "DialogMessages",
701
+ other: {
702
+ sound: Platform.OS === "android" ? void 0 : "default"
703
+ }
704
+ };
705
+ const messageId = objectId();
706
+ const optimisticMessage = {
707
+ __typename: "Post",
708
+ id: messageId,
709
+ message: currentMessageText,
710
+ createdAt: new Date().toISOString(),
711
+ updatedAt: new Date().toISOString(),
712
+ author: {
713
+ __typename: "UserAccount",
714
+ id: auth == null ? void 0 : auth.id,
715
+ picture: (auth == null ? void 0 : auth.picture) || "",
716
+ givenName: (auth == null ? void 0 : auth.givenName) || "",
717
+ familyName: (auth == null ? void 0 : auth.familyName) || "",
718
+ email: (auth == null ? void 0 : auth.email) || "",
719
+ username: (auth == null ? void 0 : auth.username) || "",
720
+ alias: [],
721
+ tokens: (auth == null ? void 0 : auth.token) ? [...auth == null ? void 0 : auth.token] : []
722
+ },
723
+ isDelivered: true,
724
+ isRead: false,
725
+ type: PostTypeEnum.Simple,
726
+ parentId: null,
727
+ fromServer: false,
728
+ channel: {
729
+ __typename: "Channel",
730
+ id: newChannelId
731
+ },
732
+ propsConfiguration: {
733
+ __typename: "MachineConfiguration",
734
+ id: null,
735
+ resource: "",
736
+ contents: null,
737
+ keys: null,
738
+ target: null,
739
+ overrides: null
740
+ },
741
+ props: {},
742
+ files: {
743
+ __typename: "FilesInfo",
744
+ data: [],
745
+ totalCount: 0
746
+ },
747
+ replies: {
748
+ __typename: "Messages",
749
+ data: [],
750
+ totalCount: 0
751
+ }
752
+ };
342
753
  await sendMsg({
343
754
  variables: {
344
- channelId,
345
- content: message,
755
+ channelId: newChannelId,
756
+ content: currentMessageText,
346
757
  notificationParams: notificationData
347
758
  },
759
+ optimisticResponse: {
760
+ __typename: "Mutation",
761
+ sendMessage: optimisticMessage
762
+ },
348
763
  update: (cache, {
349
- data: data2,
350
- errors
764
+ data: data2
351
765
  }) => {
352
- if (!data2 || errors) {
353
- setLoading(false);
766
+ if (!(data2 == null ? void 0 : data2.sendMessage))
354
767
  return;
768
+ try {
769
+ cache.writeQuery({
770
+ query: MESSAGES_DOCUMENT,
771
+ variables: {
772
+ channelId: newChannelId,
773
+ parentId: null,
774
+ limit: MESSAGES_PER_PAGE,
775
+ skip: 0
776
+ },
777
+ data: {
778
+ messages: {
779
+ __typename: "Messages",
780
+ messagesRefId: newChannelId,
781
+ data: [data2.sendMessage],
782
+ totalCount: 1
783
+ }
784
+ }
785
+ });
786
+ } catch (error2) {
787
+ console.error("Error updating cache:", error2);
788
+ let errorMsg = "Failed to update message cache";
789
+ if (__DEV__ && error2) {
790
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Cache update failed";
791
+ }
792
+ setNotificationType("error");
793
+ setErrorMessage(errorMsg);
355
794
  }
356
- const newMessage = data2 == null ? void 0 : data2.sendMessage;
357
- setChannelMessages((oldMessages) => uniqBy([...oldMessages, newMessage], ({
358
- id
359
- }) => id));
360
- setTotalCount((t) => t + 1);
361
- setChannelToTop(channelToTop + 1);
362
- setLoading(false);
363
- setMsg("");
364
795
  }
365
796
  });
797
+ setLoading(false);
798
+ return {
799
+ channelId: newChannelId
800
+ };
801
+ } catch (error2) {
802
+ setLoading(false);
803
+ let errorMsg = "Failed to create conversation";
804
+ if (__DEV__ && error2) {
805
+ errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Channel creation failed";
806
+ }
807
+ setNotificationType("error");
808
+ setErrorMessage(errorMsg);
809
+ setError(String(error2));
810
+ return {
811
+ error: String(error2)
812
+ };
813
+ }
814
+ }, [rest, messageText, addDirectChannel, sendMsg, auth]);
815
+ const onFetchOld = useCallback(() => {
816
+ if (fetchOldDebounceRef.current)
817
+ return;
818
+ if (totalCount > channelMessages.length && !loadingOldMessages) {
819
+ fetchOldDebounceRef.current = true;
820
+ fetchMoreMessagesImpl();
821
+ setTimeout(() => {
822
+ fetchOldDebounceRef.current = false;
823
+ }, 1e3);
366
824
  }
367
- }, [setChannelMessages, channelId, images, channelToTop, expoTokens]);
825
+ }, [totalCount, channelMessages.length, loadingOldMessages, fetchMoreMessagesImpl]);
826
+ const isCloseToTop = ({
827
+ layoutMeasurement,
828
+ contentOffset,
829
+ contentSize
830
+ }) => {
831
+ const paddingToTop = 60;
832
+ return contentSize.height - layoutMeasurement.height - paddingToTop <= contentOffset.y;
833
+ };
368
834
  const messageList = useMemo(() => {
369
- let res = [];
370
- const filteredMessages = channelMessages && (channelMessages == null ? void 0 : channelMessages.length) > 0 ? uniqBy([...channelMessages], ({
835
+ const pendingMessages = Object.values(pendingUploads);
836
+ if (!channelMessages || channelMessages.length === 0) {
837
+ return pendingMessages;
838
+ }
839
+ const filteredMessages = uniqBy(channelMessages, ({
371
840
  id
372
- }) => id) : [];
373
- if (channelId && (filteredMessages == null ? void 0 : filteredMessages.length) > 0) {
374
- orderBy(channelMessages, ["createdAt"], ["desc"]).map((msg2) => {
375
- var _a3, _b2, _c, _d;
376
- let message = {
377
- _id: "",
378
- text: "",
379
- createdAt: 0,
380
- user: {
381
- _id: "",
382
- name: "",
383
- avatar: ""
384
- },
385
- type: ""
386
- };
387
- const date = new Date(msg2.createdAt);
388
- message._id = msg2.id;
389
- message.text = msg2.message;
390
- message.createdAt = date;
391
- message.user = {
392
- _id: msg2.author.id,
393
- name: msg2.author.givenName + " " + msg2.author.familyName,
394
- avatar: (_a3 = msg2.author) == null ? void 0 : _a3.picture
395
- }, message.image = (_c = (_b2 = msg2.files) == null ? void 0 : _b2.data[0]) == null ? void 0 : _c.url, message.sent = msg2 == null ? void 0 : msg2.isDelivered, message.received = msg2 == null ? void 0 : msg2.isRead;
396
- message.type = msg2 == null ? void 0 : msg2.type;
397
- message.propsConfiguration = msg2 == null ? void 0 : msg2.propsConfiguration;
398
- message.replies = (_d = msg2 == null ? void 0 : msg2.replies) != null ? _d : [];
399
- message.isShowThreadMessage = isShowThreadMessage;
400
- res.push(message);
401
- });
841
+ }) => id);
842
+ const serverMessages = orderBy(filteredMessages, ["createdAt"], ["desc"]).map((msg) => {
843
+ var _a3, _b3, _c2, _d2, _e;
844
+ const date = new Date(msg.createdAt);
845
+ if (pendingUploads[msg.id]) {
846
+ return null;
847
+ }
848
+ let imageUrls = [];
849
+ let primaryImageUrl = null;
850
+ if (msg.files && typeof msg.files === "object") {
851
+ const filesData = msg.files.data || (Array.isArray(msg.files) ? msg.files : null);
852
+ if (filesData && filesData.length > 0) {
853
+ imageUrls = filesData.filter((fileData) => fileData && typeof fileData === "object" && fileData.url).map((fileData) => fileData.url);
854
+ if (imageUrls.length > 0) {
855
+ primaryImageUrl = imageUrls[0];
856
+ }
857
+ }
858
+ }
859
+ return {
860
+ _id: msg.id,
861
+ text: msg.message,
862
+ createdAt: date,
863
+ user: {
864
+ _id: ((_a3 = msg.author) == null ? void 0 : _a3.id) || "",
865
+ name: `${((_b3 = msg.author) == null ? void 0 : _b3.givenName) || ""} ${((_c2 = msg.author) == null ? void 0 : _c2.familyName) || ""}`,
866
+ avatar: ((_d2 = msg.author) == null ? void 0 : _d2.picture) || ""
867
+ },
868
+ image: primaryImageUrl,
869
+ images: imageUrls,
870
+ sent: msg == null ? void 0 : msg.isDelivered,
871
+ received: msg == null ? void 0 : msg.isRead,
872
+ type: msg == null ? void 0 : msg.type,
873
+ propsConfiguration: msg == null ? void 0 : msg.propsConfiguration,
874
+ replies: (_e = msg == null ? void 0 : msg.replies) != null ? _e : [],
875
+ isShowThreadMessage
876
+ };
877
+ }).filter(Boolean);
878
+ return [...pendingMessages, ...serverMessages];
879
+ }, [channelMessages, pendingUploads, isShowThreadMessage]);
880
+ const renderSend = useCallback((props) => {
881
+ const hasContent = !!props.text || (images == null ? void 0 : images.length) > 0;
882
+ const canSend = (channelId || (rest == null ? void 0 : rest.isCreateNewChannel)) && hasContent;
883
+ const isDisabled = !canSend;
884
+ return /* @__PURE__ */ React__default.createElement(
885
+ Send,
886
+ __spreadProps(__spreadValues({}, props), {
887
+ containerStyle: {
888
+ justifyContent: "center",
889
+ alignItems: "center",
890
+ height: 40,
891
+ width: 44,
892
+ marginRight: 4,
893
+ marginBottom: 0,
894
+ marginLeft: 4
895
+ }
896
+ }),
897
+ /* @__PURE__ */ React__default.createElement(View, { style: {
898
+ padding: 4
899
+ } }, /* @__PURE__ */ React__default.createElement(MaterialCommunityIcons, { name: "send-circle", size: 32, color: isDisabled ? colors.gray[400] : colors.blue[500] }))
900
+ );
901
+ }, [channelId, images, rest == null ? void 0 : rest.isCreateNewChannel, isUploadingImage, loading, isActionSheetVisible]);
902
+ useCallback(() => {
903
+ console.log("Opening action sheet");
904
+ setActionSheetVisible(true);
905
+ }, []);
906
+ useEffect(() => {
907
+ console.log("Action sheet visibility:", isActionSheetVisible);
908
+ if (isActionSheetVisible) {
909
+ setBottomMargin(0);
402
910
  }
403
- return (res == null ? void 0 : res.length) > 0 ? uniqBy([...res], ({
404
- _id
405
- }) => _id) : [];
406
- }, [channelMessages, channelId]);
407
- const renderSend = (props) => {
408
- return /* @__PURE__ */ React__default.createElement(Send, __spreadProps(__spreadValues({}, props), { disabled: channelId || (rest == null ? void 0 : rest.isCreateNewChannel) ? false : true }), /* @__PURE__ */ React__default.createElement(Box, null, /* @__PURE__ */ React__default.createElement(MaterialCommunityIcons, { name: "send-circle", style: {
409
- marginBottom: 5,
410
- marginRight: 5
411
- }, size: 32, color: channelId || (rest == null ? void 0 : rest.isCreateNewChannel) ? "#2e64e5" : "#b8b2b2" })));
412
- };
413
- const renderMessageText = (props) => {
414
- var _a3, _b2, _c, _d, _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;
911
+ }, [isActionSheetVisible]);
912
+ const handleRemoveImage = useCallback((index) => {
913
+ const newImages = [...images];
914
+ newImages.splice(index, 1);
915
+ setImages(newImages);
916
+ if (newImages.length === 0) {
917
+ setSelectedImage("");
918
+ if (textInputRef.current && typeof textInputRef.current.focus === "function") {
919
+ textInputRef.current.focus();
920
+ }
921
+ }
922
+ }, [images]);
923
+ const [textUpdatedInActionSheet, setTextUpdatedInActionSheet] = useState(false);
924
+ useCallback(() => {
925
+ setTextUpdatedInActionSheet(true);
926
+ setActionSheetVisible(false);
927
+ setBottomMargin(0);
928
+ }, []);
929
+ useEffect(() => {
930
+ if (!isActionSheetVisible && textUpdatedInActionSheet) {
931
+ console.log("Action sheet closed with text:", messageText);
932
+ setTextUpdatedInActionSheet(false);
933
+ const currentText = messageText;
934
+ setMessageText("");
935
+ setTimeout(() => {
936
+ setMessageText(currentText);
937
+ }, 50);
938
+ }
939
+ }, [isActionSheetVisible, textUpdatedInActionSheet]);
940
+ useEffect(() => {
941
+ if (isActionSheetVisible && Platform.OS === "ios") {
942
+ console.log("Action sheet is visible, should show the input and options");
943
+ }
944
+ }, [isActionSheetVisible]);
945
+ const handleSend = useCallback(async (messages) => {
946
+ var _a3, _b3, _c2;
947
+ const newMessageText = messages && messages.length > 0 ? ((_a3 = messages[0]) == null ? void 0 : _a3.text) || " " : " ";
948
+ if (!channelId && !(rest == null ? void 0 : rest.isCreateNewChannel)) {
949
+ return;
950
+ }
951
+ const hasText = !!newMessageText && newMessageText !== " ";
952
+ const hasImages = images && images.length > 0;
953
+ if (!hasText && !hasImages) {
954
+ return;
955
+ }
956
+ setMessageText(newMessageText);
957
+ if ((rest == null ? void 0 : rest.isCreateNewChannel) && !channelId) {
958
+ if (((_b3 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _b3.type) === ((_c2 = RoomType) == null ? void 0 : _c2.Direct)) {
959
+ await createDirectChannelImpl();
960
+ }
961
+ setIsUploadingImage(false);
962
+ setLoading(false);
963
+ return;
964
+ }
965
+ if (hasImages) {
966
+ await sendMessageWithFileImpl();
967
+ } else {
968
+ await sendMessageImpl();
969
+ }
970
+ setIsUploadingImage(false);
971
+ setLoading(false);
972
+ setTimeout(() => {
973
+ if (textInputRef.current) {
974
+ textInputRef.current.focus();
975
+ }
976
+ }, 100);
977
+ }, [channelId, images, rest == null ? void 0 : rest.isCreateNewChannel, (_d = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _d.type, createDirectChannelImpl, sendMessageWithFileImpl, sendMessageImpl]);
978
+ const renderMessageText = useCallback((props) => {
979
+ 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;
415
980
  const {
416
981
  currentMessage
417
982
  } = props;
418
- const lastReply = ((_b2 = (_a3 = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _a3.data) == null ? void 0 : _b2.length) > 0 ? (_d = (_c = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _c.data) == null ? void 0 : _d[0] : null;
983
+ 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;
984
+ if (!(currentMessage == null ? void 0 : currentMessage.text) || currentMessage.text.trim() === "") {
985
+ return null;
986
+ }
419
987
  if (currentMessage.type === "ALERT") {
420
988
  const attachment = (_f = (_e = currentMessage == null ? void 0 : currentMessage.propsConfiguration) == null ? void 0 : _e.contents) == null ? void 0 : _f.attachment;
421
989
  let action = "";
422
990
  let actionId = "";
423
- let params = {};
991
+ let params2 = {};
424
992
  if ((_g = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _g.extraParams) {
425
993
  const extraParams = (_h = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _h.extraParams;
426
994
  const route = (_i = extraParams == null ? void 0 : extraParams.route) != null ? _i : null;
@@ -437,30 +1005,24 @@ const ConversationViewComponent = (_a) => {
437
1005
  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;
438
1006
  }
439
1007
  action = path;
440
- params = __spreadValues({}, param);
1008
+ params2 = __spreadValues({}, param);
441
1009
  } else if ((_B = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _B.link) {
442
1010
  action = CALL_TO_ACTION_PATH;
443
1011
  actionId = (_C = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _C.link.split("/").pop();
444
- params = {
1012
+ params2 = {
445
1013
  reservationId: actionId
446
1014
  };
447
1015
  }
448
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, (attachment == null ? void 0 : attachment.callToAction) && action ? /* @__PURE__ */ React__default.createElement(Box, { className: `bg-[${CALL_TO_ACTION_BOX_BGCOLOR}] rounded-[15] pb-2` }, /* @__PURE__ */ React__default.createElement(
449
- Button,
450
- {
451
- variant: "outline",
452
- size: "sm",
453
- className: `border-[${CALL_TO_ACTION_BUTTON_BORDERCOLOR}]`,
454
- onPress: () => action && params && navigation.navigate(action, params)
455
- },
456
- /* @__PURE__ */ React__default.createElement(ButtonText, { className: `color-[${CALL_TO_ACTION_TEXT_COLOR}]` }, attachment.callToAction.title)
457
- ), /* @__PURE__ */ React__default.createElement(MessageText, __spreadProps(__spreadValues({}, props), { textStyle: {
1016
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, (attachment == null ? void 0 : attachment.callToAction) && action ? /* @__PURE__ */ React__default.createElement(Box, { className: `bg-[${CALL_TO_ACTION_BOX_BGCOLOR}] rounded-[15] pb-2` }, /* @__PURE__ */ React__default.createElement(MessageText, __spreadProps(__spreadValues({}, props), { containerStyle: {
458
1017
  left: {
459
- marginLeft: 5,
460
- color: CALL_TO_ACTION_TEXT_COLOR,
461
- paddingHorizontal: 2
1018
+ paddingLeft: 0,
1019
+ marginLeft: 0
462
1020
  }
463
- } }))) : /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#c0c0c0", style: {
1021
+ }, textStyle: {
1022
+ left: {
1023
+ marginLeft: 0
1024
+ }
1025
+ } })), /* @__PURE__ */ React__default.createElement(Button, { variant: "outline", size: "sm", className: `border-[${CALL_TO_ACTION_BUTTON_BORDERCOLOR}] my-2 rounded-full `, onPress: () => action && params2 && navigation.navigate(action, params2) }, /* @__PURE__ */ React__default.createElement(ButtonText, { className: `color-[${CALL_TO_ACTION_TEXT_COLOR}]` }, attachment.callToAction.title))) : /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#c0c0c0", style: {
464
1026
  width: "100%"
465
1027
  }, onPress: () => {
466
1028
  if (currentMessage == null ? void 0 : currentMessage.isShowThreadMessage)
@@ -475,16 +1037,16 @@ const ConversationViewComponent = (_a) => {
475
1037
  marginLeft: 5
476
1038
  }
477
1039
  } })), ((_E = (_D = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _D.data) == null ? void 0 : _E.length) > 0 && /* @__PURE__ */ React__default.createElement(HStack, { space: "sm", className: "px-1 items-center" }, /* @__PURE__ */ React__default.createElement(HStack, null, (_J = (_I = (_H = (_G = (_F = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _F.data) == null ? void 0 : _G.filter((v, i, a) => a.findIndex((t) => {
478
- var _a4, _b3;
479
- return ((_a4 = t == null ? void 0 : t.author) == null ? void 0 : _a4.id) === ((_b3 = v == null ? void 0 : v.author) == null ? void 0 : _b3.id);
1040
+ var _a4, _b4;
1041
+ return ((_a4 = t == null ? void 0 : t.author) == null ? void 0 : _a4.id) === ((_b4 = v == null ? void 0 : v.author) == null ? void 0 : _b4.id);
480
1042
  }) === i)) == null ? void 0 : _H.slice(0, 2)) == null ? void 0 : _I.reverse()) == null ? void 0 : _J.map((p, i) => {
481
- var _a4, _b3, _c2;
482
- return /* @__PURE__ */ React__default.createElement(Avatar, { key: "conversations-view-key-" + i, size: "sm", className: "bg-transparent" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_b3 = (_a4 = p == null ? void 0 : p.author) == null ? void 0 : _a4.username) == null ? void 0 : _b3.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "user image", style: {
1043
+ var _a4, _b4, _c3;
1044
+ return /* @__PURE__ */ React__default.createElement(Avatar, { key: "conversations-view-key-" + i, size: "sm", className: "bg-transparent" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_b4 = (_a4 = p == null ? void 0 : p.author) == null ? void 0 : _a4.username) == null ? void 0 : _b4.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "user image", style: {
483
1045
  borderRadius: 6,
484
1046
  borderWidth: 2,
485
1047
  borderColor: "#fff"
486
1048
  }, source: {
487
- uri: (_c2 = p == null ? void 0 : p.author) == null ? void 0 : _c2.picture
1049
+ uri: (_c3 = p == null ? void 0 : p.author) == null ? void 0 : _c3.picture
488
1050
  } }));
489
1051
  })), /* @__PURE__ */ React__default.createElement(Text, { style: {
490
1052
  fontSize: 12
@@ -507,16 +1069,16 @@ const ConversationViewComponent = (_a) => {
507
1069
  marginLeft: 5
508
1070
  }
509
1071
  } })), ((_N = (_M = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _M.data) == null ? void 0 : _N.length) > 0 && /* @__PURE__ */ React__default.createElement(HStack, { space: "sm", className: "px-1 items-center" }, /* @__PURE__ */ React__default.createElement(HStack, null, (_S = (_R = (_Q = (_P = (_O = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _O.data) == null ? void 0 : _P.filter((v, i, a) => a.findIndex((t) => {
510
- var _a4, _b3;
511
- return ((_a4 = t == null ? void 0 : t.author) == null ? void 0 : _a4.id) === ((_b3 = v == null ? void 0 : v.author) == null ? void 0 : _b3.id);
1072
+ var _a4, _b4;
1073
+ return ((_a4 = t == null ? void 0 : t.author) == null ? void 0 : _a4.id) === ((_b4 = v == null ? void 0 : v.author) == null ? void 0 : _b4.id);
512
1074
  }) === i)) == null ? void 0 : _Q.slice(0, 2)) == null ? void 0 : _R.reverse()) == null ? void 0 : _S.map((p, i) => {
513
- var _a4, _b3, _c2;
514
- return /* @__PURE__ */ React__default.createElement(Avatar, { key: "conversation-replies-key-" + i, className: "bg-transparent", size: "sm" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_b3 = (_a4 = p == null ? void 0 : p.author) == null ? void 0 : _a4.username) == null ? void 0 : _b3.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "user image", style: {
1075
+ var _a4, _b4, _c3;
1076
+ return /* @__PURE__ */ React__default.createElement(Avatar, { key: "conversation-replies-key-" + i, className: "bg-transparent", size: "sm" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_b4 = (_a4 = p == null ? void 0 : p.author) == null ? void 0 : _a4.username) == null ? void 0 : _b4.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "user image", style: {
515
1077
  borderRadius: 6,
516
1078
  borderWidth: 2,
517
1079
  borderColor: "#fff"
518
1080
  }, source: {
519
- uri: (_c2 = p == null ? void 0 : p.author) == null ? void 0 : _c2.picture
1081
+ uri: (_c3 = p == null ? void 0 : p.author) == null ? void 0 : _c3.picture
520
1082
  } }));
521
1083
  })), /* @__PURE__ */ React__default.createElement(Text, { style: {
522
1084
  fontSize: 12
@@ -524,149 +1086,360 @@ const ConversationViewComponent = (_a) => {
524
1086
  fontSize: 12
525
1087
  }, className: "font-bold color-gray-500" }, lastReply ? createdAtText(lastReply == null ? void 0 : lastReply.createdAt) : ""))));
526
1088
  }
527
- };
528
- const renderActions = (props) => {
529
- return /* @__PURE__ */ React__default.createElement(Actions, __spreadProps(__spreadValues({}, props), { icon: () => /* @__PURE__ */ React__default.createElement(Ionicons, { name: "image", size: 30, color: "black", onPress: onSelectImages }) }));
530
- };
531
- const renderAccessory = (props) => {
532
- return /* @__PURE__ */ React__default.createElement(Box, null, selectedImage !== "" ? /* @__PURE__ */ React__default.createElement(HStack, { className: "items-center" }, /* @__PURE__ */ React__default.createElement(Image, { key: selectedImage, alt: "image", source: {
533
- uri: selectedImage
534
- }, size: "xs", className: "ml-3" }), /* @__PURE__ */ React__default.createElement(
535
- Button,
536
- {
537
- variant: "solid",
538
- className: "bg-transparent",
539
- onPress: () => {
540
- setFiles([]);
541
- setImage("");
542
- setImages([]);
1089
+ }, [navigation, channelId, role]);
1090
+ useCallback(() => {
1091
+ if (!images.length)
1092
+ return null;
1093
+ return /* @__PURE__ */ React__default.createElement(Box, { style: {
1094
+ position: "relative",
1095
+ height: 70,
1096
+ backgroundColor: "transparent",
1097
+ justifyContent: "center"
1098
+ } }, /* @__PURE__ */ React__default.createElement(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, style: {
1099
+ flexDirection: "row",
1100
+ paddingLeft: 15,
1101
+ paddingRight: 5
1102
+ }, contentContainerStyle: {
1103
+ alignItems: "center",
1104
+ height: "100%"
1105
+ } }, images.map((img, index) => /* @__PURE__ */ React__default.createElement(View, { key: `image-preview-${index}`, style: {
1106
+ width: 40,
1107
+ height: 40,
1108
+ marginRight: 15,
1109
+ borderRadius: 4,
1110
+ backgroundColor: colors.gray[200],
1111
+ overflow: "hidden",
1112
+ borderWidth: 1,
1113
+ borderColor: "#e0e0e0",
1114
+ position: "relative",
1115
+ zIndex: 10
1116
+ } }, /* @__PURE__ */ React__default.createElement(Image, { source: {
1117
+ uri: img.uri || img.url
1118
+ }, style: {
1119
+ width: "100%",
1120
+ height: "100%"
1121
+ }, alt: `selected image ${index + 1}` }), /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: () => {
1122
+ const newImages = [...images];
1123
+ newImages.splice(index, 1);
1124
+ setImages(newImages);
1125
+ if (newImages.length === 0) {
1126
+ setSelectedImage("");
1127
+ if (textInputRef.current && typeof textInputRef.current.focus === "function") {
1128
+ textInputRef.current.focus();
543
1129
  }
544
- },
545
- /* @__PURE__ */ React__default.createElement(ButtonText, { className: "color-black" }, "Cancel")
546
- )) : null);
547
- };
1130
+ }
1131
+ }, style: {
1132
+ position: "absolute",
1133
+ top: -1,
1134
+ right: -1,
1135
+ backgroundColor: "rgba(0,0,0,0.6)",
1136
+ borderRadius: 12,
1137
+ width: 20,
1138
+ height: 20,
1139
+ alignItems: "center",
1140
+ justifyContent: "center",
1141
+ zIndex: 9999
1142
+ } }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size: 16, color: "white" }))))));
1143
+ }, [images]);
548
1144
  const setImageViewerObject = (obj, v) => {
549
1145
  setImageObject(obj);
550
1146
  setImageViewer(v);
551
1147
  };
552
1148
  const modalContent = React__default.useMemo(() => {
553
- if (!imageObject)
554
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
1149
+ if (!imageObject || !imageObject.image)
1150
+ return null;
555
1151
  const {
556
1152
  image,
557
1153
  _id
558
1154
  } = imageObject;
559
- return /* @__PURE__ */ React__default.createElement(
560
- CachedImage,
561
- {
562
- style: {
563
- width: "100%",
564
- height: "100%"
565
- },
566
- resizeMode: "cover",
567
- cacheKey: `${_id}-slack-bubble-imageKey`,
568
- source: {
569
- uri: image,
570
- expiresIn: 86400
571
- },
572
- alt: "image"
573
- }
574
- );
1155
+ return /* @__PURE__ */ React__default.createElement(CachedImage, { style: {
1156
+ width: "100%",
1157
+ height: "100%"
1158
+ }, resizeMode: "cover", cacheKey: `${_id}-modal-imageKey`, source: {
1159
+ uri: image,
1160
+ expiresIn: 86400
1161
+ }, alt: "image" });
575
1162
  }, [imageObject]);
576
1163
  const renderMessage = useCallback((props) => {
577
1164
  return /* @__PURE__ */ React__default.createElement(Message, __spreadProps(__spreadValues({}, props), { isShowImageViewer, setImageViewer: setImageViewerObject }));
578
1165
  }, [isShowImageViewer]);
1166
+ const renderPaymentMessageText = useCallback((props) => {
1167
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1168
+ const {
1169
+ currentMessage
1170
+ } = props;
1171
+ 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;
1172
+ if (!(currentMessage == null ? void 0 : currentMessage.text) || currentMessage.text.trim() === "") {
1173
+ return null;
1174
+ }
1175
+ if (currentMessage.type === "PAYMENT") {
1176
+ const paymentDetails = ((_e = currentMessage == null ? void 0 : currentMessage.propsConfiguration) == null ? void 0 : _e.payment) || {};
1177
+ const amount = paymentDetails.amount || (currentMessage == null ? void 0 : currentMessage.amount);
1178
+ const currency = paymentDetails.currency || (currentMessage == null ? void 0 : currentMessage.currency) || "$";
1179
+ const status = paymentDetails.status || (currentMessage == null ? void 0 : currentMessage.status) || "Completed";
1180
+ const paymentNote = paymentDetails.note || (currentMessage == null ? void 0 : currentMessage.text);
1181
+ return /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#e0f7fa", style: {
1182
+ width: "100%"
1183
+ }, onPress: () => {
1184
+ if (currentMessage == null ? void 0 : currentMessage.isShowThreadMessage)
1185
+ navigation.navigate(config.THREAD_MESSEGE_PATH, {
1186
+ channelId,
1187
+ title: "Message",
1188
+ postParentId: currentMessage == null ? void 0 : currentMessage._id,
1189
+ isPostParentIdThread: true
1190
+ });
1191
+ } }, /* @__PURE__ */ React__default.createElement(Box, { style: {
1192
+ backgroundColor: "#e0f7fa",
1193
+ borderRadius: 16,
1194
+ padding: 12,
1195
+ marginVertical: 2,
1196
+ borderWidth: 1,
1197
+ borderColor: "#26c6da",
1198
+ flexDirection: "row",
1199
+ alignItems: "center"
1200
+ } }, /* @__PURE__ */ React__default.createElement(MaterialCommunityIcons, { name: "credit-card-check", size: 28, color: "#00838f", style: {
1201
+ marginRight: 10
1202
+ } }), /* @__PURE__ */ React__default.createElement(VStack, { style: {
1203
+ flex: 1
1204
+ } }, /* @__PURE__ */ React__default.createElement(Text, { style: {
1205
+ fontWeight: "bold",
1206
+ color: "#00838f",
1207
+ fontSize: 16
1208
+ } }, amount ? `${currency}${amount}` : "Payment"), /* @__PURE__ */ React__default.createElement(Text, { style: {
1209
+ color: "#00838f",
1210
+ fontSize: 13,
1211
+ marginTop: 2
1212
+ } }, status), paymentNote && /* @__PURE__ */ React__default.createElement(Text, { style: {
1213
+ color: "#444",
1214
+ fontSize: 13,
1215
+ marginTop: 4
1216
+ } }, paymentNote))));
1217
+ } else {
1218
+ return /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "#c0c0c0", style: {
1219
+ width: "100%"
1220
+ }, onPress: () => {
1221
+ if (currentMessage == null ? void 0 : currentMessage.isShowThreadMessage)
1222
+ navigation.navigate(config.THREAD_MESSEGE_PATH, {
1223
+ channelId,
1224
+ title: "Message",
1225
+ postParentId: currentMessage == null ? void 0 : currentMessage._id,
1226
+ isPostParentIdThread: true
1227
+ });
1228
+ } }, /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(MessageText, __spreadProps(__spreadValues({}, props), { textStyle: {
1229
+ left: {
1230
+ marginLeft: 5
1231
+ }
1232
+ } })), ((_g = (_f = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _f.data) == null ? void 0 : _g.length) > 0 && /* @__PURE__ */ React__default.createElement(HStack, { space: "sm", className: "px-1 items-center" }, /* @__PURE__ */ React__default.createElement(HStack, null, (_l = (_k = (_j = (_i = (_h = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _h.data) == null ? void 0 : _i.filter((v, i, a) => a.findIndex((t) => {
1233
+ var _a4, _b4;
1234
+ return ((_a4 = t == null ? void 0 : t.author) == null ? void 0 : _a4.id) === ((_b4 = v == null ? void 0 : v.author) == null ? void 0 : _b4.id);
1235
+ }) === i)) == null ? void 0 : _j.slice(0, 2)) == null ? void 0 : _k.reverse()) == null ? void 0 : _l.map((p, i) => {
1236
+ var _a4, _b4, _c3;
1237
+ return /* @__PURE__ */ React__default.createElement(Avatar, { key: "conversation-replies-key-" + i, className: "bg-transparent", size: "sm" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_b4 = (_a4 = p == null ? void 0 : p.author) == null ? void 0 : _a4.username) == null ? void 0 : _b4.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "user image", style: {
1238
+ borderRadius: 6,
1239
+ borderWidth: 2,
1240
+ borderColor: "#fff"
1241
+ }, source: {
1242
+ uri: (_c3 = p == null ? void 0 : p.author) == null ? void 0 : _c3.picture
1243
+ } }));
1244
+ })), /* @__PURE__ */ React__default.createElement(Text, { style: {
1245
+ fontSize: 12
1246
+ }, className: "font-bold color-blue-800" }, (_m = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _m.totalCount, " ", ((_n = currentMessage == null ? void 0 : currentMessage.replies) == null ? void 0 : _n.totalCount) == 1 ? "reply" : "replies"), /* @__PURE__ */ React__default.createElement(Text, { style: {
1247
+ fontSize: 12
1248
+ }, className: "font-bold color-gray-500" }, lastReply ? createdAtText(lastReply == null ? void 0 : lastReply.createdAt) : ""))));
1249
+ }
1250
+ }, [navigation, channelId, role]);
1251
+ const renderPaymentMessage = useCallback((props) => {
1252
+ const {
1253
+ currentMessage
1254
+ } = props;
1255
+ if ((currentMessage == null ? void 0 : currentMessage.type) === "PAYMENT") {
1256
+ return /* @__PURE__ */ React__default.createElement(PaymentMessage, __spreadProps(__spreadValues({}, props), { navigation, channelId, config }));
1257
+ }
1258
+ return /* @__PURE__ */ React__default.createElement(Message, __spreadProps(__spreadValues({}, props), { isShowImageViewer, setImageViewer: setImageViewerObject }));
1259
+ }, [isShowImageViewer, channelId, navigation]);
579
1260
  let onScroll = false;
580
1261
  const onMomentumScrollBegin = async ({
581
1262
  nativeEvent
582
1263
  }) => {
583
1264
  onScroll = true;
584
- console.log("scroll top");
585
- if (!loadingOldMessages && isCloseToTop(nativeEvent) && totalCount > (channelMessages == null ? void 0 : channelMessages.length)) {
586
- await onFetchOld();
1265
+ if (isCloseToTop(nativeEvent)) {
1266
+ onFetchOld();
587
1267
  }
588
1268
  };
589
1269
  const onEndReached = () => {
590
- console.log("on end reached");
591
1270
  if (!onScroll)
592
1271
  return;
593
1272
  onScroll = false;
594
1273
  };
595
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, loadEarlierMsg && /* @__PURE__ */ React__default.createElement(Spinner, { color: "$blue500" }), /* @__PURE__ */ React__default.createElement(
596
- GiftedChat,
1274
+ const renderLoadEarlier = useCallback(() => {
1275
+ return loadingOldMessages ? /* @__PURE__ */ React__default.createElement(View, { style: {
1276
+ padding: 10,
1277
+ backgroundColor: "rgba(255,255,255,0.8)",
1278
+ borderRadius: 10,
1279
+ marginTop: 10
1280
+ } }, /* @__PURE__ */ React__default.createElement(Spinner, { size: "small", color: "#3b82f6" })) : null;
1281
+ }, [loadingOldMessages]);
1282
+ const [inputToolbarHeight, setInputToolbarHeight] = useState(30);
1283
+ useCallback((props) => /* @__PURE__ */ React__default.createElement(View, { style: {
1284
+ backgroundColor: "#fff",
1285
+ paddingBottom: 4,
1286
+ paddingTop: 4
1287
+ } }, /* @__PURE__ */ React__default.createElement(View, { style: {
1288
+ flexDirection: "row",
1289
+ alignItems: "center",
1290
+ minHeight: 44,
1291
+ maxHeight: 56,
1292
+ backgroundColor: "#fff",
1293
+ borderRadius: 22,
1294
+ marginHorizontal: 8,
1295
+ paddingHorizontal: 8,
1296
+ borderTopWidth: 1,
1297
+ borderTopColor: "#e0e0e0"
1298
+ } }, /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: onSelectImages, style: {
1299
+ width: 32,
1300
+ height: 32,
1301
+ borderRadius: 16,
1302
+ backgroundColor: "#fff",
1303
+ alignItems: "center",
1304
+ justifyContent: "center",
1305
+ marginRight: 8
1306
+ } }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { name: "add", size: 24, color: "#888" })), /* @__PURE__ */ React__default.createElement(TextInput, { ref: textInputRef, style: {
1307
+ flex: 1,
1308
+ maxHeight: 44,
1309
+ backgroundColor: "transparent",
1310
+ color: "#444",
1311
+ paddingHorizontal: 8,
1312
+ paddingVertical: 0,
1313
+ alignSelf: "center",
1314
+ textAlignVertical: "center"
1315
+ }, placeholder: "Jot something down", placeholderTextColor: colors.gray[400], multiline: true, value: messageText, onChangeText: setMessageText }), /* @__PURE__ */ React__default.createElement(
1316
+ TouchableOpacity,
1317
+ {
1318
+ onPress: () => handleSend([{
1319
+ text: messageText
1320
+ }]),
1321
+ disabled: false,
1322
+ style: {
1323
+ marginLeft: 8,
1324
+ opacity: !messageText.trim() && images.length === 0 ? 0.5 : 1
1325
+ }
1326
+ },
1327
+ /* @__PURE__ */ React__default.createElement(
1328
+ MaterialCommunityIcons,
1329
+ {
1330
+ name: "send-circle",
1331
+ size: 32,
1332
+ color: !messageText.trim() && images.length === 0 ? colors.gray[400] : colors.blue[500]
1333
+ }
1334
+ )
1335
+ )), images && images.length > 0 && /* @__PURE__ */ React__default.createElement(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, style: {
1336
+ marginTop: 4,
1337
+ marginLeft: 8
1338
+ } }, images.map((img, index) => /* @__PURE__ */ React__default.createElement(View, { key: `image-preview-${index}`, style: {
1339
+ width: 48,
1340
+ height: 48,
1341
+ marginRight: 8,
1342
+ borderRadius: 6,
1343
+ overflow: "hidden",
1344
+ position: "relative",
1345
+ backgroundColor: colors.gray[200]
1346
+ } }, /* @__PURE__ */ React__default.createElement(Image, { source: {
1347
+ uri: img.uri || img.url
1348
+ }, style: {
1349
+ width: "100%",
1350
+ height: "100%"
1351
+ }, alt: `selected image ${index + 1}` }), /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: () => {
1352
+ handleRemoveImage(index);
1353
+ }, style: {
1354
+ position: "absolute",
1355
+ top: 2,
1356
+ right: 2,
1357
+ backgroundColor: "rgba(0,0,0,0.6)",
1358
+ borderRadius: 10,
1359
+ width: 20,
1360
+ height: 20,
1361
+ alignItems: "center",
1362
+ justifyContent: "center"
1363
+ } }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size: 14, color: "white" })))))), [onSelectImages, messageText, images, isUploadingImage, loading, handleSend, handleRemoveImage]);
1364
+ const imageViewerModal = useMemo(() => /* @__PURE__ */ React__default.createElement(ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent }), [isShowImageViewer, modalContent]);
1365
+ const renderChatFooter = useCallback(() => {
1366
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, imageViewerModal, /* @__PURE__ */ React__default.createElement(SubscriptionHandler, { subscribeToMore: subscribe, document: CHAT_MESSAGE_ADDED, variables: {
1367
+ channelId: channelId == null ? void 0 : channelId.toString()
1368
+ }, updateQuery: void 0 }));
1369
+ }, [imageViewerModal, subscribe]);
1370
+ const listViewProps = useMemo(() => ({
1371
+ onEndReached,
1372
+ onEndReachedThreshold: 0.5,
1373
+ onMomentumScrollBegin,
1374
+ removeClippedSubviews: true,
1375
+ initialNumToRender: 10,
1376
+ maxToRenderPerBatch: 7,
1377
+ windowSize: 7,
1378
+ updateCellsBatchingPeriod: 50,
1379
+ keyExtractor: (item) => item._id
1380
+ }), [onEndReached, onMomentumScrollBegin]);
1381
+ useCallback((message, prefix = "Message") => {
1382
+ var _a3, _b3, _c2, _d2, _e, _f, _g, _h, _i;
1383
+ if (__DEV__) {
1384
+ console.log(`${prefix} ID: ${message == null ? void 0 : message.id}, Has files object: ${!!(message == null ? void 0 : message.files)}, Files typename: ${(_a3 = message == null ? void 0 : message.files) == null ? void 0 : _a3.__typename}, Files data exists: ${!!((_b3 = message == null ? void 0 : message.files) == null ? void 0 : _b3.data)}, Files count: ${((_d2 = (_c2 = message == null ? void 0 : message.files) == null ? void 0 : _c2.data) == null ? void 0 : _d2.length) || 0}`);
1385
+ if (((_e = message == null ? void 0 : message.files) == null ? void 0 : _e.data) && ((_g = (_f = message == null ? void 0 : message.files) == null ? void 0 : _f.data) == null ? void 0 : _g.length) > 0) {
1386
+ const file = (_h = message == null ? void 0 : message.files) == null ? void 0 : _h.data[0];
1387
+ console.log(`File[0] ID: ${file == null ? void 0 : file.id}, URL: ${(_i = file == null ? void 0 : file.url) == null ? void 0 : _i.substring(0, 30)}..., Name: ${file == null ? void 0 : file.name}, Type: ${file == null ? void 0 : file.mimeType}`);
1388
+ }
1389
+ }
1390
+ }, []);
1391
+ return /* @__PURE__ */ React__default.createElement(KeyboardAvoidingView, { style: {
1392
+ flex: 1,
1393
+ justifyContent: "flex-end"
1394
+ }, behavior: Platform.OS === "ios" ? "padding" : "height", keyboardVerticalOffset: Platform.OS === "ios" ? 64 : 0 }, /* @__PURE__ */ React__default.createElement(View, { style: {
1395
+ flex: 1,
1396
+ backgroundColor: "white",
1397
+ position: "relative",
1398
+ marginBottom: images.length > 0 ? 5 : bottomMargin
1399
+ } }, errorMessage ? /* @__PURE__ */ React__default.createElement(ErrorNotification, { message: errorMessage, onClose: () => setErrorMessage(""), type: notificationType }) : null, messageLoading && /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }), /* @__PURE__ */ React__default.createElement(
1400
+ GiftedChatInboxComponent,
597
1401
  {
598
1402
  ref: messageRootListRef,
599
- wrapInSafeArea: false,
600
- renderLoading: () => /* @__PURE__ */ React__default.createElement(Spinner, { color: "$blue500" }),
1403
+ errorMessage,
1404
+ images,
1405
+ onSelectImages,
1406
+ onRemoveImage: handleRemoveImage,
1407
+ selectedImage,
1408
+ setSelectedImage,
1409
+ isUploadingImage,
1410
+ loading,
1411
+ wrapInSafeArea: true,
1412
+ renderLoading: () => /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }),
601
1413
  messages: messageList,
602
- listViewProps: {
603
- onEndReached,
604
- onEndReachedThreshold: 0.5,
605
- onMomentumScrollBegin
606
- },
607
- onSend: (messages) => {
608
- var _a3, _b2, _c, _d, _e, _f;
609
- return (rest == null ? void 0 : rest.isCreateNewChannel) && !channelId ? ((_a3 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _a3.type) === ((_b2 = RoomType) == null ? void 0 : _b2.Direct) ? createDirectChannel((_d = (_c = messages[0]) == null ? void 0 : _c.text) != null ? _d : " ") : null : channelId && handleSend((_f = (_e = messages[0]) == null ? void 0 : _e.text) != null ? _f : " ");
1414
+ renderAvatar: null,
1415
+ showUserAvatar: false,
1416
+ listViewProps: __spreadProps(__spreadValues({}, listViewProps), {
1417
+ contentContainerStyle: {
1418
+ paddingBottom: inputToolbarHeight
1419
+ }
1420
+ }),
1421
+ onSend: handleSend,
1422
+ text: messageText || " ",
1423
+ onInputTextChanged: (text) => {
1424
+ setMessageText(text);
610
1425
  },
611
- text: msg ? msg : " ",
612
- onInputTextChanged: (text) => setMsg(text),
613
- renderFooter: () => loading ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "$blue500" }) : imageLoading ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "$blue500" }) : "",
1426
+ renderFooter: () => isUploadingImage ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : null,
614
1427
  scrollToBottom: true,
615
1428
  user: {
616
1429
  _id: (auth == null ? void 0 : auth.id) || ""
617
1430
  },
618
- isTyping: true,
619
- alwaysShowSend: loading ? false : true,
620
1431
  renderSend,
621
- renderMessageText,
622
- minInputToolbarHeight: 50,
623
- renderActions: channelId && renderActions,
624
- renderAccessory,
625
- renderMessage,
626
- renderChatFooter: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent }), /* @__PURE__ */ React__default.createElement(SubscriptionHandler, { channelId: channelId == null ? void 0 : channelId.toString(), subscribeToNewMessages: () => subscribeToMore({
627
- document: OnChatMessageAddedDocument,
628
- variables: {
629
- channelId: channelId == null ? void 0 : channelId.toString()
630
- },
631
- updateQuery: (prev, {
632
- subscriptionData
633
- }) => {
634
- var _a3, _b2, _c, _d, _e;
635
- if (!subscriptionData.data)
636
- return prev;
637
- setSkip(0);
638
- const newMessage = (_a3 = subscriptionData == null ? void 0 : subscriptionData.data) == null ? void 0 : _a3.chatMessageAdded;
639
- ((_b2 = prev == null ? void 0 : prev.messages) == null ? void 0 : _b2.data) ? [...prev.messages.data, newMessage] : [];
640
- const totalMsgCount = ((_c = prev == null ? void 0 : prev.messages) == null ? void 0 : _c.totalCount) + 1;
641
- setChannelMessages((oldMessages) => uniqBy([...oldMessages, newMessage], ({
642
- id
643
- }) => id));
644
- setTotalCount(totalMsgCount);
645
- const merged = __spreadProps(__spreadValues({}, prev), {
646
- messages: __spreadProps(__spreadValues({}, prev == null ? void 0 : prev.messages), {
647
- data: [...(_e = (_d = prev == null ? void 0 : prev.messages) == null ? void 0 : _d.data) != null ? _e : [], newMessage],
648
- totalCount: totalMsgCount
649
- })
650
- });
651
- return merged;
652
- }
653
- }) })),
654
- lightboxProps: {
655
- underlayColor: "transparent",
656
- springConfig: {
657
- tension: 9e4,
658
- friction: 9e4
659
- },
660
- disabled: true
661
- }
1432
+ renderMessageText: isPaymentChatUI ? renderPaymentMessageText : renderMessageText,
1433
+ renderMessage: isPaymentChatUI ? renderPaymentMessage : renderMessage,
1434
+ renderChatFooter,
1435
+ renderLoadEarlier,
1436
+ loadEarlier: totalCount > channelMessages.length,
1437
+ isLoadingEarlier: loadingOldMessages,
1438
+ placeholder: "Jot something down",
1439
+ infiniteScroll: true
662
1440
  }
663
- ));
664
- };
665
- const SubscriptionHandler = ({
666
- subscribeToNewMessages,
667
- channelId
668
- }) => {
669
- useEffect(() => subscribeToNewMessages(), [channelId]);
670
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
1441
+ )));
671
1442
  };
672
- const ConversationView = React__default.memo(ConversationViewComponent);export{ConversationView};//# sourceMappingURL=ConversationView.js.map
1443
+ const ConversationView = React__default.memo(ConversationViewComponent, (prevProps, nextProps) => {
1444
+ return prevProps.channelId === nextProps.channelId && prevProps.role === nextProps.role && prevProps.isShowThreadMessage === nextProps.isShowThreadMessage && prevProps.isPaymentChatUI === nextProps.isPaymentChatUI;
1445
+ });export{ConversationView};//# sourceMappingURL=ConversationView.js.map