@messenger-box/platform-mobile 0.0.1-alpha.369 → 0.0.1-alpha.377

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -99,8 +99,11 @@ const inboxConfig = {
99
99
  exact: true,
100
100
  name: 'Message',
101
101
  props: {
102
- initialParams: { channelId: null },
103
- component: (props) => { var _a, _b; return React.createElement(DialogMessages_1.DialogMessages, 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 })); },
102
+ initialParams: { channelId: null, role: null },
103
+ component: (props) => {
104
+ var _a, _b, _c, _d;
105
+ return (React.createElement(DialogMessages_1.DialogMessages, 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, role: (_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.role })));
106
+ },
104
107
  options: ({ navigation }) => {
105
108
  return {
106
109
  headerShown: true,
@@ -225,11 +228,11 @@ exports.DialogMessages = void 0;
225
228
  const React = __importStar(__webpack_require__(/*! react */ "react"));
226
229
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
227
230
  const ConversationView_1 = __webpack_require__(/*! ./containers/ConversationView */ "./src/screens/inbox/containers/ConversationView.tsx");
228
- function DialogMessages({ channelId }) {
231
+ function DialogMessages({ channelId, role }) {
229
232
  return (
230
233
  // <Box bg={'white'} flex={1} pt={5}>
231
234
  React.createElement(native_base_1.Box, { bg: 'white', flex: 1 },
232
- React.createElement(ConversationView_1.ConversationView, { channelId: channelId })));
235
+ React.createElement(ConversationView_1.ConversationView, { channelId: channelId, role: role })));
233
236
  }
234
237
  exports.DialogMessages = DialogMessages;
235
238
 
@@ -295,39 +298,38 @@ function DialogThreadMessages({ channelId, postParentId, isPostParentIdThread, r
295
298
  setParentId(postParentId);
296
299
  }, [postParentId]);
297
300
  React.useEffect(() => {
298
- if (data === null || data === void 0 ? void 0 : data.viewChannelDetail)
301
+ if (data === null || data === void 0 ? void 0 : data.viewChannelDetail) {
299
302
  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
303
  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 }))));
304
+ }
305
+ }, [data]);
306
+ // React.useEffect(() => {
307
+ // async function sendInitialMessage(channel: any) {
308
+ // const content = `Welcome to ${channel?.title}`;
309
+ // const createdBy = channel?.creator?.id;
310
+ // await sendThreadMessage({
311
+ // variables: {
312
+ // channelId,
313
+ // threadMessageInput: {
314
+ // content,
315
+ // role,
316
+ // },
317
+ // responderId: createdBy,
318
+ // },
319
+ // update: (cache, { data, errors }: any) => {
320
+ // if (!data) {
321
+ // return;
322
+ // }
323
+ // setParentId(data?.sendThreadMessage?.lastMessage?.id);
324
+ // },
325
+ // });
326
+ // }
327
+ // if ((!parentId || parentId == 0) && channel) {
328
+ // sendInitialMessage(channel);
329
+ // }
330
+ // if (parentId) setLoading(false);
331
+ // }, [parentId, channel]);
332
+ return (React.createElement(native_base_1.Box, { bg: 'white', flex: 1 }, loading ? (React.createElement(native_base_1.Spinner, null)) : (React.createElement(ThreadConversationView_1.ThreadConversationView, { channelId: channelId, postParentId: parentId, isPostParentIdThread: isPostParentIdThread, role: role }))));
331
333
  }
332
334
  exports.DialogThreadMessages = DialogThreadMessages;
333
335
 
@@ -1292,90 +1294,25 @@ const createdAtText = (value) => {
1292
1294
  const SupportServiceDialogsListItemComponent = function DialogsListItem({ currentUser,
1293
1295
  // users,
1294
1296
  selectedChannelId, channel, onOpen, refreshing, role, }) {
1295
- var _a, _b, _c, _d, _e;
1297
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1296
1298
  const { data: threadMessages, loading: threadMessageLoading, error, refetch: refetchThreadMessages, } = (0, platform_client_1.useThreadMessagesQuery)({
1297
1299
  variables: {
1298
1300
  channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(),
1299
1301
  role,
1300
- limit: 25,
1302
+ limit: 2,
1301
1303
  },
1302
1304
  fetchPolicy: 'cache-and-network',
1303
1305
  });
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
- // });
1315
1306
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
1316
1307
  var _a;
1317
1308
  // Do something when the screen is focused
1318
1309
  // 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 });
1310
+ refetchThreadMessages({ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(), role, limit: 2 });
1320
1311
  return () => {
1321
1312
  // Do something when the screen is unfocused
1322
1313
  // Useful for cleanup functions
1323
1314
  };
1324
1315
  }, [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
1316
  const lastMessage = (0, react_1.useMemo)(() => {
1380
1317
  var _a, _b, _c, _d, _e, _f, _g;
1381
1318
  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)) {
@@ -1416,6 +1353,22 @@ selectedChannelId, channel, onOpen, refreshing, role, }) {
1416
1353
  ? lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId
1417
1354
  : (_a = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) !== null && _a !== void 0 ? _a : 0;
1418
1355
  }, [creatorAndMembersId, lastMessage]);
1356
+ const { data: threadCreatedUpdated } = (0, platform_client_1.useOnThreadCreatedUpdatedSubscription)({
1357
+ variables: {
1358
+ channelId: (_b = channel === null || channel === void 0 ? void 0 : channel.id) === null || _b === void 0 ? void 0 : _b.toString(),
1359
+ postParentId: postParentId == null
1360
+ ? null
1361
+ : (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId)
1362
+ ? (_c = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId) !== null && _c !== void 0 ? _c : null
1363
+ : (_d = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) !== null && _d !== void 0 ? _d : null,
1364
+ },
1365
+ });
1366
+ react_1.default.useEffect(() => {
1367
+ var _a, _b;
1368
+ if ((_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data) {
1369
+ refetchThreadMessages({ channelId: (_b = channel === null || channel === void 0 ? void 0 : channel.id) === null || _b === void 0 ? void 0 : _b.toString(), role, limit: 2 });
1370
+ }
1371
+ }, [threadCreatedUpdated]);
1419
1372
  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
1373
  borderColor: 'coolGray.600',
1421
1374
  backgroundColor: 'gray.700',
@@ -1438,13 +1391,13 @@ selectedChannelId, channel, onOpen, refreshing, role, }) {
1438
1391
  bg: 'transparent',
1439
1392
  } },
1440
1393
  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))))),
1394
+ uri: (_e = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _e === void 0 ? void 0 : _e.picture,
1395
+ } }, (0, lodash_1.startCase)((_g = (_f = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _f === void 0 ? void 0 : _f.username) === null || _g === void 0 ? void 0 : _g.charAt(0))))),
1443
1396
  react_1.default.createElement(native_base_1.Box, { flex: 0.9 },
1444
1397
  react_1.default.createElement(native_base_1.HStack, { space: 1, flex: 1, direction: 'row', justifyContent: 'center', alignItems: 'center' },
1445
1398
  react_1.default.createElement(native_base_1.Box, { flex: 0.8 },
1446
1399
  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 : '')),
1400
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 1 }, (_h = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message) !== null && _h !== void 0 ? _h : '')),
1448
1401
  react_1.default.createElement(native_base_1.Box, { flex: 0.2 },
1449
1402
  react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, lastMessage ? createdAtText(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.createdAt) : '')))))));
1450
1403
  };
@@ -1461,35 +1414,16 @@ exports.SupportServiceDialogsListItem = react_1.default.memo(exports.SupportServ
1461
1414
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1462
1415
 
1463
1416
 
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;
1417
+ var __importDefault = (this && this.__importDefault) || function (mod) {
1418
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1486
1419
  };
1487
1420
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1488
1421
  exports.ThreadViewItem = exports.ThreadViewItemComponent = void 0;
1489
- const react_1 = __importStar(__webpack_require__(/*! react */ "react"));
1422
+ const react_1 = __importDefault(__webpack_require__(/*! react */ "react"));
1490
1423
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
1491
1424
  const date_fns_1 = __webpack_require__(/*! date-fns */ "date-fns");
1492
1425
  const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
1426
+ const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
1493
1427
  const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1494
1428
  const createdAtText = (value) => {
1495
1429
  if (!value)
@@ -1508,8 +1442,14 @@ const createdAtText = (value) => {
1508
1442
  */
1509
1443
  const ThreadViewItemComponent = function DialogsListItem({ currentUser,
1510
1444
  // 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;
1445
+ thread, onOpen, role, setData, }) {
1446
+ var _a, _b, _c, _d, _e, _f;
1447
+ const { data: threadCreatedUpdated } = (0, platform_client_1.useOnThreadCreatedUpdatedSubscription)({
1448
+ variables: {
1449
+ channelId: (_b = (_a = thread === null || thread === void 0 ? void 0 : thread.channel) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.toString(),
1450
+ postParentId: (_d = (_c = thread === null || thread === void 0 ? void 0 : thread.post) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.toString(),
1451
+ },
1452
+ });
1513
1453
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
1514
1454
  // Do something when the screen is focused
1515
1455
  return () => {
@@ -1517,36 +1457,51 @@ thread, onOpen, }) {
1517
1457
  // Useful for cleanup functions
1518
1458
  };
1519
1459
  }, []));
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(() => {
1460
+ react_1.default.useEffect(() => {
1542
1461
  var _a, _b;
1543
- if (!(participants === null || participants === void 0 ? void 0 : participants.length))
1462
+ if ((_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data)
1463
+ setData((_b = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _b === void 0 ? void 0 : _b.data);
1464
+ }, [threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated]);
1465
+ const threadPostReply = react_1.default.useMemo(() => {
1466
+ var _a, _b, _c, _d, _e;
1467
+ if (!(thread === null || thread === void 0 ? void 0 : thread.replies))
1544
1468
  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]);
1469
+ if ((_c = (_b = (_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.replies) === null || _c === void 0 ? void 0 : _c.length) {
1470
+ return (_e = (_d = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.replies;
1471
+ }
1472
+ else
1473
+ return thread === null || thread === void 0 ? void 0 : thread.replies;
1474
+ }, [thread, threadCreatedUpdated]);
1475
+ // const lastMessage = useMemo(() => {
1476
+ // if (!threadPost) {
1477
+ // return null;
1478
+ // }
1479
+ // const replies = threadPost?.replies?.filter((p: any) => p?.message !== '') ?? [];
1480
+ // if (replies?.length) {
1481
+ // return replies[0];
1482
+ // // return replies[replies.length - 1];
1483
+ // } else {
1484
+ // const post = threadPost?.post ?? null;
1485
+ // return post ? post?.post : null;
1486
+ // }
1487
+ // }, [threadPost]);
1488
+ // const participants: any = React.useMemo(() => {
1489
+ // if (!thread?.participants?.length) return null;
1490
+ // return thread?.participants?.filter((u: any) => u?.user?.id !== currentUser?.id) ?? [];
1491
+ // }, [thread]);
1492
+ // const allParticipantsNames: any = React.useMemo(() => {
1493
+ // if (!participants?.length) return null;
1494
+ // return (
1495
+ // participants
1496
+ // ?.map((p: any) => {
1497
+ // return p?.user?.givenName + ' ' + p?.user?.familyName ?? '';
1498
+ // })
1499
+ // ?.join(', ') ?? ''
1500
+ // );
1501
+ // }, [participants]);
1502
+ if (!threadPostReply || (threadPostReply === null || threadPostReply === void 0 ? void 0 : threadPostReply.length) == 0) {
1503
+ return react_1.default.createElement(react_1.default.Fragment, null);
1504
+ }
1550
1505
  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
1506
  borderColor: 'white',
1552
1507
  backgroundColor: 'white',
@@ -1564,41 +1519,33 @@ thread, onOpen, }) {
1564
1519
  // pl={3}
1565
1520
  py: 2, space: 2, w: '100%', flex: 1, direction: 'row', justifyContent: 'space-between', alignItems: 'center' },
1566
1521
  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
1522
  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 },
1523
+ react_1.default.createElement(native_base_1.Box, { flex: 1 }, (threadPostReply === null || threadPostReply === void 0 ? void 0 : threadPostReply.length) > 0 && (react_1.default.createElement(react_1.default.Fragment, null, (_f = (_e = threadPostReply === null || threadPostReply === void 0 ? void 0 : threadPostReply.slice(0, 2)) === null || _e === void 0 ? void 0 : _e.reverse()) === null || _f === void 0 ? void 0 : _f.map((reply, index) => {
1524
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1525
+ return (react_1.default.createElement(native_base_1.HStack, { key: index, space: 2, pb: 2, pt: 1 },
1575
1526
  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)))),
1527
+ react_1.default.createElement(native_base_1.Avatar, { bg: 'transparent', size: 8, _image: {
1528
+ borderRadius: 6,
1529
+ borderWidth: 2,
1530
+ borderColor: '#fff',
1531
+ }, source: {
1532
+ uri: (_a = reply === null || reply === void 0 ? void 0 : reply.author) === null || _a === void 0 ? void 0 : _a.picture,
1533
+ } }, (0, lodash_1.startCase)((_c = (_b = reply === null || reply === void 0 ? void 0 : reply.author) === null || _b === void 0 ? void 0 : _b.username) === null || _c === void 0 ? void 0 : _c.charAt(0)))),
1579
1534
  react_1.default.createElement(native_base_1.Box, null,
1580
1535
  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)}....`
1536
+ react_1.default.createElement(native_base_1.Text, null, (_f = (_e = (_d = reply === null || reply === void 0 ? void 0 : reply.author) === null || _d === void 0 ? void 0 : _d.givenName) !== null && _e !== void 0 ? _e : '') !== null && _f !== void 0 ? _f : '',
1537
+ ' ', (_j = (_h = (_g = reply === null || reply === void 0 ? void 0 : reply.author) === null || _g === void 0 ? void 0 : _g.familyName) !== null && _h !== void 0 ? _h : '') !== null && _j !== void 0 ? _j : ''),
1538
+ react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, (reply === null || reply === void 0 ? void 0 : reply.createdAt) ? createdAtText(reply === null || reply === void 0 ? void 0 : reply.createdAt) : '')),
1539
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 2 }, (reply === null || reply === void 0 ? void 0 : reply.message)
1540
+ ? (reply === null || reply === void 0 ? void 0 : reply.message.length) < 70
1541
+ ? `${reply === null || reply === void 0 ? void 0 : reply.message}`
1542
+ : `${reply === null || reply === void 0 ? void 0 : reply.message.substring(0, 68)}....`
1600
1543
  : ''),
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"))))))))));
1544
+ ((threadPostReply === null || threadPostReply === void 0 ? void 0 : threadPostReply.length) == 1 || index !== 0) && (react_1.default.createElement(native_base_1.Button, { size: 'xs', w: 150, variant: 'outline', _text: { fontSize: 12, color: '#000' }, onPress: () => {
1545
+ var _a, _b, _c;
1546
+ 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);
1547
+ } }, "Reply")))));
1548
+ })))))))));
1602
1549
  };
1603
1550
  exports.ThreadViewItemComponent = ThreadViewItemComponent;
1604
1551
  exports.ThreadViewItem = react_1.default.memo(exports.ThreadViewItemComponent);
@@ -1710,7 +1657,7 @@ const createdAtText = (value) => {
1710
1657
  return 'Yesterday';
1711
1658
  return (0, date_fns_1.format)(new Date(value), 'MMM dd, yyyy');
1712
1659
  };
1713
- const ConversationViewComponent = ({ channelId }) => {
1660
+ const ConversationViewComponent = ({ channelId, role }) => {
1714
1661
  var _a;
1715
1662
  const [channelToTop, setChannelToTop] = (0, react_1.useState)(0);
1716
1663
  const [channelMessages, setChannelMessages] = (0, react_1.useState)([]);
@@ -2356,7 +2303,7 @@ const ConversationViewComponent = ({ channelId }) => {
2356
2303
  react_1.default.createElement(vector_icons_1.MaterialCommunityIcons, { name: "send-circle", style: { marginBottom: 5, marginRight: 5 }, size: 32, color: "#2e64e5" }))));
2357
2304
  };
2358
2305
  const renderMessageText = (props) => {
2359
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
2306
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13;
2360
2307
  const { currentMessage } = props;
2361
2308
  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
2309
  if (currentMessage.type === 'ALERT') {
@@ -2364,22 +2311,33 @@ const ConversationViewComponent = ({ channelId }) => {
2364
2311
  let action = '';
2365
2312
  let actionId = '';
2366
2313
  let params = {};
2367
- if ((_g = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _g === void 0 ? void 0 : _g.route) {
2368
- const { path, params: routeParams } = (_h = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _h === void 0 ? void 0 : _h.route;
2314
+ if ((_g = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _g === void 0 ? void 0 : _g.extraParams) {
2315
+ const extraParams = (_h = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _h === void 0 ? void 0 : _h.extraParams;
2316
+ const route = (_j = extraParams === null || extraParams === void 0 ? void 0 : extraParams.route) !== null && _j !== void 0 ? _j : null;
2317
+ let path = null;
2318
+ let param = null;
2319
+ if (role && role == platform_client_1.IPreDefinedRole.Guest) {
2320
+ path = ((_k = route === null || route === void 0 ? void 0 : route.guest) === null || _k === void 0 ? void 0 : _k.name) ? (_m = (_l = route === null || route === void 0 ? void 0 : route.guest) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : null : null;
2321
+ param = ((_o = route === null || route === void 0 ? void 0 : route.guest) === null || _o === void 0 ? void 0 : _o.params) ? (_q = (_p = route === null || route === void 0 ? void 0 : route.guest) === null || _p === void 0 ? void 0 : _p.params) !== null && _q !== void 0 ? _q : null : null;
2322
+ }
2323
+ else if (role && role == platform_client_1.IPreDefinedRole.Owner) {
2324
+ path = ((_r = route === null || route === void 0 ? void 0 : route.host) === null || _r === void 0 ? void 0 : _r.name) ? (_t = (_s = route === null || route === void 0 ? void 0 : route.host) === null || _s === void 0 ? void 0 : _s.name) !== null && _t !== void 0 ? _t : null : null;
2325
+ param = ((_u = route === null || route === void 0 ? void 0 : route.host) === null || _u === void 0 ? void 0 : _u.params) ? (_w = (_v = route === null || route === void 0 ? void 0 : route.host) === null || _v === void 0 ? void 0 : _v.params) !== null && _w !== void 0 ? _w : null : null;
2326
+ }
2327
+ else {
2328
+ path = ((_x = route === null || route === void 0 ? void 0 : route.host) === null || _x === void 0 ? void 0 : _x.name) ? (_z = (_y = route === null || route === void 0 ? void 0 : route.host) === null || _y === void 0 ? void 0 : _y.name) !== null && _z !== void 0 ? _z : null : null;
2329
+ param = ((_0 = route === null || route === void 0 ? void 0 : route.host) === null || _0 === void 0 ? void 0 : _0.params) ? (_2 = (_1 = route === null || route === void 0 ? void 0 : route.host) === null || _1 === void 0 ? void 0 : _1.params) !== null && _2 !== void 0 ? _2 : null : null;
2330
+ }
2369
2331
  action = path;
2370
- params = Object.assign({}, routeParams);
2332
+ params = Object.assign({}, param);
2371
2333
  }
2372
- else if ((_j = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _j === void 0 ? void 0 : _j.link) {
2334
+ else if ((_3 = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _3 === void 0 ? void 0 : _3.link) {
2373
2335
  action = CALL_TO_ACTION_PATH;
2374
- actionId = (_k = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _k === void 0 ? void 0 : _k.link.split('/').pop();
2336
+ actionId = (_4 = attachment === null || attachment === void 0 ? void 0 : attachment.callToAction) === null || _4 === void 0 ? void 0 : _4.link.split('/').pop();
2375
2337
  params = { reservationId: actionId };
2376
2338
  }
2377
- // if (attachment?.callToAction?.link?.includes('my-reservation-details')) {
2378
- // action = 'm-reservation-detail';
2379
- // actionId = attachment?.callToAction?.link.split('/').pop();
2380
- // }
2381
2339
  return (react_1.default.createElement(native_base_1.Box, { bg: CALL_TO_ACTION_BOX_BGCOLOR, borderRadius: 15, pb: 2 },
2382
- (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, params) },
2340
+ (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: () => action && params && navigation.navigate(action, params) },
2383
2341
  react_1.default.createElement(native_base_1.Text, { color: CALL_TO_ACTION_TEXT_COLOR }, attachment.callToAction.title))) : null,
2384
2342
  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 } } }))));
2385
2343
  }
@@ -2392,8 +2350,8 @@ const ConversationViewComponent = ({ channelId }) => {
2392
2350
  }) },
2393
2351
  react_1.default.createElement(react_1.default.Fragment, null,
2394
2352
  react_1.default.createElement(react_native_gifted_chat_1.MessageText, Object.assign({}, props, { textStyle: { left: { marginLeft: 5 } } })),
2395
- ((_m = (_l = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.length) > 0 && (react_1.default.createElement(native_base_1.HStack, { space: 1, px: 1, alignItems: 'center' },
2396
- react_1.default.createElement(native_base_1.HStack, null, (_s = (_r = (_q = (_p = (_o = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.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 || _q === void 0 ? void 0 : _q.slice(0, 2)) === null || _r === void 0 ? void 0 : _r.reverse()) === null || _s === void 0 ? void 0 : _s.map((p, i) => {
2353
+ ((_6 = (_5 = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _5 === void 0 ? void 0 : _5.data) === null || _6 === void 0 ? void 0 : _6.length) > 0 && (react_1.default.createElement(native_base_1.HStack, { space: 1, px: 1, alignItems: 'center' },
2354
+ react_1.default.createElement(native_base_1.HStack, null, (_11 = (_10 = (_9 = (_8 = (_7 = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _7 === void 0 ? void 0 : _7.data) === null || _8 === void 0 ? void 0 : _8.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 || _9 === void 0 ? void 0 : _9.slice(0, 2)) === null || _10 === void 0 ? void 0 : _10.reverse()) === null || _11 === void 0 ? void 0 : _11.map((p, i) => {
2397
2355
  var _a, _b, _c;
2398
2356
  return (react_1.default.createElement(native_base_1.Avatar, { key: 'key' + i, bg: 'transparent', size: 6,
2399
2357
  // top={i == 1 ? 4 : 0}
@@ -2403,10 +2361,10 @@ const ConversationViewComponent = ({ channelId }) => {
2403
2361
  uri: (_a = p === null || p === void 0 ? void 0 : p.author) === null || _a === void 0 ? void 0 : _a.picture,
2404
2362
  } }, (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))));
2405
2363
  })),
2406
- react_1.default.createElement(native_base_1.Text, { fontSize: 12, fontWeight: 'bold', color: 'blue.800' }, (_t = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _t === void 0 ? void 0 :
2407
- _t.totalCount,
2364
+ react_1.default.createElement(native_base_1.Text, { fontSize: 12, fontWeight: 'bold', color: 'blue.800' }, (_12 = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _12 === void 0 ? void 0 :
2365
+ _12.totalCount,
2408
2366
  ' ',
2409
- ((_u = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _u === void 0 ? void 0 : _u.totalCount) == 1 ? 'reply' : 'replies'),
2367
+ ((_13 = currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.replies) === null || _13 === void 0 ? void 0 : _13.totalCount) == 1 ? 'reply' : 'replies'),
2410
2368
  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) : ''))))));
2411
2369
  }
2412
2370
  };
@@ -2578,7 +2536,7 @@ const DialogsComponent = (props) => {
2578
2536
  },
2579
2537
  onCompleted: (data) => {
2580
2538
  setRefresh(false);
2581
- }
2539
+ },
2582
2540
  });
2583
2541
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
2584
2542
  // Do something when the screen is focused
@@ -2634,6 +2592,7 @@ const DialogsComponent = (props) => {
2634
2592
  if (params === null || params === void 0 ? void 0 : params.channelId) {
2635
2593
  navigation.navigate(config_1.config.INBOX_MESSEGE_PATH, {
2636
2594
  channelId: params === null || params === void 0 ? void 0 : params.channelId,
2595
+ role: params === null || params === void 0 ? void 0 : params.role,
2637
2596
  title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : null,
2638
2597
  hideTabBar: true,
2639
2598
  });
@@ -2641,6 +2600,7 @@ const DialogsComponent = (props) => {
2641
2600
  else {
2642
2601
  navigation.navigate(config_1.config.INBOX_MESSEGE_PATH, {
2643
2602
  channelId: id,
2603
+ role: channelRole,
2644
2604
  title: title,
2645
2605
  hideTabBar: true,
2646
2606
  });
@@ -2940,10 +2900,10 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2940
2900
  const { data: threads, totalCount: threadTotalCount } = threadMessagesData === null || threadMessagesData === void 0 ? void 0 : threadMessagesData.threadMessages;
2941
2901
  const threadMessage = threads === null || threads === void 0 ? void 0 : threads.map((t) => t === null || t === void 0 ? void 0 : t.post);
2942
2902
  setThreadPost(threadMessage);
2943
- if (!isPostParentIdThread) {
2944
- // setTotalCount((pc: any) => pc + threadTotalCount);
2945
- setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...threadMessage, ...oldMessages], ({ id }) => id));
2946
- }
2903
+ // if (!isPostParentIdThread) {
2904
+ // // setTotalCount((pc: any) => pc + threadTotalCount);
2905
+ // setChannelMessages((oldMessages: any) => uniqBy([...threadMessage, ...oldMessages], ({ id }) => id));
2906
+ // }
2947
2907
  }
2948
2908
  }, [threadMessagesData, isPostParentIdThread]);
2949
2909
  react_1.default.useEffect(() => {
@@ -2965,7 +2925,7 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2965
2925
  // }
2966
2926
  // }, [data, loadingOldMessages, channelMessages, totalCount]);
2967
2927
  (0, react_1.useEffect)(() => {
2968
- var _a, _b;
2928
+ var _a, _b, _c;
2969
2929
  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)) {
2970
2930
  const { data: messages, totalCount: messeageTotalCount } = data.messages;
2971
2931
  if (messages && messages.length > 0) {
@@ -2976,7 +2936,11 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2976
2936
  if (loadingOldMessages)
2977
2937
  setLoadingOldMessages(false);
2978
2938
  }
2979
- }, [data, loadingOldMessages, channelMessages]);
2939
+ if ((threadPost === null || threadPost === void 0 ? void 0 : threadPost.length) && ((_c = data === null || data === void 0 ? void 0 : data.messages) === null || _c === void 0 ? void 0 : _c.totalCount) == channelMessages.length) {
2940
+ // setTotalCount((pc: any) => pc + threadTotalCount);
2941
+ setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...threadPost, ...oldMessages], ({ id }) => id));
2942
+ }
2943
+ }, [data, loadingOldMessages, channelMessages, threadPost]);
2980
2944
  // useEffect(() => {
2981
2945
  // if (
2982
2946
  // !messageLoading &&
@@ -3133,6 +3097,7 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3133
3097
  }
3134
3098
  const responseMessage = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage;
3135
3099
  if (!parentId || parentId == 0) {
3100
+ setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3136
3101
  setChannelMessages((messages) => [
3137
3102
  ...messages,
3138
3103
  Object.assign(Object.assign({}, responseMessage), { files: {
@@ -3145,9 +3110,9 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3145
3110
  setChannelToTop(channelToTop + 1);
3146
3111
  setLoading(false);
3147
3112
  setMsg('');
3148
- if (!parentId || parentId == 0) {
3149
- setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3150
- }
3113
+ // if (!parentId || parentId == 0) {
3114
+ // setParentId(responseMessage?.id);
3115
+ // }
3151
3116
  const msg = message == '' ? 'Send a file' : message;
3152
3117
  fetchTokenAndSendPushNotification(msg, channelId, parentId);
3153
3118
  },
@@ -3173,15 +3138,16 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3173
3138
  }
3174
3139
  const responseMessage = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage;
3175
3140
  if (!parentId || parentId == 0) {
3141
+ setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3176
3142
  setChannelMessages((messages) => [...messages, responseMessage]);
3177
3143
  setTotalCount((t) => t + 1);
3178
3144
  }
3179
3145
  setChannelToTop(channelToTop + 1);
3180
3146
  setLoading(false);
3181
3147
  setMsg('');
3182
- if (!parentId || parentId == 0) {
3183
- setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3184
- }
3148
+ // if (!parentId || parentId == 0) {
3149
+ // setParentId(responseMessage?.id);
3150
+ // }
3185
3151
  fetchTokenAndSendPushNotification(message, channelId, parentId);
3186
3152
  },
3187
3153
  });
@@ -3416,7 +3382,9 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3416
3382
  },
3417
3383
  fetchPolicy: 'cache-and-network',
3418
3384
  });
3419
- const { data: threadCreatedUpdated } = (0, platform_client_1.useOnThreadCreatedUpdatedSubscription)();
3385
+ // const { data: threadCreatedUpdated } = useOnThreadCreatedUpdatedSubscription({
3386
+ // variables: { channelId: channelId?.toString() },
3387
+ // });
3420
3388
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
3421
3389
  var _a;
3422
3390
  // Do something when the screen is focused
@@ -3439,7 +3407,7 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3439
3407
  // Do something when the screen is unfocused
3440
3408
  // Useful for cleanup functions
3441
3409
  };
3442
- }, []));
3410
+ }, [channelId]));
3443
3411
  react_1.default.useEffect(() => {
3444
3412
  var _a, _b;
3445
3413
  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) {
@@ -3447,26 +3415,42 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3447
3415
  setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
3448
3416
  }
3449
3417
  }, [data]);
3450
- react_1.default.useEffect(() => {
3451
- var _a;
3452
- if ((_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data) {
3453
- const { data: newThreads } = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated;
3454
- setThreadsData((oldThreads) => {
3455
- const i = oldThreads.findIndex((el) => el.id === (newThreads === null || newThreads === void 0 ? void 0 : newThreads.id));
3456
- if (i > -1)
3457
- oldThreads[i] = newThreads; // (2)
3458
- else
3459
- oldThreads.push(newThreads);
3460
- return oldThreads;
3461
- });
3462
- // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
3463
- }
3464
- }, [threadCreatedUpdated]);
3418
+ // React.useEffect(() => {
3419
+ // if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
3420
+ // const { data: newThreads } = threadCreatedUpdated?.threadCreatedUpdated;
3421
+ // setThreadsData((oldThreads: any) => {
3422
+ // const i = oldThreads.findIndex((el: any) => el.id === newThreads?.id);
3423
+ // if (i > -1) oldThreads[i] = newThreads; // (2)
3424
+ // else oldThreads.push(newThreads);
3425
+ // return oldThreads;
3426
+ // });
3427
+ // // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
3428
+ // }
3429
+ // }, [threadCreatedUpdated]);
3430
+ const setData = react_1.default.useCallback((newThreads) => {
3431
+ setThreadsData((oldThreads) => {
3432
+ const i = oldThreads.findIndex((el) => el.id === (newThreads === null || newThreads === void 0 ? void 0 : newThreads.id));
3433
+ if (i > -1)
3434
+ oldThreads[i] = newThreads; // (2)
3435
+ else
3436
+ oldThreads.push(newThreads);
3437
+ return oldThreads;
3438
+ });
3439
+ // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
3440
+ }, []);
3465
3441
  const threads = react_1.default.useMemo(() => {
3466
3442
  if (!(threadData === null || threadData === void 0 ? void 0 : threadData.length))
3467
3443
  return null;
3468
- return threadData || [];
3444
+ return (0, lodash_1.orderBy)(threadData, ['updatedAt'], ['desc']) || [];
3445
+ //return threadData || [];
3469
3446
  }, [threadData]);
3447
+ const threadReplies = react_1.default.useMemo(() => {
3448
+ var _a;
3449
+ if (!(threads === null || threads === void 0 ? void 0 : threads.length))
3450
+ return null;
3451
+ return ((_a = threads === null || threads === void 0 ? void 0 : threads.map((t) => t === null || t === void 0 ? void 0 : t.replies)) === null || _a === void 0 ? void 0 : _a.flat(1)) || [];
3452
+ //return threadData || [];
3453
+ }, [threads]);
3470
3454
  // const threads = React.useMemo(() => {
3471
3455
  // if (!data?.threadMessages?.data?.length) return null;
3472
3456
  // return data?.threadMessages?.data || [];
@@ -3518,6 +3502,13 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3518
3502
  skip: threads === null || threads === void 0 ? void 0 : threads.length,
3519
3503
  });
3520
3504
  }, []);
3505
+ // if (!threadReplies || threadReplies?.length == 0) {
3506
+ // return (
3507
+ // <Center w="full" bg={'f8f8f8'} height={'full'}>
3508
+ // You don't have any message yet!
3509
+ // </Center>
3510
+ // );
3511
+ // }
3521
3512
  return (react_1.default.createElement(native_base_1.Box, { flex: 1, p: 2, pb: 0, _dark: {
3522
3513
  borderColor: 'coolGray.600',
3523
3514
  backgroundColor: 'gray.700',
@@ -3527,7 +3518,7 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3527
3518
  }, _light: {
3528
3519
  backgroundColor: 'gray.50',
3529
3520
  } },
3530
- 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,
3521
+ 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, index }) => (react_1.default.createElement(ThreadsViewItem_1.ThreadViewItem, { key: index, onOpen: handleSelectThread, currentUser: auth, thread: thread, role: role, setData: setData })), ListEmptyComponent: () => (react_1.default.createElement(react_1.default.Fragment, null,
3531
3522
  !threadLoading || (threads === null || threads === void 0 ? void 0 : threads.length) == 0,
3532
3523
  react_1.default.createElement(native_base_1.Box, { p: 5 },
3533
3524
  react_1.default.createElement(native_base_1.Center, { mt: 6 },