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