@messenger-box/platform-mobile 10.0.3-alpha.40 → 10.0.3-alpha.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/lib/compute.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/queries/inboxQueries.js +77 -0
- package/lib/queries/inboxQueries.js.map +1 -0
- package/lib/routes.json +2 -3
- package/lib/screens/inbox/DialogThreadMessages.js +3 -7
- package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreads.js +3 -7
- package/lib/screens/inbox/DialogThreads.js.map +1 -1
- package/lib/screens/inbox/components/DialogsListItem.js +47 -46
- package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js +313 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +72 -57
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +115 -14
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/components/SubscriptionHandler.js +24 -0
- package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
- package/lib/screens/inbox/containers/ConversationView.js +640 -493
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +100 -181
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +659 -245
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadsView.js +3 -3
- package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
- package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
- package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +2 -0
- package/src/queries/inboxQueries.ts +298 -0
- package/src/queries/index.d.ts +2 -0
- package/src/queries/index.ts +1 -0
- package/src/screens/inbox/DialogThreadMessages.tsx +3 -11
- package/src/screens/inbox/DialogThreads.tsx +3 -7
- package/src/screens/inbox/components/Actionsheet.tsx +30 -0
- package/src/screens/inbox/components/DialogsListItem.tsx +89 -148
- package/src/screens/inbox/components/ExpandableInput.tsx +460 -0
- package/src/screens/inbox/components/ExpandableInputActionSheet.tsx +518 -0
- package/src/screens/inbox/components/GiftedChatInboxComponent.tsx +411 -0
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +202 -221
- package/src/screens/inbox/components/SlackInput.tsx +23 -0
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +216 -30
- package/src/screens/inbox/components/SubscriptionHandler.tsx +41 -0
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +6 -7
- package/src/screens/inbox/containers/ConversationView.tsx +1109 -669
- package/src/screens/inbox/containers/Dialogs.tsx +198 -342
- package/src/screens/inbox/containers/SupportServiceDialogs.tsx +2 -2
- package/src/screens/inbox/containers/ThreadConversationView.tsx +1141 -402
- package/src/screens/inbox/containers/ThreadsView.tsx +5 -5
- package/src/screens/inbox/hooks/useInboxMessages.ts +34 -0
- package/src/screens/inbox/machines/threadsMachine.ts +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React__default,{useState,useRef,useMemo,useEffect,useCallback}from'react';import {Box,Button,ButtonText,HStack,Avatar,AvatarFallbackText,AvatarImage,Text,Image,Spinner
|
|
1
|
+
import React__default,{useState,useRef,useMemo,useEffect,useCallback}from'react';import {useToast,Box,Button,ButtonText,HStack,Avatar,AvatarFallbackText,AvatarImage,Text,ScrollView,Image,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 {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';var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -46,6 +46,56 @@ 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
101
|
channelId: initialChannelId,
|
|
@@ -57,9 +107,11 @@ const ConversationViewComponent = (_a) => {
|
|
|
57
107
|
"isShowThreadMessage"
|
|
58
108
|
]);
|
|
59
109
|
var _a2, _b2, _c, _d;
|
|
110
|
+
const {
|
|
111
|
+
params
|
|
112
|
+
} = useRoute();
|
|
60
113
|
const [channelId, setChannelId] = useState(initialChannelId || null);
|
|
61
114
|
const [messageText, setMessageText] = useState("");
|
|
62
|
-
const [skip, setSkip] = useState(0);
|
|
63
115
|
const [loading, setLoading] = useState(false);
|
|
64
116
|
const [loadingOldMessages, setLoadingOldMessages] = useState(false);
|
|
65
117
|
const [error, setError] = useState(null);
|
|
@@ -67,40 +119,45 @@ const ConversationViewComponent = (_a) => {
|
|
|
67
119
|
const [images, setImages] = useState([]);
|
|
68
120
|
const [isShowImageViewer, setImageViewer] = useState(false);
|
|
69
121
|
const [imageObject, setImageObject] = useState({});
|
|
122
|
+
const [errorMessage, setErrorMessage] = useState("");
|
|
123
|
+
const [notificationType, setNotificationType] = useState("error");
|
|
124
|
+
const [isActionSheetVisible, setActionSheetVisible] = useState(false);
|
|
125
|
+
const [bottomMargin, setBottomMargin] = useState(0);
|
|
70
126
|
const messageRootListRef = useRef(null);
|
|
127
|
+
const textInputRef = useRef(null);
|
|
71
128
|
const isMounted = useRef(true);
|
|
72
129
|
const fetchOldDebounceRef = useRef(false);
|
|
73
|
-
const auth = useSelector(userSelector);
|
|
130
|
+
const auth = useSelector(userSelector, shallowEqual);
|
|
74
131
|
const currentRoute = navigationRef.isReady() ? (_a2 = navigationRef) == null ? void 0 : _a2.getCurrentRoute() : null;
|
|
75
132
|
const navigation = useNavigation();
|
|
76
133
|
const isFocused = useIsFocused();
|
|
77
|
-
const [addDirectChannel] =
|
|
134
|
+
const [addDirectChannel] = useAddDirectChannel();
|
|
78
135
|
const {
|
|
79
136
|
startUpload
|
|
80
137
|
} = useUploadFilesNative();
|
|
81
|
-
const [sendMsg] =
|
|
82
|
-
const [
|
|
138
|
+
const [sendMsg] = useSendChannelMessage();
|
|
139
|
+
const [sendExpoNotification] = useSendExpoNotification();
|
|
140
|
+
const [skip, setSkip] = useState(0);
|
|
83
141
|
const {
|
|
84
142
|
data,
|
|
85
143
|
loading: messageLoading,
|
|
86
144
|
refetch,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
145
|
+
subscribe
|
|
146
|
+
} = useInboxMessages({
|
|
147
|
+
useQueryHook: useChannelMessagesQuery,
|
|
148
|
+
queryVariables: {
|
|
91
149
|
channelId: channelId == null ? void 0 : channelId.toString(),
|
|
92
150
|
parentId: null,
|
|
93
151
|
limit: MESSAGES_PER_PAGE,
|
|
94
|
-
skip
|
|
152
|
+
skip,
|
|
153
|
+
orgName: params == null ? void 0 : params.orgName
|
|
95
154
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
onError: (
|
|
102
|
-
setError(String(error2));
|
|
103
|
-
}
|
|
155
|
+
subscriptionDocument: CHAT_MESSAGE_ADDED,
|
|
156
|
+
subscriptionVariables: {
|
|
157
|
+
channelId: channelId == null ? void 0 : channelId.toString()
|
|
158
|
+
},
|
|
159
|
+
updateQuery: void 0,
|
|
160
|
+
onError: (err) => setError(String(err))
|
|
104
161
|
});
|
|
105
162
|
const channelMessages = useMemo(() => {
|
|
106
163
|
var _a3;
|
|
@@ -126,25 +183,18 @@ const ConversationViewComponent = (_a) => {
|
|
|
126
183
|
if (channelId) {
|
|
127
184
|
refetch();
|
|
128
185
|
}
|
|
129
|
-
|
|
130
|
-
};
|
|
131
|
-
}, [channelId, isFocused, refetch]));
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
if (selectedImage) {
|
|
134
|
-
setLoading(false);
|
|
135
|
-
}
|
|
136
|
-
}, [selectedImage]);
|
|
186
|
+
}, [isFocused, refetch]));
|
|
137
187
|
const fetchMoreMessagesImpl = useCallback(async () => {
|
|
138
188
|
var _a3, _b3;
|
|
139
189
|
try {
|
|
140
190
|
setLoadingOldMessages(true);
|
|
141
|
-
const response = await
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
191
|
+
const response = await refetch({
|
|
192
|
+
channelId: channelId == null ? void 0 : channelId.toString(),
|
|
193
|
+
parentId: null,
|
|
194
|
+
limit: MESSAGES_PER_PAGE,
|
|
195
|
+
skip: channelMessages.length
|
|
147
196
|
});
|
|
197
|
+
setSkip(channelMessages.length);
|
|
148
198
|
setLoadingOldMessages(false);
|
|
149
199
|
if (!((_b3 = (_a3 = response == null ? void 0 : response.data) == null ? void 0 : _a3.messages) == null ? void 0 : _b3.data)) {
|
|
150
200
|
return {
|
|
@@ -161,9 +211,9 @@ const ConversationViewComponent = (_a) => {
|
|
|
161
211
|
error: String(error2)
|
|
162
212
|
};
|
|
163
213
|
}
|
|
164
|
-
}, [channelId, channelMessages.length,
|
|
214
|
+
}, [channelId, channelMessages.length, refetch]);
|
|
165
215
|
const sendMessageImpl = useCallback(async () => {
|
|
166
|
-
var _a3;
|
|
216
|
+
var _a3, _b3, _c2, _d2, _e, _f, _g, _h;
|
|
167
217
|
try {
|
|
168
218
|
const currentMessageText = messageText;
|
|
169
219
|
setMessageText("");
|
|
@@ -188,12 +238,13 @@ const ConversationViewComponent = (_a) => {
|
|
|
188
238
|
author: {
|
|
189
239
|
__typename: "UserAccount",
|
|
190
240
|
id: auth == null ? void 0 : auth.id,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
241
|
+
givenName: ((_a3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _a3.given_name) || "",
|
|
242
|
+
familyName: ((_b3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _b3.family_name) || "",
|
|
243
|
+
email: ((_c2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _c2.email) || "",
|
|
244
|
+
username: ((_d2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _d2.nickname) || "",
|
|
245
|
+
fullName: ((_e = auth == null ? void 0 : auth.profile) == null ? void 0 : _e.name) || "",
|
|
246
|
+
picture: ((_f = auth == null ? void 0 : auth.profile) == null ? void 0 : _f.picture) || "",
|
|
247
|
+
alias: [(_g = auth == null ? void 0 : auth.authUserId) != null ? _g : ""],
|
|
197
248
|
tokens: []
|
|
198
249
|
},
|
|
199
250
|
isDelivered: true,
|
|
@@ -234,45 +285,51 @@ const ConversationViewComponent = (_a) => {
|
|
|
234
285
|
update: (cache, {
|
|
235
286
|
data: data2
|
|
236
287
|
}) => {
|
|
237
|
-
if (data2 == null ? void 0 : data2.sendMessage)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
288
|
+
if (!(data2 == null ? void 0 : data2.sendMessage))
|
|
289
|
+
return;
|
|
290
|
+
try {
|
|
291
|
+
cache.writeQuery({
|
|
292
|
+
query: MESSAGES_DOCUMENT,
|
|
293
|
+
variables: {
|
|
294
|
+
channelId: channelId == null ? void 0 : channelId.toString(),
|
|
295
|
+
parentId: null,
|
|
296
|
+
limit: MESSAGES_PER_PAGE,
|
|
297
|
+
skip: 0
|
|
298
|
+
},
|
|
299
|
+
data: {
|
|
300
|
+
messages: {
|
|
301
|
+
__typename: "Messages",
|
|
302
|
+
messagesRefId: channelId,
|
|
303
|
+
data: [data2.sendMessage],
|
|
304
|
+
totalCount: 1
|
|
246
305
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
parentId: null,
|
|
255
|
-
limit: MESSAGES_PER_PAGE,
|
|
256
|
-
skip: 0
|
|
257
|
-
},
|
|
258
|
-
data: {
|
|
259
|
-
messages: __spreadProps(__spreadValues({}, existingData.messages), {
|
|
260
|
-
data: [data2.sendMessage, ...existingData.messages.data],
|
|
261
|
-
totalCount: (existingData.messages.totalCount || 0) + 1
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
} catch (error2) {
|
|
266
|
-
console.error("Error updating cache:", error2);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
} catch (error2) {
|
|
309
|
+
console.error("Error updating cache:", error2);
|
|
310
|
+
let errorMsg = "Failed to update message cache";
|
|
311
|
+
if (__DEV__ && error2) {
|
|
312
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Cache update failed";
|
|
267
313
|
}
|
|
314
|
+
setNotificationType("error");
|
|
315
|
+
setErrorMessage(errorMsg);
|
|
268
316
|
}
|
|
269
317
|
}
|
|
270
318
|
});
|
|
319
|
+
setIsUploadingImage(false);
|
|
320
|
+
setLoading(false);
|
|
271
321
|
return {
|
|
272
|
-
message: (
|
|
322
|
+
message: (_h = response.data) == null ? void 0 : _h.sendMessage
|
|
273
323
|
};
|
|
274
324
|
} catch (error2) {
|
|
275
325
|
setLoading(false);
|
|
326
|
+
setIsUploadingImage(false);
|
|
327
|
+
let errorMsg = "Failed to send message";
|
|
328
|
+
if (__DEV__ && error2) {
|
|
329
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Message sending failed";
|
|
330
|
+
}
|
|
331
|
+
setNotificationType("error");
|
|
332
|
+
setErrorMessage(errorMsg);
|
|
276
333
|
setError(String(error2));
|
|
277
334
|
return {
|
|
278
335
|
error: String(error2)
|
|
@@ -280,32 +337,42 @@ const ConversationViewComponent = (_a) => {
|
|
|
280
337
|
}
|
|
281
338
|
}, [channelId, messageText, sendMsg, auth]);
|
|
282
339
|
const onSelectImages = async () => {
|
|
283
|
-
var _a3;
|
|
284
340
|
setLoading(true);
|
|
285
341
|
try {
|
|
286
342
|
let imageSource = await ImagePicker.launchImageLibraryAsync({
|
|
287
343
|
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
|
288
|
-
allowsEditing:
|
|
344
|
+
allowsEditing: false,
|
|
289
345
|
aspect: [4, 3],
|
|
290
346
|
quality: 0.8,
|
|
291
347
|
base64: true,
|
|
292
|
-
exif: false
|
|
348
|
+
exif: false,
|
|
349
|
+
allowsMultipleSelection: true
|
|
293
350
|
});
|
|
294
351
|
if (!(imageSource == null ? void 0 : imageSource.canceled)) {
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
352
|
+
const selectedAssets = (imageSource == null ? void 0 : imageSource.assets) || [];
|
|
353
|
+
if (selectedAssets.length === 0) {
|
|
297
354
|
setLoading(false);
|
|
298
355
|
return;
|
|
299
356
|
}
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
357
|
+
const newImages = selectedAssets.map((selectedAsset) => {
|
|
358
|
+
const base64Data = selectedAsset.base64;
|
|
359
|
+
const previewImage = base64Data ? `data:image/jpeg;base64,${base64Data}` : selectedAsset.uri;
|
|
360
|
+
const asset = __spreadProps(__spreadValues({}, selectedAsset), {
|
|
361
|
+
url: selectedAsset.uri,
|
|
362
|
+
fileName: selectedAsset.fileName || `image_${Date.now()}.jpg`,
|
|
363
|
+
mimeType: "image/jpeg"
|
|
364
|
+
});
|
|
365
|
+
return asset;
|
|
306
366
|
});
|
|
307
|
-
|
|
308
|
-
|
|
367
|
+
if (newImages.length > 0) {
|
|
368
|
+
const base64Data = newImages[0].base64;
|
|
369
|
+
const previewImage = base64Data ? `data:image/jpeg;base64,${base64Data}` : newImages[0].uri;
|
|
370
|
+
setSelectedImage(previewImage);
|
|
371
|
+
}
|
|
372
|
+
setImages((currentImages) => [...currentImages, ...newImages]);
|
|
373
|
+
if (!isActionSheetVisible) {
|
|
374
|
+
setActionSheetVisible(true);
|
|
375
|
+
}
|
|
309
376
|
} else {
|
|
310
377
|
setLoading(false);
|
|
311
378
|
}
|
|
@@ -314,12 +381,72 @@ const ConversationViewComponent = (_a) => {
|
|
|
314
381
|
}
|
|
315
382
|
};
|
|
316
383
|
const [uploadingMessageId, setUploadingMessageId] = useState(null);
|
|
384
|
+
const [pendingUploads, setPendingUploads] = useState({});
|
|
385
|
+
const [uploadErrors, setUploadErrors] = useState({});
|
|
386
|
+
const [isUploadingImage, setIsUploadingImage] = useState(false);
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
if (images.length === 0) {
|
|
389
|
+
setIsUploadingImage(false);
|
|
390
|
+
}
|
|
391
|
+
}, [images]);
|
|
392
|
+
useToast();
|
|
393
|
+
const removeMessageFromUI = useCallback((messageId) => {
|
|
394
|
+
setPendingUploads((prev) => {
|
|
395
|
+
const newPending = __spreadValues({}, prev);
|
|
396
|
+
delete newPending[messageId];
|
|
397
|
+
return newPending;
|
|
398
|
+
});
|
|
399
|
+
setUploadErrors((prev) => {
|
|
400
|
+
const newErrors = __spreadValues({}, prev);
|
|
401
|
+
delete newErrors[messageId];
|
|
402
|
+
return newErrors;
|
|
403
|
+
});
|
|
404
|
+
setIsUploadingImage(false);
|
|
405
|
+
}, []);
|
|
317
406
|
const sendMessageWithFileImpl = useCallback(async () => {
|
|
318
|
-
var _a3, _b3, _c2, _d2, _e, _f;
|
|
407
|
+
var _a3, _b3, _c2, _d2, _e, _f, _g;
|
|
319
408
|
try {
|
|
320
|
-
setLoading(true);
|
|
321
409
|
const postId = objectId();
|
|
322
|
-
|
|
410
|
+
setIsUploadingImage(true);
|
|
411
|
+
setLoading(false);
|
|
412
|
+
setUploadingMessageId(null);
|
|
413
|
+
if (!images || images.length === 0) {
|
|
414
|
+
setIsUploadingImage(false);
|
|
415
|
+
setLoading(false);
|
|
416
|
+
return {
|
|
417
|
+
error: "No images available to upload"
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const currentMessageText = messageText;
|
|
421
|
+
const currentImages = [...images];
|
|
422
|
+
const imageUris = currentImages.map((img) => img.uri || img.url);
|
|
423
|
+
setMessageText("");
|
|
424
|
+
setSelectedImage("");
|
|
425
|
+
setImages([]);
|
|
426
|
+
const clientMessage = {
|
|
427
|
+
_id: postId,
|
|
428
|
+
text: currentMessageText || " ",
|
|
429
|
+
createdAt: new Date(),
|
|
430
|
+
user: {
|
|
431
|
+
_id: (auth == null ? void 0 : auth.id) || "",
|
|
432
|
+
name: `${(auth == null ? void 0 : auth.givenName) || ""} ${(auth == null ? void 0 : auth.familyName) || ""}`,
|
|
433
|
+
avatar: (auth == null ? void 0 : auth.picture) || ""
|
|
434
|
+
},
|
|
435
|
+
image: imageUris[0],
|
|
436
|
+
images: imageUris,
|
|
437
|
+
sent: true,
|
|
438
|
+
received: true,
|
|
439
|
+
pending: false,
|
|
440
|
+
type: "TEXT",
|
|
441
|
+
replies: {
|
|
442
|
+
data: [],
|
|
443
|
+
totalCount: 0
|
|
444
|
+
},
|
|
445
|
+
isShowThreadMessage: false
|
|
446
|
+
};
|
|
447
|
+
setPendingUploads((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
448
|
+
[postId]: clientMessage
|
|
449
|
+
}));
|
|
323
450
|
const notificationData = {
|
|
324
451
|
url: config.INBOX_MESSEGE_PATH,
|
|
325
452
|
params: {
|
|
@@ -331,23 +458,6 @@ const ConversationViewComponent = (_a) => {
|
|
|
331
458
|
sound: Platform.OS === "android" ? void 0 : "default"
|
|
332
459
|
}
|
|
333
460
|
};
|
|
334
|
-
if (!images || images.length === 0) {
|
|
335
|
-
setLoading(false);
|
|
336
|
-
setUploadingMessageId(null);
|
|
337
|
-
return {
|
|
338
|
-
error: "No images available to upload"
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
const imagesToUpload = images.map((img) => {
|
|
342
|
-
return __spreadProps(__spreadValues({}, img), {
|
|
343
|
-
uri: img.uri || img.url,
|
|
344
|
-
type: "image/jpeg",
|
|
345
|
-
name: img.fileName || `image_${Date.now()}.jpg`
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
const currentMessageText = messageText;
|
|
349
|
-
setMessageText("");
|
|
350
|
-
const fileId = objectId();
|
|
351
461
|
const optimisticMessage = {
|
|
352
462
|
__typename: "Post",
|
|
353
463
|
id: postId,
|
|
@@ -357,12 +467,13 @@ const ConversationViewComponent = (_a) => {
|
|
|
357
467
|
author: {
|
|
358
468
|
__typename: "UserAccount",
|
|
359
469
|
id: auth == null ? void 0 : auth.id,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
470
|
+
givenName: ((_a3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _a3.given_name) || "",
|
|
471
|
+
familyName: ((_b3 = auth == null ? void 0 : auth.profile) == null ? void 0 : _b3.family_name) || "",
|
|
472
|
+
email: ((_c2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _c2.email) || "",
|
|
473
|
+
username: ((_d2 = auth == null ? void 0 : auth.profile) == null ? void 0 : _d2.nickname) || "",
|
|
474
|
+
fullName: ((_e = auth == null ? void 0 : auth.profile) == null ? void 0 : _e.name) || "",
|
|
475
|
+
picture: ((_f = auth == null ? void 0 : auth.profile) == null ? void 0 : _f.picture) || "",
|
|
476
|
+
alias: [(_g = auth == null ? void 0 : auth.authUserId) != null ? _g : ""],
|
|
366
477
|
tokens: []
|
|
367
478
|
},
|
|
368
479
|
isDelivered: true,
|
|
@@ -381,20 +492,21 @@ const ConversationViewComponent = (_a) => {
|
|
|
381
492
|
props: {},
|
|
382
493
|
files: {
|
|
383
494
|
__typename: "FilesInfo",
|
|
384
|
-
data:
|
|
495
|
+
data: imageUris.map((uri, index) => ({
|
|
385
496
|
__typename: "FileInfo",
|
|
386
|
-
id:
|
|
387
|
-
url:
|
|
388
|
-
name:
|
|
497
|
+
id: `temp-file-${index}-${postId}`,
|
|
498
|
+
url: uri,
|
|
499
|
+
name: `image-${index}.jpg`,
|
|
389
500
|
extension: "jpg",
|
|
390
501
|
mimeType: "image/jpeg",
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
502
|
+
size: 0,
|
|
503
|
+
height: 300,
|
|
504
|
+
width: 300,
|
|
505
|
+
channel: null,
|
|
506
|
+
post: null,
|
|
507
|
+
refType: FileRefType.Post
|
|
508
|
+
})),
|
|
509
|
+
totalCount: imageUris.length
|
|
398
510
|
},
|
|
399
511
|
replies: {
|
|
400
512
|
__typename: "Messages",
|
|
@@ -402,137 +514,149 @@ const ConversationViewComponent = (_a) => {
|
|
|
402
514
|
totalCount: 0
|
|
403
515
|
}
|
|
404
516
|
};
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
517
|
+
setTimeout(async () => {
|
|
518
|
+
var _a4;
|
|
519
|
+
try {
|
|
520
|
+
const imagesToUpload = currentImages.map((img) => __spreadProps(__spreadValues({}, img), {
|
|
521
|
+
uri: img.uri || img.url,
|
|
522
|
+
type: img.mimeType || "image/jpeg",
|
|
523
|
+
name: img.fileName || `image_${Date.now()}.jpg`
|
|
524
|
+
}));
|
|
525
|
+
const uploadResponse = await startUpload({
|
|
526
|
+
file: imagesToUpload,
|
|
527
|
+
saveUploadedFile: {
|
|
528
|
+
variables: {
|
|
529
|
+
postId
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
createUploadLink: {
|
|
533
|
+
variables: {
|
|
534
|
+
postId
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
if (uploadResponse == null ? void 0 : uploadResponse.error) {
|
|
539
|
+
console.error("Upload error:", uploadResponse.error);
|
|
540
|
+
let errorMsg = "Failed to upload image. Please try again.";
|
|
541
|
+
if (__DEV__ && uploadResponse.error) {
|
|
542
|
+
errorMsg = typeof uploadResponse.error === "string" ? uploadResponse.error : uploadResponse.error.message || errorMsg;
|
|
543
|
+
}
|
|
544
|
+
setNotificationType("error");
|
|
545
|
+
setErrorMessage(errorMsg);
|
|
546
|
+
setUploadErrors((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
547
|
+
[postId]: errorMsg
|
|
548
|
+
}));
|
|
549
|
+
removeMessageFromUI(postId);
|
|
550
|
+
setIsUploadingImage(false);
|
|
551
|
+
setLoading(false);
|
|
552
|
+
return;
|
|
415
553
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
size: file.size,
|
|
440
|
-
refType: file.refType,
|
|
441
|
-
ref: postId
|
|
442
|
-
})),
|
|
443
|
-
totalCount: uploadedFiles.length
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
const response = await sendMsg({
|
|
447
|
-
variables: {
|
|
448
|
-
postId,
|
|
449
|
-
channelId,
|
|
450
|
-
content: currentMessageText || " ",
|
|
451
|
-
files,
|
|
452
|
-
notificationParams: notificationData
|
|
453
|
-
},
|
|
454
|
-
optimisticResponse: {
|
|
455
|
-
__typename: "Mutation",
|
|
456
|
-
sendMessage: realMessage
|
|
457
|
-
},
|
|
458
|
-
update: (cache, {
|
|
459
|
-
data: data2
|
|
460
|
-
}) => {
|
|
461
|
-
if (data2 == null ? void 0 : data2.sendMessage) {
|
|
462
|
-
try {
|
|
463
|
-
const existingData = cache.readQuery({
|
|
464
|
-
query: MessagesDocument,
|
|
465
|
-
variables: {
|
|
466
|
-
channelId: channelId == null ? void 0 : channelId.toString(),
|
|
467
|
-
parentId: null,
|
|
468
|
-
limit: MESSAGES_PER_PAGE,
|
|
469
|
-
skip: 0
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
if (!existingData)
|
|
473
|
-
return;
|
|
474
|
-
const messageWithFiles = __spreadProps(__spreadValues({}, data2.sendMessage), {
|
|
475
|
-
files: data2.sendMessage.files || {
|
|
476
|
-
__typename: "FilesInfo",
|
|
477
|
-
data: uploadedFiles.map((file) => ({
|
|
478
|
-
__typename: "FileInfo",
|
|
479
|
-
id: file.id,
|
|
480
|
-
url: file.url,
|
|
481
|
-
name: file.name,
|
|
482
|
-
extension: file.extension,
|
|
483
|
-
mimeType: file.mimeType,
|
|
484
|
-
height: file.height,
|
|
485
|
-
width: file.width,
|
|
486
|
-
size: file.size,
|
|
487
|
-
refType: file.refType,
|
|
488
|
-
ref: postId
|
|
489
|
-
})),
|
|
490
|
-
totalCount: uploadedFiles.length
|
|
554
|
+
const uploadedFiles = uploadResponse.data;
|
|
555
|
+
const fileIds = (_a4 = uploadedFiles == null ? void 0 : uploadedFiles.map((f) => f.id)) != null ? _a4 : null;
|
|
556
|
+
if ((fileIds == null ? void 0 : fileIds.length) > 0) {
|
|
557
|
+
await sendMsg({
|
|
558
|
+
variables: {
|
|
559
|
+
postId,
|
|
560
|
+
channelId,
|
|
561
|
+
content: currentMessageText || " ",
|
|
562
|
+
files: fileIds,
|
|
563
|
+
notificationParams: notificationData
|
|
564
|
+
},
|
|
565
|
+
optimisticResponse: {
|
|
566
|
+
__typename: "Mutation",
|
|
567
|
+
sendMessage: optimisticMessage
|
|
568
|
+
},
|
|
569
|
+
update: (cache, {
|
|
570
|
+
data: data2
|
|
571
|
+
}) => {
|
|
572
|
+
var _a5, _b4;
|
|
573
|
+
if (!(data2 == null ? void 0 : data2.sendMessage)) {
|
|
574
|
+
setIsUploadingImage(false);
|
|
575
|
+
setLoading(false);
|
|
576
|
+
return;
|
|
491
577
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
578
|
+
try {
|
|
579
|
+
cache.writeQuery({
|
|
580
|
+
query: MESSAGES_DOCUMENT,
|
|
581
|
+
variables: {
|
|
582
|
+
channelId: channelId == null ? void 0 : channelId.toString(),
|
|
583
|
+
parentId: null,
|
|
584
|
+
limit: MESSAGES_PER_PAGE,
|
|
585
|
+
skip: 0
|
|
586
|
+
},
|
|
587
|
+
data: {
|
|
588
|
+
messages: {
|
|
589
|
+
__typename: "Messages",
|
|
590
|
+
messagesRefId: channelId,
|
|
591
|
+
data: [data2.sendMessage],
|
|
592
|
+
totalCount: 1
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
const serverMessage = data2.sendMessage;
|
|
597
|
+
const hasServerImage = (_b4 = (_a5 = serverMessage == null ? void 0 : serverMessage.files) == null ? void 0 : _a5.data) == null ? void 0 : _b4.some((file) => file.url);
|
|
598
|
+
if (hasServerImage) {
|
|
599
|
+
removeMessageFromUI(postId);
|
|
600
|
+
}
|
|
601
|
+
setIsUploadingImage(false);
|
|
602
|
+
setLoading(false);
|
|
603
|
+
} catch (error2) {
|
|
604
|
+
console.error("Cache update error:", error2);
|
|
605
|
+
let errorMsg = "Failed to update message.";
|
|
606
|
+
if (__DEV__ && error2) {
|
|
607
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Cache update failed";
|
|
608
|
+
}
|
|
609
|
+
setNotificationType("error");
|
|
610
|
+
setErrorMessage(errorMsg);
|
|
611
|
+
setIsUploadingImage(false);
|
|
612
|
+
setLoading(false);
|
|
506
613
|
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
} else {
|
|
617
|
+
setIsUploadingImage(false);
|
|
618
|
+
setLoading(false);
|
|
513
619
|
}
|
|
620
|
+
} catch (error2) {
|
|
621
|
+
console.error("Background process error:", error2);
|
|
622
|
+
let errorMsg = "Failed to send image. Please try again.";
|
|
623
|
+
if (__DEV__ && error2) {
|
|
624
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Background process failed";
|
|
625
|
+
}
|
|
626
|
+
setNotificationType("error");
|
|
627
|
+
setErrorMessage(errorMsg);
|
|
628
|
+
removeMessageFromUI(postId);
|
|
629
|
+
setIsUploadingImage(false);
|
|
630
|
+
setLoading(false);
|
|
514
631
|
}
|
|
515
|
-
});
|
|
516
|
-
setLoading(false);
|
|
517
|
-
setUploadingMessageId(null);
|
|
632
|
+
}, 0);
|
|
518
633
|
return {
|
|
519
|
-
|
|
634
|
+
success: true
|
|
520
635
|
};
|
|
521
636
|
} catch (error2) {
|
|
522
|
-
|
|
523
|
-
|
|
637
|
+
console.error("Send message error:", error2);
|
|
638
|
+
let errorMsg = "Failed to process image. Please try again.";
|
|
639
|
+
if (__DEV__ && error2) {
|
|
640
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Image processing failed";
|
|
641
|
+
}
|
|
642
|
+
setNotificationType("error");
|
|
643
|
+
setErrorMessage(errorMsg);
|
|
524
644
|
setError(String(error2));
|
|
645
|
+
setIsUploadingImage(false);
|
|
646
|
+
setLoading(false);
|
|
525
647
|
return {
|
|
526
648
|
error: String(error2)
|
|
527
649
|
};
|
|
528
650
|
}
|
|
529
|
-
}, [channelId, messageText, images, selectedImage, startUpload, sendMsg, auth]);
|
|
651
|
+
}, [channelId, messageText, images, selectedImage, startUpload, sendMsg, auth, removeMessageFromUI]);
|
|
530
652
|
const createDirectChannelImpl = useCallback(async () => {
|
|
531
653
|
var _a3, _b3, _c2, _d2, _e, _f, _g, _h;
|
|
532
654
|
try {
|
|
533
655
|
setLoading(true);
|
|
534
656
|
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)) {
|
|
535
657
|
setLoading(false);
|
|
658
|
+
setNotificationType("error");
|
|
659
|
+
setErrorMessage(__DEV__ ? "Invalid channel data" : "Unable to create conversation");
|
|
536
660
|
return {
|
|
537
661
|
error: "Invalid channel data"
|
|
538
662
|
};
|
|
@@ -547,6 +671,8 @@ const ConversationViewComponent = (_a) => {
|
|
|
547
671
|
});
|
|
548
672
|
if (!((_h = (_g = response == null ? void 0 : response.data) == null ? void 0 : _g.createDirectChannel) == null ? void 0 : _h.id)) {
|
|
549
673
|
setLoading(false);
|
|
674
|
+
setNotificationType("error");
|
|
675
|
+
setErrorMessage(__DEV__ ? "Failed to create channel" : "Unable to create conversation");
|
|
550
676
|
return {
|
|
551
677
|
error: "Failed to create channel"
|
|
552
678
|
};
|
|
@@ -580,7 +706,7 @@ const ConversationViewComponent = (_a) => {
|
|
|
580
706
|
email: (auth == null ? void 0 : auth.email) || "",
|
|
581
707
|
username: (auth == null ? void 0 : auth.username) || "",
|
|
582
708
|
alias: [],
|
|
583
|
-
tokens: []
|
|
709
|
+
tokens: (auth == null ? void 0 : auth.token) ? [...auth == null ? void 0 : auth.token] : []
|
|
584
710
|
},
|
|
585
711
|
isDelivered: true,
|
|
586
712
|
isRead: false,
|
|
@@ -620,28 +746,34 @@ const ConversationViewComponent = (_a) => {
|
|
|
620
746
|
update: (cache, {
|
|
621
747
|
data: data2
|
|
622
748
|
}) => {
|
|
623
|
-
if (data2 == null ? void 0 : data2.sendMessage)
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
749
|
+
if (!(data2 == null ? void 0 : data2.sendMessage))
|
|
750
|
+
return;
|
|
751
|
+
try {
|
|
752
|
+
cache.writeQuery({
|
|
753
|
+
query: MESSAGES_DOCUMENT,
|
|
754
|
+
variables: {
|
|
755
|
+
channelId: newChannelId,
|
|
756
|
+
parentId: null,
|
|
757
|
+
limit: MESSAGES_PER_PAGE,
|
|
758
|
+
skip: 0
|
|
759
|
+
},
|
|
760
|
+
data: {
|
|
761
|
+
messages: {
|
|
762
|
+
__typename: "Messages",
|
|
763
|
+
messagesRefId: newChannelId,
|
|
764
|
+
data: [data2.sendMessage],
|
|
765
|
+
totalCount: 1
|
|
640
766
|
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
} catch (error2) {
|
|
770
|
+
console.error("Error updating cache:", error2);
|
|
771
|
+
let errorMsg = "Failed to update message cache";
|
|
772
|
+
if (__DEV__ && error2) {
|
|
773
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Cache update failed";
|
|
644
774
|
}
|
|
775
|
+
setNotificationType("error");
|
|
776
|
+
setErrorMessage(errorMsg);
|
|
645
777
|
}
|
|
646
778
|
}
|
|
647
779
|
});
|
|
@@ -651,6 +783,12 @@ const ConversationViewComponent = (_a) => {
|
|
|
651
783
|
};
|
|
652
784
|
} catch (error2) {
|
|
653
785
|
setLoading(false);
|
|
786
|
+
let errorMsg = "Failed to create conversation";
|
|
787
|
+
if (__DEV__ && error2) {
|
|
788
|
+
errorMsg = error2.message ? error2.message.replace("[ApolloError: ", "").replace("]", "") : "Channel creation failed";
|
|
789
|
+
}
|
|
790
|
+
setNotificationType("error");
|
|
791
|
+
setErrorMessage(errorMsg);
|
|
654
792
|
setError(String(error2));
|
|
655
793
|
return {
|
|
656
794
|
error: String(error2)
|
|
@@ -677,25 +815,27 @@ const ConversationViewComponent = (_a) => {
|
|
|
677
815
|
return contentSize.height - layoutMeasurement.height - paddingToTop <= contentOffset.y;
|
|
678
816
|
};
|
|
679
817
|
const messageList = useMemo(() => {
|
|
818
|
+
const pendingMessages = Object.values(pendingUploads);
|
|
680
819
|
if (!channelMessages || channelMessages.length === 0) {
|
|
681
|
-
return
|
|
820
|
+
return pendingMessages;
|
|
682
821
|
}
|
|
683
822
|
const filteredMessages = uniqBy(channelMessages, ({
|
|
684
823
|
id
|
|
685
824
|
}) => id);
|
|
686
|
-
|
|
687
|
-
return [];
|
|
688
|
-
}
|
|
689
|
-
return orderBy(filteredMessages, ["createdAt"], ["desc"]).map((msg) => {
|
|
825
|
+
const serverMessages = orderBy(filteredMessages, ["createdAt"], ["desc"]).map((msg) => {
|
|
690
826
|
var _a3, _b3, _c2, _d2, _e;
|
|
691
827
|
const date = new Date(msg.createdAt);
|
|
692
|
-
|
|
828
|
+
if (pendingUploads[msg.id]) {
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
let imageUrls = [];
|
|
832
|
+
let primaryImageUrl = null;
|
|
693
833
|
if (msg.files && typeof msg.files === "object") {
|
|
694
834
|
const filesData = msg.files.data || (Array.isArray(msg.files) ? msg.files : null);
|
|
695
835
|
if (filesData && filesData.length > 0) {
|
|
696
|
-
|
|
697
|
-
if (
|
|
698
|
-
|
|
836
|
+
imageUrls = filesData.filter((fileData) => fileData && typeof fileData === "object" && fileData.url).map((fileData) => fileData.url);
|
|
837
|
+
if (imageUrls.length > 0) {
|
|
838
|
+
primaryImageUrl = imageUrls[0];
|
|
699
839
|
}
|
|
700
840
|
}
|
|
701
841
|
}
|
|
@@ -708,7 +848,8 @@ const ConversationViewComponent = (_a) => {
|
|
|
708
848
|
name: `${((_b3 = msg.author) == null ? void 0 : _b3.givenName) || ""} ${((_c2 = msg.author) == null ? void 0 : _c2.familyName) || ""}`,
|
|
709
849
|
avatar: ((_d2 = msg.author) == null ? void 0 : _d2.picture) || ""
|
|
710
850
|
},
|
|
711
|
-
image:
|
|
851
|
+
image: primaryImageUrl,
|
|
852
|
+
images: imageUrls,
|
|
712
853
|
sent: msg == null ? void 0 : msg.isDelivered,
|
|
713
854
|
received: msg == null ? void 0 : msg.isRead,
|
|
714
855
|
type: msg == null ? void 0 : msg.type,
|
|
@@ -716,23 +857,74 @@ const ConversationViewComponent = (_a) => {
|
|
|
716
857
|
replies: (_e = msg == null ? void 0 : msg.replies) != null ? _e : [],
|
|
717
858
|
isShowThreadMessage
|
|
718
859
|
};
|
|
719
|
-
});
|
|
720
|
-
|
|
860
|
+
}).filter(Boolean);
|
|
861
|
+
return [...pendingMessages, ...serverMessages];
|
|
862
|
+
}, [channelMessages, pendingUploads, isShowThreadMessage]);
|
|
721
863
|
const renderSend = useCallback((props) => {
|
|
722
864
|
const hasContent = !!props.text || (images == null ? void 0 : images.length) > 0;
|
|
723
865
|
const canSend = (channelId || (rest == null ? void 0 : rest.isCreateNewChannel)) && hasContent;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
866
|
+
const isDisabled = !canSend;
|
|
867
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
868
|
+
Send,
|
|
869
|
+
__spreadProps(__spreadValues({}, props), {
|
|
870
|
+
containerStyle: {
|
|
871
|
+
justifyContent: "center",
|
|
872
|
+
alignItems: "center",
|
|
873
|
+
height: 40,
|
|
874
|
+
width: 44,
|
|
875
|
+
marginRight: 4,
|
|
876
|
+
marginBottom: 0,
|
|
877
|
+
marginLeft: 4
|
|
878
|
+
}
|
|
879
|
+
}),
|
|
880
|
+
/* @__PURE__ */ React__default.createElement(View, { style: {
|
|
881
|
+
padding: 4
|
|
882
|
+
} }, /* @__PURE__ */ React__default.createElement(MaterialCommunityIcons, { name: "send-circle", size: 32, color: isDisabled ? colors.gray[400] : colors.blue[500] }))
|
|
883
|
+
);
|
|
884
|
+
}, [channelId, images, rest == null ? void 0 : rest.isCreateNewChannel, isUploadingImage, loading, isActionSheetVisible]);
|
|
885
|
+
useCallback(() => {
|
|
886
|
+
console.log("Opening action sheet");
|
|
887
|
+
setActionSheetVisible(true);
|
|
888
|
+
}, []);
|
|
889
|
+
useEffect(() => {
|
|
890
|
+
console.log("Action sheet visibility:", isActionSheetVisible);
|
|
891
|
+
if (isActionSheetVisible) {
|
|
892
|
+
setBottomMargin(0);
|
|
893
|
+
}
|
|
894
|
+
}, [isActionSheetVisible]);
|
|
895
|
+
const handleRemoveImage = useCallback((index) => {
|
|
896
|
+
const newImages = [...images];
|
|
897
|
+
newImages.splice(index, 1);
|
|
898
|
+
setImages(newImages);
|
|
899
|
+
if (newImages.length === 0) {
|
|
900
|
+
setSelectedImage("");
|
|
901
|
+
if (textInputRef.current && typeof textInputRef.current.focus === "function") {
|
|
902
|
+
textInputRef.current.focus();
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}, [images]);
|
|
906
|
+
const [textUpdatedInActionSheet, setTextUpdatedInActionSheet] = useState(false);
|
|
907
|
+
useCallback(() => {
|
|
908
|
+
setTextUpdatedInActionSheet(true);
|
|
909
|
+
setActionSheetVisible(false);
|
|
910
|
+
setBottomMargin(0);
|
|
911
|
+
}, []);
|
|
912
|
+
useEffect(() => {
|
|
913
|
+
if (!isActionSheetVisible && textUpdatedInActionSheet) {
|
|
914
|
+
console.log("Action sheet closed with text:", messageText);
|
|
915
|
+
setTextUpdatedInActionSheet(false);
|
|
916
|
+
const currentText = messageText;
|
|
917
|
+
setMessageText("");
|
|
918
|
+
setTimeout(() => {
|
|
919
|
+
setMessageText(currentText);
|
|
920
|
+
}, 50);
|
|
921
|
+
}
|
|
922
|
+
}, [isActionSheetVisible, textUpdatedInActionSheet]);
|
|
923
|
+
useEffect(() => {
|
|
924
|
+
if (isActionSheetVisible && Platform.OS === "ios") {
|
|
925
|
+
console.log("Action sheet is visible, should show the input and options");
|
|
926
|
+
}
|
|
927
|
+
}, [isActionSheetVisible]);
|
|
736
928
|
const handleSend = useCallback(async (messages) => {
|
|
737
929
|
var _a3, _b3, _c2;
|
|
738
930
|
const newMessageText = messages && messages.length > 0 ? ((_a3 = messages[0]) == null ? void 0 : _a3.text) || " " : " ";
|
|
@@ -747,15 +939,24 @@ const ConversationViewComponent = (_a) => {
|
|
|
747
939
|
setMessageText(newMessageText);
|
|
748
940
|
if ((rest == null ? void 0 : rest.isCreateNewChannel) && !channelId) {
|
|
749
941
|
if (((_b3 = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _b3.type) === ((_c2 = RoomType) == null ? void 0 : _c2.Direct)) {
|
|
750
|
-
createDirectChannelImpl();
|
|
942
|
+
await createDirectChannelImpl();
|
|
751
943
|
}
|
|
944
|
+
setIsUploadingImage(false);
|
|
945
|
+
setLoading(false);
|
|
752
946
|
return;
|
|
753
947
|
}
|
|
754
948
|
if (hasImages) {
|
|
755
|
-
sendMessageWithFileImpl();
|
|
949
|
+
await sendMessageWithFileImpl();
|
|
756
950
|
} else {
|
|
757
|
-
sendMessageImpl();
|
|
951
|
+
await sendMessageImpl();
|
|
758
952
|
}
|
|
953
|
+
setIsUploadingImage(false);
|
|
954
|
+
setLoading(false);
|
|
955
|
+
setTimeout(() => {
|
|
956
|
+
if (textInputRef.current) {
|
|
957
|
+
textInputRef.current.focus();
|
|
958
|
+
}
|
|
959
|
+
}, 100);
|
|
759
960
|
}, [channelId, images, rest == null ? void 0 : rest.isCreateNewChannel, (_d = rest == null ? void 0 : rest.newChannelData) == null ? void 0 : _d.type, createDirectChannelImpl, sendMessageWithFileImpl, sendMessageImpl]);
|
|
760
961
|
const renderMessageText = useCallback((props) => {
|
|
761
962
|
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;
|
|
@@ -763,11 +964,14 @@ const ConversationViewComponent = (_a) => {
|
|
|
763
964
|
currentMessage
|
|
764
965
|
} = props;
|
|
765
966
|
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;
|
|
967
|
+
if (!(currentMessage == null ? void 0 : currentMessage.text) || currentMessage.text.trim() === "") {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
766
970
|
if (currentMessage.type === "ALERT") {
|
|
767
971
|
const attachment = (_f = (_e = currentMessage == null ? void 0 : currentMessage.propsConfiguration) == null ? void 0 : _e.contents) == null ? void 0 : _f.attachment;
|
|
768
972
|
let action = "";
|
|
769
973
|
let actionId = "";
|
|
770
|
-
let
|
|
974
|
+
let params2 = {};
|
|
771
975
|
if ((_g = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _g.extraParams) {
|
|
772
976
|
const extraParams = (_h = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _h.extraParams;
|
|
773
977
|
const route = (_i = extraParams == null ? void 0 : extraParams.route) != null ? _i : null;
|
|
@@ -784,15 +988,15 @@ const ConversationViewComponent = (_a) => {
|
|
|
784
988
|
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;
|
|
785
989
|
}
|
|
786
990
|
action = path;
|
|
787
|
-
|
|
991
|
+
params2 = __spreadValues({}, param);
|
|
788
992
|
} else if ((_B = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _B.link) {
|
|
789
993
|
action = CALL_TO_ACTION_PATH;
|
|
790
994
|
actionId = (_C = attachment == null ? void 0 : attachment.callToAction) == null ? void 0 : _C.link.split("/").pop();
|
|
791
|
-
|
|
995
|
+
params2 = {
|
|
792
996
|
reservationId: actionId
|
|
793
997
|
};
|
|
794
998
|
}
|
|
795
|
-
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(Button, { variant: "outline", size: "sm", className: `border-[${CALL_TO_ACTION_BUTTON_BORDERCOLOR}]`, onPress: () => action &&
|
|
999
|
+
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(Button, { variant: "outline", size: "sm", className: `border-[${CALL_TO_ACTION_BUTTON_BORDERCOLOR}] mt-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(MessageText, __spreadProps(__spreadValues({}, props), { textStyle: {
|
|
796
1000
|
left: {
|
|
797
1001
|
marginLeft: 5,
|
|
798
1002
|
color: CALL_TO_ACTION_TEXT_COLOR,
|
|
@@ -863,112 +1067,60 @@ const ConversationViewComponent = (_a) => {
|
|
|
863
1067
|
}, className: "font-bold color-gray-500" }, lastReply ? createdAtText(lastReply == null ? void 0 : lastReply.createdAt) : ""))));
|
|
864
1068
|
}
|
|
865
1069
|
}, [navigation, channelId, role]);
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
Actions,
|
|
869
|
-
__spreadProps(__spreadValues({}, props), {
|
|
870
|
-
options: {
|
|
871
|
-
["Choose from Library"]: onSelectImages,
|
|
872
|
-
["Cancel"]: () => {
|
|
873
|
-
}
|
|
874
|
-
},
|
|
875
|
-
optionTintColor: "#000000",
|
|
876
|
-
cancelButtonIndex: 1,
|
|
877
|
-
icon: () => /* @__PURE__ */ React__default.createElement(Box, { style: {
|
|
878
|
-
width: 32,
|
|
879
|
-
height: 32,
|
|
880
|
-
alignItems: "center",
|
|
881
|
-
justifyContent: "center"
|
|
882
|
-
} }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "image", size: 24, color: colors.blue[500] })),
|
|
883
|
-
containerStyle: {
|
|
884
|
-
alignItems: "center",
|
|
885
|
-
justifyContent: "center",
|
|
886
|
-
marginLeft: 8,
|
|
887
|
-
marginBottom: 0
|
|
888
|
-
}
|
|
889
|
-
})
|
|
890
|
-
);
|
|
891
|
-
};
|
|
892
|
-
const renderAccessory = useCallback(() => {
|
|
893
|
-
var _a3;
|
|
894
|
-
if (!selectedImage) {
|
|
1070
|
+
useCallback(() => {
|
|
1071
|
+
if (!images.length)
|
|
895
1072
|
return null;
|
|
896
|
-
|
|
897
|
-
|
|
1073
|
+
return /* @__PURE__ */ React__default.createElement(Box, { style: {
|
|
1074
|
+
position: "relative",
|
|
898
1075
|
height: 70,
|
|
899
|
-
backgroundColor: "
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
flexDirection: "row",
|
|
903
|
-
alignItems: "center",
|
|
904
|
-
margin: 0,
|
|
905
|
-
padding: 0,
|
|
906
|
-
paddingVertical: 0,
|
|
907
|
-
position: "absolute",
|
|
908
|
-
bottom: Platform.OS === "ios" ? 105 : 95,
|
|
909
|
-
left: 0,
|
|
910
|
-
right: 0,
|
|
911
|
-
zIndex: 1,
|
|
912
|
-
elevation: 3,
|
|
913
|
-
shadowColor: "#000",
|
|
914
|
-
shadowOffset: {
|
|
915
|
-
width: 0,
|
|
916
|
-
height: -1
|
|
917
|
-
},
|
|
918
|
-
shadowOpacity: 0.05,
|
|
919
|
-
shadowRadius: 2
|
|
920
|
-
} }, /* @__PURE__ */ React__default.createElement(View, { style: {
|
|
921
|
-
flex: 1,
|
|
1076
|
+
backgroundColor: "transparent",
|
|
1077
|
+
justifyContent: "center"
|
|
1078
|
+
} }, /* @__PURE__ */ React__default.createElement(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, style: {
|
|
922
1079
|
flexDirection: "row",
|
|
923
|
-
alignItems: "center",
|
|
924
1080
|
paddingLeft: 15,
|
|
925
1081
|
paddingRight: 5
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
height:
|
|
1082
|
+
}, contentContainerStyle: {
|
|
1083
|
+
alignItems: "center",
|
|
1084
|
+
height: "100%"
|
|
1085
|
+
} }, images.map((img, index) => /* @__PURE__ */ React__default.createElement(View, { key: `image-preview-${index}`, style: {
|
|
1086
|
+
width: 40,
|
|
1087
|
+
height: 40,
|
|
929
1088
|
marginRight: 15,
|
|
930
1089
|
borderRadius: 4,
|
|
931
1090
|
backgroundColor: colors.gray[200],
|
|
932
1091
|
overflow: "hidden",
|
|
933
1092
|
borderWidth: 1,
|
|
934
|
-
borderColor: "#e0e0e0"
|
|
935
|
-
|
|
936
|
-
|
|
1093
|
+
borderColor: "#e0e0e0",
|
|
1094
|
+
position: "relative",
|
|
1095
|
+
zIndex: 10
|
|
1096
|
+
} }, /* @__PURE__ */ React__default.createElement(Image, { source: {
|
|
1097
|
+
uri: img.uri || img.url
|
|
937
1098
|
}, style: {
|
|
938
1099
|
width: "100%",
|
|
939
1100
|
height: "100%"
|
|
940
|
-
},
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
flex: 1
|
|
951
|
-
} }, /* @__PURE__ */ React__default.createElement(Text, { style: {
|
|
952
|
-
fontSize: 14,
|
|
953
|
-
fontWeight: "400",
|
|
954
|
-
color: colors.gray[800]
|
|
955
|
-
} }, ((_a3 = images[0]) == null ? void 0 : _a3.fileName) || "image_" + new Date().getTime() + ".jpg"), /* @__PURE__ */ React__default.createElement(Text, { style: {
|
|
956
|
-
fontSize: 12,
|
|
957
|
-
color: colors.gray[500],
|
|
958
|
-
marginTop: 2
|
|
959
|
-
} }, loading ? "Preparing..." : "Ready to send")), /* @__PURE__ */ React__default.createElement(TouchableHighlight, { underlayColor: "rgba(0,0,0,0.1)", onPress: () => {
|
|
960
|
-
setSelectedImage("");
|
|
961
|
-
setImages([]);
|
|
1101
|
+
}, alt: `selected image ${index + 1}` }), /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: () => {
|
|
1102
|
+
const newImages = [...images];
|
|
1103
|
+
newImages.splice(index, 1);
|
|
1104
|
+
setImages(newImages);
|
|
1105
|
+
if (newImages.length === 0) {
|
|
1106
|
+
setSelectedImage("");
|
|
1107
|
+
if (textInputRef.current && typeof textInputRef.current.focus === "function") {
|
|
1108
|
+
textInputRef.current.focus();
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
962
1111
|
}, style: {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1112
|
+
position: "absolute",
|
|
1113
|
+
top: -1,
|
|
1114
|
+
right: -1,
|
|
1115
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
1116
|
+
borderRadius: 12,
|
|
1117
|
+
width: 20,
|
|
1118
|
+
height: 20,
|
|
967
1119
|
alignItems: "center",
|
|
968
1120
|
justifyContent: "center",
|
|
969
|
-
|
|
970
|
-
} }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size:
|
|
971
|
-
}, [
|
|
1121
|
+
zIndex: 9999
|
|
1122
|
+
} }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size: 16, color: "white" }))))));
|
|
1123
|
+
}, [images]);
|
|
972
1124
|
const setImageViewerObject = (obj, v) => {
|
|
973
1125
|
setImageObject(obj);
|
|
974
1126
|
setImageViewer(v);
|
|
@@ -989,36 +1141,8 @@ const ConversationViewComponent = (_a) => {
|
|
|
989
1141
|
}, alt: "image" });
|
|
990
1142
|
}, [imageObject]);
|
|
991
1143
|
const renderMessage = useCallback((props) => {
|
|
992
|
-
const isUploading = props.currentMessage._id === uploadingMessageId && loading;
|
|
993
|
-
if (isUploading && props.currentMessage.image) {
|
|
994
|
-
return /* @__PURE__ */ React__default.createElement(View, { style: {
|
|
995
|
-
padding: 10,
|
|
996
|
-
marginBottom: 10,
|
|
997
|
-
marginRight: 10,
|
|
998
|
-
alignSelf: "flex-end",
|
|
999
|
-
borderRadius: 15,
|
|
1000
|
-
backgroundColor: colors.gray[100],
|
|
1001
|
-
maxWidth: "80%"
|
|
1002
|
-
} }, props.currentMessage.text && props.currentMessage.text.trim() !== "" && /* @__PURE__ */ React__default.createElement(Box, { style: {
|
|
1003
|
-
height: 15,
|
|
1004
|
-
borderRadius: 4,
|
|
1005
|
-
backgroundColor: colors.gray[200],
|
|
1006
|
-
overflow: "hidden",
|
|
1007
|
-
marginBottom: 8
|
|
1008
|
-
} }, /* @__PURE__ */ React__default.createElement(Skeleton, { variant: "rounded", style: {
|
|
1009
|
-
flex: 1
|
|
1010
|
-
} })), /* @__PURE__ */ React__default.createElement(Box, { style: {
|
|
1011
|
-
height: 150,
|
|
1012
|
-
width: 150,
|
|
1013
|
-
borderRadius: 10,
|
|
1014
|
-
backgroundColor: colors.gray[200],
|
|
1015
|
-
overflow: "hidden"
|
|
1016
|
-
} }, /* @__PURE__ */ React__default.createElement(Skeleton, { variant: "rounded", style: {
|
|
1017
|
-
flex: 1
|
|
1018
|
-
} })));
|
|
1019
|
-
}
|
|
1020
1144
|
return /* @__PURE__ */ React__default.createElement(Message, __spreadProps(__spreadValues({}, props), { isShowImageViewer, setImageViewer: setImageViewerObject }));
|
|
1021
|
-
}, [isShowImageViewer
|
|
1145
|
+
}, [isShowImageViewer]);
|
|
1022
1146
|
let onScroll = false;
|
|
1023
1147
|
const onMomentumScrollBegin = async ({
|
|
1024
1148
|
nativeEvent
|
|
@@ -1041,30 +1165,94 @@ const ConversationViewComponent = (_a) => {
|
|
|
1041
1165
|
marginTop: 10
|
|
1042
1166
|
} }, /* @__PURE__ */ React__default.createElement(Spinner, { size: "small", color: "#3b82f6" })) : null;
|
|
1043
1167
|
}, [loadingOldMessages]);
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1168
|
+
const [inputToolbarHeight, setInputToolbarHeight] = useState(30);
|
|
1169
|
+
useCallback((props) => /* @__PURE__ */ React__default.createElement(View, { style: {
|
|
1170
|
+
backgroundColor: "#fff",
|
|
1171
|
+
paddingBottom: 4,
|
|
1172
|
+
paddingTop: 4
|
|
1173
|
+
} }, /* @__PURE__ */ React__default.createElement(View, { style: {
|
|
1174
|
+
flexDirection: "row",
|
|
1175
|
+
alignItems: "center",
|
|
1176
|
+
minHeight: 44,
|
|
1177
|
+
maxHeight: 56,
|
|
1178
|
+
backgroundColor: "#fff",
|
|
1179
|
+
borderRadius: 22,
|
|
1180
|
+
marginHorizontal: 8,
|
|
1181
|
+
paddingHorizontal: 8,
|
|
1182
|
+
borderTopWidth: 1,
|
|
1183
|
+
borderTopColor: "#e0e0e0"
|
|
1184
|
+
} }, /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: onSelectImages, style: {
|
|
1185
|
+
width: 32,
|
|
1186
|
+
height: 32,
|
|
1187
|
+
borderRadius: 16,
|
|
1188
|
+
backgroundColor: "#fff",
|
|
1189
|
+
alignItems: "center",
|
|
1190
|
+
justifyContent: "center",
|
|
1191
|
+
marginRight: 8
|
|
1192
|
+
} }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { name: "add", size: 24, color: "#888" })), /* @__PURE__ */ React__default.createElement(TextInput, { ref: textInputRef, style: {
|
|
1193
|
+
flex: 1,
|
|
1194
|
+
maxHeight: 44,
|
|
1195
|
+
backgroundColor: "transparent",
|
|
1196
|
+
color: "#444",
|
|
1197
|
+
paddingHorizontal: 8,
|
|
1198
|
+
paddingVertical: 0,
|
|
1199
|
+
alignSelf: "center",
|
|
1200
|
+
textAlignVertical: "center"
|
|
1201
|
+
}, placeholder: "Jot something down", placeholderTextColor: colors.gray[400], multiline: true, value: messageText, onChangeText: setMessageText }), /* @__PURE__ */ React__default.createElement(
|
|
1202
|
+
TouchableOpacity,
|
|
1203
|
+
{
|
|
1204
|
+
onPress: () => handleSend([{
|
|
1205
|
+
text: messageText
|
|
1206
|
+
}]),
|
|
1207
|
+
disabled: false,
|
|
1208
|
+
style: {
|
|
1209
|
+
marginLeft: 8,
|
|
1210
|
+
opacity: !messageText.trim() && images.length === 0 ? 0.5 : 1
|
|
1211
|
+
}
|
|
1212
|
+
},
|
|
1213
|
+
/* @__PURE__ */ React__default.createElement(
|
|
1214
|
+
MaterialCommunityIcons,
|
|
1215
|
+
{
|
|
1216
|
+
name: "send-circle",
|
|
1217
|
+
size: 32,
|
|
1218
|
+
color: !messageText.trim() && images.length === 0 ? colors.gray[400] : colors.blue[500]
|
|
1219
|
+
}
|
|
1220
|
+
)
|
|
1221
|
+
)), images && images.length > 0 && /* @__PURE__ */ React__default.createElement(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, style: {
|
|
1222
|
+
marginTop: 4,
|
|
1223
|
+
marginLeft: 8
|
|
1224
|
+
} }, images.map((img, index) => /* @__PURE__ */ React__default.createElement(View, { key: `image-preview-${index}`, style: {
|
|
1225
|
+
width: 48,
|
|
1226
|
+
height: 48,
|
|
1227
|
+
marginRight: 8,
|
|
1228
|
+
borderRadius: 6,
|
|
1229
|
+
overflow: "hidden",
|
|
1230
|
+
position: "relative",
|
|
1231
|
+
backgroundColor: colors.gray[200]
|
|
1232
|
+
} }, /* @__PURE__ */ React__default.createElement(Image, { source: {
|
|
1233
|
+
uri: img.uri || img.url
|
|
1234
|
+
}, style: {
|
|
1235
|
+
width: "100%",
|
|
1236
|
+
height: "100%"
|
|
1237
|
+
}, alt: `selected image ${index + 1}` }), /* @__PURE__ */ React__default.createElement(TouchableOpacity, { onPress: () => {
|
|
1238
|
+
handleRemoveImage(index);
|
|
1239
|
+
}, style: {
|
|
1240
|
+
position: "absolute",
|
|
1241
|
+
top: 2,
|
|
1242
|
+
right: 2,
|
|
1243
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
1244
|
+
borderRadius: 10,
|
|
1245
|
+
width: 20,
|
|
1246
|
+
height: 20,
|
|
1247
|
+
alignItems: "center",
|
|
1248
|
+
justifyContent: "center"
|
|
1249
|
+
} }, /* @__PURE__ */ React__default.createElement(Ionicons, { name: "close", size: 14, color: "white" })))))), [onSelectImages, messageText, images, isUploadingImage, loading, handleSend, handleRemoveImage]);
|
|
1058
1250
|
const imageViewerModal = useMemo(() => /* @__PURE__ */ React__default.createElement(ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent }), [isShowImageViewer, modalContent]);
|
|
1059
|
-
const subscriptionHandler = useMemo(() => /* @__PURE__ */ React__default.createElement(SubscriptionHandler, { channelId: channelId == null ? void 0 : channelId.toString(), subscribeToNewMessages: () => subscribeToMore({
|
|
1060
|
-
document: OnChatMessageAddedDocument,
|
|
1061
|
-
variables: {
|
|
1062
|
-
channelId: channelId == null ? void 0 : channelId.toString()
|
|
1063
|
-
}
|
|
1064
|
-
}) }), [channelId, subscribeToMore, auth == null ? void 0 : auth.id]);
|
|
1065
1251
|
const renderChatFooter = useCallback(() => {
|
|
1066
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, imageViewerModal,
|
|
1067
|
-
|
|
1252
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, imageViewerModal, /* @__PURE__ */ React__default.createElement(SubscriptionHandler, { subscribeToMore: subscribe, document: CHAT_MESSAGE_ADDED, variables: {
|
|
1253
|
+
channelId: channelId == null ? void 0 : channelId.toString()
|
|
1254
|
+
}, updateQuery: void 0 }));
|
|
1255
|
+
}, [imageViewerModal, subscribe]);
|
|
1068
1256
|
const listViewProps = useMemo(() => ({
|
|
1069
1257
|
onEndReached,
|
|
1070
1258
|
onEndReachedThreshold: 0.5,
|
|
@@ -1086,98 +1274,57 @@ const ConversationViewComponent = (_a) => {
|
|
|
1086
1274
|
}
|
|
1087
1275
|
}
|
|
1088
1276
|
}, []);
|
|
1089
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
1277
|
+
return /* @__PURE__ */ React__default.createElement(KeyboardAvoidingView, { style: {
|
|
1278
|
+
flex: 1,
|
|
1279
|
+
justifyContent: "flex-end"
|
|
1280
|
+
}, behavior: Platform.OS === "ios" ? "padding" : "height", keyboardVerticalOffset: Platform.OS === "ios" ? 64 : 0 }, /* @__PURE__ */ React__default.createElement(View, { style: {
|
|
1090
1281
|
flex: 1,
|
|
1091
1282
|
backgroundColor: "white",
|
|
1092
|
-
position: "relative"
|
|
1093
|
-
|
|
1094
|
-
|
|
1283
|
+
position: "relative",
|
|
1284
|
+
marginBottom: images.length > 0 ? 5 : bottomMargin
|
|
1285
|
+
} }, 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(
|
|
1286
|
+
GiftedChatInboxComponent,
|
|
1095
1287
|
{
|
|
1096
1288
|
ref: messageRootListRef,
|
|
1289
|
+
errorMessage,
|
|
1290
|
+
images,
|
|
1291
|
+
onSelectImages,
|
|
1292
|
+
onRemoveImage: handleRemoveImage,
|
|
1293
|
+
selectedImage,
|
|
1294
|
+
setSelectedImage,
|
|
1295
|
+
isUploadingImage,
|
|
1296
|
+
loading,
|
|
1097
1297
|
wrapInSafeArea: true,
|
|
1098
1298
|
renderLoading: () => /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }),
|
|
1099
1299
|
messages: messageList,
|
|
1300
|
+
renderAvatar: null,
|
|
1301
|
+
showUserAvatar: false,
|
|
1100
1302
|
listViewProps: __spreadProps(__spreadValues({}, listViewProps), {
|
|
1101
1303
|
contentContainerStyle: {
|
|
1102
|
-
paddingBottom:
|
|
1304
|
+
paddingBottom: inputToolbarHeight
|
|
1103
1305
|
}
|
|
1104
1306
|
}),
|
|
1105
1307
|
onSend: handleSend,
|
|
1106
1308
|
text: messageText || " ",
|
|
1107
|
-
onInputTextChanged: (text) =>
|
|
1108
|
-
|
|
1309
|
+
onInputTextChanged: (text) => {
|
|
1310
|
+
setMessageText(text);
|
|
1311
|
+
},
|
|
1312
|
+
renderFooter: () => isUploadingImage ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : null,
|
|
1109
1313
|
scrollToBottom: true,
|
|
1110
1314
|
user: {
|
|
1111
1315
|
_id: (auth == null ? void 0 : auth.id) || ""
|
|
1112
1316
|
},
|
|
1113
|
-
isTyping: false,
|
|
1114
|
-
alwaysShowSend: true,
|
|
1115
1317
|
renderSend,
|
|
1116
1318
|
renderMessageText,
|
|
1117
|
-
renderInputToolbar,
|
|
1118
|
-
minInputToolbarHeight: 50,
|
|
1119
|
-
renderActions: channelId && renderActions,
|
|
1120
1319
|
renderMessage,
|
|
1121
1320
|
renderChatFooter,
|
|
1122
1321
|
renderLoadEarlier,
|
|
1123
1322
|
loadEarlier: totalCount > channelMessages.length,
|
|
1124
1323
|
isLoadingEarlier: loadingOldMessages,
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
style: {
|
|
1128
|
-
borderWidth: 1,
|
|
1129
|
-
borderColor: colors.gray[300],
|
|
1130
|
-
backgroundColor: "#f8f8f8",
|
|
1131
|
-
borderRadius: 20,
|
|
1132
|
-
minHeight: 36,
|
|
1133
|
-
maxHeight: 80,
|
|
1134
|
-
color: "#000",
|
|
1135
|
-
padding: 8,
|
|
1136
|
-
paddingHorizontal: 15,
|
|
1137
|
-
fontSize: 16,
|
|
1138
|
-
flex: 1,
|
|
1139
|
-
marginVertical: 2,
|
|
1140
|
-
marginBottom: 0
|
|
1141
|
-
},
|
|
1142
|
-
multiline: true,
|
|
1143
|
-
returnKeyType: "default",
|
|
1144
|
-
enablesReturnKeyAutomatically: true,
|
|
1145
|
-
placeholderTextColor: colors.gray[400]
|
|
1146
|
-
},
|
|
1147
|
-
minComposerHeight: 36,
|
|
1148
|
-
maxComposerHeight: 100,
|
|
1149
|
-
isKeyboardInternallyHandled: true,
|
|
1150
|
-
placeholder: "Type a message...",
|
|
1151
|
-
lightboxProps: {
|
|
1152
|
-
underlayColor: "transparent",
|
|
1153
|
-
springConfig: {
|
|
1154
|
-
tension: 9e4,
|
|
1155
|
-
friction: 9e4
|
|
1156
|
-
},
|
|
1157
|
-
disabled: true
|
|
1158
|
-
},
|
|
1159
|
-
infiniteScroll: false
|
|
1160
|
-
}
|
|
1161
|
-
));
|
|
1162
|
-
};
|
|
1163
|
-
const SubscriptionHandler = ({
|
|
1164
|
-
subscribeToNewMessages,
|
|
1165
|
-
channelId
|
|
1166
|
-
}) => {
|
|
1167
|
-
const channelIdRef = useRef(channelId);
|
|
1168
|
-
useEffect(() => {
|
|
1169
|
-
if (!channelId) {
|
|
1170
|
-
return;
|
|
1324
|
+
placeholder: "Jot something down",
|
|
1325
|
+
infiniteScroll: true
|
|
1171
1326
|
}
|
|
1172
|
-
|
|
1173
|
-
channelIdRef.current = channelId;
|
|
1174
|
-
return () => {
|
|
1175
|
-
if (unsubscribe && typeof unsubscribe === "function") {
|
|
1176
|
-
unsubscribe();
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
}, [channelId, subscribeToNewMessages]);
|
|
1180
|
-
return null;
|
|
1327
|
+
)));
|
|
1181
1328
|
};
|
|
1182
1329
|
const ConversationView = React__default.memo(ConversationViewComponent, (prevProps, nextProps) => {
|
|
1183
1330
|
return prevProps.channelId === nextProps.channelId && prevProps.role === nextProps.role && prevProps.isShowThreadMessage === nextProps.isShowThreadMessage;
|