@messenger-box/platform-mobile 0.0.1-alpha.362 → 0.0.1-alpha.365

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/index.js +2281 -553
  3. package/lib/index.js.map +1 -1
  4. package/lib/screens/inbox/DialogThreadMessages.d.ts +7 -0
  5. package/lib/screens/inbox/DialogThreads.d.ts +6 -0
  6. package/lib/screens/inbox/components/SupportServiceDialogsListItem.d.ts +21 -0
  7. package/lib/screens/inbox/components/ThreadsViewItem.d.ts +18 -0
  8. package/lib/screens/inbox/config/config.d.ts +2 -0
  9. package/lib/screens/inbox/containers/Dialogs.d.ts +1 -0
  10. package/lib/screens/inbox/containers/SupportServiceDialogs.d.ts +6 -0
  11. package/lib/screens/inbox/containers/ThreadConversationView.d.ts +11 -0
  12. package/lib/screens/inbox/containers/ThreadsView.d.ts +8 -0
  13. package/lib/screens/index.d.ts +2 -0
  14. package/package.json +4 -4
  15. package/src/navigation/InboxNavigation.tsx +63 -0
  16. package/src/screens/inbox/DialogThreadMessages.tsx +90 -0
  17. package/src/screens/inbox/DialogThreads.tsx +107 -0
  18. package/src/screens/inbox/Inbox.tsx +5 -3
  19. package/src/screens/inbox/components/DialogsListItem.tsx +7 -3
  20. package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +5 -5
  21. package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +295 -0
  22. package/src/screens/inbox/components/ThreadsViewItem.tsx +236 -0
  23. package/src/screens/inbox/config/config.ts +4 -0
  24. package/src/screens/inbox/containers/ConversationView.tsx +440 -156
  25. package/src/screens/inbox/containers/Dialogs.tsx +2 -1
  26. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +119 -0
  27. package/src/screens/inbox/containers/ThreadConversationView.tsx +764 -0
  28. package/src/screens/inbox/containers/ThreadsView.tsx +205 -0
  29. package/src/screens/index.ts +3 -1
package/lib/index.js CHANGED
@@ -90,6 +90,8 @@ exports.inboxFeature = void 0;
90
90
  const React = __importStar(__webpack_require__(/*! react */ "react"));
91
91
  const client_react_1 = __webpack_require__(/*! @common-stack/client-react */ "@common-stack/client-react");
92
92
  const DialogMessages_1 = __webpack_require__(/*! ../screens/inbox/DialogMessages */ "./src/screens/inbox/DialogMessages.tsx");
93
+ const DialogThreads_1 = __webpack_require__(/*! ../screens/inbox/DialogThreads */ "./src/screens/inbox/DialogThreads.tsx");
94
+ const DialogThreadMessages_1 = __webpack_require__(/*! ../screens/inbox/DialogThreadMessages */ "./src/screens/inbox/DialogThreadMessages.tsx");
93
95
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
94
96
  const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
95
97
  const inboxConfig = {
@@ -111,6 +113,48 @@ const inboxConfig = {
111
113
  },
112
114
  },
113
115
  },
116
+ ['//thread']: {
117
+ exact: true,
118
+ name: 'Thread',
119
+ props: {
120
+ initialParams: { channelId: null, postParentId: null, role: null },
121
+ component: (props) => {
122
+ var _a, _b, _c, _d, _e, _f;
123
+ return (React.createElement(DialogThreads_1.DialogThreads, Object.assign({}, props, { channelId: (_b = (_a = props === null || props === void 0 ? void 0 : props.route) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.channelId, postParentId: (_d = (_c = props === null || props === void 0 ? void 0 : props.route) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.postParentId, role: (_f = (_e = props === null || props === void 0 ? void 0 : props.route) === null || _e === void 0 ? void 0 : _e.params) === null || _f === void 0 ? void 0 : _f.role })));
124
+ },
125
+ options: ({ navigation }) => {
126
+ return {
127
+ headerShown: true,
128
+ title: 'Thread',
129
+ headerBackTitleVisible: false,
130
+ gestureEnabled: false,
131
+ swipeEnabled: false,
132
+ headerLeft: (props) => (React.createElement(native_base_1.IconButton, { onPress: () => navigation.goBack(), icon: React.createElement(native_base_1.Icon, { size: 'lg', as: vector_icons_1.MaterialIcons, name: "arrow-back-ios", color: 'black' }) })),
133
+ };
134
+ },
135
+ },
136
+ },
137
+ ['//threadmessage']: {
138
+ exact: true,
139
+ name: 'ThreadMessage',
140
+ props: {
141
+ initialParams: { channelId: null, postParentId: null, isPostParentIdThread: null, role: null },
142
+ component: (props) => {
143
+ var _a, _b, _c, _d, _e, _f, _g, _h;
144
+ return (React.createElement(DialogThreadMessages_1.DialogThreadMessages, Object.assign({}, props, { channelId: (_b = (_a = props === null || props === void 0 ? void 0 : props.route) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.channelId, postParentId: (_d = (_c = props === null || props === void 0 ? void 0 : props.route) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.postParentId, isPostParentIdThread: (_f = (_e = props === null || props === void 0 ? void 0 : props.route) === null || _e === void 0 ? void 0 : _e.params) === null || _f === void 0 ? void 0 : _f.isPostParentIdThread, role: (_h = (_g = props === null || props === void 0 ? void 0 : props.route) === null || _g === void 0 ? void 0 : _g.params) === null || _h === void 0 ? void 0 : _h.role })));
145
+ },
146
+ options: ({ navigation }) => {
147
+ return {
148
+ headerShown: true,
149
+ title: 'Inbox',
150
+ headerBackTitleVisible: false,
151
+ gestureEnabled: false,
152
+ swipeEnabled: false,
153
+ headerLeft: (props) => (React.createElement(native_base_1.IconButton, { onPress: () => navigation.goBack(), icon: React.createElement(native_base_1.Icon, { size: 'lg', as: vector_icons_1.MaterialIcons, name: "arrow-back-ios", color: 'black' }) })),
154
+ };
155
+ },
156
+ },
157
+ },
114
158
  };
115
159
  exports.inboxFeature = new client_react_1.Feature({
116
160
  routeConfig: inboxConfig,
@@ -190,6 +234,214 @@ function DialogMessages({ channelId }) {
190
234
  exports.DialogMessages = DialogMessages;
191
235
 
192
236
 
237
+ /***/ }),
238
+
239
+ /***/ "./src/screens/inbox/DialogThreadMessages.tsx":
240
+ /*!****************************************************!*\
241
+ !*** ./src/screens/inbox/DialogThreadMessages.tsx ***!
242
+ \****************************************************/
243
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
244
+
245
+
246
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
247
+ if (k2 === undefined) k2 = k;
248
+ var desc = Object.getOwnPropertyDescriptor(m, k);
249
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
250
+ desc = { enumerable: true, get: function() { return m[k]; } };
251
+ }
252
+ Object.defineProperty(o, k2, desc);
253
+ }) : (function(o, m, k, k2) {
254
+ if (k2 === undefined) k2 = k;
255
+ o[k2] = m[k];
256
+ }));
257
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
258
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
259
+ }) : function(o, v) {
260
+ o["default"] = v;
261
+ });
262
+ var __importStar = (this && this.__importStar) || function (mod) {
263
+ if (mod && mod.__esModule) return mod;
264
+ var result = {};
265
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
266
+ __setModuleDefault(result, mod);
267
+ return result;
268
+ };
269
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
270
+ exports.DialogThreadMessages = void 0;
271
+ const React = __importStar(__webpack_require__(/*! react */ "react"));
272
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
273
+ const ThreadConversationView_1 = __webpack_require__(/*! ./containers/ThreadConversationView */ "./src/screens/inbox/containers/ThreadConversationView.tsx");
274
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
275
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
276
+ function DialogThreadMessages({ channelId, postParentId, isPostParentIdThread, role }) {
277
+ const { data, loading: channelLoading, refetch, } = (0, platform_client_1.useViewChannelDetailQuery)({
278
+ variables: {
279
+ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
280
+ },
281
+ });
282
+ const [sendThreadMessage] = (0, platform_client_1.useSendThreadMessageMutation)();
283
+ const [loading, setLoading] = React.useState(true);
284
+ const [channel, setChannel] = React.useState(null);
285
+ const [parentId, setParentId] = React.useState(postParentId);
286
+ const refetchChannelDetail = React.useCallback((id) => {
287
+ return refetch({ id: id === null || id === void 0 ? void 0 : id.toString() });
288
+ }, [channelId]);
289
+ (0, native_1.useFocusEffect)(React.useCallback(() => {
290
+ // Do something when the screen is focused
291
+ refetchChannelDetail(channelId);
292
+ return () => { };
293
+ }, []));
294
+ React.useEffect(() => {
295
+ setParentId(postParentId);
296
+ }, [postParentId]);
297
+ React.useEffect(() => {
298
+ if (data === null || data === void 0 ? void 0 : data.viewChannelDetail)
299
+ setChannel(data === null || data === void 0 ? void 0 : data.viewChannelDetail);
300
+ }, [data]);
301
+ React.useEffect(() => {
302
+ async function sendInitialMessage(channel) {
303
+ var _a;
304
+ const content = `Welcome to ${channel === null || channel === void 0 ? void 0 : channel.title}`;
305
+ const createdBy = (_a = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _a === void 0 ? void 0 : _a.id;
306
+ await sendThreadMessage({
307
+ variables: {
308
+ channelId,
309
+ threadMessageInput: {
310
+ content,
311
+ role,
312
+ },
313
+ responderId: createdBy,
314
+ },
315
+ update: (cache, { data, errors }) => {
316
+ var _a, _b;
317
+ if (!data) {
318
+ return;
319
+ }
320
+ setParentId((_b = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage) === null || _b === void 0 ? void 0 : _b.id);
321
+ },
322
+ });
323
+ }
324
+ if ((!parentId || parentId == 0) && channel) {
325
+ sendInitialMessage(channel);
326
+ }
327
+ if (parentId)
328
+ setLoading(false);
329
+ }, [parentId, channel]);
330
+ return (React.createElement(native_base_1.Box, { bg: 'white', flex: 1 }, loading && !parentId ? (React.createElement(native_base_1.Spinner, null)) : (React.createElement(ThreadConversationView_1.ThreadConversationView, { channelId: channelId, postParentId: parentId, isPostParentIdThread: isPostParentIdThread, role: role }))));
331
+ }
332
+ exports.DialogThreadMessages = DialogThreadMessages;
333
+
334
+
335
+ /***/ }),
336
+
337
+ /***/ "./src/screens/inbox/DialogThreads.tsx":
338
+ /*!*********************************************!*\
339
+ !*** ./src/screens/inbox/DialogThreads.tsx ***!
340
+ \*********************************************/
341
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
342
+
343
+
344
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
345
+ if (k2 === undefined) k2 = k;
346
+ var desc = Object.getOwnPropertyDescriptor(m, k);
347
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
348
+ desc = { enumerable: true, get: function() { return m[k]; } };
349
+ }
350
+ Object.defineProperty(o, k2, desc);
351
+ }) : (function(o, m, k, k2) {
352
+ if (k2 === undefined) k2 = k;
353
+ o[k2] = m[k];
354
+ }));
355
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
356
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
357
+ }) : function(o, v) {
358
+ o["default"] = v;
359
+ });
360
+ var __importStar = (this && this.__importStar) || function (mod) {
361
+ if (mod && mod.__esModule) return mod;
362
+ var result = {};
363
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
364
+ __setModuleDefault(result, mod);
365
+ return result;
366
+ };
367
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
368
+ exports.DialogThreads = void 0;
369
+ const React = __importStar(__webpack_require__(/*! react */ "react"));
370
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
371
+ const ThreadsView_1 = __webpack_require__(/*! ./containers/ThreadsView */ "./src/screens/inbox/containers/ThreadsView.tsx");
372
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
373
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
374
+ function DialogThreads({ channelId, postParentId, role }) {
375
+ const { data, loading: channelLoading, refetch, } = (0, platform_client_1.useViewChannelDetailQuery)({
376
+ variables: {
377
+ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
378
+ },
379
+ });
380
+ const channelsDetail = React.useMemo(() => {
381
+ if (!(data === null || data === void 0 ? void 0 : data.viewChannelDetail))
382
+ return null;
383
+ return data === null || data === void 0 ? void 0 : data.viewChannelDetail;
384
+ }, [data]);
385
+ const refetchChannelDetail = React.useCallback((id) => {
386
+ return refetch({ id: id === null || id === void 0 ? void 0 : id.toString() });
387
+ }, [channelId]);
388
+ (0, native_1.useFocusEffect)(React.useCallback(() => {
389
+ // Do something when the screen is focused
390
+ refetchChannelDetail(channelId);
391
+ return () => { };
392
+ }, []));
393
+ return (
394
+ // <Box bg={'white'} flex={1} pt={5}>
395
+ React.createElement(React.Fragment, null, channelLoading ? (React.createElement(native_base_1.Spinner, null)) : (React.createElement(React.Fragment, null,
396
+ React.createElement(native_base_1.Box, { flex: 1, _dark: {
397
+ borderColor: 'coolGray.600',
398
+ backgroundColor: 'gray.700',
399
+ }, _light: {
400
+ backgroundColor: 'gray.50',
401
+ } },
402
+ React.createElement(ThreadsView_1.ThreadsView, { channelId: channelId, role: role, channelsDetail: channelsDetail, refetchChannelDetail: refetchChannelDetail }))))));
403
+ // return (
404
+ // // <Box bg={'white'} flex={1} pt={5}>
405
+ // <>
406
+ // {channelLoading ? (
407
+ // <Spinner />
408
+ // ) : (
409
+ // <>
410
+ // {postParentId || postParentId == 0 ? (
411
+ // <Box bg={'white'} flex={1}>
412
+ // <ThreadConversationView
413
+ // channelId={channelId}
414
+ // postParentId={postParentId}
415
+ // channelsDetail={channelsDetail}
416
+ // refetchChannelDetail={refetchChannelDetail}
417
+ // />
418
+ // </Box>
419
+ // ) : (
420
+ // <Box
421
+ // flex={1}
422
+ // _dark={{
423
+ // borderColor: 'coolGray.600',
424
+ // backgroundColor: 'gray.700',
425
+ // }}
426
+ // _light={{
427
+ // backgroundColor: 'gray.50',
428
+ // }}
429
+ // >
430
+ // <ThreadsView
431
+ // channelId={channelId}
432
+ // channelsDetail={channelsDetail}
433
+ // refetchChannelDetail={refetchChannelDetail}
434
+ // />
435
+ // </Box>
436
+ // )}
437
+ // </>
438
+ // )}
439
+ // </>
440
+ // );
441
+ }
442
+ exports.DialogThreads = DialogThreads;
443
+
444
+
193
445
  /***/ }),
194
446
 
195
447
  /***/ "./src/screens/inbox/Inbox.tsx":
@@ -227,9 +479,11 @@ exports.Inbox = void 0;
227
479
  const React = __importStar(__webpack_require__(/*! react */ "react"));
228
480
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
229
481
  const Dialogs_1 = __webpack_require__(/*! ./containers/Dialogs */ "./src/screens/inbox/containers/Dialogs.tsx");
482
+ const SupportServiceDialogs_1 = __webpack_require__(/*! ./containers/SupportServiceDialogs */ "./src/screens/inbox/containers/SupportServiceDialogs.tsx");
230
483
  const Inbox = (props) => {
231
- const { channelFilters, channelRole } = props;
484
+ const { channelFilters, channelRole, supportServices } = props;
232
485
  return (React.createElement(native_base_1.Box, { bg: 'white', flex: 1 },
486
+ supportServices && React.createElement(SupportServiceDialogs_1.SupportServiceDialogs, Object.assign({ channelFilters: channelFilters, channelRole: channelRole }, props)),
233
487
  React.createElement(Dialogs_1.Dialogs, Object.assign({ channelFilters: channelFilters, channelRole: channelRole }, props))));
234
488
  };
235
489
  exports.Inbox = Inbox;
@@ -452,17 +706,19 @@ const DialogsListItemComponent = function DialogsListItem({ currentUser,
452
706
  // users,
453
707
  selectedChannelId, channel, onOpen, }) {
454
708
  var _a, _b, _c;
709
+ const parentId = null;
455
710
  const { data: messagesQuery, loading: messageLoading, refetch: refetchMessages, } = (0, platform_client_1.useMessagesQuery)({
456
711
  variables: {
457
712
  channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(),
458
- limit: 1,
713
+ parentId: parentId,
714
+ limit: 25,
459
715
  },
460
716
  fetchPolicy: 'cache-and-network',
461
717
  });
462
718
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
463
719
  var _a;
464
720
  // Do something when the screen is focused
465
- refetchMessages({ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(), limit: 1 });
721
+ refetchMessages({ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(), parentId: parentId, limit: 25 });
466
722
  return () => {
467
723
  // Do something when the screen is unfocused
468
724
  // Useful for cleanup functions
@@ -474,7 +730,9 @@ selectedChannelId, channel, onOpen, }) {
474
730
  return null;
475
731
  }
476
732
  const { data } = messagesQuery.messages;
477
- return data[data.length - 1];
733
+ const filteredData = data === null || data === void 0 ? void 0 : data.filter((p) => (p === null || p === void 0 ? void 0 : p.message) !== '');
734
+ return filteredData[0];
735
+ //return data[data.length - 1];
478
736
  }, [messagesQuery]);
479
737
  const channelMembers = (0, react_1.useMemo)(() => {
480
738
  var _a, _b, _c;
@@ -691,7 +949,7 @@ class Bubble extends react_1.default.Component {
691
949
  return this.props.renderMessageImage(messageImageProps);
692
950
  }
693
951
  const { image, _id } = messageImageProps === null || messageImageProps === void 0 ? void 0 : messageImageProps.currentMessage;
694
- return (react_1.default.createElement(react_native_1.TouchableOpacity, { onPress: () => this.props.setImageViewer(messageImageProps === null || messageImageProps === void 0 ? void 0 : messageImageProps.currentMessage, true) },
952
+ return (react_1.default.createElement(react_native_1.TouchableHighlight, { underlayColor: '#c0c0c0', style: { width: '100%' }, onPress: () => this.props.setImageViewer(messageImageProps === null || messageImageProps === void 0 ? void 0 : messageImageProps.currentMessage, true) },
695
953
  react_1.default.createElement(react_native_1.View, { style: {
696
954
  width: windowWidth - (windowWidth - 150),
697
955
  height: windowHeight - (windowHeight - 100),
@@ -756,7 +1014,7 @@ class Bubble extends react_1.default.Component {
756
1014
  this.renderTime(),
757
1015
  this.renderTicks()));
758
1016
  return (react_1.default.createElement(react_native_1.View, { style: [styles.container, this.props.containerStyle] },
759
- react_1.default.createElement(react_native_1.TouchableOpacity, Object.assign({ disabled: true, accessibilityTraits: "text" }, this.props.touchableProps),
1017
+ react_1.default.createElement(react_native_1.TouchableHighlight, Object.assign({ style: { width: '100%' }, underlayColor: '#c0c0c0', disabled: true, accessibilityTraits: "text" }, this.props.touchableProps),
760
1018
  react_1.default.createElement(react_native_1.View, { style: [styles.wrapper, this.props.wrapperStyle] },
761
1019
  react_1.default.createElement(react_native_1.View, null,
762
1020
  this.renderCustomView(),
@@ -978,48 +1236,10 @@ exports.ImageViewerModal = ImageViewerModal_1.default;
978
1236
 
979
1237
  /***/ }),
980
1238
 
981
- /***/ "./src/screens/inbox/config/config.ts":
982
- /*!********************************************!*\
983
- !*** ./src/screens/inbox/config/config.ts ***!
984
- \********************************************/
985
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
986
-
987
-
988
- Object.defineProperty(exports, "__esModule", ({ value: true }));
989
- exports.config = void 0;
990
- const envalid_1 = __webpack_require__(/*! envalid */ "envalid");
991
- exports.config = (0, envalid_1.cleanEnv)(process['APP_ENV'] || process.env, {
992
- MESSAGES_PER_PAGE: (0, envalid_1.num)({ devDefault: 10, default: 20 }),
993
- FILES_PER_MESSAGE: (0, envalid_1.num)({ default: 10 }),
994
- INBOX_MESSEGE_PATH: (0, envalid_1.str)({ default: 'MainStack.Message' }),
995
- CALL_TO_ACTION_PATH: (0, envalid_1.str)({ default: 'MainStack.MyReservationDetails' }),
996
- CALL_TO_ACTION_BOX_BGCOLOR: (0, envalid_1.str)({ default: '#0084ff' }),
997
- CALL_TO_ACTION_BUTTON_BORDERCOLOR: (0, envalid_1.str)({ default: '#fff' }),
998
- CALL_TO_ACTION_TEXT_COLOR: (0, envalid_1.str)({ default: '#fff' }),
999
- });
1000
-
1001
-
1002
- /***/ }),
1003
-
1004
- /***/ "./src/screens/inbox/config/index.ts":
1005
- /*!*******************************************!*\
1006
- !*** ./src/screens/inbox/config/index.ts ***!
1007
- \*******************************************/
1008
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1009
-
1010
-
1011
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1012
- exports.config = void 0;
1013
- var config_1 = __webpack_require__(/*! ./config */ "./src/screens/inbox/config/config.ts");
1014
- Object.defineProperty(exports, "config", ({ enumerable: true, get: function () { return config_1.config; } }));
1015
-
1016
-
1017
- /***/ }),
1018
-
1019
- /***/ "./src/screens/inbox/containers/ConversationView.tsx":
1020
- /*!***********************************************************!*\
1021
- !*** ./src/screens/inbox/containers/ConversationView.tsx ***!
1022
- \***********************************************************/
1239
+ /***/ "./src/screens/inbox/components/SupportServiceDialogsListItem.tsx":
1240
+ /*!************************************************************************!*\
1241
+ !*** ./src/screens/inbox/components/SupportServiceDialogsListItem.tsx ***!
1242
+ \************************************************************************/
1023
1243
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1024
1244
 
1025
1245
 
@@ -1046,214 +1266,1757 @@ var __importStar = (this && this.__importStar) || function (mod) {
1046
1266
  __setModuleDefault(result, mod);
1047
1267
  return result;
1048
1268
  };
1049
- var __importDefault = (this && this.__importDefault) || function (mod) {
1050
- return (mod && mod.__esModule) ? mod : { "default": mod };
1051
- };
1052
1269
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1053
- exports.ConversationView = void 0;
1270
+ exports.SupportServiceDialogsListItem = exports.SupportServiceDialogsListItemComponent = void 0;
1054
1271
  const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
1055
1272
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
1056
- const react_native_1 = __webpack_require__(/*! react-native */ "react-native");
1273
+ const date_fns_1 = __webpack_require__(/*! date-fns */ "date-fns");
1057
1274
  const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
1058
- const react_redux_1 = __webpack_require__(/*! react-redux */ "react-redux");
1059
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1060
- const ImagePicker = __importStar(__webpack_require__(/*! expo-image-picker */ "expo-image-picker"));
1061
- const base_64_1 = __webpack_require__(/*! base-64 */ "base-64");
1062
- const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
1063
- const react_native_gifted_chat_1 = __webpack_require__(/*! react-native-gifted-chat */ "react-native-gifted-chat");
1064
1275
  const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
1065
- const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
1066
- const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
1067
- const SlackMessageContainer_1 = __webpack_require__(/*! ../components/SlackMessageContainer */ "./src/screens/inbox/components/SlackMessageContainer/index.ts");
1068
- const CachedImage_1 = __importDefault(__webpack_require__(/*! ../components/CachedImage */ "./src/screens/inbox/components/CachedImage/index.tsx"));
1069
- const { MESSAGES_PER_PAGE, CALL_TO_ACTION_BOX_BGCOLOR, CALL_TO_ACTION_PATH, CALL_TO_ACTION_BUTTON_BORDERCOLOR, CALL_TO_ACTION_TEXT_COLOR, } = config_1.config;
1070
- const ConversationViewComponent = ({ channelId }) => {
1071
- var _a;
1072
- const [channelToTop, setChannelToTop] = (0, react_1.useState)(0);
1073
- const [channelMessages, setChannelMessages] = (0, react_1.useState)([]);
1074
- const auth = (0, react_redux_1.useSelector)(user_auth0_client_1.userSelector);
1075
- const [totalCount, setTotalCount] = (0, react_1.useState)(0);
1076
- const [selectedImage, setImage] = (0, react_1.useState)('');
1077
- const [loadingOldMessages, setLoadingOldMessages] = (0, react_1.useState)(false);
1078
- const color = (0, native_base_1.useColorModeValue)('white', 'black');
1079
- // const color = useColorModeValue('black', 'white');
1080
- const navigation = (0, native_1.useNavigation)();
1081
- const [files, setFiles] = (0, react_1.useState)([]);
1082
- const [images, setImages] = (0, react_1.useState)([]);
1083
- const [msg, setMsg] = (0, react_1.useState)('');
1084
- const [loading, setLoading] = (0, react_1.useState)(false);
1085
- const [imageLoading, setImageLoading] = (0, react_1.useState)(false);
1086
- const [expoTokens, setExpoTokens] = (0, react_1.useState)([]);
1087
- const [isShowImageViewer, setImageViewer] = (0, react_1.useState)(false);
1088
- const [imageObject, setImageObject] = (0, react_1.useState)({});
1089
- const { startUpload } = (0, platform_client_1.useUploadFilesNative)();
1090
- const [sendMsg] = (0, platform_client_1.useSendMessagesMutation)();
1091
- const { data, loading: messageLoading, refetch, } = (0, platform_client_1.useMessagesQuery)({
1276
+ const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1277
+ const createdAtText = (value) => {
1278
+ if (!value)
1279
+ return '';
1280
+ let date = new Date(value);
1281
+ if ((0, date_fns_1.isToday)(date))
1282
+ return 'Today';
1283
+ if ((0, date_fns_1.isYesterday)(date))
1284
+ return 'Yesterday';
1285
+ return (0, date_fns_1.format)(new Date(value), 'MMM dd, yyyy');
1286
+ };
1287
+ /**
1288
+ * TODO:
1289
+ * - Get Reservation info: reservation date, status
1290
+ * - Add ability to get property information: name, logo
1291
+ */
1292
+ const SupportServiceDialogsListItemComponent = function DialogsListItem({ currentUser,
1293
+ // users,
1294
+ selectedChannelId, channel, onOpen, refreshing, role, }) {
1295
+ var _a, _b, _c, _d, _e;
1296
+ const { data: threadMessages, loading: threadMessageLoading, error, refetch: refetchThreadMessages, } = (0, platform_client_1.useThreadMessagesQuery)({
1092
1297
  variables: {
1093
- channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1094
- limit: MESSAGES_PER_PAGE,
1298
+ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(),
1299
+ role,
1300
+ limit: 25,
1095
1301
  },
1096
- skip: !channelId,
1097
1302
  fetchPolicy: 'cache-and-network',
1098
1303
  });
1099
- const { data: channelsDetail, loading: channelLoading, refetch: refetchChannelDetail, } = (0, platform_client_1.useViewChannelDetailQuery)({
1100
- variables: {
1101
- id: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1102
- },
1103
- });
1104
- // const { data: users } = useGetAllUsersQuery();
1105
- const { data: checkForMessages } = (0, platform_client_1.useCheckForNewMessagesQuery)({
1106
- variables: {
1107
- channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1108
- },
1109
- skip: !channelId,
1110
- fetchPolicy: 'network-only',
1111
- pollInterval: 5000,
1112
- });
1304
+ // const {
1305
+ // data: messagesQuery,
1306
+ // loading: messageLoading,
1307
+ // refetch: refetchMessages,
1308
+ // } = useMessagesQuery({
1309
+ // variables: {
1310
+ // channelId: channel?.id?.toString(),
1311
+ // limit: 25,
1312
+ // },
1313
+ // fetchPolicy: 'cache-and-network',
1314
+ // });
1113
1315
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
1316
+ var _a;
1114
1317
  // Do something when the screen is focused
1115
- refetchChannelDetail({ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString() });
1116
- refetch({
1117
- channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1118
- limit: MESSAGES_PER_PAGE,
1119
- }).then(({ data }) => {
1120
- if (!(data === null || data === void 0 ? void 0 : data.messages)) {
1121
- return;
1122
- }
1123
- const { data: messages, totalCount } = data.messages;
1318
+ // refetchMessages({ channelId: channel?.id?.toString(), limit: 25 });
1319
+ refetchThreadMessages({ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(), limit: 25 });
1320
+ return () => {
1321
+ // Do something when the screen is unfocused
1322
+ // Useful for cleanup functions
1323
+ };
1324
+ }, [refreshing]));
1325
+ react_1.default.useEffect(() => {
1326
+ var _a;
1327
+ if (refreshing) {
1328
+ // refetchMessages({ channelId: channel?.id?.toString(), limit: 25 });
1329
+ refetchThreadMessages({ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(), limit: 25 });
1330
+ }
1331
+ }, [refreshing]);
1332
+ // const lastMessageCreatorAndMembers = useMemo(() => {
1333
+ // const replyCount = threadMessages?.threadMessages?.data?.reduce((rc: any, t: any) => rc + t?.replyCount, 0);
1334
+ // if (!messagesQuery?.messages?.data?.length || threadMessages?.threadMessages?.totalCount == 0) {
1335
+ // return null;
1336
+ // }
1337
+ // const { data } = messagesQuery.messages;
1338
+ // const filteredData = data?.filter((p: any) => p?.message !== '');
1339
+ // if (replyCount == 0) {
1340
+ // const post: any =
1341
+ // threadMessages?.threadMessages?.data?.find((t: any) => {
1342
+ // return t?.post?.message !== '';
1343
+ // }) ??
1344
+ // threadMessages?.threadMessages?.data?.find((t: any) => {
1345
+ // return t?.post;
1346
+ // }) ??
1347
+ // null;
1348
+ // return post ? post?.post : null;
1349
+ // } else {
1350
+ // return filteredData[0];
1351
+ // }
1352
+ // // return data[data.length - 1];
1353
+ // }, [threadMessages, messagesQuery]);
1354
+ // const lastMessage = useMemo(() => {
1355
+ // if (!threadMessages?.threadMessages?.data?.length) {
1356
+ // return null;
1357
+ // }
1358
+ // const { data }: any = threadMessages.threadMessages;
1359
+ // const replies =
1360
+ // data
1361
+ // ?.map((t: any) => t?.replies)
1362
+ // ?.flat(1)
1363
+ // ?.filter((p: any) => p?.message !== '') ?? [];
1364
+ // if (replies?.length) {
1365
+ // return replies[0];
1366
+ // // return replies[replies.length - 1];
1367
+ // } else {
1368
+ // const post =
1369
+ // data?.find((t: any) => {
1370
+ // return t?.post?.message !== '';
1371
+ // }) ??
1372
+ // data?.find((t: any) => {
1373
+ // return t?.post;
1374
+ // }) ??
1375
+ // null;
1376
+ // return post ? post?.post : null;
1377
+ // }
1378
+ // }, [threadMessages]);
1379
+ const lastMessage = (0, react_1.useMemo)(() => {
1380
+ var _a, _b, _c, _d, _e, _f, _g;
1381
+ if (!((_b = (_a = threadMessages === null || threadMessages === void 0 ? void 0 : threadMessages.threadMessages) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length)) {
1382
+ return null;
1383
+ }
1384
+ const { data } = threadMessages.threadMessages;
1385
+ const replies = (_e = (_d = (_c = data === null || data === void 0 ? void 0 : data.map((t) => t === null || t === void 0 ? void 0 : t.replies)) === null || _c === void 0 ? void 0 : _c.flat(1)) === null || _d === void 0 ? void 0 : _d.filter((p) => (p === null || p === void 0 ? void 0 : p.message) !== '')) !== null && _e !== void 0 ? _e : [];
1386
+ if (replies === null || replies === void 0 ? void 0 : replies.length) {
1387
+ return replies[0];
1388
+ // return replies[replies.length - 1];
1389
+ }
1390
+ else {
1391
+ const post = (_g = (_f = data === null || data === void 0 ? void 0 : data.find((t) => {
1392
+ var _a;
1393
+ return ((_a = t === null || t === void 0 ? void 0 : t.post) === null || _a === void 0 ? void 0 : _a.message) !== '';
1394
+ })) !== null && _f !== void 0 ? _f : data === null || data === void 0 ? void 0 : data.find((t) => {
1395
+ return t === null || t === void 0 ? void 0 : t.post;
1396
+ })) !== null && _g !== void 0 ? _g : null;
1397
+ return post ? post === null || post === void 0 ? void 0 : post.post : null;
1398
+ }
1399
+ }, [threadMessages]);
1400
+ const creatorAndMembersId = react_1.default.useMemo(() => {
1401
+ var _a, _b, _c, _d, _e, _f;
1402
+ if (!(channel === null || channel === void 0 ? void 0 : channel.members))
1403
+ return null;
1404
+ const membersIds = (_c = (_b = (_a = channel === null || channel === void 0 ? void 0 : channel.members) === null || _a === void 0 ? void 0 : _a.filter((m) => { var _a; return ((_a = m === null || m === void 0 ? void 0 : m.user) === null || _a === void 0 ? void 0 : _a.id) !== (currentUser === null || currentUser === void 0 ? void 0 : currentUser.id); })) === null || _b === void 0 ? void 0 : _b.map((mu) => { var _a; return (_a = mu === null || mu === void 0 ? void 0 : mu.user) === null || _a === void 0 ? void 0 : _a.id; })) !== null && _c !== void 0 ? _c : [];
1405
+ const creatorId = (_d = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _d === void 0 ? void 0 : _d.id;
1406
+ const mergedIds = (_e = [].concat(membersIds, creatorId)) !== null && _e !== void 0 ? _e : [];
1407
+ return (_f = mergedIds === null || mergedIds === void 0 ? void 0 : mergedIds.filter((m, pos) => (mergedIds === null || mergedIds === void 0 ? void 0 : mergedIds.indexOf(m)) === pos)) !== null && _f !== void 0 ? _f : [];
1408
+ }, [channel]);
1409
+ const postParentId = react_1.default.useMemo(() => {
1410
+ var _a;
1411
+ if (!(creatorAndMembersId === null || creatorAndMembersId === void 0 ? void 0 : creatorAndMembersId.length))
1412
+ return null;
1413
+ return (creatorAndMembersId === null || creatorAndMembersId === void 0 ? void 0 : creatorAndMembersId.length) && (creatorAndMembersId === null || creatorAndMembersId === void 0 ? void 0 : creatorAndMembersId.includes(currentUser === null || currentUser === void 0 ? void 0 : currentUser.id))
1414
+ ? null
1415
+ : (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId)
1416
+ ? lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId
1417
+ : (_a = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) !== null && _a !== void 0 ? _a : 0;
1418
+ }, [creatorAndMembersId, lastMessage]);
1419
+ return (react_1.default.createElement(native_base_1.Pressable, { onPress: () => (channel === null || channel === void 0 ? void 0 : channel.id) !== selectedChannelId && onOpen(channel === null || channel === void 0 ? void 0 : channel.id, channel === null || channel === void 0 ? void 0 : channel.title, postParentId), borderWidth: '1', borderRadius: 10, borderColor: 'gray.200', flex: 1, _dark: {
1420
+ borderColor: 'coolGray.600',
1421
+ backgroundColor: 'gray.700',
1422
+ }, _web: {
1423
+ shadow: 2,
1424
+ borderWidth: 0,
1425
+ }, _light: {
1426
+ backgroundColor: 'gray.50',
1427
+ } },
1428
+ react_1.default.createElement(native_base_1.HStack
1429
+ // px={2}
1430
+ // pl={3}
1431
+ , {
1432
+ // px={2}
1433
+ // pl={3}
1434
+ py: 3, space: 2, w: '100%', flex: 1, direction: 'row', justifyContent: 'space-between', alignItems: 'center' },
1435
+ react_1.default.createElement(native_base_1.Box, { flex: 0.1, alignItems: 'flex-start', pl: 3 },
1436
+ react_1.default.createElement(native_base_1.Avatar.Group, { _avatar: {
1437
+ size: 'sm',
1438
+ bg: 'transparent',
1439
+ } },
1440
+ react_1.default.createElement(native_base_1.Avatar, { key: 'service-channels-key', bg: 'transparent', size: 9, top: 0, right: 0, zIndex: 1, _image: { borderRadius: 6, borderWidth: 2, borderColor: '#fff' }, source: {
1441
+ uri: (_b = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _b === void 0 ? void 0 : _b.picture,
1442
+ } }, (0, lodash_1.startCase)((_d = (_c = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _c === void 0 ? void 0 : _c.username) === null || _d === void 0 ? void 0 : _d.charAt(0))))),
1443
+ react_1.default.createElement(native_base_1.Box, { flex: 0.9 },
1444
+ react_1.default.createElement(native_base_1.HStack, { space: 1, flex: 1, direction: 'row', justifyContent: 'center', alignItems: 'center' },
1445
+ react_1.default.createElement(native_base_1.Box, { flex: 0.8 },
1446
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", fontSize: "lg", flexWrap: 'wrap', fontWeight: "semibold" }, channel === null || channel === void 0 ? void 0 : channel.title),
1447
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 1 }, (_e = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message) !== null && _e !== void 0 ? _e : '')),
1448
+ react_1.default.createElement(native_base_1.Box, { flex: 0.2 },
1449
+ react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, lastMessage ? createdAtText(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.createdAt) : '')))))));
1450
+ };
1451
+ exports.SupportServiceDialogsListItemComponent = SupportServiceDialogsListItemComponent;
1452
+ exports.SupportServiceDialogsListItem = react_1.default.memo(exports.SupportServiceDialogsListItemComponent);
1453
+
1454
+
1455
+ /***/ }),
1456
+
1457
+ /***/ "./src/screens/inbox/components/ThreadsViewItem.tsx":
1458
+ /*!**********************************************************!*\
1459
+ !*** ./src/screens/inbox/components/ThreadsViewItem.tsx ***!
1460
+ \**********************************************************/
1461
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1462
+
1463
+
1464
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1465
+ if (k2 === undefined) k2 = k;
1466
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1467
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1468
+ desc = { enumerable: true, get: function() { return m[k]; } };
1469
+ }
1470
+ Object.defineProperty(o, k2, desc);
1471
+ }) : (function(o, m, k, k2) {
1472
+ if (k2 === undefined) k2 = k;
1473
+ o[k2] = m[k];
1474
+ }));
1475
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1476
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1477
+ }) : function(o, v) {
1478
+ o["default"] = v;
1479
+ });
1480
+ var __importStar = (this && this.__importStar) || function (mod) {
1481
+ if (mod && mod.__esModule) return mod;
1482
+ var result = {};
1483
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1484
+ __setModuleDefault(result, mod);
1485
+ return result;
1486
+ };
1487
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1488
+ exports.ThreadViewItem = exports.ThreadViewItemComponent = void 0;
1489
+ const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
1490
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
1491
+ const date_fns_1 = __webpack_require__(/*! date-fns */ "date-fns");
1492
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
1493
+ const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1494
+ const createdAtText = (value) => {
1495
+ if (!value)
1496
+ return '';
1497
+ let date = new Date(value);
1498
+ if ((0, date_fns_1.isToday)(date))
1499
+ return 'Today';
1500
+ if ((0, date_fns_1.isYesterday)(date))
1501
+ return 'Yesterday';
1502
+ return (0, date_fns_1.format)(new Date(value), 'MMM dd, yyyy');
1503
+ };
1504
+ /**
1505
+ * TODO:
1506
+ * - Get Reservation info: reservation date, status
1507
+ * - Add ability to get property information: name, logo
1508
+ */
1509
+ const ThreadViewItemComponent = function DialogsListItem({ currentUser,
1510
+ // users,
1511
+ thread, onOpen, }) {
1512
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1513
+ (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
1514
+ // Do something when the screen is focused
1515
+ return () => {
1516
+ // Do something when the screen is unfocused
1517
+ // Useful for cleanup functions
1518
+ };
1519
+ }, []));
1520
+ const lastMessage = (0, react_1.useMemo)(() => {
1521
+ var _a, _b, _c;
1522
+ if (!thread) {
1523
+ return null;
1524
+ }
1525
+ const replies = (_b = (_a = thread === null || thread === void 0 ? void 0 : thread.replies) === null || _a === void 0 ? void 0 : _a.filter((p) => (p === null || p === void 0 ? void 0 : p.message) !== '')) !== null && _b !== void 0 ? _b : [];
1526
+ if (replies === null || replies === void 0 ? void 0 : replies.length) {
1527
+ return replies[0];
1528
+ // return replies[replies.length - 1];
1529
+ }
1530
+ else {
1531
+ const post = (_c = thread === null || thread === void 0 ? void 0 : thread.post) !== null && _c !== void 0 ? _c : null;
1532
+ return post ? post === null || post === void 0 ? void 0 : post.post : null;
1533
+ }
1534
+ }, [thread]);
1535
+ const participants = react_1.default.useMemo(() => {
1536
+ var _a, _b, _c;
1537
+ if (!((_a = thread === null || thread === void 0 ? void 0 : thread.participants) === null || _a === void 0 ? void 0 : _a.length))
1538
+ return null;
1539
+ return (_c = (_b = thread === null || thread === void 0 ? void 0 : thread.participants) === null || _b === void 0 ? void 0 : _b.filter((u) => { var _a; return ((_a = u === null || u === void 0 ? void 0 : u.user) === null || _a === void 0 ? void 0 : _a.id) !== (currentUser === null || currentUser === void 0 ? void 0 : currentUser.id); })) !== null && _c !== void 0 ? _c : [];
1540
+ }, [thread]);
1541
+ const allParticipantsNames = react_1.default.useMemo(() => {
1542
+ var _a, _b;
1543
+ if (!(participants === null || participants === void 0 ? void 0 : participants.length))
1544
+ return null;
1545
+ return ((_b = (_a = participants === null || participants === void 0 ? void 0 : participants.map((p) => {
1546
+ var _a, _b, _c;
1547
+ return (_c = ((_a = p === null || p === void 0 ? void 0 : p.user) === null || _a === void 0 ? void 0 : _a.givenName) + ' ' + ((_b = p === null || p === void 0 ? void 0 : p.user) === null || _b === void 0 ? void 0 : _b.familyName)) !== null && _c !== void 0 ? _c : '';
1548
+ })) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : '');
1549
+ }, [participants]);
1550
+ return (react_1.default.createElement(native_base_1.VStack, { space: 1, py: 2, px: 2, borderWidth: '1', borderRadius: 10, borderColor: 'gray.200', flex: 1, _dark: {
1551
+ borderColor: 'white',
1552
+ backgroundColor: 'white',
1553
+ }, _web: {
1554
+ shadow: 2,
1555
+ borderWidth: 0,
1556
+ }, _light: {
1557
+ backgroundColor: 'white',
1558
+ } },
1559
+ react_1.default.createElement(native_base_1.HStack
1560
+ // px={2}
1561
+ // pl={3}
1562
+ , {
1563
+ // px={2}
1564
+ // pl={3}
1565
+ py: 2, space: 2, w: '100%', flex: 1, direction: 'row', justifyContent: 'space-between', alignItems: 'center' },
1566
+ react_1.default.createElement(native_base_1.Box, { flex: 1 },
1567
+ react_1.default.createElement(native_base_1.HStack, { flex: 1, space: 5, py: 2, alignItems: 'baseline' },
1568
+ react_1.default.createElement(native_base_1.Box, null,
1569
+ react_1.default.createElement(native_base_1.Avatar.Badge, { size: 4, left: 0, zIndex: 1, bg: "green.800" })),
1570
+ react_1.default.createElement(native_base_1.Box, null,
1571
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", fontSize: "lg", flexWrap: 'wrap', fontWeight: "semibold" }, allParticipantsNames || ''))),
1572
+ react_1.default.createElement(native_base_1.HStack, { space: 1, flex: 1, direction: 'row', justifyContent: 'center', alignItems: 'center' },
1573
+ react_1.default.createElement(native_base_1.Box, { flex: 1 },
1574
+ react_1.default.createElement(native_base_1.HStack, { space: 2, py: 2 },
1575
+ react_1.default.createElement(native_base_1.Box, null,
1576
+ react_1.default.createElement(native_base_1.Avatar, { bg: 'transparent', size: 8, _image: { borderRadius: 6, borderWidth: 2, borderColor: '#fff' }, source: {
1577
+ uri: (_b = (_a = thread === null || thread === void 0 ? void 0 : thread.post) === null || _a === void 0 ? void 0 : _a.author) === null || _b === void 0 ? void 0 : _b.picture,
1578
+ } }, (0, lodash_1.startCase)((_e = (_d = (_c = thread === null || thread === void 0 ? void 0 : thread.post) === null || _c === void 0 ? void 0 : _c.author) === null || _d === void 0 ? void 0 : _d.username) === null || _e === void 0 ? void 0 : _e.charAt(0)))),
1579
+ react_1.default.createElement(native_base_1.Box, null,
1580
+ react_1.default.createElement(native_base_1.HStack, { space: 4 },
1581
+ react_1.default.createElement(native_base_1.Text, null, (_k = ((_g = (_f = thread === null || thread === void 0 ? void 0 : thread.post) === null || _f === void 0 ? void 0 : _f.author) === null || _g === void 0 ? void 0 : _g.givenName) + ' ' + ((_j = (_h = thread === null || thread === void 0 ? void 0 : thread.post) === null || _h === void 0 ? void 0 : _h.author) === null || _j === void 0 ? void 0 : _j.familyName)) !== null && _k !== void 0 ? _k : ''),
1582
+ react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, (thread === null || thread === void 0 ? void 0 : thread.post) ? createdAtText((_l = thread === null || thread === void 0 ? void 0 : thread.post) === null || _l === void 0 ? void 0 : _l.createdAt) : '')),
1583
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 2 }, (_o = (_m = thread === null || thread === void 0 ? void 0 : thread.post) === null || _m === void 0 ? void 0 : _m.message) !== null && _o !== void 0 ? _o : ''),
1584
+ !((_p = thread === null || thread === void 0 ? void 0 : thread.replies) === null || _p === void 0 ? void 0 : _p.length) && (react_1.default.createElement(native_base_1.Button, { size: 'xs', w: 150, variant: 'outline', _text: { fontSize: 12, color: '#000' }, onPress: () => { var _a, _b, _c; return onOpen((_a = thread === null || thread === void 0 ? void 0 : thread.channel) === null || _a === void 0 ? void 0 : _a.id, (_b = thread === null || thread === void 0 ? void 0 : thread.channel) === null || _b === void 0 ? void 0 : _b.title, (_c = thread === null || thread === void 0 ? void 0 : thread.post) === null || _c === void 0 ? void 0 : _c.id); } }, "Reply")))),
1585
+ ((_q = thread === null || thread === void 0 ? void 0 : thread.replies) === null || _q === void 0 ? void 0 : _q.length) > 0 && (react_1.default.createElement(native_base_1.HStack, { space: 2, pb: 2, pt: 1 },
1586
+ react_1.default.createElement(native_base_1.Box, null,
1587
+ react_1.default.createElement(native_base_1.Avatar, { bg: 'transparent', size: 8, _image: { borderRadius: 6, borderWidth: 2, borderColor: '#fff' }, source: {
1588
+ uri: (_r = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.author) === null || _r === void 0 ? void 0 : _r.picture,
1589
+ } }, (0, lodash_1.startCase)((_t = (_s = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.author) === null || _s === void 0 ? void 0 : _s.username) === null || _t === void 0 ? void 0 : _t.charAt(0)))),
1590
+ react_1.default.createElement(native_base_1.Box, null,
1591
+ react_1.default.createElement(native_base_1.HStack, { space: 4 },
1592
+ react_1.default.createElement(native_base_1.Text, null, (_w = ((_u = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.author) === null || _u === void 0 ? void 0 : _u.givenName) +
1593
+ ' ' +
1594
+ ((_v = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.author) === null || _v === void 0 ? void 0 : _v.familyName)) !== null && _w !== void 0 ? _w : ''),
1595
+ react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, lastMessage ? createdAtText(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.createdAt) : '')),
1596
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 2 }, (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message)
1597
+ ? (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message.length) < 70
1598
+ ? `${lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message}`
1599
+ : `${lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message.substring(0, 68)}....`
1600
+ : ''),
1601
+ react_1.default.createElement(native_base_1.Button, { size: 'xs', w: 150, variant: 'outline', _text: { fontSize: 12, color: '#000' }, onPress: () => { var _a, _b, _c; return onOpen((_a = thread === null || thread === void 0 ? void 0 : thread.channel) === null || _a === void 0 ? void 0 : _a.id, (_b = thread === null || thread === void 0 ? void 0 : thread.channel) === null || _b === void 0 ? void 0 : _b.title, (_c = thread === null || thread === void 0 ? void 0 : thread.post) === null || _c === void 0 ? void 0 : _c.id); } }, "Reply"))))))))));
1602
+ };
1603
+ exports.ThreadViewItemComponent = ThreadViewItemComponent;
1604
+ exports.ThreadViewItem = react_1.default.memo(exports.ThreadViewItemComponent);
1605
+
1606
+
1607
+ /***/ }),
1608
+
1609
+ /***/ "./src/screens/inbox/config/config.ts":
1610
+ /*!********************************************!*\
1611
+ !*** ./src/screens/inbox/config/config.ts ***!
1612
+ \********************************************/
1613
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1614
+
1615
+
1616
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1617
+ exports.config = void 0;
1618
+ const envalid_1 = __webpack_require__(/*! envalid */ "envalid");
1619
+ exports.config = (0, envalid_1.cleanEnv)(process['APP_ENV'] || process.env, {
1620
+ MESSAGES_PER_PAGE: (0, envalid_1.num)({ devDefault: 10, default: 20 }),
1621
+ FILES_PER_MESSAGE: (0, envalid_1.num)({ default: 10 }),
1622
+ INBOX_MESSEGE_PATH: (0, envalid_1.str)({ default: 'MainStack.Message' }),
1623
+ // THREAD_MESSEGE_PATH: str({ default: 'MainStack.Thread' }),
1624
+ // THREADS_PATH: str({ default: 'MainStack.ThreadMessage' }),
1625
+ THREAD_MESSEGE_PATH: (0, envalid_1.str)({ default: 'MainStack.ThreadMessage' }),
1626
+ THREADS_PATH: (0, envalid_1.str)({ default: 'MainStack.Thread' }),
1627
+ CALL_TO_ACTION_PATH: (0, envalid_1.str)({ default: 'MainStack.MyReservationDetails' }),
1628
+ CALL_TO_ACTION_BOX_BGCOLOR: (0, envalid_1.str)({ default: '#0084ff' }),
1629
+ CALL_TO_ACTION_BUTTON_BORDERCOLOR: (0, envalid_1.str)({ default: '#fff' }),
1630
+ CALL_TO_ACTION_TEXT_COLOR: (0, envalid_1.str)({ default: '#fff' }),
1631
+ });
1632
+
1633
+
1634
+ /***/ }),
1635
+
1636
+ /***/ "./src/screens/inbox/config/index.ts":
1637
+ /*!*******************************************!*\
1638
+ !*** ./src/screens/inbox/config/index.ts ***!
1639
+ \*******************************************/
1640
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1641
+
1642
+
1643
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1644
+ exports.config = void 0;
1645
+ var config_1 = __webpack_require__(/*! ./config */ "./src/screens/inbox/config/config.ts");
1646
+ Object.defineProperty(exports, "config", ({ enumerable: true, get: function () { return config_1.config; } }));
1647
+
1648
+
1649
+ /***/ }),
1650
+
1651
+ /***/ "./src/screens/inbox/containers/ConversationView.tsx":
1652
+ /*!***********************************************************!*\
1653
+ !*** ./src/screens/inbox/containers/ConversationView.tsx ***!
1654
+ \***********************************************************/
1655
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1656
+
1657
+
1658
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1659
+ if (k2 === undefined) k2 = k;
1660
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1661
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1662
+ desc = { enumerable: true, get: function() { return m[k]; } };
1663
+ }
1664
+ Object.defineProperty(o, k2, desc);
1665
+ }) : (function(o, m, k, k2) {
1666
+ if (k2 === undefined) k2 = k;
1667
+ o[k2] = m[k];
1668
+ }));
1669
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1670
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1671
+ }) : function(o, v) {
1672
+ o["default"] = v;
1673
+ });
1674
+ var __importStar = (this && this.__importStar) || function (mod) {
1675
+ if (mod && mod.__esModule) return mod;
1676
+ var result = {};
1677
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1678
+ __setModuleDefault(result, mod);
1679
+ return result;
1680
+ };
1681
+ var __importDefault = (this && this.__importDefault) || function (mod) {
1682
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1683
+ };
1684
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1685
+ exports.ConversationView = void 0;
1686
+ const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
1687
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
1688
+ const react_native_1 = __webpack_require__(/*! react-native */ "react-native");
1689
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
1690
+ const react_redux_1 = __webpack_require__(/*! react-redux */ "react-redux");
1691
+ const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1692
+ const ImagePicker = __importStar(__webpack_require__(/*! expo-image-picker */ "expo-image-picker"));
1693
+ const base_64_1 = __webpack_require__(/*! base-64 */ "base-64");
1694
+ const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
1695
+ const react_native_gifted_chat_1 = __webpack_require__(/*! react-native-gifted-chat */ "react-native-gifted-chat");
1696
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
1697
+ const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
1698
+ const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
1699
+ const SlackMessageContainer_1 = __webpack_require__(/*! ../components/SlackMessageContainer */ "./src/screens/inbox/components/SlackMessageContainer/index.ts");
1700
+ const CachedImage_1 = __importDefault(__webpack_require__(/*! ../components/CachedImage */ "./src/screens/inbox/components/CachedImage/index.tsx"));
1701
+ const date_fns_1 = __webpack_require__(/*! date-fns */ "date-fns");
1702
+ const { MESSAGES_PER_PAGE, CALL_TO_ACTION_BOX_BGCOLOR, CALL_TO_ACTION_PATH, CALL_TO_ACTION_BUTTON_BORDERCOLOR, CALL_TO_ACTION_TEXT_COLOR, } = config_1.config;
1703
+ const createdAtText = (value) => {
1704
+ if (!value)
1705
+ return '';
1706
+ let date = new Date(value);
1707
+ if ((0, date_fns_1.isToday)(date))
1708
+ return 'Today';
1709
+ if ((0, date_fns_1.isYesterday)(date))
1710
+ return 'Yesterday';
1711
+ return (0, date_fns_1.format)(new Date(value), 'MMM dd, yyyy');
1712
+ };
1713
+ const ConversationViewComponent = ({ channelId }) => {
1714
+ var _a;
1715
+ const [channelToTop, setChannelToTop] = (0, react_1.useState)(0);
1716
+ const [channelMessages, setChannelMessages] = (0, react_1.useState)([]);
1717
+ const auth = (0, react_redux_1.useSelector)(user_auth0_client_1.userSelector);
1718
+ const [totalCount, setTotalCount] = (0, react_1.useState)(0);
1719
+ const [selectedImage, setImage] = (0, react_1.useState)('');
1720
+ const [loadingOldMessages, setLoadingOldMessages] = (0, react_1.useState)(false);
1721
+ const color = (0, native_base_1.useColorModeValue)('white', 'black');
1722
+ // const color = useColorModeValue('black', 'white');
1723
+ const navigation = (0, native_1.useNavigation)();
1724
+ const [files, setFiles] = (0, react_1.useState)([]);
1725
+ const [images, setImages] = (0, react_1.useState)([]);
1726
+ const [msg, setMsg] = (0, react_1.useState)('');
1727
+ const [loading, setLoading] = (0, react_1.useState)(false);
1728
+ const [loadEarlierMsg, setLoadEarlierMsg] = (0, react_1.useState)(false);
1729
+ const [imageLoading, setImageLoading] = (0, react_1.useState)(false);
1730
+ const [expoTokens, setExpoTokens] = (0, react_1.useState)([]);
1731
+ const [isShowImageViewer, setImageViewer] = (0, react_1.useState)(false);
1732
+ const [imageObject, setImageObject] = (0, react_1.useState)({});
1733
+ const isFocused = (0, native_1.useIsFocused)();
1734
+ const { data: mongooseObjectId } = (0, platform_client_1.useGetNewMongooseObjectIdQuery)({
1735
+ fetchPolicy: 'network-only',
1736
+ pollInterval: 5000,
1737
+ });
1738
+ const { data: newMessage, loading: newMsgLoading, error: newMsgError, } = (0, platform_client_1.useOnChatMessageAddedSubscription)({
1739
+ variables: {
1740
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1741
+ },
1742
+ });
1743
+ const { startUpload } = (0, platform_client_1.useUploadFilesNative)();
1744
+ const [sendMsg] = (0, platform_client_1.useSendMessagesMutation)();
1745
+ const { data, loading: messageLoading, refetch, } = (0, platform_client_1.useMessagesQuery)({
1746
+ variables: {
1747
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1748
+ parentId: null,
1749
+ limit: MESSAGES_PER_PAGE,
1750
+ },
1751
+ skip: !channelId,
1752
+ fetchPolicy: 'cache-and-network',
1753
+ nextFetchPolicy: 'cache-first',
1754
+ });
1755
+ const { data: channelsDetail, loading: channelLoading, refetch: refetchChannelDetail, } = (0, platform_client_1.useViewChannelDetailQuery)({
1756
+ variables: {
1757
+ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1758
+ },
1759
+ });
1760
+ // const { data: users } = useGetAllUsersQuery();
1761
+ // const { data: checkForMessages }: any = useCheckForNewMessagesQuery({
1762
+ // variables: {
1763
+ // channelId: channelId?.toString(),
1764
+ // },
1765
+ // skip: !channelId,
1766
+ // fetchPolicy: 'network-only',
1767
+ // pollInterval: 5000,
1768
+ // });
1769
+ (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
1770
+ // Do something when the screen is focused
1771
+ refetchChannelDetail({ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString() });
1772
+ refetch({
1773
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
1774
+ parentId: null,
1775
+ limit: MESSAGES_PER_PAGE,
1776
+ }).then(({ data }) => {
1777
+ if (!(data === null || data === void 0 ? void 0 : data.messages)) {
1778
+ return;
1779
+ }
1780
+ const { data: messages, totalCount } = data.messages;
1781
+ setTotalCount(totalCount);
1782
+ setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...oldMessages, ...messages], ({ id }) => id));
1783
+ });
1784
+ return () => {
1785
+ // Do something when the screen is unfocused
1786
+ // Useful for cleanup functions
1787
+ setTotalCount(0);
1788
+ setChannelMessages([]);
1789
+ };
1790
+ }, [isFocused]));
1791
+ react_1.default.useEffect(() => {
1792
+ if (selectedImage)
1793
+ setImageLoading(false);
1794
+ }, [selectedImage]);
1795
+ // const currentUser = useMemo(
1796
+ // () => users?.getUsers?.find(({ alias }: any) => alias?.includes(auth?.auth0UserId)),
1797
+ // [users, auth],
1798
+ // );
1799
+ // useEffect(() => {
1800
+ // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
1801
+ // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1802
+ // if (messages && messages.length > 0) {
1803
+ // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1804
+ // }
1805
+ // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1806
+ // }
1807
+ // }, [data, loadingOldMessages, channelMessages]);
1808
+ // useEffect(() => {
1809
+ // if (data?.messages?.data) {
1810
+ // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1811
+ // if (
1812
+ // messages &&
1813
+ // messages.length > 0 &&
1814
+ // totalCount !== messeageTotalCount &&
1815
+ // (loadingOldMessages || channelMessages.length === 0)
1816
+ // ) {
1817
+ // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1818
+ // setLoadingOldMessages(false);
1819
+ // setTotalCount(messeageTotalCount);
1820
+ // }
1821
+ // // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1822
+ // }
1823
+ // }, [data, loadingOldMessages, channelMessages]);///
1824
+ ////......... initiate messages ......................////
1825
+ // useEffect(() => {
1826
+ // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
1827
+ // console.log('loading msg')
1828
+ // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1829
+ // if (messages && messages.length > 0) {
1830
+ // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1831
+ // setLoadingOldMessages(false);
1832
+ // }
1833
+ // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1834
+ // }
1835
+ // }, [data, loadingOldMessages, channelMessages, totalCount]);
1836
+ ////.... initiate messages end................................////
1837
+ // useEffect(() => {
1838
+ // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
1839
+ // console.log('initiate msg')
1840
+ // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1841
+ // if (messages && messages.length > 0) {
1842
+ // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1843
+ // setTotalCount(messeageTotalCount);
1844
+ // }
1845
+ // if(loadingOldMessages) setLoadingOldMessages(false);
1846
+ // }
1847
+ // }, [data, channelMessages,loadingOldMessages]);
1848
+ (0, react_1.useEffect)(() => {
1849
+ var _a, _b;
1850
+ if ((((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.data) && channelMessages.length === 0) || (((_b = data === null || data === void 0 ? void 0 : data.messages) === null || _b === void 0 ? void 0 : _b.data) && loadingOldMessages)) {
1851
+ const { data: messages, totalCount: messeageTotalCount } = data.messages;
1852
+ if (messages && messages.length > 0) {
1853
+ setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...messages, ...oldMessages], ({ id }) => id));
1854
+ setTotalCount(messeageTotalCount);
1855
+ }
1856
+ setLoadEarlierMsg(false);
1857
+ if (loadingOldMessages)
1858
+ setLoadingOldMessages(false);
1859
+ }
1860
+ }, [data, loadingOldMessages, channelMessages]);
1861
+ react_1.default.useEffect(() => {
1862
+ if (newMessage) {
1863
+ const msg = newMessage === null || newMessage === void 0 ? void 0 : newMessage.chatMessageAdded;
1864
+ setTotalCount((preCount) => preCount + 1);
1865
+ setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...oldMessages, msg], ({ id }) => id));
1866
+ }
1867
+ }, [newMessage]);
1868
+ // useEffect(() => {
1869
+ // if (data?.messages?.data) {
1870
+ // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1871
+ // console.log('messeageTotalCount',messeageTotalCount)
1872
+ // console.log('totalCount',totalCount)
1873
+ // if (messages && messages.length > 0) {
1874
+ // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1875
+ // }
1876
+ // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1877
+ // }
1878
+ // }, [data]);
1879
+ // useEffect(() => {
1880
+ // if (checkForMessages?.messages?.totalCount > totalCount) {
1881
+ // const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
1882
+ // refetch({
1883
+ // limit: numberOfNewMessages,
1884
+ // }).then(({ data }) => {
1885
+ // if (!data?.messages) {
1886
+ // return;
1887
+ // }
1888
+ // const { data: messages, totalCount }:any = data.messages;
1889
+ // setTotalCount(totalCount);
1890
+ // setChannelMessages((oldMessages:any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
1891
+ // });
1892
+ // }
1893
+ // }, [checkForMessages, totalCount]);
1894
+ ////////...............New msg check...........////
1895
+ // useEffect(() => {
1896
+ // if (
1897
+ // !messageLoading &&
1898
+ // checkForMessages?.messages?.totalCount &&
1899
+ // checkForMessages?.messages?.totalCount > totalCount
1900
+ // ) {
1901
+ // const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
1902
+ // console.log('new msg check');
1903
+ // refetch({
1904
+ // channelId: channelId?.toString(),
1905
+ // parentId: null,
1906
+ // limit: numberOfNewMessages,
1907
+ // }).then(({ data }) => {
1908
+ // if (!data?.messages) {
1909
+ // return;
1910
+ // }
1911
+ // const { data: messages, totalCount }: any = data.messages;
1912
+ // setTotalCount(totalCount);
1913
+ // setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
1914
+ // });
1915
+ // }
1916
+ // }, [checkForMessages, totalCount]);
1917
+ ////////////....new msg check end.........//
1918
+ // const onFetchOld = useCallback(() => {
1919
+ // // if (data?.messages?.totalCount > channelMessages.length) {
1920
+ // //if(channelMessages.length !== data?.messages?.totalCount){
1921
+ // if(totalCount > channelMessages.length){
1922
+ // setLoadingOldMessages(true);
1923
+ // refetch({ skip: channelMessages.length });
1924
+ // }
1925
+ // }, [data, channelMessages]);
1926
+ // const onFetchOld = () => {
1927
+ // // if (data?.messages?.totalCount > channelMessages.length) {
1928
+ // //if(channelMessages.length !== data?.messages?.totalCount){
1929
+ // if(totalCount > channelMessages.length){
1930
+ // setLoadingOldMessages(true);
1931
+ // refetch({ skip: channelMessages.length });
1932
+ // }
1933
+ // };
1934
+ // const onFetchOld = useCallback(() => {
1935
+ // if (data?.messages?.totalCount > channelMessages.length) {
1936
+ // console.log('fetchmore')
1937
+ // refetch({ channelId: channelId?.toString(), parentId: null, skip: channelMessages.length })?.then((res:any)=>{
1938
+ // setLoadingOldMessages(true);
1939
+ // });
1940
+ // }
1941
+ // }, [data, channelMessages]);
1942
+ const onFetchOld = (0, react_1.useCallback)((data, channelMessages) => {
1943
+ var _a, _b;
1944
+ if (((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.totalCount) > channelMessages.length) {
1945
+ setLoadEarlierMsg(true);
1946
+ (_b = refetch({ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(), parentId: null, skip: channelMessages.length })) === null || _b === void 0 ? void 0 : _b.then((res) => setLoadingOldMessages(true));
1947
+ }
1948
+ }, []);
1949
+ // const onFetchOld = () => {
1950
+ // if(totalCount > channelMessages.length){
1951
+ // console.log('totalCount',totalCount)
1952
+ // console.log('channelMessages.length',channelMessages.length)
1953
+ // setLoadingOldMessages(true);
1954
+ // refetch({
1955
+ // skip: channelMessages.length
1956
+ // });
1957
+ // }
1958
+ // };
1959
+ // const isCloseToTop = ({ layoutMeasurement, contentOffset, contentSize }) => {
1960
+ // return contentOffset.y <= 100; // 100px from top
1961
+ // };
1962
+ const isCloseToTop = ({ layoutMeasurement, contentOffset, contentSize }) => {
1963
+ const paddingToTop = 60;
1964
+ return contentSize.height - layoutMeasurement.height - paddingToTop <= contentOffset.y;
1965
+ };
1966
+ const dataURLtoFile = (dataurl, filename) => {
1967
+ var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = (0, base_64_1.encode)(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
1968
+ while (n--) {
1969
+ u8arr[n] = bstr.charCodeAt(n);
1970
+ }
1971
+ return new File([u8arr], filename, { type: mime });
1972
+ };
1973
+ const onSelectImages = async () => {
1974
+ setImageLoading(true);
1975
+ let imageSource = await ImagePicker.launchImageLibraryAsync({
1976
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
1977
+ allowsEditing: true,
1978
+ aspect: [4, 3],
1979
+ quality: 1,
1980
+ base64: true,
1981
+ });
1982
+ if (!imageSource.cancelled) {
1983
+ const image = 'data:image/jpeg;base64,' + (imageSource === null || imageSource === void 0 ? void 0 : imageSource.base64);
1984
+ setImage(image);
1985
+ const file = dataURLtoFile(image, 'inputImage.jpg');
1986
+ setFiles((files) => files.concat(file));
1987
+ setImages((images) => images.concat(imageSource));
1988
+ }
1989
+ if (imageSource.cancelled)
1990
+ setLoading(false);
1991
+ };
1992
+ const sendPushNotification = async (title, body, data, to) => {
1993
+ try {
1994
+ const response = await fetch('https://exp.host/--/api/v2/push/send/', {
1995
+ method: 'POST',
1996
+ headers: {
1997
+ Accept: 'application/json',
1998
+ 'Accept-Encoding': 'gzip, deflate',
1999
+ 'Content-Type': 'application/json',
2000
+ },
2001
+ body: JSON.stringify({
2002
+ to: to,
2003
+ data: data,
2004
+ title: title,
2005
+ body: body,
2006
+ sound: react_native_1.Platform.OS === 'android' ? false || null : 'default',
2007
+ }),
2008
+ });
2009
+ const result = await response.json();
2010
+ console.log('expo api response', result);
2011
+ }
2012
+ catch (error) {
2013
+ console.error('Error:', error);
2014
+ }
2015
+ // fetch('https://exp.host/--/api/v2/push/send/', {
2016
+ // method: 'POST',
2017
+ // headers: {
2018
+ // Accept: 'application/json',
2019
+ // 'Accept-Encoding': 'gzip, deflate',
2020
+ // 'Content-Type': 'application/json',
2021
+ // },
2022
+ // body: JSON.stringify({
2023
+ // to: to,
2024
+ // data: data,
2025
+ // title: title,
2026
+ // body: body,
2027
+ // sound: Platform.OS === 'android' ? null : 'default',
2028
+ // }),
2029
+ // });
2030
+ };
2031
+ // const handleSend = useCallback(
2032
+ // async (message: string) => {
2033
+ // // if (!(message && channelId)) {
2034
+ // // return;
2035
+ // // }
2036
+ // if (!channelId) return;
2037
+ // if (!message && message != ' ' && images.length == 0) return;
2038
+ // setLoading(true);
2039
+ // const { data } = await sendMsg({
2040
+ // variables: {
2041
+ // channelId,
2042
+ // content: message,
2043
+ // },
2044
+ // update: (cache, { data, errors }) => {
2045
+ // if (!data || errors) {
2046
+ // setLoading(false);
2047
+ // return;
2048
+ // }
2049
+ // setChannelMessages((messages) => [...messages, data?.sendMessage]);
2050
+ // setTotalCount((t) => t + 1);
2051
+ // setChannelToTop(channelToTop + 1);
2052
+ // setLoading(false);
2053
+ // const title: String = currentUser?.givenName+' '+currentUser?.familyName+' in Followup Chat';
2054
+ // const body: String = message;
2055
+ // const notificationData: any = {
2056
+ // url: config.INBOX_MESSEGE_PATH,
2057
+ // params: { channelId, hideTabBar: true },
2058
+ // screen: 'DialogMessages',
2059
+ // };
2060
+ // console.log('expo to',JSON.stringify(expoTokens));
2061
+ // if (expoTokens?.length > 0) {
2062
+ // const to: any = expoTokens?.length > 0 ? expoTokens : [];
2063
+ // sendPushNotification(title, body, notificationData, to);
2064
+ // }
2065
+ // setMsg('');
2066
+ // },
2067
+ // });
2068
+ // if (images && images.length > 0 && data?.sendMessage?.id) {
2069
+ // const { id: postId } = data.sendMessage;
2070
+ // setLoading(true);
2071
+ // const uploadResponse = await startUpload({
2072
+ // file: images,
2073
+ // saveUploadedFile: {
2074
+ // variables: {
2075
+ // postId,
2076
+ // },
2077
+ // },
2078
+ // createUploadLink: {
2079
+ // variables: {
2080
+ // postId,
2081
+ // },
2082
+ // },
2083
+ // });
2084
+ // if (uploadResponse?.error) setLoading(false);
2085
+ // const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
2086
+ // if (uploadResponse.data) {
2087
+ // setImage('');
2088
+ // setFiles([]);
2089
+ // setImages([]);
2090
+ // setLoading(false);
2091
+ // }
2092
+ // setChannelMessages((messages) =>
2093
+ // messages.map((message) => {
2094
+ // if (message.id === postId) {
2095
+ // return {
2096
+ // ...message,
2097
+ // files: {
2098
+ // totalCount: uploadedFiles.length,
2099
+ // data: uploadedFiles,
2100
+ // },
2101
+ // };
2102
+ // }
2103
+ // return message;
2104
+ // }),
2105
+ // );
2106
+ // }
2107
+ // },
2108
+ // [setChannelMessages, currentUser, channelId, images,expoTokens],
2109
+ // );
2110
+ const handleSend = (0, react_1.useCallback)(async (message) => {
2111
+ var _a;
2112
+ if (!channelId)
2113
+ return;
2114
+ if (!message && message != ' ' && images.length == 0)
2115
+ return;
2116
+ if (images && images.length > 0) {
2117
+ const postId = mongooseObjectId === null || mongooseObjectId === void 0 ? void 0 : mongooseObjectId.getNewMongooseObjectId;
2118
+ setLoading(true);
2119
+ const uploadResponse = await startUpload({
2120
+ file: images,
2121
+ saveUploadedFile: {
2122
+ variables: {
2123
+ postId,
2124
+ },
2125
+ },
2126
+ createUploadLink: {
2127
+ variables: {
2128
+ postId,
2129
+ },
2130
+ },
2131
+ });
2132
+ if (uploadResponse === null || uploadResponse === void 0 ? void 0 : uploadResponse.error)
2133
+ setLoading(false);
2134
+ const uploadedFiles = uploadResponse.data;
2135
+ if (uploadResponse.data) {
2136
+ setImage('');
2137
+ setFiles([]);
2138
+ setImages([]);
2139
+ //setLoading(false);
2140
+ const files = (_a = uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.map((f) => f.id)) !== null && _a !== void 0 ? _a : null;
2141
+ await sendMsg({
2142
+ variables: {
2143
+ postId,
2144
+ channelId,
2145
+ content: message,
2146
+ files,
2147
+ },
2148
+ update: (cache, { data, errors }) => {
2149
+ if (!data || errors) {
2150
+ setLoading(false);
2151
+ return;
2152
+ }
2153
+ // setChannelMessages((messages: any) => [
2154
+ // ...messages,
2155
+ // {
2156
+ // ...data?.sendMessage,
2157
+ // files: {
2158
+ // totalCount: uploadedFiles.length,
2159
+ // data: uploadedFiles,
2160
+ // },
2161
+ // },
2162
+ // ]);
2163
+ // setTotalCount((t: any) => t + 1);
2164
+ setChannelToTop(channelToTop + 1);
2165
+ setLoading(false);
2166
+ setMsg('');
2167
+ const msg = message == '' ? 'Send a file' : message;
2168
+ fetchTokenAndSendPushNotification(msg, channelId);
2169
+ },
2170
+ });
2171
+ }
2172
+ }
2173
+ else {
2174
+ setLoading(true);
2175
+ await sendMsg({
2176
+ variables: {
2177
+ channelId,
2178
+ content: message,
2179
+ },
2180
+ update: (cache, { data, errors }) => {
2181
+ if (!data || errors) {
2182
+ setLoading(false);
2183
+ return;
2184
+ }
2185
+ // setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
2186
+ // setTotalCount((t: any) => t + 1);
2187
+ setChannelToTop(channelToTop + 1);
2188
+ setLoading(false);
2189
+ setMsg('');
2190
+ fetchTokenAndSendPushNotification(message, channelId);
2191
+ },
2192
+ });
2193
+ }
2194
+ }, [mongooseObjectId, setChannelMessages, channelId, images, channelToTop, expoTokens]);
2195
+ const fetchTokenAndSendPushNotification = (message, channelId) => {
2196
+ var _a, _b, _c, _d, _e;
2197
+ const givenName = (_b = (_a = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _a === void 0 ? void 0 : _a.given_name) !== null && _b !== void 0 ? _b : '';
2198
+ const familyName = (_d = (_c = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _c === void 0 ? void 0 : _c.family_name) !== null && _d !== void 0 ? _d : '';
2199
+ const fullName = givenName ? givenName + ' ' + familyName : '';
2200
+ const title = fullName ? fullName : 'Message';
2201
+ const body = message;
2202
+ const notificationData = {
2203
+ url: config_1.config.INBOX_MESSEGE_PATH,
2204
+ params: { channelId, hideTabBar: true },
2205
+ screen: 'DialogMessages',
2206
+ };
2207
+ (_e = refetchChannelDetail({ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString() })) === null || _e === void 0 ? void 0 : _e.then((res) => {
2208
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2209
+ if ((_c = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.viewChannelDetail) === null || _b === void 0 ? void 0 : _b.members) === null || _c === void 0 ? void 0 : _c.length) {
2210
+ const channelData = (_g = (_f = (_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.viewChannelDetail) === null || _e === void 0 ? void 0 : _e.members) === null || _f === void 0 ? void 0 : _f.filter((mu) => { var _a; return ((_a = mu === null || mu === void 0 ? void 0 : mu.user) === null || _a === void 0 ? void 0 : _a.id) != (auth === null || auth === void 0 ? void 0 : auth.id); })) !== null && _g !== void 0 ? _g : [];
2211
+ const tokens = (_l = (_k = (_j = (_h = channelData === null || channelData === void 0 ? void 0 : channelData.map((u) => {
2212
+ var _a, _b, _c, _d;
2213
+ return (_d = (_c = (_b = (_a = u === null || u === void 0 ? void 0 : u.user) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.filter((t) => (t === null || t === void 0 ? void 0 : t.type) == 'EXPO_NOTIFICATION_TOKEN')) === null || _c === void 0 ? void 0 : _c.map((et) => et === null || et === void 0 ? void 0 : et.token)) !== null && _d !== void 0 ? _d : [];
2214
+ })) === null || _h === void 0 ? void 0 : _h.flat(1)) === null || _j === void 0 ? void 0 : _j.filter((t) => t)) === null || _k === void 0 ? void 0 : _k.filter((value, index, array) => array.indexOf(value) === index)) !== null && _l !== void 0 ? _l : [];
2215
+ console.log('expo to', JSON.stringify(tokens));
2216
+ if ((tokens === null || tokens === void 0 ? void 0 : tokens.length) > 0) {
2217
+ const to = (tokens === null || tokens === void 0 ? void 0 : tokens.length) > 0 ? tokens : [];
2218
+ sendPushNotification(title, body, notificationData, to);
2219
+ }
2220
+ }
2221
+ });
2222
+ };
2223
+ // const handleSend1 = async (message: string) => {
2224
+ // if (!channelId) return;
2225
+ // if (!message && message != ' ' && images.length == 0) return;
2226
+ // setLoading(true);
2227
+ // const { data } = await sendMsg({
2228
+ // variables: {
2229
+ // channelId,
2230
+ // content: message,
2231
+ // },
2232
+ // update: (cache, { data, errors }: any) => {
2233
+ // if (!data || errors) {
2234
+ // setLoading(false);
2235
+ // return;
2236
+ // }
2237
+ // setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
2238
+ // setTotalCount((t: any) => t + 1);
2239
+ // setChannelToTop(channelToTop + 1);
2240
+ // setLoading(false);
2241
+ // setMsg('');
2242
+ // const givenName = auth?.profile?.given_name ?? '';
2243
+ // const familyName = auth?.profile?.family_name ?? '';
2244
+ // const fullName = givenName ? givenName + ' ' + familyName : '';
2245
+ // const title: String = fullName ? fullName : 'Message';
2246
+ // const body: String = message;
2247
+ // const notificationData: any = {
2248
+ // url: config.INBOX_MESSEGE_PATH,
2249
+ // params: { channelId, hideTabBar: true },
2250
+ // screen: 'DialogMessages',
2251
+ // };
2252
+ // refetchChannelDetail({ id: channelId?.toString() })?.then((res: any) => {
2253
+ // if (res?.data?.viewChannelDetail?.members?.length) {
2254
+ // const channelData: any =
2255
+ // res?.data?.viewChannelDetail?.members?.filter((mu: any) => mu?.user?.id != auth?.id) ?? [];
2256
+ // const tokens: any =
2257
+ // channelData
2258
+ // ?.map(
2259
+ // (u: any) =>
2260
+ // u?.user?.tokens
2261
+ // ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
2262
+ // ?.map((et: any) => et?.token) ?? [],
2263
+ // )
2264
+ // ?.flat(1)
2265
+ // ?.filter((t: any) => t)
2266
+ // ?.filter((value: any, index: any, array: any) => array.indexOf(value) === index) ?? [];
2267
+ // console.log('expo to', JSON.stringify(tokens));
2268
+ // if (tokens?.length > 0) {
2269
+ // const to: any = tokens?.length > 0 ? tokens : [];
2270
+ // sendPushNotification(title, body, notificationData, to);
2271
+ // }
2272
+ // }
2273
+ // });
2274
+ // },
2275
+ // });
2276
+ // if (images && images.length > 0 && data?.sendMessage?.id) {
2277
+ // const { id: postId } = data.sendMessage;
2278
+ // setLoading(true);
2279
+ // const uploadResponse = await startUpload({
2280
+ // file: images,
2281
+ // saveUploadedFile: {
2282
+ // variables: {
2283
+ // postId,
2284
+ // },
2285
+ // },
2286
+ // createUploadLink: {
2287
+ // variables: {
2288
+ // postId,
2289
+ // },
2290
+ // },
2291
+ // });
2292
+ // if (uploadResponse?.error) setLoading(false);
2293
+ // const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
2294
+ // if (uploadResponse.data) {
2295
+ // setImage('');
2296
+ // setFiles([]);
2297
+ // setImages([]);
2298
+ // setLoading(false);
2299
+ // }
2300
+ // setChannelMessages((messages: any) =>
2301
+ // messages.map((message: any) => {
2302
+ // if (message.id === postId) {
2303
+ // return {
2304
+ // ...message,
2305
+ // files: {
2306
+ // totalCount: uploadedFiles.length,
2307
+ // data: uploadedFiles,
2308
+ // },
2309
+ // };
2310
+ // }
2311
+ // return message;
2312
+ // }),
2313
+ // );
2314
+ // }
2315
+ // };
2316
+ const messageList = (0, react_1.useMemo)(() => {
2317
+ let currentDate = '';
2318
+ let res = [];
2319
+ if (channelMessages.length) {
2320
+ (0, lodash_1.orderBy)(channelMessages, ['createdAt'], ['desc']).map((msg) => {
2321
+ var _a, _b, _c, _d;
2322
+ let message = {
2323
+ _id: '',
2324
+ text: '',
2325
+ createdAt: 0,
2326
+ user: {
2327
+ _id: '',
2328
+ name: '',
2329
+ avatar: '',
2330
+ },
2331
+ type: '',
2332
+ };
2333
+ const date = new Date(msg.createdAt);
2334
+ message._id = msg.id;
2335
+ message.text = msg.message;
2336
+ message.createdAt = date;
2337
+ (message.user = {
2338
+ _id: msg.author.id,
2339
+ name: msg.author.givenName + ' ' + msg.author.familyName,
2340
+ avatar: (_a = msg.author) === null || _a === void 0 ? void 0 : _a.picture,
2341
+ }),
2342
+ (message.image = (_c = (_b = msg.files) === null || _b === void 0 ? void 0 : _b.data[0]) === null || _c === void 0 ? void 0 : _c.url),
2343
+ (message.sent = msg === null || msg === void 0 ? void 0 : msg.isDelivered),
2344
+ (message.received = msg === null || msg === void 0 ? void 0 : msg.isRead);
2345
+ message.type = msg === null || msg === void 0 ? void 0 : msg.type;
2346
+ message.propsConfiguration = msg === null || msg === void 0 ? void 0 : msg.propsConfiguration;
2347
+ message.replies = (_d = msg === null || msg === void 0 ? void 0 : msg.replies) !== null && _d !== void 0 ? _d : [];
2348
+ res.push(message);
2349
+ });
2350
+ }
2351
+ return res;
2352
+ }, [channelMessages]);
2353
+ const renderSend = (props) => {
2354
+ return (react_1.default.createElement(react_native_gifted_chat_1.Send, Object.assign({}, props),
2355
+ react_1.default.createElement(native_base_1.Box, null,
2356
+ react_1.default.createElement(vector_icons_1.MaterialCommunityIcons, { name: "send-circle", style: { marginBottom: 5, marginRight: 5 }, size: 32, color: "#2e64e5" }))));
2357
+ };
2358
+ const renderMessageText = (props) => {
2359
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
2360
+ const { currentMessage } = props;
2361
+ const lastReply = ((_b = (_a = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length) > 0 ? (_d = (_c = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d[0] : null;
2362
+ if (currentMessage.type === 'ALERT') {
2363
+ const attachment = (_f = (_e = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.propsConfiguration) === null || _e === void 0 ? void 0 : _e.contents) === null || _f === void 0 ? void 0 : _f.attachment;
2364
+ let action = '';
2365
+ let actionId = '';
2366
+ if ((_h = (_g = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _g === void 0 ? void 0 : _g.link) === null || _h === void 0 ? void 0 : _h.includes('my-reservation-details')) {
2367
+ action = CALL_TO_ACTION_PATH;
2368
+ actionId = (_j = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _j === void 0 ? void 0 : _j.link.split('/').pop();
2369
+ }
2370
+ // if (attachment?.callToAction?.link?.includes('my-reservation-details')) {
2371
+ // action = 'm-reservation-detail';
2372
+ // actionId = attachment?.callToAction?.link.split('/').pop();
2373
+ // }
2374
+ return (react_1.default.createElement(native_base_1.Box, { bg: CALL_TO_ACTION_BOX_BGCOLOR, borderRadius: 15, pb: 2 },
2375
+ (attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) ? (react_1.default.createElement(native_base_1.Button, { variant: 'outline', size: 'sm', borderColor: CALL_TO_ACTION_BUTTON_BORDERCOLOR, onPress: () => navigation.navigate(action, { reservationId: actionId }) },
2376
+ react_1.default.createElement(native_base_1.Text, { color: CALL_TO_ACTION_TEXT_COLOR }, attachment.callToAction.title))) : null,
2377
+ react_1.default.createElement(react_native_gifted_chat_1.MessageText, Object.assign({}, props, { textStyle: { left: { marginLeft: 5, color: CALL_TO_ACTION_TEXT_COLOR, paddingHorizontal: 2 } } }))));
2378
+ }
2379
+ else {
2380
+ return (react_1.default.createElement(react_native_1.TouchableHighlight, { underlayColor: '#c0c0c0', style: { width: '100%' }, onPress: () => navigation.navigate(config_1.config.THREAD_MESSEGE_PATH, {
2381
+ channelId: channelId,
2382
+ title: 'Message',
2383
+ postParentId: currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage._id,
2384
+ isPostParentIdThread: true,
2385
+ }) },
2386
+ react_1.default.createElement(react_1.default.Fragment, null,
2387
+ react_1.default.createElement(react_native_gifted_chat_1.MessageText, Object.assign({}, props, { textStyle: { left: { marginLeft: 5 } } })),
2388
+ ((_l = (_k = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.length) > 0 && (react_1.default.createElement(native_base_1.HStack, { space: 1, px: 1, alignItems: 'center' },
2389
+ react_1.default.createElement(native_base_1.HStack, null, (_r = (_q = (_p = (_o = (_m = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.filter((v, i, a) => a.findIndex((t) => { var _a, _b; return ((_a = t === null || t === void 0 ? void 0 : t.author) === null || _a === void 0 ? void 0 : _a.id) === ((_b = v === null || v === void 0 ? void 0 : v.author) === null || _b === void 0 ? void 0 : _b.id); }) === i)) === null || _p === void 0 ? void 0 : _p.slice(0, 2)) === null || _q === void 0 ? void 0 : _q.reverse()) === null || _r === void 0 ? void 0 : _r.map((p, i) => {
2390
+ var _a, _b, _c;
2391
+ return (react_1.default.createElement(native_base_1.Avatar, { key: 'key' + i, bg: 'transparent', size: 6,
2392
+ // top={i == 1 ? 4 : 0}
2393
+ // right={i == 1 ? -2 : 0}
2394
+ // zIndex={i == 1 ? 5 : 1}
2395
+ _image: { borderRadius: 6, borderWidth: 2, borderColor: '#fff' }, source: {
2396
+ uri: (_a = p === null || p === void 0 ? void 0 : p.author) === null || _a === void 0 ? void 0 : _a.picture,
2397
+ } }, (0, lodash_1.startCase)((_c = (_b = p === null || p === void 0 ? void 0 : p.author) === null || _b === void 0 ? void 0 : _b.username) === null || _c === void 0 ? void 0 : _c.charAt(0))));
2398
+ })),
2399
+ react_1.default.createElement(native_base_1.Text, { fontSize: 12, fontWeight: 'bold', color: 'blue.800' }, (_s = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _s === void 0 ? void 0 :
2400
+ _s.totalCount,
2401
+ ' ',
2402
+ ((_t = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _t === void 0 ? void 0 : _t.totalCount) == 1 ? 'reply' : 'replies'),
2403
+ react_1.default.createElement(native_base_1.Text, { fontSize: 12, fontWeight: 'bold', color: 'gray.500' }, lastReply ? createdAtText(lastReply === null || lastReply === void 0 ? void 0 : lastReply.createdAt) : ''))))));
2404
+ }
2405
+ };
2406
+ const renderActions = (props) => {
2407
+ return (react_1.default.createElement(react_native_gifted_chat_1.Actions, Object.assign({}, props, { icon: () => react_1.default.createElement(native_base_1.Icon, { as: vector_icons_1.Ionicons, name: 'image', size: 'lg', color: 'black', onPress: onSelectImages }) })));
2408
+ };
2409
+ const renderAccessory = (props) => {
2410
+ return (react_1.default.createElement(native_base_1.Box, null, selectedImage !== '' ? (react_1.default.createElement(native_base_1.HStack, { alignItems: 'center' },
2411
+ react_1.default.createElement(native_base_1.Image, { ml: 3, key: selectedImage, alt: 'image', source: { uri: selectedImage }, size: 'xs' }),
2412
+ react_1.default.createElement(native_base_1.Button, { variant: 'ghost', colorScheme: 'secondary', onPress: () => {
2413
+ setFiles([]);
2414
+ setImage('');
2415
+ setImages([]);
2416
+ } }, "Cancel"))) : null));
2417
+ };
2418
+ const setImageViewerObject = (obj, v) => {
2419
+ setImageObject(obj);
2420
+ setImageViewer(v);
2421
+ };
2422
+ const modalContent = react_1.default.useMemo(() => {
2423
+ if (!imageObject)
2424
+ return react_1.default.createElement(react_1.default.Fragment, null);
2425
+ const { image, _id } = imageObject;
2426
+ return (react_1.default.createElement(CachedImage_1.default, { style: { width: '100%', height: '100%' }, resizeMode: 'cover',
2427
+ // cacheKey={`${_id}-conversation-modal-image-key`}
2428
+ cacheKey: `${_id}-slack-bubble-imageKey`, source: {
2429
+ uri: image,
2430
+ //headers: `Authorization: Bearer ${token}`,
2431
+ expiresIn: 86400,
2432
+ }, alt: 'image' }));
2433
+ }, [imageObject]);
2434
+ const renderMessage = (props) => {
2435
+ // const {
2436
+ // currentMessage: { text: currText },
2437
+ // } = props;
2438
+ //let messageTextStyle: any;
2439
+ // Make "pure emoji" messages much bigger than plain text.
2440
+ // if (currText && emojiUtils.isPureEmojiString(currText)) {
2441
+ // messageTextStyle = {
2442
+ // fontSize: 28,
2443
+ // // Emoji get clipped if lineHeight isn't increased; make it consistent across platforms.
2444
+ // lineHeight: Platform.OS === 'android' ? 34 : 30,
2445
+ // }
2446
+ // }
2447
+ // return <SlackMessage {...props} messageTextStyle={messageTextStyle} />;
2448
+ return react_1.default.createElement(SlackMessageContainer_1.SlackMessage, Object.assign({}, props, { isShowImageViewer: isShowImageViewer, setImageViewer: setImageViewerObject }));
2449
+ };
2450
+ let onScroll = false;
2451
+ // const onEndReached = () => {
2452
+ // console.log('on end reached');
2453
+ // if (!onScroll) return;
2454
+ // // load messages, show ActivityIndicator
2455
+ // onScroll = false;
2456
+ // // setLoadingOldMessages(true);
2457
+ // };
2458
+ // const onMomentumScrollBegin = useCallback(
2459
+ // ({ nativeEvent }: any) => {
2460
+ // onScroll = true;
2461
+ // console.log('scroll top');
2462
+ // if (!loadingOldMessages && channelMessages?.length <= 10 && channelMessages?.length != totalCount) {
2463
+ // onFetchOld();
2464
+ // } else if (!loadingOldMessages && isCloseToTop(nativeEvent) && channelMessages?.length != totalCount) {
2465
+ // onFetchOld();
2466
+ // }
2467
+ // },
2468
+ // [loadingOldMessages, channelMessages],
2469
+ // );
2470
+ // const onMomentumScrollBegin = ({ nativeEvent }: any) => {
2471
+ // onScroll = true;
2472
+ // console.log('scroll top');
2473
+ // if (
2474
+ // !loadingOldMessages &&
2475
+ // (channelMessages?.length <= 10 || isCloseToTop(nativeEvent)) &&
2476
+ // channelMessages?.length != totalCount
2477
+ // ) {
2478
+ // onFetchOld();
2479
+ // }
2480
+ // };
2481
+ return (react_1.default.createElement(react_1.default.Fragment, null,
2482
+ loadEarlierMsg && react_1.default.createElement(native_base_1.Spinner, null),
2483
+ react_1.default.createElement(react_native_gifted_chat_1.GiftedChat, { wrapInSafeArea: false, renderLoading: () => react_1.default.createElement(native_base_1.Spinner, null), messages: messageList,
2484
+ // listViewProps={{
2485
+ // onEndReached: onEndReached,
2486
+ // onEndReachedThreshold: 0.5,
2487
+ // onMomentumScrollBegin: onMomentumScrollBegin,
2488
+ // }}
2489
+ // listViewProps={{
2490
+ // scrollEventThrottle: 400,
2491
+ // onScroll: ({ nativeEvent }) => { console.log('scroll')
2492
+ // if (!loadingOldMessages && isCloseToTop(nativeEvent)) {
2493
+ // onFetchOld();
2494
+ // }
2495
+ // }
2496
+ // }}
2497
+ onSend: (messages) => { var _a, _b; return handleSend((_b = (_a = messages[0]) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : ' '); }, text: msg ? msg : ' ', onInputTextChanged: (text) => setMsg(text), renderFooter: () => (loading ? react_1.default.createElement(native_base_1.Spinner, null) : imageLoading ? react_1.default.createElement(native_base_1.Spinner, null) : ''), scrollToBottom: true, user: {
2498
+ // _id: currentUser?.id || '',
2499
+ _id: (auth === null || auth === void 0 ? void 0 : auth.id) || '',
2500
+ }, isTyping: true, alwaysShowSend: loading ? false : true,
2501
+ //onLoadEarlier={onFetchOld}
2502
+ //infiniteScroll={true}
2503
+ renderSend: renderSend, loadEarlier: ((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.totalCount) > channelMessages.length, isLoadingEarlier: loadEarlierMsg,
2504
+ //extraData={{ isLoadingEarlier: loadingOldMessages }}
2505
+ renderLoadEarlier: () => !loadEarlierMsg && (react_1.default.createElement(native_base_1.Center, { py: 2 },
2506
+ react_1.default.createElement(native_base_1.Button, { onPress: () => onFetchOld(data, channelMessages), variant: 'outline', _text: { color: 'black', fontSize: 15, fontWeight: 'bold' } }, "Load earlier messages"))), renderMessageText: renderMessageText, minInputToolbarHeight: 50, renderActions: renderActions, renderAccessory: renderAccessory, renderMessage: renderMessage, renderChatFooter: () => (react_1.default.createElement(SlackMessageContainer_1.ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent: modalContent })), lightboxProps: {
2507
+ underlayColor: 'transparent',
2508
+ springConfig: { tension: 90000, friction: 90000 },
2509
+ disabled: true,
2510
+ } })));
2511
+ };
2512
+ exports.ConversationView = react_1.default.memo(ConversationViewComponent);
2513
+
2514
+
2515
+ /***/ }),
2516
+
2517
+ /***/ "./src/screens/inbox/containers/Dialogs.tsx":
2518
+ /*!**************************************************!*\
2519
+ !*** ./src/screens/inbox/containers/Dialogs.tsx ***!
2520
+ \**************************************************/
2521
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
2522
+
2523
+
2524
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2525
+ if (k2 === undefined) k2 = k;
2526
+ var desc = Object.getOwnPropertyDescriptor(m, k);
2527
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2528
+ desc = { enumerable: true, get: function() { return m[k]; } };
2529
+ }
2530
+ Object.defineProperty(o, k2, desc);
2531
+ }) : (function(o, m, k, k2) {
2532
+ if (k2 === undefined) k2 = k;
2533
+ o[k2] = m[k];
2534
+ }));
2535
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
2536
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
2537
+ }) : function(o, v) {
2538
+ o["default"] = v;
2539
+ });
2540
+ var __importStar = (this && this.__importStar) || function (mod) {
2541
+ if (mod && mod.__esModule) return mod;
2542
+ var result = {};
2543
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2544
+ __setModuleDefault(result, mod);
2545
+ return result;
2546
+ };
2547
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2548
+ exports.Dialogs = void 0;
2549
+ const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
2550
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
2551
+ const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
2552
+ const react_redux_1 = __webpack_require__(/*! react-redux */ "react-redux");
2553
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
2554
+ const DialogsListItem_1 = __webpack_require__(/*! ../components/DialogsListItem */ "./src/screens/inbox/components/DialogsListItem.tsx");
2555
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
2556
+ const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
2557
+ const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
2558
+ const DialogsComponent = (props) => {
2559
+ const { channelFilters, channelRole } = props;
2560
+ const { params } = (0, native_1.useRoute)();
2561
+ const auth = (0, react_redux_1.useSelector)(user_auth0_client_1.userSelector);
2562
+ const dispatch = (0, react_redux_1.useDispatch)();
2563
+ const navigation = (0, native_1.useNavigation)();
2564
+ const isFocused = (0, native_1.useIsFocused)();
2565
+ const [refreshing, setRefresh] = (0, react_1.useState)(false);
2566
+ // const [userDirectChannel, setUserDirectChannel] = useState<any>([]);
2567
+ const { data: userChannels, loading: userChannelsLoading, refetch: getChannelsRefetch, } = (0, platform_client_1.useGetChannelsByUserQuery)({
2568
+ variables: {
2569
+ role: channelRole,
2570
+ criteria: channelFilters,
2571
+ },
2572
+ onCompleted: (data) => {
2573
+ setRefresh(false);
2574
+ }
2575
+ });
2576
+ (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
2577
+ // Do something when the screen is focused
2578
+ setRefresh(false);
2579
+ getChannelsRefetch({ role: channelRole, criteria: channelFilters });
2580
+ return () => {
2581
+ // Do something when the screen is unfocused
2582
+ // Useful for cleanup functions
2583
+ };
2584
+ }, [channelFilters]));
2585
+ const channels = react_1.default.useMemo(() => {
2586
+ var _a, _b, _c;
2587
+ if (!((_a = userChannels === null || userChannels === void 0 ? void 0 : userChannels.channelsByUser) === null || _a === void 0 ? void 0 : _a.length))
2588
+ return null;
2589
+ let uChannels = (_c = (_b = userChannels === null || userChannels === void 0 ? void 0 : userChannels.channelsByUser) === null || _b === void 0 ? void 0 : _b.filter((c) => c.members.some((u) => { var _a; return ((_a = u === null || u === void 0 ? void 0 : u.user) === null || _a === void 0 ? void 0 : _a.id) != (auth === null || auth === void 0 ? void 0 : auth.id) && u.user.__typename == 'UserAccount'; }))) !== null && _c !== void 0 ? _c : [];
2590
+ return uChannels || [];
2591
+ }, [userChannels]);
2592
+ // useEffect(() => {
2593
+ // setTimeout(() => {
2594
+ // dispatch({
2595
+ // type: CHANGE_SETTINGS_ACTION,
2596
+ // payload: {
2597
+ // footerRender: false,
2598
+ // },
2599
+ // } as any);
2600
+ // }, 0);
2601
+ // return () => {
2602
+ // dispatch({
2603
+ // type: CHANGE_SETTINGS_ACTION,
2604
+ // payload: {
2605
+ // footerRender: true,
2606
+ // },
2607
+ // } as any);
2608
+ // };
2609
+ // }, []);
2610
+ // useEffect(() => {
2611
+ // if (userChannels?.channelsByUser) {
2612
+ // if (userChannels?.channelsByUser?.length == 0) {
2613
+ // setUserDirectChannel([]);
2614
+ // }
2615
+ // //Direct channel
2616
+ // let userDirectChannels: any =
2617
+ // userChannels?.channelsByUser
2618
+ // ?.filter((i: any) => i.type == 'DIRECT')
2619
+ // ?.filter((c: any) =>
2620
+ // c.members.some((u: any) => u?.user?.id != auth?.id && u.user.__typename == 'UserAccount'),
2621
+ // ) ?? [];
2622
+ // if (userDirectChannels?.length > 0) setUserDirectChannel(userDirectChannels);
2623
+ // }
2624
+ // }, [userChannels?.channelsByUser]);
2625
+ const handleSelectChannel = (0, react_1.useCallback)((id, title) => {
2626
+ var _a;
2627
+ if (params === null || params === void 0 ? void 0 : params.channelId) {
2628
+ navigation.navigate(config_1.config.INBOX_MESSEGE_PATH, {
2629
+ channelId: params === null || params === void 0 ? void 0 : params.channelId,
2630
+ title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : null,
2631
+ hideTabBar: true,
2632
+ });
2633
+ }
2634
+ else {
2635
+ navigation.navigate(config_1.config.INBOX_MESSEGE_PATH, {
2636
+ channelId: id,
2637
+ title: title,
2638
+ hideTabBar: true,
2639
+ });
2640
+ }
2641
+ }, []);
2642
+ const handleRefresh = (0, react_1.useCallback)(() => {
2643
+ //if(userChannels?.channelsByUser?.length != channels?.length)setRefresh(true);
2644
+ getChannelsRefetch({ role: channelRole, criteria: channelFilters });
2645
+ }, []);
2646
+ return (react_1.default.createElement(native_base_1.Box, { p: 2, pt: (props === null || props === void 0 ? void 0 : props.supportServices) ? 0 : 2 },
2647
+ react_1.default.createElement(native_base_1.FlatList, { data: channels && (channels === null || channels === void 0 ? void 0 : channels.length) > 0 ? channels : [], onRefresh: handleRefresh, refreshing: userChannelsLoading, contentContainerStyle: { minHeight: '100%' }, ItemSeparatorComponent: () => react_1.default.createElement(native_base_1.Box, { height: "0.5", backgroundColor: "gray.200" }), renderItem: ({ item: channel }) => (react_1.default.createElement(DialogsListItem_1.DialogsListItem, { onOpen: handleSelectChannel, currentUser: auth, channel: channel, selectedChannelId: params === null || params === void 0 ? void 0 : params.channelId })), ListEmptyComponent: () => (react_1.default.createElement(react_1.default.Fragment, null, userChannelsLoading ? (react_1.default.createElement(native_base_1.Spinner, null)) : (react_1.default.createElement(native_base_1.Box, { p: 5 },
2648
+ react_1.default.createElement(native_base_1.Heading, null, "Chat"),
2649
+ react_1.default.createElement(native_base_1.Input, { height: 50, mt: 3, placeholder: "Search", borderRadius: 50, borderColor: 'gray.200', borderWidth: 2 }),
2650
+ react_1.default.createElement(native_base_1.Center, { mt: 6 },
2651
+ react_1.default.createElement(native_base_1.Icon, { as: vector_icons_1.Ionicons, name: "chatbubbles", size: 'xl' }),
2652
+ react_1.default.createElement(native_base_1.Text, null, "You don't have any messages yet!")))))), keyExtractor: (item, index) => 'key' + index })));
2653
+ };
2654
+ exports.Dialogs = react_1.default.memo(DialogsComponent);
2655
+
2656
+
2657
+ /***/ }),
2658
+
2659
+ /***/ "./src/screens/inbox/containers/SupportServiceDialogs.tsx":
2660
+ /*!****************************************************************!*\
2661
+ !*** ./src/screens/inbox/containers/SupportServiceDialogs.tsx ***!
2662
+ \****************************************************************/
2663
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
2664
+
2665
+
2666
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2667
+ if (k2 === undefined) k2 = k;
2668
+ var desc = Object.getOwnPropertyDescriptor(m, k);
2669
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2670
+ desc = { enumerable: true, get: function() { return m[k]; } };
2671
+ }
2672
+ Object.defineProperty(o, k2, desc);
2673
+ }) : (function(o, m, k, k2) {
2674
+ if (k2 === undefined) k2 = k;
2675
+ o[k2] = m[k];
2676
+ }));
2677
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
2678
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
2679
+ }) : function(o, v) {
2680
+ o["default"] = v;
2681
+ });
2682
+ var __importStar = (this && this.__importStar) || function (mod) {
2683
+ if (mod && mod.__esModule) return mod;
2684
+ var result = {};
2685
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2686
+ __setModuleDefault(result, mod);
2687
+ return result;
2688
+ };
2689
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2690
+ exports.SupportServiceDialogs = void 0;
2691
+ const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
2692
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
2693
+ const react_redux_1 = __webpack_require__(/*! react-redux */ "react-redux");
2694
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
2695
+ const SupportServiceDialogsListItem_1 = __webpack_require__(/*! ../components/SupportServiceDialogsListItem */ "./src/screens/inbox/components/SupportServiceDialogsListItem.tsx");
2696
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
2697
+ const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
2698
+ const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
2699
+ const SupportServiceDialogsComponent = (props) => {
2700
+ const { channelFilters, channelRole } = props;
2701
+ const { params } = (0, native_1.useRoute)();
2702
+ const auth = (0, react_redux_1.useSelector)(user_auth0_client_1.userSelector);
2703
+ const dispatch = (0, react_redux_1.useDispatch)();
2704
+ const navigation = (0, native_1.useNavigation)();
2705
+ const isFocused = (0, native_1.useIsFocused)();
2706
+ const [refreshing, setRefresh] = (0, react_1.useState)(false);
2707
+ // const [userDirectChannel, setUserDirectChannel] = useState<any>([]);
2708
+ const { data: serviceChannels, loading: serviceChannelsLoading, refetch: getServiceChannelsRefetch, } = (0, platform_client_1.useSupportServiceChannelsQuery)({
2709
+ variables: {
2710
+ criteria: { type: 'SERVICE' },
2711
+ },
2712
+ onCompleted: (data) => {
2713
+ //setRefresh(false);
2714
+ },
2715
+ });
2716
+ (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
2717
+ // Do something when the screen is focused
2718
+ setRefresh(false);
2719
+ getServiceChannelsRefetch({ criteria: { type: 'SERVICE' } });
2720
+ return () => {
2721
+ // Do something when the screen is unfocused
2722
+ // Useful for cleanup functions
2723
+ };
2724
+ }, []));
2725
+ const channels = react_1.default.useMemo(() => {
2726
+ var _a, _b, _c;
2727
+ if (!((_a = serviceChannels === null || serviceChannels === void 0 ? void 0 : serviceChannels.supportServiceChannels) === null || _a === void 0 ? void 0 : _a.length))
2728
+ return null;
2729
+ let uChannels = (_c = (_b = serviceChannels === null || serviceChannels === void 0 ? void 0 : serviceChannels.supportServiceChannels) === null || _b === void 0 ? void 0 : _b.filter((c) => c.members.some((u) => u.user.__typename == 'UserAccount'))) !== null && _c !== void 0 ? _c : [];
2730
+ return uChannels || [];
2731
+ }, [serviceChannels]);
2732
+ const handleSelectChannel = (0, react_1.useCallback)((id, title, postParentId) => {
2733
+ var _a;
2734
+ if (params === null || params === void 0 ? void 0 : params.channelId) {
2735
+ navigation.navigate((params === null || params === void 0 ? void 0 : params.postParentId) || (params === null || params === void 0 ? void 0 : params.postParentId) == 0 ? config_1.config.THREAD_MESSEGE_PATH : config_1.config.THREADS_PATH, {
2736
+ channelId: params === null || params === void 0 ? void 0 : params.channelId,
2737
+ role: params === null || params === void 0 ? void 0 : params.role,
2738
+ title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : null,
2739
+ postParentId: params === null || params === void 0 ? void 0 : params.postParentId,
2740
+ hideTabBar: true,
2741
+ });
2742
+ }
2743
+ else {
2744
+ navigation.navigate(postParentId || postParentId == 0 ? config_1.config.THREAD_MESSEGE_PATH : config_1.config.THREADS_PATH, {
2745
+ channelId: id,
2746
+ role: channelRole,
2747
+ title: title,
2748
+ postParentId: postParentId,
2749
+ hideTabBar: true,
2750
+ });
2751
+ }
2752
+ }, []);
2753
+ const handleRefresh = (0, react_1.useCallback)(() => {
2754
+ var _a;
2755
+ //if(userChannels?.channelsByUser?.length != channels?.length)setRefresh(true);
2756
+ setRefresh(true);
2757
+ (_a = getServiceChannelsRefetch({ criteria: { type: 'SERVICE' } })) === null || _a === void 0 ? void 0 : _a.then((res) => setRefresh(false));
2758
+ }, []);
2759
+ return (react_1.default.createElement(native_base_1.Box, { p: 2, pb: 0 },
2760
+ react_1.default.createElement(native_base_1.FlatList, { data: channels && (channels === null || channels === void 0 ? void 0 : channels.length) > 0 ? channels : [], onRefresh: handleRefresh, refreshing: serviceChannelsLoading, contentContainerStyle: {}, ItemSeparatorComponent: () => react_1.default.createElement(native_base_1.Box, { height: "0.5", backgroundColor: "gray.200" }), renderItem: ({ item: channel }) => (react_1.default.createElement(SupportServiceDialogsListItem_1.SupportServiceDialogsListItem, { onOpen: handleSelectChannel, currentUser: auth, channel: channel, refreshing: refreshing, selectedChannelId: params === null || params === void 0 ? void 0 : params.channelId, role: channelRole })), keyExtractor: (item, index) => 'support-service-key' + index })));
2761
+ };
2762
+ exports.SupportServiceDialogs = react_1.default.memo(SupportServiceDialogsComponent);
2763
+
2764
+
2765
+ /***/ }),
2766
+
2767
+ /***/ "./src/screens/inbox/containers/ThreadConversationView.tsx":
2768
+ /*!*****************************************************************!*\
2769
+ !*** ./src/screens/inbox/containers/ThreadConversationView.tsx ***!
2770
+ \*****************************************************************/
2771
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
2772
+
2773
+
2774
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2775
+ if (k2 === undefined) k2 = k;
2776
+ var desc = Object.getOwnPropertyDescriptor(m, k);
2777
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2778
+ desc = { enumerable: true, get: function() { return m[k]; } };
2779
+ }
2780
+ Object.defineProperty(o, k2, desc);
2781
+ }) : (function(o, m, k, k2) {
2782
+ if (k2 === undefined) k2 = k;
2783
+ o[k2] = m[k];
2784
+ }));
2785
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
2786
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
2787
+ }) : function(o, v) {
2788
+ o["default"] = v;
2789
+ });
2790
+ var __importStar = (this && this.__importStar) || function (mod) {
2791
+ if (mod && mod.__esModule) return mod;
2792
+ var result = {};
2793
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2794
+ __setModuleDefault(result, mod);
2795
+ return result;
2796
+ };
2797
+ var __importDefault = (this && this.__importDefault) || function (mod) {
2798
+ return (mod && mod.__esModule) ? mod : { "default": mod };
2799
+ };
2800
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2801
+ exports.ThreadConversationView = void 0;
2802
+ const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
2803
+ const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
2804
+ const react_native_1 = __webpack_require__(/*! react-native */ "react-native");
2805
+ const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
2806
+ const react_redux_1 = __webpack_require__(/*! react-redux */ "react-redux");
2807
+ const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
2808
+ const ImagePicker = __importStar(__webpack_require__(/*! expo-image-picker */ "expo-image-picker"));
2809
+ const base_64_1 = __webpack_require__(/*! base-64 */ "base-64");
2810
+ const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
2811
+ const react_native_gifted_chat_1 = __webpack_require__(/*! react-native-gifted-chat */ "react-native-gifted-chat");
2812
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
2813
+ const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
2814
+ const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
2815
+ const SlackMessageContainer_1 = __webpack_require__(/*! ../components/SlackMessageContainer */ "./src/screens/inbox/components/SlackMessageContainer/index.ts");
2816
+ const CachedImage_1 = __importDefault(__webpack_require__(/*! ../components/CachedImage */ "./src/screens/inbox/components/CachedImage/index.tsx"));
2817
+ const date_fns_1 = __webpack_require__(/*! date-fns */ "date-fns");
2818
+ const { MESSAGES_PER_PAGE, CALL_TO_ACTION_BOX_BGCOLOR, CALL_TO_ACTION_PATH, CALL_TO_ACTION_BUTTON_BORDERCOLOR, CALL_TO_ACTION_TEXT_COLOR, } = config_1.config;
2819
+ const createdAtText = (value) => {
2820
+ if (!value)
2821
+ return '';
2822
+ let date = new Date(value);
2823
+ if ((0, date_fns_1.isToday)(date))
2824
+ return 'Today';
2825
+ if ((0, date_fns_1.isYesterday)(date))
2826
+ return 'Yesterday';
2827
+ return (0, date_fns_1.format)(new Date(value), 'MMM dd, yyyy');
2828
+ };
2829
+ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParentIdThread, role }) => {
2830
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
2831
+ const { params } = (0, native_1.useRoute)();
2832
+ const [channelToTop, setChannelToTop] = (0, react_1.useState)(0);
2833
+ const [channelMessages, setChannelMessages] = (0, react_1.useState)([]);
2834
+ const auth = (0, react_redux_1.useSelector)(user_auth0_client_1.userSelector);
2835
+ const [totalCount, setTotalCount] = (0, react_1.useState)(0);
2836
+ const [selectedImage, setImage] = (0, react_1.useState)('');
2837
+ const [loadingOldMessages, setLoadingOldMessages] = (0, react_1.useState)(false);
2838
+ const [loadEarlierMsg, setLoadEarlierMsg] = (0, react_1.useState)(false);
2839
+ const color = (0, native_base_1.useColorModeValue)('white', 'black');
2840
+ // const color = useColorModeValue('black', 'white');
2841
+ const navigation = (0, native_1.useNavigation)();
2842
+ const [files, setFiles] = (0, react_1.useState)([]);
2843
+ const [images, setImages] = (0, react_1.useState)([]);
2844
+ const [msg, setMsg] = (0, react_1.useState)('');
2845
+ const [loading, setLoading] = (0, react_1.useState)(false);
2846
+ const [imageLoading, setImageLoading] = (0, react_1.useState)(false);
2847
+ const [expoTokens, setExpoTokens] = (0, react_1.useState)([]);
2848
+ const [isShowImageViewer, setImageViewer] = (0, react_1.useState)(false);
2849
+ const [imageObject, setImageObject] = (0, react_1.useState)({});
2850
+ const [parentId, setParentId] = (0, react_1.useState)(postParentId);
2851
+ const { startUpload } = (0, platform_client_1.useUploadFilesNative)();
2852
+ const [threadPost, setThreadPost] = (0, react_1.useState)([]);
2853
+ const { data: mongooseObjectId } = (0, platform_client_1.useGetNewMongooseObjectIdQuery)({
2854
+ fetchPolicy: 'network-only',
2855
+ pollInterval: 5000,
2856
+ });
2857
+ const { data: newThreadMsg, loading: newThreadMsgLoading, error: newThreadMsgError, } = (0, platform_client_1.useOnThreadChatMessageAddedSubscription)({
2858
+ variables: {
2859
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2860
+ postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2861
+ },
2862
+ });
2863
+ const [sendThreadMessage] = (0, platform_client_1.useSendThreadMessageMutation)();
2864
+ const [getThreadMessages, { data: threadMessagesData, loading: threadLoading, refetch: refetchThreadMessages }] = (0, platform_client_1.useThreadMessagesLazyQuery)({
2865
+ variables: {
2866
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2867
+ role: role === null || role === void 0 ? void 0 : role.toString(),
2868
+ postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2869
+ },
2870
+ fetchPolicy: 'cache-and-network',
2871
+ });
2872
+ const { data, loading: messageLoading, refetch, } = (0, platform_client_1.useMessagesQuery)({
2873
+ variables: {
2874
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2875
+ parentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2876
+ limit: MESSAGES_PER_PAGE,
2877
+ },
2878
+ skip: !channelId,
2879
+ fetchPolicy: 'cache-and-network',
2880
+ });
2881
+ // const { data: checkForMessages }: any = useCheckForNewMessagesQuery({
2882
+ // variables: {
2883
+ // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2884
+ // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2885
+ // },
2886
+ // skip: !channelId,
2887
+ // fetchPolicy: 'network-only',
2888
+ // pollInterval: 5000,
2889
+ // });
2890
+ (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
2891
+ var _a;
2892
+ navigation === null || navigation === void 0 ? void 0 : navigation.setOptions({ title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : 'Thread' });
2893
+ if (parentId || parentId == 0) {
2894
+ refetchThreadMessages({
2895
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2896
+ role: role === null || role === void 0 ? void 0 : role.toString(),
2897
+ postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2898
+ });
2899
+ }
2900
+ refetch({
2901
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2902
+ parentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2903
+ limit: MESSAGES_PER_PAGE,
2904
+ }).then(({ data }) => {
2905
+ if (!(data === null || data === void 0 ? void 0 : data.messages)) {
2906
+ return;
2907
+ }
2908
+ const { data: messages, totalCount } = data.messages;
1124
2909
  setTotalCount(totalCount);
1125
2910
  setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...oldMessages, ...messages], ({ id }) => id));
1126
2911
  });
1127
2912
  return () => {
1128
- // Do something when the screen is unfocused
1129
- // Useful for cleanup functions
1130
2913
  setTotalCount(0);
1131
2914
  setChannelMessages([]);
1132
2915
  };
1133
2916
  }, []));
2917
+ (0, react_1.useEffect)(() => {
2918
+ setParentId(postParentId);
2919
+ }, [postParentId]);
2920
+ (0, react_1.useEffect)(() => {
2921
+ if (parentId && parentId == 0) {
2922
+ getThreadMessages({
2923
+ variables: {
2924
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2925
+ role: role === null || role === void 0 ? void 0 : role.toString(),
2926
+ postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2927
+ },
2928
+ });
2929
+ }
2930
+ }, [parentId]);
2931
+ (0, react_1.useEffect)(() => {
2932
+ if (threadMessagesData === null || threadMessagesData === void 0 ? void 0 : threadMessagesData.threadMessages) {
2933
+ const { data: threads, totalCount: threadTotalCount } = threadMessagesData === null || threadMessagesData === void 0 ? void 0 : threadMessagesData.threadMessages;
2934
+ const threadMessage = threads === null || threads === void 0 ? void 0 : threads.map((t) => t === null || t === void 0 ? void 0 : t.post);
2935
+ setThreadPost(threadMessage);
2936
+ if (!isPostParentIdThread) {
2937
+ // setTotalCount((pc: any) => pc + threadTotalCount);
2938
+ setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...threadMessage, ...oldMessages], ({ id }) => id));
2939
+ }
2940
+ }
2941
+ }, [threadMessagesData, isPostParentIdThread]);
1134
2942
  react_1.default.useEffect(() => {
1135
- if (selectedImage)
1136
- setImageLoading(false);
1137
- }, [selectedImage]);
1138
- // const currentUser = useMemo(
1139
- // () => users?.getUsers?.find(({ alias }: any) => alias?.includes(auth?.auth0UserId)),
1140
- // [users, auth],
1141
- // );
2943
+ if (newThreadMsg) {
2944
+ console.log('newThreadMsg');
2945
+ const msg = newThreadMsg === null || newThreadMsg === void 0 ? void 0 : newThreadMsg.threadChatMessageAdded;
2946
+ setTotalCount((preCount) => preCount + 1);
2947
+ setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...oldMessages, msg], ({ id }) => id));
2948
+ }
2949
+ }, [newThreadMsg]);
1142
2950
  // useEffect(() => {
1143
2951
  // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
1144
2952
  // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1145
2953
  // if (messages && messages.length > 0) {
1146
2954
  // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1147
- // }
1148
- // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1149
- // }
1150
- // }, [data, loadingOldMessages, channelMessages]);
1151
- // useEffect(() => {
1152
- // if (data?.messages?.data) {
1153
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1154
- // if (
1155
- // messages &&
1156
- // messages.length > 0 &&
1157
- // totalCount !== messeageTotalCount &&
1158
- // (loadingOldMessages || channelMessages.length === 0)
1159
- // ) {
1160
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1161
2955
  // setLoadingOldMessages(false);
1162
- // setTotalCount(messeageTotalCount);
1163
2956
  // }
1164
- // // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
2957
+ // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1165
2958
  // }
1166
- // }, [data, loadingOldMessages, channelMessages]);///
2959
+ // }, [data, loadingOldMessages, channelMessages, totalCount]);
1167
2960
  (0, react_1.useEffect)(() => {
1168
- var _a;
1169
- if (((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.data) && (loadingOldMessages || channelMessages.length === 0)) {
2961
+ var _a, _b;
2962
+ if ((((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.data) && channelMessages.length === 0) || (((_b = data === null || data === void 0 ? void 0 : data.messages) === null || _b === void 0 ? void 0 : _b.data) && loadingOldMessages)) {
1170
2963
  const { data: messages, totalCount: messeageTotalCount } = data.messages;
1171
2964
  if (messages && messages.length > 0) {
1172
2965
  setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...messages, ...oldMessages], ({ id }) => id));
1173
- setLoadingOldMessages(false);
1174
- }
1175
- if (totalCount !== messeageTotalCount)
1176
2966
  setTotalCount(messeageTotalCount);
2967
+ }
2968
+ setLoadEarlierMsg(false);
2969
+ if (loadingOldMessages)
2970
+ setLoadingOldMessages(false);
1177
2971
  }
1178
- }, [data, loadingOldMessages, channelMessages, totalCount]);
1179
- // useEffect(() => {
1180
- // if (data?.messages?.data) {
1181
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
1182
- // console.log('messeageTotalCount',messeageTotalCount)
1183
- // console.log('totalCount',totalCount)
1184
- // if (messages && messages.length > 0) {
1185
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
1186
- // }
1187
- // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
1188
- // }
1189
- // }, [data]);
2972
+ }, [data, loadingOldMessages, channelMessages]);
1190
2973
  // useEffect(() => {
1191
- // if (checkForMessages?.messages?.totalCount > totalCount) {
2974
+ // if (
2975
+ // !messageLoading &&
2976
+ // checkForMessages?.messages?.totalCount &&
2977
+ // checkForMessages?.messages?.totalCount > totalCount
2978
+ // ) {
1192
2979
  // const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
2980
+ // console.log('new msg check');
1193
2981
  // refetch({
2982
+ // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2983
+ // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
1194
2984
  // limit: numberOfNewMessages,
1195
2985
  // }).then(({ data }) => {
1196
2986
  // if (!data?.messages) {
1197
2987
  // return;
1198
2988
  // }
1199
- // const { data: messages, totalCount }:any = data.messages;
2989
+ // const { data: messages, totalCount }: any = data.messages;
1200
2990
  // setTotalCount(totalCount);
1201
- // setChannelMessages((oldMessages:any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
2991
+ // setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
1202
2992
  // });
1203
2993
  // }
1204
- // }, [checkForMessages, totalCount]);
1205
- (0, react_1.useEffect)(() => {
1206
- var _a, _b, _c;
1207
- if (!messageLoading &&
1208
- ((_a = checkForMessages === null || checkForMessages === void 0 ? void 0 : checkForMessages.messages) === null || _a === void 0 ? void 0 : _a.totalCount) &&
1209
- ((_b = checkForMessages === null || checkForMessages === void 0 ? void 0 : checkForMessages.messages) === null || _b === void 0 ? void 0 : _b.totalCount) > totalCount) {
1210
- const numberOfNewMessages = ((_c = checkForMessages === null || checkForMessages === void 0 ? void 0 : checkForMessages.messages) === null || _c === void 0 ? void 0 : _c.totalCount) - totalCount;
1211
- console.log('new msg check');
1212
- refetch({
1213
- limit: numberOfNewMessages,
1214
- }).then(({ data }) => {
1215
- if (!(data === null || data === void 0 ? void 0 : data.messages)) {
1216
- return;
1217
- }
1218
- const { data: messages, totalCount } = data.messages;
1219
- setTotalCount(totalCount);
1220
- setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...oldMessages, ...messages], ({ id }) => id));
1221
- });
1222
- }
1223
- }, [checkForMessages, totalCount]);
2994
+ // }, [checkForMessages, totalCount, parentId]);
2995
+ react_1.default.useEffect(() => {
2996
+ if (selectedImage)
2997
+ setImageLoading(false);
2998
+ }, [selectedImage]);
1224
2999
  // const onFetchOld = useCallback(() => {
1225
- // // if (data?.messages?.totalCount > channelMessages.length) {
1226
- // //if(channelMessages.length !== data?.messages?.totalCount){
1227
- // if(totalCount > channelMessages.length){
1228
- // setLoadingOldMessages(true);
1229
- // refetch({ skip: channelMessages.length });
3000
+ // if (data?.messages?.totalCount > channelMessages.length) {
3001
+ // setLoadEarlierMsg(true);
3002
+ // refetch({
3003
+ // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
3004
+ // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
3005
+ // skip: channelMessages.length,
3006
+ // })?.then((res: any) => setLoadingOldMessages(true));
1230
3007
  // }
1231
3008
  // }, [data, channelMessages]);
1232
- // const onFetchOld = () => {
1233
- // // if (data?.messages?.totalCount > channelMessages.length) {
1234
- // //if(channelMessages.length !== data?.messages?.totalCount){
1235
- // if(totalCount > channelMessages.length){
1236
- // setLoadingOldMessages(true);
1237
- // refetch({ skip: channelMessages.length });
1238
- // }
1239
- // };
1240
- const onFetchOld = (0, react_1.useCallback)(() => {
1241
- var _a;
3009
+ const onFetchOld = (0, react_1.useCallback)((data, channelMessages) => {
3010
+ var _a, _b;
1242
3011
  if (((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.totalCount) > channelMessages.length) {
1243
- setLoadingOldMessages(true);
1244
- refetch({ skip: channelMessages.length });
3012
+ setLoadEarlierMsg(true);
3013
+ (_b = refetch({
3014
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3015
+ parentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
3016
+ skip: channelMessages.length,
3017
+ })) === null || _b === void 0 ? void 0 : _b.then((res) => setLoadingOldMessages(true));
1245
3018
  }
1246
- }, [data, channelMessages]);
1247
- // const onFetchOld = () => {
1248
- // if(totalCount > channelMessages.length){
1249
- // console.log('totalCount',totalCount)
1250
- // console.log('channelMessages.length',channelMessages.length)
1251
- // setLoadingOldMessages(true);
1252
- // refetch({
1253
- // skip: channelMessages.length
1254
- // });
1255
- // }
1256
- // };
3019
+ }, []);
1257
3020
  // const isCloseToTop = ({ layoutMeasurement, contentOffset, contentSize }) => {
1258
3021
  // return contentOffset.y <= 100; // 100px from top
1259
3022
  // };
@@ -1271,192 +3034,56 @@ const ConversationViewComponent = ({ channelId }) => {
1271
3034
  const onSelectImages = async () => {
1272
3035
  setImageLoading(true);
1273
3036
  let imageSource = await ImagePicker.launchImageLibraryAsync({
1274
- mediaTypes: ImagePicker.MediaTypeOptions.Images,
1275
- allowsEditing: true,
1276
- aspect: [4, 3],
1277
- quality: 1,
1278
- base64: true,
1279
- });
1280
- if (!imageSource.cancelled) {
1281
- const image = 'data:image/jpeg;base64,' + (imageSource === null || imageSource === void 0 ? void 0 : imageSource.base64);
1282
- setImage(image);
1283
- const file = dataURLtoFile(image, 'inputImage.jpg');
1284
- setFiles((files) => files.concat(file));
1285
- setImages((images) => images.concat(imageSource));
1286
- }
1287
- if (imageSource.cancelled)
1288
- setLoading(false);
1289
- };
1290
- const sendPushNotification = async (title, body, data, to) => {
1291
- try {
1292
- const response = await fetch('https://exp.host/--/api/v2/push/send/', {
1293
- method: 'POST',
1294
- headers: {
1295
- Accept: 'application/json',
1296
- 'Accept-Encoding': 'gzip, deflate',
1297
- 'Content-Type': 'application/json',
1298
- },
1299
- body: JSON.stringify({
1300
- to: to,
1301
- data: data,
1302
- title: title,
1303
- body: body,
1304
- sound: react_native_1.Platform.OS === 'android' ? false || null : 'default',
1305
- }),
1306
- });
1307
- const result = await response.json();
1308
- console.log('expo api response', result);
1309
- }
1310
- catch (error) {
1311
- console.error('Error:', error);
1312
- }
1313
- // fetch('https://exp.host/--/api/v2/push/send/', {
1314
- // method: 'POST',
1315
- // headers: {
1316
- // Accept: 'application/json',
1317
- // 'Accept-Encoding': 'gzip, deflate',
1318
- // 'Content-Type': 'application/json',
1319
- // },
1320
- // body: JSON.stringify({
1321
- // to: to,
1322
- // data: data,
1323
- // title: title,
1324
- // body: body,
1325
- // sound: Platform.OS === 'android' ? null : 'default',
1326
- // }),
1327
- // });
1328
- };
1329
- // const handleSend = useCallback(
1330
- // async (message: string) => {
1331
- // // if (!(message && channelId)) {
1332
- // // return;
1333
- // // }
1334
- // if (!channelId) return;
1335
- // if (!message && message != ' ' && images.length == 0) return;
1336
- // setLoading(true);
1337
- // const { data } = await sendMsg({
1338
- // variables: {
1339
- // channelId,
1340
- // content: message,
1341
- // },
1342
- // update: (cache, { data, errors }) => {
1343
- // if (!data || errors) {
1344
- // setLoading(false);
1345
- // return;
1346
- // }
1347
- // setChannelMessages((messages) => [...messages, data?.sendMessage]);
1348
- // setTotalCount((t) => t + 1);
1349
- // setChannelToTop(channelToTop + 1);
1350
- // setLoading(false);
1351
- // const title: String = currentUser?.givenName+' '+currentUser?.familyName+' in Followup Chat';
1352
- // const body: String = message;
1353
- // const notificationData: any = {
1354
- // url: config.INBOX_MESSEGE_PATH,
1355
- // params: { channelId, hideTabBar: true },
1356
- // screen: 'DialogMessages',
1357
- // };
1358
- // console.log('expo to',JSON.stringify(expoTokens));
1359
- // if (expoTokens?.length > 0) {
1360
- // const to: any = expoTokens?.length > 0 ? expoTokens : [];
1361
- // sendPushNotification(title, body, notificationData, to);
1362
- // }
1363
- // setMsg('');
1364
- // },
1365
- // });
1366
- // if (images && images.length > 0 && data?.sendMessage?.id) {
1367
- // const { id: postId } = data.sendMessage;
1368
- // setLoading(true);
1369
- // const uploadResponse = await startUpload({
1370
- // file: images,
1371
- // saveUploadedFile: {
1372
- // variables: {
1373
- // postId,
1374
- // },
1375
- // },
1376
- // createUploadLink: {
1377
- // variables: {
1378
- // postId,
1379
- // },
1380
- // },
1381
- // });
1382
- // if (uploadResponse?.error) setLoading(false);
1383
- // const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
1384
- // if (uploadResponse.data) {
1385
- // setImage('');
1386
- // setFiles([]);
1387
- // setImages([]);
1388
- // setLoading(false);
1389
- // }
1390
- // setChannelMessages((messages) =>
1391
- // messages.map((message) => {
1392
- // if (message.id === postId) {
1393
- // return {
1394
- // ...message,
1395
- // files: {
1396
- // totalCount: uploadedFiles.length,
1397
- // data: uploadedFiles,
1398
- // },
1399
- // };
1400
- // }
1401
- // return message;
1402
- // }),
1403
- // );
1404
- // }
1405
- // },
1406
- // [setChannelMessages, currentUser, channelId, images,expoTokens],
1407
- // );
1408
- const handleSend = async (message) => {
3037
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
3038
+ allowsEditing: true,
3039
+ aspect: [4, 3],
3040
+ quality: 1,
3041
+ base64: true,
3042
+ });
3043
+ if (!imageSource.cancelled) {
3044
+ const image = 'data:image/jpeg;base64,' + (imageSource === null || imageSource === void 0 ? void 0 : imageSource.base64);
3045
+ setImage(image);
3046
+ const file = dataURLtoFile(image, 'inputImage.jpg');
3047
+ setFiles((files) => files.concat(file));
3048
+ setImages((images) => images.concat(imageSource));
3049
+ }
3050
+ if (imageSource.cancelled)
3051
+ setLoading(false);
3052
+ };
3053
+ const sendPushNotification = async (title, body, data, to) => {
3054
+ try {
3055
+ const response = await fetch('https://exp.host/--/api/v2/push/send/', {
3056
+ method: 'POST',
3057
+ headers: {
3058
+ Accept: 'application/json',
3059
+ 'Accept-Encoding': 'gzip, deflate',
3060
+ 'Content-Type': 'application/json',
3061
+ },
3062
+ body: JSON.stringify({
3063
+ to: to,
3064
+ data: data,
3065
+ title: title,
3066
+ body: body,
3067
+ sound: react_native_1.Platform.OS === 'android' ? false || null : 'default',
3068
+ }),
3069
+ });
3070
+ const result = await response.json();
3071
+ console.log('expo api response', result);
3072
+ }
3073
+ catch (error) {
3074
+ console.error('Error:', error);
3075
+ }
3076
+ };
3077
+ // const ObjectId = (m = Math, d = Date, h = 16, s = (s:any) => m.floor(s).toString(h)) =>
3078
+ // s(d.now() / 1000) + ' '.repeat(h).replace(/./g, () => s(m.random() * h))
3079
+ const handleSend = (0, react_1.useCallback)(async (message) => {
1409
3080
  var _a;
1410
3081
  if (!channelId)
1411
3082
  return;
1412
3083
  if (!message && message != ' ' && images.length == 0)
1413
3084
  return;
1414
- setLoading(true);
1415
- const { data } = await sendMsg({
1416
- variables: {
1417
- channelId,
1418
- content: message,
1419
- },
1420
- update: (cache, { data, errors }) => {
1421
- var _a, _b, _c, _d, _e;
1422
- if (!data || errors) {
1423
- setLoading(false);
1424
- return;
1425
- }
1426
- setChannelMessages((messages) => [...messages, data === null || data === void 0 ? void 0 : data.sendMessage]);
1427
- setTotalCount((t) => t + 1);
1428
- setChannelToTop(channelToTop + 1);
1429
- setLoading(false);
1430
- setMsg('');
1431
- const givenName = (_b = (_a = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _a === void 0 ? void 0 : _a.given_name) !== null && _b !== void 0 ? _b : '';
1432
- const familyName = (_d = (_c = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _c === void 0 ? void 0 : _c.family_name) !== null && _d !== void 0 ? _d : '';
1433
- const fullName = givenName ? givenName + ' ' + familyName : '';
1434
- const title = fullName ? fullName : 'Message';
1435
- const body = message;
1436
- const notificationData = {
1437
- url: config_1.config.INBOX_MESSEGE_PATH,
1438
- params: { channelId, hideTabBar: true },
1439
- screen: 'DialogMessages',
1440
- };
1441
- (_e = refetchChannelDetail({ id: channelId === null || channelId === void 0 ? void 0 : channelId.toString() })) === null || _e === void 0 ? void 0 : _e.then((res) => {
1442
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1443
- if ((_c = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.viewChannelDetail) === null || _b === void 0 ? void 0 : _b.members) === null || _c === void 0 ? void 0 : _c.length) {
1444
- const channelData = (_g = (_f = (_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.viewChannelDetail) === null || _e === void 0 ? void 0 : _e.members) === null || _f === void 0 ? void 0 : _f.filter((mu) => { var _a; return ((_a = mu === null || mu === void 0 ? void 0 : mu.user) === null || _a === void 0 ? void 0 : _a.id) != (auth === null || auth === void 0 ? void 0 : auth.id); })) !== null && _g !== void 0 ? _g : [];
1445
- const tokens = (_l = (_k = (_j = (_h = channelData === null || channelData === void 0 ? void 0 : channelData.map((u) => {
1446
- var _a, _b, _c, _d;
1447
- return (_d = (_c = (_b = (_a = u === null || u === void 0 ? void 0 : u.user) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.filter((t) => (t === null || t === void 0 ? void 0 : t.type) == 'EXPO_NOTIFICATION_TOKEN')) === null || _c === void 0 ? void 0 : _c.map((et) => et === null || et === void 0 ? void 0 : et.token)) !== null && _d !== void 0 ? _d : [];
1448
- })) === null || _h === void 0 ? void 0 : _h.flat(1)) === null || _j === void 0 ? void 0 : _j.filter((t) => t)) === null || _k === void 0 ? void 0 : _k.filter((value, index, array) => array.indexOf(value) === index)) !== null && _l !== void 0 ? _l : [];
1449
- console.log('expo to', JSON.stringify(tokens));
1450
- if ((tokens === null || tokens === void 0 ? void 0 : tokens.length) > 0) {
1451
- const to = (tokens === null || tokens === void 0 ? void 0 : tokens.length) > 0 ? tokens : [];
1452
- sendPushNotification(title, body, notificationData, to);
1453
- }
1454
- }
1455
- });
1456
- },
1457
- });
1458
- if (images && images.length > 0 && ((_a = data === null || data === void 0 ? void 0 : data.sendMessage) === null || _a === void 0 ? void 0 : _a.id)) {
1459
- const { id: postId } = data.sendMessage;
3085
+ if (images && images.length > 0) {
3086
+ const postId = mongooseObjectId === null || mongooseObjectId === void 0 ? void 0 : mongooseObjectId.getNewMongooseObjectId;
1460
3087
  setLoading(true);
1461
3088
  const uploadResponse = await startUpload({
1462
3089
  file: images,
@@ -1478,25 +3105,122 @@ const ConversationViewComponent = ({ channelId }) => {
1478
3105
  setImage('');
1479
3106
  setFiles([]);
1480
3107
  setImages([]);
1481
- setLoading(false);
3108
+ //setLoading(false);
3109
+ const files = (_a = uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.map((f) => f.id)) !== null && _a !== void 0 ? _a : null;
3110
+ await sendThreadMessage({
3111
+ variables: {
3112
+ postId,
3113
+ channelId,
3114
+ postParentId: !parentId || parentId == 0 ? null : parentId,
3115
+ threadMessageInput: {
3116
+ content: message,
3117
+ files,
3118
+ role,
3119
+ },
3120
+ },
3121
+ update: (cache, { data, errors }) => {
3122
+ var _a;
3123
+ if (!data || errors) {
3124
+ setLoading(false);
3125
+ return;
3126
+ }
3127
+ const responseMessage = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage;
3128
+ if (!parentId || parentId == 0) {
3129
+ setChannelMessages((messages) => [
3130
+ ...messages,
3131
+ Object.assign(Object.assign({}, responseMessage), { files: {
3132
+ totalCount: uploadedFiles.length,
3133
+ data: uploadedFiles,
3134
+ } }),
3135
+ ]);
3136
+ }
3137
+ setTotalCount((t) => t + 1);
3138
+ setChannelToTop(channelToTop + 1);
3139
+ setLoading(false);
3140
+ setMsg('');
3141
+ if (!parentId || parentId == 0) {
3142
+ setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3143
+ }
3144
+ const msg = message == '' ? 'Send a file' : message;
3145
+ fetchTokenAndSendPushNotification(msg, channelId, parentId);
3146
+ },
3147
+ });
1482
3148
  }
1483
- setChannelMessages((messages) => messages.map((message) => {
1484
- if (message.id === postId) {
1485
- return Object.assign(Object.assign({}, message), { files: {
1486
- totalCount: uploadedFiles.length,
1487
- data: uploadedFiles,
1488
- } });
3149
+ }
3150
+ else {
3151
+ setLoading(true);
3152
+ await sendThreadMessage({
3153
+ variables: {
3154
+ channelId,
3155
+ postParentId: !parentId || parentId == 0 ? null : parentId,
3156
+ threadMessageInput: {
3157
+ content: message,
3158
+ role,
3159
+ },
3160
+ },
3161
+ update: (cache, { data, errors }) => {
3162
+ var _a;
3163
+ if (!data || errors) {
3164
+ setLoading(false);
3165
+ return;
3166
+ }
3167
+ const responseMessage = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage;
3168
+ if (!parentId || parentId == 0) {
3169
+ setChannelMessages((messages) => [...messages, responseMessage]);
3170
+ setTotalCount((t) => t + 1);
3171
+ }
3172
+ setChannelToTop(channelToTop + 1);
3173
+ setLoading(false);
3174
+ setMsg('');
3175
+ if (!parentId || parentId == 0) {
3176
+ setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3177
+ }
3178
+ fetchTokenAndSendPushNotification(message, channelId, parentId);
3179
+ },
3180
+ });
3181
+ }
3182
+ }, [mongooseObjectId, setChannelMessages, channelId, images, parentId, expoTokens]);
3183
+ const fetchTokenAndSendPushNotification = (message, channelId, parentId) => {
3184
+ var _a, _b, _c, _d, _e, _f;
3185
+ const givenName = (_b = (_a = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _a === void 0 ? void 0 : _a.given_name) !== null && _b !== void 0 ? _b : '';
3186
+ const familyName = (_d = (_c = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _c === void 0 ? void 0 : _c.family_name) !== null && _d !== void 0 ? _d : '';
3187
+ const fullName = givenName ? givenName + ' ' + familyName : '';
3188
+ const title = fullName ? fullName : 'Message';
3189
+ const body = message;
3190
+ const notificationData = {
3191
+ url: config_1.config.THREAD_MESSEGE_PATH,
3192
+ params: { channelId, title: (_e = params === null || params === void 0 ? void 0 : params.title) !== null && _e !== void 0 ? _e : 'Thread', postParentId: parentId, hideTabBar: true },
3193
+ screen: 'DialogThreadMessages',
3194
+ };
3195
+ if (parentId || parentId == 0) {
3196
+ (_f = refetchThreadMessages({
3197
+ channelId: !parentId || parentId == 0 ? null : channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3198
+ role: role === null || role === void 0 ? void 0 : role.toString(),
3199
+ postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
3200
+ })) === null || _f === void 0 ? void 0 : _f.then((res) => {
3201
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
3202
+ if (((_c = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.threadMessages) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.length) > 0) {
3203
+ const participants = (_h = (_g = (_f = (_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.threadMessages) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.map((t) => t === null || t === void 0 ? void 0 : t.participants)) === null || _g === void 0 ? void 0 : _g.flat(1)) !== null && _h !== void 0 ? _h : [];
3204
+ const participantsTokens = (participants === null || participants === void 0 ? void 0 : participants.length) > 0
3205
+ ? (_k = (_j = participants === null || participants === void 0 ? void 0 : participants.filter((u) => (u === null || u === void 0 ? void 0 : u.id) != (auth === null || auth === void 0 ? void 0 : auth.id))) === null || _j === void 0 ? void 0 : _j.map((p) => p.tokens)) === null || _k === void 0 ? void 0 : _k.flat(1)
3206
+ : [];
3207
+ const expoTokens = (participantsTokens === null || participantsTokens === void 0 ? void 0 : participantsTokens.length) > 0
3208
+ ? (_l = participantsTokens === null || participantsTokens === void 0 ? void 0 : participantsTokens.filter((t) => (t === null || t === void 0 ? void 0 : t.type) == 'EXPO_NOTIFICATION_TOKEN')) === null || _l === void 0 ? void 0 : _l.map((et) => et === null || et === void 0 ? void 0 : et.token)
3209
+ : [];
3210
+ if ((expoTokens === null || expoTokens === void 0 ? void 0 : expoTokens.length) > 0) {
3211
+ const to = expoTokens;
3212
+ sendPushNotification(title, body, notificationData, to);
3213
+ }
1489
3214
  }
1490
- return message;
1491
- }));
3215
+ });
1492
3216
  }
1493
3217
  };
1494
3218
  const messageList = (0, react_1.useMemo)(() => {
1495
3219
  let currentDate = '';
1496
3220
  let res = [];
1497
- if (channelMessages.length) {
3221
+ if (channelMessages === null || channelMessages === void 0 ? void 0 : channelMessages.length) {
1498
3222
  (0, lodash_1.orderBy)(channelMessages, ['createdAt'], ['desc']).map((msg) => {
1499
- var _a, _b, _c;
3223
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
1500
3224
  let message = {
1501
3225
  _id: '',
1502
3226
  text: '',
@@ -1513,11 +3237,11 @@ const ConversationViewComponent = ({ channelId }) => {
1513
3237
  message.text = msg.message;
1514
3238
  message.createdAt = date;
1515
3239
  (message.user = {
1516
- _id: msg.author.id,
1517
- name: msg.author.givenName + ' ' + msg.author.familyName,
1518
- avatar: (_a = msg.author) === null || _a === void 0 ? void 0 : _a.picture,
3240
+ _id: (_b = (_a = msg === null || msg === void 0 ? void 0 : msg.author) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : (_c = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _c === void 0 ? void 0 : _c.id,
3241
+ name: (_h = (_e = (_d = msg === null || msg === void 0 ? void 0 : msg.author) === null || _d === void 0 ? void 0 : _d.givenName) !== null && _e !== void 0 ? _e : ((_f = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _f === void 0 ? void 0 : _f.given_name) + ' ' + ((_g = msg === null || msg === void 0 ? void 0 : msg.author) === null || _g === void 0 ? void 0 : _g.familyName)) !== null && _h !== void 0 ? _h : (_j = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _j === void 0 ? void 0 : _j.family_name,
3242
+ avatar: (_l = (_k = msg === null || msg === void 0 ? void 0 : msg.author) === null || _k === void 0 ? void 0 : _k.picture) !== null && _l !== void 0 ? _l : (_m = auth === null || auth === void 0 ? void 0 : auth.profile) === null || _m === void 0 ? void 0 : _m.picture,
1519
3243
  }),
1520
- (message.image = (_c = (_b = msg.files) === null || _b === void 0 ? void 0 : _b.data[0]) === null || _c === void 0 ? void 0 : _c.url),
3244
+ (message.image = (_p = (_o = msg.files) === null || _o === void 0 ? void 0 : _o.data[0]) === null || _p === void 0 ? void 0 : _p.url),
1521
3245
  (message.sent = msg === null || msg === void 0 ? void 0 : msg.isDelivered),
1522
3246
  (message.received = msg === null || msg === void 0 ? void 0 : msg.isRead);
1523
3247
  message.type = msg === null || msg === void 0 ? void 0 : msg.type;
@@ -1543,10 +3267,6 @@ const ConversationViewComponent = ({ channelId }) => {
1543
3267
  action = CALL_TO_ACTION_PATH;
1544
3268
  actionId = (_e = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _e === void 0 ? void 0 : _e.link.split('/').pop();
1545
3269
  }
1546
- // if (attachment?.callToAction?.link?.includes('my-reservation-details')) {
1547
- // action = 'm-reservation-detail';
1548
- // actionId = attachment?.callToAction?.link.split('/').pop();
1549
- // }
1550
3270
  return (react_1.default.createElement(native_base_1.Box, { bg: CALL_TO_ACTION_BOX_BGCOLOR, borderRadius: 15, pb: 2 },
1551
3271
  (attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) ? (react_1.default.createElement(native_base_1.Button, { variant: 'outline', size: 'sm', borderColor: CALL_TO_ACTION_BUTTON_BORDERCOLOR, onPress: () => navigation.navigate(action, { reservationId: actionId }) },
1552
3272
  react_1.default.createElement(native_base_1.Text, { color: CALL_TO_ACTION_TEXT_COLOR }, attachment.callToAction.title))) : null,
@@ -1585,89 +3305,55 @@ const ConversationViewComponent = ({ channelId }) => {
1585
3305
  }, alt: 'image' }));
1586
3306
  }, [imageObject]);
1587
3307
  const renderMessage = (props) => {
1588
- // const {
1589
- // currentMessage: { text: currText },
1590
- // } = props;
1591
- //let messageTextStyle: any;
1592
- // Make "pure emoji" messages much bigger than plain text.
1593
- // if (currText && emojiUtils.isPureEmojiString(currText)) {
1594
- // messageTextStyle = {
1595
- // fontSize: 28,
1596
- // // Emoji get clipped if lineHeight isn't increased; make it consistent across platforms.
1597
- // lineHeight: Platform.OS === 'android' ? 34 : 30,
1598
- // }
1599
- // }
1600
- // return <SlackMessage {...props} messageTextStyle={messageTextStyle} />;
1601
3308
  return react_1.default.createElement(SlackMessageContainer_1.SlackMessage, Object.assign({}, props, { isShowImageViewer: isShowImageViewer, setImageViewer: setImageViewerObject }));
1602
3309
  };
1603
- let onScroll = false;
1604
- const onEndReached = () => {
1605
- console.log('on end reached');
1606
- if (!onScroll)
1607
- return;
1608
- // load messages, show ActivityIndicator
1609
- onScroll = false;
1610
- // setLoadingOldMessages(true);
1611
- };
1612
- // const onMomentumScrollBegin = useCallback(
1613
- // ({ nativeEvent }: any) => {
1614
- // onScroll = true;
1615
- // console.log('scroll top');
1616
- // if (!loadingOldMessages && channelMessages?.length <= 10 && channelMessages?.length != totalCount) {
1617
- // onFetchOld();
1618
- // } else if (!loadingOldMessages && isCloseToTop(nativeEvent) && channelMessages?.length != totalCount) {
1619
- // onFetchOld();
1620
- // }
1621
- // },
1622
- // [loadingOldMessages, channelMessages],
1623
- // );
1624
- const onMomentumScrollBegin = ({ nativeEvent }) => {
1625
- onScroll = true;
1626
- console.log('scroll top');
1627
- if (!loadingOldMessages &&
1628
- ((channelMessages === null || channelMessages === void 0 ? void 0 : channelMessages.length) <= 10 || isCloseToTop(nativeEvent)) &&
1629
- (channelMessages === null || channelMessages === void 0 ? void 0 : channelMessages.length) != totalCount) {
1630
- onFetchOld();
1631
- }
1632
- };
1633
3310
  return (react_1.default.createElement(react_1.default.Fragment, null,
1634
- loadingOldMessages && react_1.default.createElement(native_base_1.Spinner, null),
1635
- react_1.default.createElement(react_native_gifted_chat_1.GiftedChat, { wrapInSafeArea: false, renderLoading: () => react_1.default.createElement(native_base_1.Spinner, null), messages: messageList,
1636
- // listViewProps={{
1637
- // onEndReached: onEndReached,
1638
- // onEndReachedThreshold: 0.5,
1639
- // onMomentumScrollBegin: onMomentumScrollBegin,
1640
- // }}////
1641
- // listViewProps={{
1642
- // scrollEventThrottle: 400,
1643
- // onScroll: ({ nativeEvent }) => { console.log('scroll')
1644
- // if (!loadingOldMessages && isCloseToTop(nativeEvent)) {
1645
- // onFetchOld();
1646
- // }
1647
- // }
1648
- // }}
1649
- onSend: (messages) => { var _a, _b; return handleSend((_b = (_a = messages[0]) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : ' '); }, text: msg ? msg : ' ', onInputTextChanged: (text) => setMsg(text), renderFooter: () => (loading ? react_1.default.createElement(native_base_1.Spinner, null) : imageLoading ? react_1.default.createElement(native_base_1.Spinner, null) : ''), scrollToBottom: true, user: {
1650
- // _id: currentUser?.id || '',
3311
+ loadEarlierMsg && react_1.default.createElement(native_base_1.Spinner, null),
3312
+ isPostParentIdThread && (react_1.default.createElement(react_1.default.Fragment, null, (threadPost === null || threadPost === void 0 ? void 0 : threadPost.length) > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
3313
+ react_1.default.createElement(native_base_1.VStack, { px: 2, pt: 2, pb: 0, space: 2 },
3314
+ react_1.default.createElement(native_base_1.HStack, { space: 2, alignItems: 'center' },
3315
+ react_1.default.createElement(native_base_1.Avatar, { bg: 'transparent', size: 10, _image: { borderRadius: 6, borderWidth: 2, borderColor: '#fff' }, source: {
3316
+ uri: (_b = (_a = threadPost[0]) === null || _a === void 0 ? void 0 : _a.author) === null || _b === void 0 ? void 0 : _b.picture,
3317
+ } }, (0, lodash_1.startCase)((_e = (_d = (_c = threadPost[0]) === null || _c === void 0 ? void 0 : _c.author) === null || _d === void 0 ? void 0 : _d.username) === null || _e === void 0 ? void 0 : _e.charAt(0))),
3318
+ react_1.default.createElement(native_base_1.Box, null,
3319
+ react_1.default.createElement(native_base_1.Text, { color: 'black', fontWeight: 'bold' }, (_h = (_g = (_f = threadPost[0]) === null || _f === void 0 ? void 0 : _f.author) === null || _g === void 0 ? void 0 : _g.givenName) !== null && _h !== void 0 ? _h : '',
3320
+ ' ', (_l = (_k = (_j = threadPost[0]) === null || _j === void 0 ? void 0 : _j.author) === null || _k === void 0 ? void 0 : _k.familyName) !== null && _l !== void 0 ? _l : ''),
3321
+ react_1.default.createElement(native_base_1.Text, { color: 'gray.500', pl: 0 },
3322
+ createdAtText((_m = threadPost[0]) === null || _m === void 0 ? void 0 : _m.createdAt),
3323
+ " at",
3324
+ ' ',
3325
+ (0, date_fns_1.format)(new Date((_o = threadPost[0]) === null || _o === void 0 ? void 0 : _o.createdAt), 'hh:ss:a')))),
3326
+ react_1.default.createElement(native_base_1.HStack, { px: 2, space: 2, alignItems: 'center' },
3327
+ react_1.default.createElement(native_base_1.Text, null, (_q = (_p = threadPost[0]) === null || _p === void 0 ? void 0 : _p.message) !== null && _q !== void 0 ? _q : ''))),
3328
+ react_1.default.createElement(native_base_1.Box, { py: 4 },
3329
+ react_1.default.createElement(native_base_1.Box, { px: 4, borderTopWidth: 1, borderBottomWidth: 1, py: 2, borderColor: 'gray.200' },
3330
+ react_1.default.createElement(native_base_1.Text, { color: 'gray.600', fontWeight: 'bold' }, (_s = (_r = threadPost[0]) === null || _r === void 0 ? void 0 : _r.replies) === null || _s === void 0 ? void 0 :
3331
+ _s.totalCount,
3332
+ ' ',
3333
+ ((_u = (_t = threadPost[0]) === null || _t === void 0 ? void 0 : _t.replies) === null || _u === void 0 ? void 0 : _u.totalCount) > 0 ? 'replies' : 'reply'))))))),
3334
+ react_1.default.createElement(react_native_gifted_chat_1.GiftedChat, { wrapInSafeArea: false, renderLoading: () => react_1.default.createElement(native_base_1.Spinner, null), messages: messageList, onSend: (messages) => { var _a, _b; return handleSend((_b = (_a = messages[0]) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : ' '); }, text: msg ? msg : ' ', onInputTextChanged: (text) => setMsg(text), renderFooter: () => (loading ? react_1.default.createElement(native_base_1.Spinner, null) : imageLoading ? react_1.default.createElement(native_base_1.Spinner, null) : ''), scrollToBottom: true, user: {
1651
3335
  _id: (auth === null || auth === void 0 ? void 0 : auth.id) || '',
1652
- }, isTyping: true, alwaysShowSend: loading ? false : true, onLoadEarlier: onFetchOld, infiniteScroll: true, renderSend: renderSend, loadEarlier: ((_a = data === null || data === void 0 ? void 0 : data.messages) === null || _a === void 0 ? void 0 : _a.totalCount) > channelMessages.length,
1653
- //isLoadingEarlier={isLoadingEarlier}
1654
- //extraData={{ isLoadingEarlier: loadingOldMessages }}
1655
- //renderLoadEarlier={() => <Spinner />}}
1656
- renderMessageText: renderMessageText, minInputToolbarHeight: 50, renderActions: renderActions, renderAccessory: renderAccessory, renderMessage: renderMessage, renderChatFooter: () => (react_1.default.createElement(SlackMessageContainer_1.ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent: modalContent })), lightboxProps: {
3336
+ }, isTyping: true, alwaysShowSend: loading ? false : true,
3337
+ // onLoadEarlier={onFetchOld}
3338
+ infiniteScroll: true, renderSend: renderSend, loadEarlier: ((_v = data === null || data === void 0 ? void 0 : data.messages) === null || _v === void 0 ? void 0 : _v.totalCount) > channelMessages.length, isLoadingEarlier: loadEarlierMsg, renderLoadEarlier: () => !loadEarlierMsg && (react_1.default.createElement(native_base_1.Center, { py: 2 },
3339
+ react_1.default.createElement(native_base_1.Button, { onPress: () => onFetchOld(data, channelMessages), variant: 'outline', _text: { color: 'black', fontSize: 15, fontWeight: 'bold' } }, "Load earlier messages"))), renderMessageText: renderMessageText, minInputToolbarHeight: 50, renderActions: renderActions, renderAccessory: renderAccessory, renderMessage: renderMessage, renderChatFooter: () => (react_1.default.createElement(SlackMessageContainer_1.ImageViewerModal, { isVisible: isShowImageViewer, setVisible: setImageViewer, modalContent: modalContent })), messagesContainerStyle: (messageList === null || messageList === void 0 ? void 0 : messageList.length) == 0 && { transform: [{ scaleY: -1 }] }, renderChatEmpty: () => (react_1.default.createElement(react_1.default.Fragment, null, !threadLoading && !messageLoading && messageList && (messageList === null || messageList === void 0 ? void 0 : messageList.length) == 0 && (react_1.default.createElement(native_base_1.Box, { p: 5 },
3340
+ react_1.default.createElement(native_base_1.Center, { mt: 6 },
3341
+ react_1.default.createElement(native_base_1.Icon, { as: vector_icons_1.Ionicons, name: "chatbubbles", size: 'xl' }),
3342
+ react_1.default.createElement(native_base_1.Text, null, "You don't have any message yet!")))))), lightboxProps: {
1657
3343
  underlayColor: 'transparent',
1658
3344
  springConfig: { tension: 90000, friction: 90000 },
1659
3345
  disabled: true,
1660
3346
  } })));
1661
3347
  };
1662
- exports.ConversationView = react_1.default.memo(ConversationViewComponent);
3348
+ exports.ThreadConversationView = react_1.default.memo(ThreadConversationViewComponent);
1663
3349
 
1664
3350
 
1665
3351
  /***/ }),
1666
3352
 
1667
- /***/ "./src/screens/inbox/containers/Dialogs.tsx":
1668
- /*!**************************************************!*\
1669
- !*** ./src/screens/inbox/containers/Dialogs.tsx ***!
1670
- \**************************************************/
3353
+ /***/ "./src/screens/inbox/containers/ThreadsView.tsx":
3354
+ /*!******************************************************!*\
3355
+ !*** ./src/screens/inbox/containers/ThreadsView.tsx ***!
3356
+ \******************************************************/
1671
3357
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1672
3358
 
1673
3359
 
@@ -1695,113 +3381,153 @@ var __importStar = (this && this.__importStar) || function (mod) {
1695
3381
  return result;
1696
3382
  };
1697
3383
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1698
- exports.Dialogs = void 0;
3384
+ exports.ThreadsView = void 0;
1699
3385
  const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
1700
3386
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
1701
3387
  const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
1702
3388
  const react_redux_1 = __webpack_require__(/*! react-redux */ "react-redux");
1703
3389
  const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
1704
- const DialogsListItem_1 = __webpack_require__(/*! ../components/DialogsListItem */ "./src/screens/inbox/components/DialogsListItem.tsx");
3390
+ const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
3391
+ const ThreadsViewItem_1 = __webpack_require__(/*! ../components/ThreadsViewItem */ "./src/screens/inbox/components/ThreadsViewItem.tsx");
1705
3392
  const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
1706
3393
  const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
1707
3394
  const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
1708
- const DialogsComponent = (props) => {
1709
- const { channelFilters, channelRole } = props;
3395
+ const { MESSAGES_PER_PAGE } = config_1.config;
3396
+ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelDetail }) => {
1710
3397
  const { params } = (0, native_1.useRoute)();
1711
3398
  const auth = (0, react_redux_1.useSelector)(user_auth0_client_1.userSelector);
1712
3399
  const dispatch = (0, react_redux_1.useDispatch)();
1713
3400
  const navigation = (0, native_1.useNavigation)();
1714
3401
  const isFocused = (0, native_1.useIsFocused)();
1715
3402
  const [refreshing, setRefresh] = (0, react_1.useState)(false);
1716
- // const [userDirectChannel, setUserDirectChannel] = useState<any>([]);
1717
- const { data: userChannels, loading: userChannelsLoading, refetch: getChannelsRefetch, } = (0, platform_client_1.useGetChannelsByUserQuery)({
3403
+ const [threadData, setThreadsData] = (0, react_1.useState)([]);
3404
+ const { data, loading: threadLoading, error, refetch, } = (0, platform_client_1.useThreadMessagesQuery)({
1718
3405
  variables: {
1719
- role: channelRole,
1720
- criteria: channelFilters,
3406
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3407
+ role: role === null || role === void 0 ? void 0 : role.toString(),
3408
+ limit: MESSAGES_PER_PAGE,
1721
3409
  },
1722
- onCompleted: (data) => {
1723
- setRefresh(false);
1724
- }
3410
+ fetchPolicy: 'cache-and-network',
1725
3411
  });
3412
+ const { data: threadCreatedUpdated } = (0, platform_client_1.useOnThreadCreatedUpdatedSubscription)();
1726
3413
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
3414
+ var _a;
1727
3415
  // Do something when the screen is focused
1728
- setRefresh(false);
1729
- getChannelsRefetch({ role: channelRole, criteria: channelFilters });
3416
+ navigation === null || navigation === void 0 ? void 0 : navigation.setOptions({ title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : 'Thread' });
3417
+ refetch({
3418
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3419
+ role: role === null || role === void 0 ? void 0 : role.toString(),
3420
+ limit: MESSAGES_PER_PAGE,
3421
+ }).then(({ data }) => {
3422
+ var _a, _b, _c;
3423
+ if (!((_a = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _a === void 0 ? void 0 : _a.data)) {
3424
+ return;
3425
+ }
3426
+ if ((_c = (_b = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.length) {
3427
+ const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3428
+ setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
3429
+ }
3430
+ });
1730
3431
  return () => {
1731
3432
  // Do something when the screen is unfocused
1732
3433
  // Useful for cleanup functions
1733
3434
  };
1734
- }, [channelFilters]));
1735
- const channels = react_1.default.useMemo(() => {
1736
- var _a, _b, _c;
1737
- if (!((_a = userChannels === null || userChannels === void 0 ? void 0 : userChannels.channelsByUser) === null || _a === void 0 ? void 0 : _a.length))
1738
- return null;
1739
- let uChannels = (_c = (_b = userChannels === null || userChannels === void 0 ? void 0 : userChannels.channelsByUser) === null || _b === void 0 ? void 0 : _b.filter((c) => c.members.some((u) => { var _a; return ((_a = u === null || u === void 0 ? void 0 : u.user) === null || _a === void 0 ? void 0 : _a.id) != (auth === null || auth === void 0 ? void 0 : auth.id) && u.user.__typename == 'UserAccount'; }))) !== null && _c !== void 0 ? _c : [];
1740
- return uChannels || [];
1741
- }, [userChannels]);
1742
- // useEffect(() => {
1743
- // setTimeout(() => {
1744
- // dispatch({
1745
- // type: CHANGE_SETTINGS_ACTION,
1746
- // payload: {
1747
- // footerRender: false,
1748
- // },
1749
- // } as any);
1750
- // }, 0);
1751
- // return () => {
1752
- // dispatch({
1753
- // type: CHANGE_SETTINGS_ACTION,
1754
- // payload: {
1755
- // footerRender: true,
1756
- // },
1757
- // } as any);
1758
- // };
1759
- // }, []);
1760
- // useEffect(() => {
1761
- // if (userChannels?.channelsByUser) {
1762
- // if (userChannels?.channelsByUser?.length == 0) {
1763
- // setUserDirectChannel([]);
1764
- // }
1765
- // //Direct channel
1766
- // let userDirectChannels: any =
1767
- // userChannels?.channelsByUser
1768
- // ?.filter((i: any) => i.type == 'DIRECT')
1769
- // ?.filter((c: any) =>
1770
- // c.members.some((u: any) => u?.user?.id != auth?.id && u.user.__typename == 'UserAccount'),
1771
- // ) ?? [];
1772
- // if (userDirectChannels?.length > 0) setUserDirectChannel(userDirectChannels);
1773
- // }
1774
- // }, [userChannels?.channelsByUser]);
1775
- const handleSelectChannel = (0, react_1.useCallback)((id, title) => {
1776
- var _a;
1777
- if (params === null || params === void 0 ? void 0 : params.channelId) {
1778
- navigation.navigate(config_1.config.INBOX_MESSEGE_PATH, {
1779
- channelId: params === null || params === void 0 ? void 0 : params.channelId,
1780
- title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : null,
1781
- hideTabBar: true,
1782
- });
3435
+ }, []));
3436
+ react_1.default.useEffect(() => {
3437
+ var _a, _b;
3438
+ if ((_b = (_a = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length) {
3439
+ const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3440
+ setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
1783
3441
  }
1784
- else {
1785
- navigation.navigate(config_1.config.INBOX_MESSEGE_PATH, {
1786
- channelId: id,
1787
- title: title,
1788
- hideTabBar: true,
3442
+ }, [data]);
3443
+ react_1.default.useEffect(() => {
3444
+ var _a;
3445
+ if ((_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data) {
3446
+ const { data: newThreads } = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated;
3447
+ setThreadsData((oldThreads) => {
3448
+ const i = oldThreads.findIndex((el) => el.id === (newThreads === null || newThreads === void 0 ? void 0 : newThreads.id));
3449
+ if (i > -1)
3450
+ oldThreads[i] = newThreads; // (2)
3451
+ else
3452
+ oldThreads.push(newThreads);
3453
+ return oldThreads;
1789
3454
  });
3455
+ // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
1790
3456
  }
3457
+ }, [threadCreatedUpdated]);
3458
+ const threads = react_1.default.useMemo(() => {
3459
+ if (!(threadData === null || threadData === void 0 ? void 0 : threadData.length))
3460
+ return null;
3461
+ return threadData || [];
3462
+ }, [threadData]);
3463
+ // const threads = React.useMemo(() => {
3464
+ // if (!data?.threadMessages?.data?.length) return null;
3465
+ // return data?.threadMessages?.data || [];
3466
+ // }, [data]);
3467
+ const handleSelectThread = (0, react_1.useCallback)((id, title, postParentId) => {
3468
+ navigation.navigate(config_1.config.THREAD_MESSEGE_PATH, {
3469
+ channelId: id,
3470
+ role: role === null || role === void 0 ? void 0 : role.toString(),
3471
+ title: title,
3472
+ postParentId: postParentId,
3473
+ hideTabBar: true,
3474
+ });
3475
+ // if (params?.channelId) {
3476
+ // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
3477
+ // channelId: params?.channelId,
3478
+ // title: params?.title ?? null,
3479
+ // postParentId: postParentId,
3480
+ // hideTabBar: true,
3481
+ // });
3482
+ // } else {
3483
+ // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
3484
+ // channelId: id,
3485
+ // title: title,
3486
+ // postParentId: postParentId,
3487
+ // hideTabBar: true,
3488
+ // });
3489
+ // }
1791
3490
  }, []);
1792
3491
  const handleRefresh = (0, react_1.useCallback)(() => {
1793
- //if(userChannels?.channelsByUser?.length != channels?.length)setRefresh(true);
1794
- getChannelsRefetch({ role: channelRole, criteria: channelFilters });
3492
+ refetch({
3493
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3494
+ role: role === null || role === void 0 ? void 0 : role.toString(),
3495
+ limit: MESSAGES_PER_PAGE,
3496
+ }).then(({ data }) => {
3497
+ var _a, _b, _c;
3498
+ if (!((_a = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _a === void 0 ? void 0 : _a.data)) {
3499
+ return;
3500
+ }
3501
+ if ((_c = (_b = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.length) {
3502
+ const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3503
+ setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
3504
+ }
3505
+ });
1795
3506
  }, []);
1796
- return (react_1.default.createElement(native_base_1.Box, { p: 2 },
1797
- react_1.default.createElement(native_base_1.FlatList, { data: channels && (channels === null || channels === void 0 ? void 0 : channels.length) > 0 ? channels : [], onRefresh: handleRefresh, refreshing: userChannelsLoading, contentContainerStyle: { minHeight: '100%' }, ItemSeparatorComponent: () => react_1.default.createElement(native_base_1.Box, { height: "0.5", backgroundColor: "gray.200" }), renderItem: ({ item: channel }) => (react_1.default.createElement(DialogsListItem_1.DialogsListItem, { onOpen: handleSelectChannel, currentUser: auth, channel: channel, selectedChannelId: params === null || params === void 0 ? void 0 : params.channelId })), ListEmptyComponent: () => (react_1.default.createElement(react_1.default.Fragment, null, userChannelsLoading ? (react_1.default.createElement(native_base_1.Spinner, null)) : (react_1.default.createElement(native_base_1.Box, { p: 5 },
1798
- react_1.default.createElement(native_base_1.Heading, null, "Chat"),
1799
- react_1.default.createElement(native_base_1.Input, { height: 50, mt: 3, placeholder: "Search", borderRadius: 50, borderColor: 'gray.200', borderWidth: 2 }),
1800
- react_1.default.createElement(native_base_1.Center, { mt: 6 },
1801
- react_1.default.createElement(native_base_1.Icon, { as: vector_icons_1.Ionicons, name: "chatbubbles", size: 'xl' }),
1802
- react_1.default.createElement(native_base_1.Text, null, "You don't have any messages yet!")))))), keyExtractor: (item, index) => 'key' + index })));
3507
+ const fetchMoreThreads = (0, react_1.useCallback)(() => {
3508
+ refetch({
3509
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3510
+ role: role === null || role === void 0 ? void 0 : role.toString(),
3511
+ skip: threads === null || threads === void 0 ? void 0 : threads.length,
3512
+ });
3513
+ }, []);
3514
+ return (react_1.default.createElement(native_base_1.Box, { flex: 1, p: 2, pb: 0, _dark: {
3515
+ borderColor: 'coolGray.600',
3516
+ backgroundColor: 'gray.700',
3517
+ }, _web: {
3518
+ shadow: 2,
3519
+ borderWidth: 0,
3520
+ }, _light: {
3521
+ backgroundColor: 'gray.50',
3522
+ } },
3523
+ react_1.default.createElement(native_base_1.FlatList, { style: { flex: 1 }, data: threads && (threads === null || threads === void 0 ? void 0 : threads.length) > 0 ? threads : [], onRefresh: handleRefresh, refreshing: threadLoading, contentContainerStyle: { paddingBottom: 60 }, ItemSeparatorComponent: () => react_1.default.createElement(native_base_1.Box, { height: "0.5", backgroundColor: "gray.200" }), renderItem: ({ item: thread }) => (react_1.default.createElement(ThreadsViewItem_1.ThreadViewItem, { onOpen: handleSelectThread, currentUser: auth, thread: thread })), ListEmptyComponent: () => (react_1.default.createElement(react_1.default.Fragment, null,
3524
+ !threadLoading || (threads === null || threads === void 0 ? void 0 : threads.length) == 0,
3525
+ react_1.default.createElement(native_base_1.Box, { p: 5 },
3526
+ react_1.default.createElement(native_base_1.Center, { mt: 6 },
3527
+ react_1.default.createElement(native_base_1.Icon, { as: vector_icons_1.Ionicons, name: "chatbubbles", size: 'xl' }),
3528
+ react_1.default.createElement(native_base_1.Text, null, "You don't have any message yet!"))))), keyExtractor: (item, index) => 'threads-view-key' + index, onEndReached: fetchMoreThreads, onEndReachedThreshold: 0.1 })));
1803
3529
  };
1804
- exports.Dialogs = react_1.default.memo(DialogsComponent);
3530
+ exports.ThreadsView = react_1.default.memo(ThreadsViewComponent);
1805
3531
 
1806
3532
 
1807
3533
  /***/ }),
@@ -1830,6 +3556,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1830
3556
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1831
3557
  __exportStar(__webpack_require__(/*! ./inbox/Inbox */ "./src/screens/inbox/Inbox.tsx"), exports);
1832
3558
  __exportStar(__webpack_require__(/*! ./inbox/DialogMessages */ "./src/screens/inbox/DialogMessages.tsx"), exports);
3559
+ __exportStar(__webpack_require__(/*! ./inbox/DialogThreads */ "./src/screens/inbox/DialogThreads.tsx"), exports);
3560
+ __exportStar(__webpack_require__(/*! ./inbox/DialogThreadMessages */ "./src/screens/inbox/DialogThreadMessages.tsx"), exports);
1833
3561
 
1834
3562
 
1835
3563
  /***/ }),