@messenger-box/platform-mobile 0.0.1-alpha.411 → 0.0.1-alpha.421

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
@@ -1371,8 +1371,9 @@ const createdAtText = (value) => {
1371
1371
  const SupportServiceDialogsListItemComponent = function DialogsListItem({ currentUser,
1372
1372
  // users,
1373
1373
  selectedChannelId, channel, onOpen, refreshing, role, }) {
1374
- var _a, _b, _c, _d, _e, _f, _g, _h;
1375
- const { data: threadMessages, loading: threadMessageLoading, error, refetch: refetchThreadMessages, } = (0, platform_client_1.useThreadMessagesQuery)({
1374
+ var _a, _b, _c, _d;
1375
+ const [servicePostParentId, setServicePostParentId] = react_1.default.useState(null);
1376
+ const { data: threadMessages, loading: threadMessageLoading, error, refetch: refetchThreadMessages, subscribeToMore, } = (0, platform_client_1.useThreadMessagesQuery)({
1376
1377
  variables: {
1377
1378
  channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(),
1378
1379
  role,
@@ -1411,6 +1412,12 @@ selectedChannelId, channel, onOpen, refreshing, role, }) {
1411
1412
  return post ? post === null || post === void 0 ? void 0 : post.post : null;
1412
1413
  }
1413
1414
  }, [threadMessages]);
1415
+ react_1.default.useEffect(() => {
1416
+ if (lastMessage) {
1417
+ const sParentId = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId) ? lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId : lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id;
1418
+ setServicePostParentId(sParentId);
1419
+ }
1420
+ }, [lastMessage]);
1414
1421
  const creatorAndMembersId = react_1.default.useMemo(() => {
1415
1422
  var _a, _b, _c, _d, _e, _f;
1416
1423
  if (!(channel === null || channel === void 0 ? void 0 : channel.members))
@@ -1430,22 +1437,22 @@ selectedChannelId, channel, onOpen, refreshing, role, }) {
1430
1437
  ? lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId
1431
1438
  : (_a = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) !== null && _a !== void 0 ? _a : 0;
1432
1439
  }, [creatorAndMembersId, lastMessage]);
1433
- const { data: threadCreatedUpdated } = (0, platform_client_1.useOnThreadCreatedUpdatedSubscription)({
1434
- variables: {
1435
- channelId: (_b = channel === null || channel === void 0 ? void 0 : channel.id) === null || _b === void 0 ? void 0 : _b.toString(),
1436
- postParentId: postParentId == null
1437
- ? null
1438
- : (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId)
1439
- ? (_c = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parentId) !== null && _c !== void 0 ? _c : null
1440
- : (_d = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) !== null && _d !== void 0 ? _d : null,
1441
- },
1442
- });
1443
- react_1.default.useEffect(() => {
1444
- var _a, _b;
1445
- if ((_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data) {
1446
- refetchThreadMessages({ channelId: (_b = channel === null || channel === void 0 ? void 0 : channel.id) === null || _b === void 0 ? void 0 : _b.toString(), role, limit: 2 });
1447
- }
1448
- }, [threadCreatedUpdated]);
1440
+ // const { data: threadCreatedUpdated } = useOnThreadCreatedUpdatedSubscription({
1441
+ // variables: {
1442
+ // channelId: channel?.id?.toString(),
1443
+ // postParentId:
1444
+ // postParentId == null
1445
+ // ? null
1446
+ // : lastMessage?.parentId
1447
+ // ? lastMessage?.parentId ?? null
1448
+ // : lastMessage?.id ?? null,
1449
+ // },
1450
+ // });
1451
+ // React.useEffect(() => {
1452
+ // if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
1453
+ // refetchThreadMessages({ channelId: channel?.id?.toString(), role, limit: 2 });
1454
+ // }
1455
+ // }, [threadCreatedUpdated]);
1449
1456
  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: {
1450
1457
  borderColor: 'coolGray.600',
1451
1458
  backgroundColor: 'gray.700',
@@ -1468,17 +1475,45 @@ selectedChannelId, channel, onOpen, refreshing, role, }) {
1468
1475
  bg: 'transparent',
1469
1476
  } },
1470
1477
  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: {
1471
- uri: (_e = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _e === void 0 ? void 0 : _e.picture,
1472
- } }, (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))))),
1478
+ uri: (_b = channel === null || channel === void 0 ? void 0 : channel.creator) === null || _b === void 0 ? void 0 : _b.picture,
1479
+ } }, (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))))),
1473
1480
  react_1.default.createElement(native_base_1.Box, { flex: 0.9 },
1474
- react_1.default.createElement(native_base_1.HStack, { space: 1, flex: 1, direction: 'row', justifyContent: 'center', alignItems: 'center' },
1475
- react_1.default.createElement(native_base_1.Box, { flex: 0.8 },
1476
- 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),
1477
- 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 : '')),
1478
- react_1.default.createElement(native_base_1.Box, { flex: 0.2 },
1479
- react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, lastMessage ? createdAtText(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.createdAt) : '')))))));
1481
+ react_1.default.createElement(ServiceChannelWithLastMessage, { channel: channel, lastMessage: lastMessage, subscribeToNewMessages: () => {
1482
+ var _a;
1483
+ return subscribeToMore({
1484
+ document: platform_client_1.OnThreadCreatedUpdatedDocument,
1485
+ variables: {
1486
+ channelId: (_a = channel === null || channel === void 0 ? void 0 : channel.id) === null || _a === void 0 ? void 0 : _a.toString(),
1487
+ postParentId: postParentId ? servicePostParentId : null,
1488
+ },
1489
+ updateQuery: (prev, { subscriptionData }) => {
1490
+ var _a, _b, _c, _d, _e, _f;
1491
+ if (!subscriptionData.data)
1492
+ return prev;
1493
+ const newPostThreadData = (_b = (_a = subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data) === null || _a === void 0 ? void 0 : _a.threadCreatedUpdated) === null || _b === void 0 ? void 0 : _b.data;
1494
+ const newMessage = (_d = (_c = subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data) === null || _c === void 0 ? void 0 : _c.threadCreatedUpdated) === null || _d === void 0 ? void 0 : _d.lastMessage;
1495
+ const data = (_f = (_e = prev === null || prev === void 0 ? void 0 : prev.threadMessages) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.map((t) => t.id === (newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.id)
1496
+ ? Object.assign(Object.assign({}, t), { replies: [...t === null || t === void 0 ? void 0 : t.replies, newMessage], replyCount: newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.replyCount, lastReplyAt: newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.lastReplyAt, updatedAt: newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.updatedAt }) : t);
1497
+ return Object.assign({}, prev, {
1498
+ threadMessages: Object.assign(Object.assign({}, prev === null || prev === void 0 ? void 0 : prev.threadMessages), {
1499
+ // totalCount: prev?.threadMessages?.totalCount + 1,
1500
+ data: data }),
1501
+ });
1502
+ },
1503
+ });
1504
+ } })))));
1480
1505
  };
1481
1506
  exports.SupportServiceDialogsListItemComponent = SupportServiceDialogsListItemComponent;
1507
+ const ServiceChannelWithLastMessage = react_1.default.memo(({ channel, lastMessage, subscribeToNewMessages }) => {
1508
+ var _a;
1509
+ react_1.default.useEffect(() => subscribeToNewMessages(), []);
1510
+ return (react_1.default.createElement(native_base_1.HStack, { space: 1, flex: 1, direction: 'row', justifyContent: 'center', alignItems: 'center' },
1511
+ react_1.default.createElement(native_base_1.Box, { flex: 0.8 },
1512
+ 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),
1513
+ react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 1 }, (_a = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message) !== null && _a !== void 0 ? _a : '')),
1514
+ react_1.default.createElement(native_base_1.Box, { flex: 0.2 },
1515
+ react_1.default.createElement(native_base_1.Text, { color: "gray.500" }, lastMessage ? createdAtText(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.createdAt) : ''))));
1516
+ });
1482
1517
  exports.SupportServiceDialogsListItem = react_1.default.memo(exports.SupportServiceDialogsListItemComponent);
1483
1518
 
1484
1519
 
@@ -1500,7 +1535,6 @@ const react_1 = __importDefault(__webpack_require__(/*! react */ "react"));
1500
1535
  const native_base_1 = __webpack_require__(/*! native-base */ "native-base");
1501
1536
  const date_fns_1 = __webpack_require__(/*! date-fns */ "date-fns");
1502
1537
  const native_1 = __webpack_require__(/*! @react-navigation/native */ "@react-navigation/native");
1503
- const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
1504
1538
  const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1505
1539
  const createdAtText = (value) => {
1506
1540
  if (!value)
@@ -1520,13 +1554,13 @@ const createdAtText = (value) => {
1520
1554
  const ThreadViewItemComponent = function DialogsListItem({ currentUser,
1521
1555
  // users,
1522
1556
  thread, onOpen, role, setData, }) {
1523
- var _a, _b, _c, _d, _e, _f;
1524
- const { data: threadCreatedUpdated } = (0, platform_client_1.useOnThreadCreatedUpdatedSubscription)({
1525
- variables: {
1526
- 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(),
1527
- 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(),
1528
- },
1529
- });
1557
+ // const { data: threadCreatedUpdated } = useOnThreadCreatedUpdatedSubscription({
1558
+ // variables: {
1559
+ // channelId: thread?.channel?.id?.toString(),
1560
+ // postParentId: thread?.post?.id?.toString(),
1561
+ // },
1562
+ // });
1563
+ var _a, _b;
1530
1564
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
1531
1565
  // Do something when the screen is focused
1532
1566
  return () => {
@@ -1534,21 +1568,20 @@ thread, onOpen, role, setData, }) {
1534
1568
  // Useful for cleanup functions
1535
1569
  };
1536
1570
  }, []));
1537
- react_1.default.useEffect(() => {
1538
- var _a, _b;
1539
- if ((_a = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _a === void 0 ? void 0 : _a.data)
1540
- setData((_b = threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated) === null || _b === void 0 ? void 0 : _b.data);
1541
- }, [threadCreatedUpdated === null || threadCreatedUpdated === void 0 ? void 0 : threadCreatedUpdated.threadCreatedUpdated]);
1542
1571
  const threadPostReply = react_1.default.useMemo(() => {
1543
- var _a, _b, _c, _d, _e;
1544
1572
  if (!(thread === null || thread === void 0 ? void 0 : thread.replies))
1545
1573
  return null;
1546
- 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) {
1547
- 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;
1548
- }
1549
- else
1550
- return thread === null || thread === void 0 ? void 0 : thread.replies;
1551
- }, [thread, threadCreatedUpdated]);
1574
+ return thread === null || thread === void 0 ? void 0 : thread.replies;
1575
+ }, [thread]);
1576
+ // React.useEffect(() => {
1577
+ // if (threadCreatedUpdated?.threadCreatedUpdated?.data) setData(threadCreatedUpdated?.threadCreatedUpdated?.data);
1578
+ // }, [threadCreatedUpdated?.threadCreatedUpdated]);
1579
+ // const threadPostReply = React.useMemo(() => {
1580
+ // if (!thread?.replies) return null;
1581
+ // if (threadCreatedUpdated?.threadCreatedUpdated?.data?.replies?.length) {
1582
+ // return threadCreatedUpdated?.threadCreatedUpdated?.data?.replies;
1583
+ // } else return thread?.replies;
1584
+ // }, [thread, threadCreatedUpdated]);
1552
1585
  // const lastMessage = useMemo(() => {
1553
1586
  // if (!threadPost) {
1554
1587
  // return null;
@@ -1597,8 +1630,8 @@ thread, onOpen, role, setData, }) {
1597
1630
  py: 2, space: 2, w: '100%', flex: 1, direction: 'row', justifyContent: 'space-between', alignItems: 'center' },
1598
1631
  react_1.default.createElement(native_base_1.Box, { flex: 1 },
1599
1632
  react_1.default.createElement(native_base_1.HStack, { space: 1, flex: 1, direction: 'row', justifyContent: 'center', alignItems: 'center' },
1600
- 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) => {
1601
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1633
+ 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, (_b = (_a = threadPostReply === null || threadPostReply === void 0 ? void 0 : threadPostReply.slice(0, 2)) === null || _a === void 0 ? void 0 : _a.reverse()) === null || _b === void 0 ? void 0 : _b.map((reply, index) => {
1634
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
1602
1635
  return (react_1.default.createElement(native_base_1.HStack, { key: index, space: 2, pb: 2, pt: 1 },
1603
1636
  react_1.default.createElement(native_base_1.Box, null,
1604
1637
  react_1.default.createElement(native_base_1.Avatar, { bg: 'transparent', size: 8, _image: {
@@ -1613,11 +1646,19 @@ thread, onOpen, role, setData, }) {
1613
1646
  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 : '',
1614
1647
  ' ', (_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 : ''),
1615
1648
  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) : '')),
1616
- react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 2 }, (reply === null || reply === void 0 ? void 0 : reply.message)
1617
- ? (reply === null || reply === void 0 ? void 0 : reply.message.length) < 70
1649
+ react_1.default.createElement(native_base_1.VStack, { space: 1 },
1650
+ (reply === null || reply === void 0 ? void 0 : reply.message) && (react_1.default.createElement(native_base_1.Text, { color: "gray.600", noOfLines: 2 }, (reply === null || reply === void 0 ? void 0 : reply.message.length) < 70
1618
1651
  ? `${reply === null || reply === void 0 ? void 0 : reply.message}`
1619
- : `${reply === null || reply === void 0 ? void 0 : reply.message.substring(0, 68)}....`
1620
- : ''),
1652
+ : `${reply === null || reply === void 0 ? void 0 : reply.message.substring(0, 68)}....`)),
1653
+ react_1.default.createElement(react_1.default.Fragment, null, ((_l = (_k = reply === null || reply === void 0 ? void 0 : reply.files) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.length) > 0 &&
1654
+ ((_o = (_m = reply === null || reply === void 0 ? void 0 : reply.files) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.map((f) => (react_1.default.createElement(native_base_1.Box, null,
1655
+ react_1.default.createElement(native_base_1.Avatar, { bg: 'transparent', size: 8, _image: {
1656
+ borderRadius: 6,
1657
+ borderWidth: 2,
1658
+ borderColor: '#fff',
1659
+ }, source: {
1660
+ uri: f === null || f === void 0 ? void 0 : f.url,
1661
+ } }, "I"))))))),
1621
1662
  ((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: () => {
1622
1663
  var _a, _b, _c;
1623
1664
  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);
@@ -1718,6 +1759,7 @@ const base_64_1 = __webpack_require__(/*! base-64 */ "base-64");
1718
1759
  const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
1719
1760
  const react_native_gifted_chat_1 = __webpack_require__(/*! react-native-gifted-chat */ "react-native-gifted-chat");
1720
1761
  const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
1762
+ const core_1 = __webpack_require__(/*! @messenger-box/core */ "@messenger-box/core");
1721
1763
  const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
1722
1764
  const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
1723
1765
  const SlackMessageContainer_1 = __webpack_require__(/*! ../components/SlackMessageContainer */ "./src/screens/inbox/components/SlackMessageContainer/index.ts");
@@ -1756,9 +1798,6 @@ const ConversationViewComponent = ({ channelId, role }) => {
1756
1798
  const [skip, setSkip] = (0, react_1.useState)(0);
1757
1799
  const messageRootListRef = (0, react_1.useRef)(null);
1758
1800
  const isFocused = (0, native_1.useIsFocused)();
1759
- const { data: mongooseObjectId, refetch: refetchNewPostId } = (0, platform_client_1.useGetNewMongooseObjectIdQuery)({
1760
- fetchPolicy: 'network-only',
1761
- });
1762
1801
  const { startUpload } = (0, platform_client_1.useUploadFilesNative)();
1763
1802
  const [sendMsg] = (0, platform_client_1.useSendMessagesMutation)();
1764
1803
  const [sendExpoNotificationOnPostMutation] = (0, platform_client_1.useSendExpoNotificationOnPostMutation)();
@@ -1881,7 +1920,7 @@ const ConversationViewComponent = ({ channelId, role }) => {
1881
1920
  setLoading(false);
1882
1921
  };
1883
1922
  const handleSend = (0, react_1.useCallback)(async (message) => {
1884
- var _a, _b, _c;
1923
+ var _a;
1885
1924
  if (!channelId)
1886
1925
  return;
1887
1926
  if (!message && message != ' ' && images.length == 0)
@@ -1893,8 +1932,7 @@ const ConversationViewComponent = ({ channelId, role }) => {
1893
1932
  other: { sound: react_native_1.Platform.OS === 'android' ? false || null : 'default' },
1894
1933
  };
1895
1934
  if (images && images.length > 0) {
1896
- const newPostId = await refetchNewPostId();
1897
- const postId = (_b = (_a = newPostId === null || newPostId === void 0 ? void 0 : newPostId.data) === null || _a === void 0 ? void 0 : _a.getNewMongooseObjectId) === null || _b === void 0 ? void 0 : _b.toString();
1935
+ const postId = (0, core_1.objectId)();
1898
1936
  setLoading(true);
1899
1937
  const uploadResponse = await startUpload({
1900
1938
  file: images,
@@ -1917,7 +1955,7 @@ const ConversationViewComponent = ({ channelId, role }) => {
1917
1955
  setFiles([]);
1918
1956
  setImages([]);
1919
1957
  //setLoading(false);
1920
- const files = (_c = uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.map((f) => f.id)) !== null && _c !== void 0 ? _c : null;
1958
+ const files = (_a = uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.map((f) => f.id)) !== null && _a !== void 0 ? _a : null;
1921
1959
  await sendMsg({
1922
1960
  variables: {
1923
1961
  postId,
@@ -1957,7 +1995,7 @@ const ConversationViewComponent = ({ channelId, role }) => {
1957
1995
  },
1958
1996
  });
1959
1997
  }
1960
- }, [mongooseObjectId, setChannelMessages, channelId, images, channelToTop, expoTokens]);
1998
+ }, [setChannelMessages, channelId, images, channelToTop, expoTokens]);
1961
1999
  const messageList = (0, react_1.useMemo)(() => {
1962
2000
  let currentDate = '';
1963
2001
  let res = [];
@@ -2551,6 +2589,7 @@ const base_64_1 = __webpack_require__(/*! base-64 */ "base-64");
2551
2589
  const vector_icons_1 = __webpack_require__(/*! @expo/vector-icons */ "@expo/vector-icons");
2552
2590
  const react_native_gifted_chat_1 = __webpack_require__(/*! react-native-gifted-chat */ "react-native-gifted-chat");
2553
2591
  const platform_client_1 = __webpack_require__(/*! @messenger-box/platform-client */ "@messenger-box/platform-client");
2592
+ const core_1 = __webpack_require__(/*! @messenger-box/core */ "@messenger-box/core");
2554
2593
  const config_1 = __webpack_require__(/*! ../config */ "./src/screens/inbox/config/index.ts");
2555
2594
  const user_auth0_client_1 = __webpack_require__(/*! @adminide-stack/user-auth0-client */ "@adminide-stack/user-auth0-client");
2556
2595
  const SlackMessageContainer_1 = __webpack_require__(/*! ../components/SlackMessageContainer */ "./src/screens/inbox/components/SlackMessageContainer/index.ts");
@@ -2589,81 +2628,15 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2589
2628
  const [isShowImageViewer, setImageViewer] = (0, react_1.useState)(false);
2590
2629
  const [imageObject, setImageObject] = (0, react_1.useState)({});
2591
2630
  const [parentId, setParentId] = (0, react_1.useState)(postParentId);
2631
+ const [postThread, setPostThread] = (0, react_1.useState)();
2592
2632
  const { startUpload } = (0, platform_client_1.useUploadFilesNative)();
2593
2633
  const [threadPost, setThreadPost] = (0, react_1.useState)([]);
2594
- const [skip, setSkip] = (0, react_1.useState)(0);
2595
2634
  const [isScrollToBottom, setIsScrollToBottom] = (0, react_1.useState)(false);
2596
2635
  const threadMessageListRef = (0, react_1.useRef)(null);
2597
- const { data: mongooseObjectId, refetch: refetchNewPostId } = (0, platform_client_1.useGetNewMongooseObjectIdQuery)({
2598
- fetchPolicy: 'network-only',
2599
- // pollInterval: 5000,
2600
- });
2601
- const { data: newThreadMsg, loading: newThreadMsgLoading, error: newThreadMsgError, } = (0, platform_client_1.useOnThreadChatMessageAddedSubscription)({
2602
- variables: {
2603
- channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
2604
- postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2605
- },
2606
- });
2607
- const [sendThreadMessage] = (0, platform_client_1.useSendThreadMessageMutation)();
2636
+ // const [sendThreadMessage] = useSendThreadMessageMutation();
2637
+ const [sendThreadMessage] = (0, platform_client_1.useCreatePostThreadMutation)();
2608
2638
  const [sendExpoNotificationOnPostMutation] = (0, platform_client_1.useSendExpoNotificationOnPostMutation)();
2609
- // const [getThreadMessages, { data: threadMessagesData, loading: threadLoading, refetch: refetchThreadMessages }] =
2610
- // useThreadMessagesLazyQuery({
2611
- // variables: {
2612
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2613
- // role: role?.toString(),
2614
- // postParentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2615
- // },
2616
- // fetchPolicy: 'cache-and-network',
2617
- // });
2618
- const [getThreadMessages, { data, loading: threadLoading, fetchMore: fetchMoreMessages, refetch: refetchThreadMessages, subscribeToMore },] = (0, platform_client_1.useThreadMessagesLazyQuery)();
2619
- // const {
2620
- // data,
2621
- // loading: messageLoading,
2622
- // refetch,
2623
- // fetchMore: fetchMoreMessages,
2624
- // subscribeToMore,
2625
- // }: any = usePostThreadMessagesQuery({
2626
- // variables: {
2627
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2628
- // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2629
- // limit: MESSAGES_PER_PAGE,
2630
- // skip: skip,
2631
- // },
2632
- // skip: !channelId,
2633
- // fetchPolicy: 'cache-and-network',
2634
- // refetchWritePolicy: 'merge',
2635
- // });
2636
- // useFocusEffect(
2637
- // React.useCallback(() => {
2638
- // navigation?.setOptions({ title: params?.title ?? 'Thread' });
2639
- // if (parentId || parentId == 0) {
2640
- // refetchThreadMessages({
2641
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2642
- // role: role?.toString(),
2643
- // postParentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2644
- // });
2645
- // }
2646
- // refetch({
2647
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2648
- // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2649
- // limit: MESSAGES_PER_PAGE,
2650
- // skip: 0,
2651
- // }).then(({ data }) => {
2652
- // if (!data?.messages) {
2653
- // return;
2654
- // }
2655
- // const { data: messages, totalCount }: any = data.messages;
2656
- // setTotalCount(totalCount);
2657
- // setChannelMessages(messages);
2658
- // //setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
2659
- // });
2660
- // return () => {
2661
- // setTotalCount(0);
2662
- // setChannelMessages([]);
2663
- // setThreadPost([]);
2664
- // };
2665
- // }, [channelId, parentId]),
2666
- // );
2639
+ const [getThreadMessages, { data, loading: threadLoading, fetchMore: fetchMoreMessages, refetch: refetchThreadMessages, subscribeToMore },] = (0, platform_client_1.useGetPostThreadLazyQuery)({ fetchPolicy: 'cache-and-network' });
2667
2640
  (0, native_1.useFocusEffect)(react_1.default.useCallback(() => {
2668
2641
  var _a;
2669
2642
  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' });
@@ -2673,10 +2646,7 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2673
2646
  role: role === null || role === void 0 ? void 0 : role.toString(),
2674
2647
  postParentId: postParentId === null || postParentId === void 0 ? void 0 : postParentId.toString(),
2675
2648
  selectedFields: 'id channel post replies replyCount lastReplyAt createdAt updatedAt',
2676
- repliesLimit2: MESSAGES_PER_PAGE,
2677
- repliesSkip2: 0,
2678
- skip: 0,
2679
- limit: 1,
2649
+ limit: MESSAGES_PER_PAGE,
2680
2650
  });
2681
2651
  }
2682
2652
  setParentId(postParentId);
@@ -2686,9 +2656,6 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2686
2656
  setThreadPost([]);
2687
2657
  };
2688
2658
  }, [postParentId]));
2689
- // useEffect(() => {
2690
- // setParentId(postParentId);
2691
- // }, [postParentId]);
2692
2659
  (0, react_1.useEffect)(() => {
2693
2660
  //if (parentId && parentId == 0) {
2694
2661
  if (channelId && parentId) {
@@ -2698,22 +2665,19 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2698
2665
  role: role === null || role === void 0 ? void 0 : role.toString(),
2699
2666
  postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2700
2667
  selectedFields: 'id channel post replies replyCount lastReplyAt createdAt updatedAt',
2701
- repliesLimit2: MESSAGES_PER_PAGE,
2702
- repliesSkip2: 0,
2703
- skip: 0,
2704
- limit: 1,
2668
+ limit: MESSAGES_PER_PAGE,
2705
2669
  },
2706
2670
  });
2707
2671
  }
2708
2672
  }, [parentId]);
2709
2673
  react_1.default.useEffect(() => {
2710
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2711
- if ((_a = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _a === void 0 ? void 0 : _a.data) {
2712
- const threads = data.threadMessages;
2713
- const threadPost = (_c = (_b = threads === null || threads === void 0 ? void 0 : threads.data) === null || _b === void 0 ? void 0 : _b.map((t) => t === null || t === void 0 ? void 0 : t.post)) !== null && _c !== void 0 ? _c : [];
2714
- const threadReplies = (_f = (_e = (_d = threads === null || threads === void 0 ? void 0 : threads.data) === null || _d === void 0 ? void 0 : _d.map((t) => t === null || t === void 0 ? void 0 : t.replies)) === null || _e === void 0 ? void 0 : _e.flat(1)) !== null && _f !== void 0 ? _f : [];
2715
- const messeageTotalCount = (_j = (_h = (_g = threads === null || threads === void 0 ? void 0 : threads.data) === null || _g === void 0 ? void 0 : _g.map((t) => t === null || t === void 0 ? void 0 : t.replyCount)) === null || _h === void 0 ? void 0 : _h[0]) !== null && _j !== void 0 ? _j : 0;
2716
- const messages = [...threadPost, ...threadReplies];
2674
+ var _a, _b, _c;
2675
+ if (data === null || data === void 0 ? void 0 : data.getPostThread) {
2676
+ const threads = data.getPostThread;
2677
+ const threadPost = (_a = threads === null || threads === void 0 ? void 0 : threads.post) !== null && _a !== void 0 ? _a : [];
2678
+ const threadReplies = (_b = threads === null || threads === void 0 ? void 0 : threads.replies) !== null && _b !== void 0 ? _b : [];
2679
+ const messeageTotalCount = (_c = threads === null || threads === void 0 ? void 0 : threads.replyCount) !== null && _c !== void 0 ? _c : 0;
2680
+ const messages = [threadPost, ...threadReplies];
2717
2681
  if ((messages && messages.length > 0 && messeageTotalCount > totalCount) ||
2718
2682
  (messages && messages.length > 0 && channelMessages.length === 0)) {
2719
2683
  setThreadMessages(messages, messeageTotalCount);
@@ -2731,144 +2695,18 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2731
2695
  setChannelMessages((oldMessages) => (0, lodash_1.uniqBy)([...messages, ...oldMessages], ({ id }) => id));
2732
2696
  setTotalCount(messagesTotalCount);
2733
2697
  };
2734
- // useEffect(() => {
2735
- // //if (threadMessagesData?.threadMessages?.data) {
2736
- // // console.log('threadMessagesData?.threadMessages', JSON.stringify(threadMessagesData?.threadMessages));
2737
- // const threads: any = threadMessagesData?.threadMessages;
2738
- // if (threadPost?.length == 0 && threads?.data?.length > 0) {
2739
- // const threadMessage = threads?.data?.map((t: any) => t?.post);
2740
- // setThreadPost(threadMessage);
2741
- // setChannelMessages((oldMessages: any) => uniqBy([...threadMessage, ...oldMessages], ({ id }) => id));
2742
- // }
2743
- // // if (!isPostParentIdThread) {
2744
- // // // setTotalCount((pc: any) => pc + threadTotalCount);
2745
- // // setChannelMessages((oldMessages: any) => uniqBy([...threadMessage, ...oldMessages], ({ id }) => id));
2746
- // // }
2747
- // // }
2748
- // }, [threadMessagesData, threadPost, isPostParentIdThread]);
2749
- // React.useEffect(() => {
2750
- // if (newThreadMsg) {
2751
- // console.log('newThreadMsg');
2752
- // const msg = newThreadMsg?.threadChatMessageAdded;
2753
- // setTotalCount((preCount: any) => preCount + 1);
2754
- // setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, msg], ({ id }) => id));
2755
- // }
2756
- // }, [newThreadMsg]);
2757
- // React.useEffect(() => {
2758
- // if (newThreadMsg) {
2759
- // console.log('newThreadMsg');
2760
- // refetch({
2761
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2762
- // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2763
- // limit: MESSAGES_PER_PAGE,
2764
- // skip: 0,
2765
- // });
2766
- // }
2767
- // }, [newThreadMsg, skip, parentId]);
2768
- // useEffect(() => {
2769
- // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
2770
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
2771
- // if (messages && messages.length > 0) {
2772
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
2773
- // setLoadingOldMessages(false);
2774
- // }
2775
- // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
2776
- // }
2777
- // }, [data, loadingOldMessages, channelMessages, totalCount]);
2778
- // useEffect(() => {
2779
- // if ((data?.messages?.data && channelMessages.length === 0) || (data?.messages?.data && loadingOldMessages)) {
2780
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
2781
- // if (messages && messages.length > 0) {
2782
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
2783
- // setTotalCount(messeageTotalCount);
2784
- // }
2785
- // setLoadEarlierMsg(false);
2786
- // if (loadingOldMessages) setLoadingOldMessages(false);
2787
- // }
2788
- // if (threadPost?.length && data?.messages?.totalCount == channelMessages.length) {
2789
- // // setTotalCount((pc: any) => pc + threadTotalCount);
2790
- // setChannelMessages((oldMessages: any) => uniqBy([...threadPost, ...oldMessages], ({ id }) => id));
2791
- // }
2792
- // }, [data, loadingOldMessages, channelMessages, threadPost]);
2793
- // React.useEffect(() => {
2794
- // if (data?.messages?.data) {
2795
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
2796
- // if (
2797
- // (messages && messages.length > 0 && messeageTotalCount > totalCount) ||
2798
- // (messages && messages.length > 0 && (loadingOldMessages || channelMessages.length === 0))
2799
- // ) {
2800
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
2801
- // setTotalCount(messeageTotalCount);
2802
- // setLoadEarlierMsg(false);
2803
- // }
2804
- // if (loadingOldMessages && channelMessages) setLoadingOldMessages(false);
2805
- // // if (
2806
- // // channelMessages &&
2807
- // // channelMessages?.length == MESSAGES_PER_PAGE &&
2808
- // // totalCount > channelMessages?.length
2809
- // // ) {
2810
- // // onFetchOld();
2811
- // // }
2812
- // }
2813
- // // if (threadPost?.length > 0 && channelMessages.length == (0 || MESSAGES_PER_PAGE)) {
2814
- // // setChannelMessages((oldMessages: any) => uniqBy([...threadPost, ...oldMessages], ({ id }) => id));
2815
- // // }
2816
- // }, [data, loadingOldMessages, totalCount, channelMessages, isScrollToBottom]);
2817
- // useEffect(() => {
2818
- // if (
2819
- // !messageLoading &&
2820
- // checkForMessages?.messages?.totalCount &&
2821
- // checkForMessages?.messages?.totalCount > totalCount
2822
- // ) {
2823
- // const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
2824
- // console.log('new msg check');
2825
- // refetch({
2826
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2827
- // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2828
- // limit: numberOfNewMessages,
2829
- // }).then(({ data }) => {
2830
- // if (!data?.messages) {
2831
- // return;
2832
- // }
2833
- // const { data: messages, totalCount }: any = data.messages;
2834
- // setTotalCount(totalCount);
2835
- // setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
2836
- // });
2837
- // }
2838
- // }, [checkForMessages, totalCount, parentId]);
2839
2698
  react_1.default.useEffect(() => {
2840
2699
  if (selectedImage)
2841
2700
  setImageLoading(false);
2842
2701
  }, [selectedImage]);
2843
- // const onFetchOld = useCallback(() => {
2844
- // if (data?.messages?.totalCount > channelMessages.length) {
2845
- // setLoadEarlierMsg(true);
2846
- // refetch({
2847
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2848
- // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2849
- // skip: channelMessages.length,
2850
- // })?.then((res: any) => setLoadingOldMessages(true));
2851
- // }
2852
- // }, [data, channelMessages]);
2853
2702
  const scrollToBottom = react_1.default.useCallback(() => {
2854
2703
  if (threadMessageListRef === null || threadMessageListRef === void 0 ? void 0 : threadMessageListRef.current) {
2855
2704
  setIsScrollToBottom(false);
2856
2705
  threadMessageListRef.current.scrollTop = threadMessageListRef.current.scrollHeight;
2857
2706
  }
2858
2707
  }, [threadMessageListRef]);
2859
- // const onFetchOld = useCallback((data: any, channelMessages: any) => {
2860
- // if (data?.messages?.totalCount > channelMessages.length) {
2861
- // setLoadEarlierMsg(true);
2862
- // refetch({
2863
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
2864
- // parentId: !parentId || parentId == 0 ? null : parentId?.toString(),
2865
- // skip: channelMessages.length,
2866
- // })?.then((res: any) => setLoadingOldMessages(true));
2867
- // }
2868
- // }, []);
2869
2708
  const onFetchOld = (0, react_1.useCallback)(() => {
2870
2709
  if (totalCount > channelMessages.length && !loadingOldMessages) {
2871
- setSkip(channelMessages.length);
2872
2710
  setLoadEarlierMsg(true);
2873
2711
  fetchMoreMessages({
2874
2712
  variables: {
@@ -2876,20 +2714,16 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2876
2714
  role: role === null || role === void 0 ? void 0 : role.toString(),
2877
2715
  postParentId: parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
2878
2716
  selectedFields: 'id channel post replies replyCount lastReplyAt createdAt updatedAt',
2879
- repliesLimit2: MESSAGES_PER_PAGE,
2880
- repliesSkip2: channelMessages.length - 1,
2881
- skip: 0,
2882
- limit: 1,
2883
- // channelId: channelId?.toString(),
2884
- // parentId: null,
2885
- // skip: channelMessages.length,
2717
+ limit: MESSAGES_PER_PAGE,
2718
+ skip: channelMessages.length - 1,
2886
2719
  },
2887
2720
  })
2888
2721
  .then((res) => {
2889
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2890
- if ((_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) {
2891
- const threadReplies = (_g = (_f = (_e = (_d = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.threadMessages) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.map((t) => t === null || t === void 0 ? void 0 : t.replies)) === null || _f === void 0 ? void 0 : _f.flat(1)) !== null && _g !== void 0 ? _g : [];
2892
- const messeageTotalCount = (_m = (_l = (_k = (_j = (_h = res === null || res === void 0 ? void 0 : res.data) === null || _h === void 0 ? void 0 : _h.threadMessages) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.map((t) => t === null || t === void 0 ? void 0 : t.replyCount)) === null || _l === void 0 ? void 0 : _l[0]) !== null && _m !== void 0 ? _m : 0;
2722
+ var _a, _b, _c, _d;
2723
+ if ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.getPostThread) {
2724
+ const threads = (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.getPostThread;
2725
+ const threadReplies = (_c = threads === null || threads === void 0 ? void 0 : threads.replies) !== null && _c !== void 0 ? _c : [];
2726
+ const messeageTotalCount = (_d = threads === null || threads === void 0 ? void 0 : threads.replyCount) !== null && _d !== void 0 ? _d : 0;
2893
2727
  setThreadMessages(threadReplies, messeageTotalCount);
2894
2728
  }
2895
2729
  })
@@ -2901,10 +2735,6 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2901
2735
  setLoadEarlierMsg(false);
2902
2736
  setLoadingOldMessages(false);
2903
2737
  });
2904
- //?.then((res: any) => setLoadingOldMessages(true));
2905
- // refetch({ channelId: channelId?.toString(), parentId: null, skip: channelMessages.length })?.then(
2906
- // (res: any) => setLoadingOldMessages(true),
2907
- // );
2908
2738
  }
2909
2739
  }, [parentId, channelId, totalCount, channelMessages]);
2910
2740
  // const isCloseToTop = ({ layoutMeasurement, contentOffset, contentSize }) => {
@@ -2940,41 +2770,14 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2940
2770
  if (imageSource.cancelled)
2941
2771
  setLoading(false);
2942
2772
  };
2943
- // const sendPushNotification = async (title: String, body: String, data: any, to: any) => {
2944
- // try {
2945
- // const response = await fetch('https://exp.host/--/api/v2/push/send/', {
2946
- // method: 'POST',
2947
- // headers: {
2948
- // Accept: 'application/json',
2949
- // 'Accept-Encoding': 'gzip, deflate',
2950
- // 'Content-Type': 'application/json',
2951
- // },
2952
- // body: JSON.stringify({
2953
- // to: to,
2954
- // data: data,
2955
- // title: title,
2956
- // body: body,
2957
- // sound: Platform.OS === 'android' ? undefined || null : 'default',
2958
- // }),
2959
- // });
2960
- // const result: any = await response.json();
2961
- // console.log('expo api response', result);
2962
- // } catch (error) {
2963
- // console.error('Error:', error);
2964
- // }
2965
- // };
2966
- // const ObjectId = (m = Math, d = Date, h = 16, s = (s:any) => m.floor(s).toString(h)) =>
2967
- // s(d.now() / 1000) + ' '.repeat(h).replace(/./g, () => s(m.random() * h))
2968
2773
  const handleSend = (0, react_1.useCallback)(async (message) => {
2969
- var _a, _b, _c;
2774
+ var _a;
2970
2775
  if (!channelId)
2971
2776
  return;
2972
2777
  if (!message && message != ' ' && images.length == 0)
2973
2778
  return;
2779
+ const postId = (0, core_1.objectId)();
2974
2780
  if (images && images.length > 0) {
2975
- const newPostId = await refetchNewPostId();
2976
- const postId = (_b = (_a = newPostId === null || newPostId === void 0 ? void 0 : newPostId.data) === null || _a === void 0 ? void 0 : _a.getNewMongooseObjectId) === null || _b === void 0 ? void 0 : _b.toString();
2977
- // const postId: any = mongooseObjectId?.getNewMongooseObjectId;
2978
2781
  setLoading(true);
2979
2782
  const uploadResponse = await startUpload({
2980
2783
  file: images,
@@ -2997,11 +2800,12 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
2997
2800
  setFiles([]);
2998
2801
  setImages([]);
2999
2802
  //setLoading(false);
3000
- const files = (_c = uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.map((f) => f.id)) !== null && _c !== void 0 ? _c : null;
2803
+ const files = (_a = uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles.map((f) => f.id)) !== null && _a !== void 0 ? _a : null;
3001
2804
  await sendThreadMessage({
3002
2805
  variables: {
3003
2806
  postId,
3004
2807
  channelId,
2808
+ postThreadId: postThread && (postThread === null || postThread === void 0 ? void 0 : postThread.id),
3005
2809
  postParentId: !parentId || parentId == 0 ? null : parentId,
3006
2810
  threadMessageInput: {
3007
2811
  content: message,
@@ -3010,34 +2814,21 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3010
2814
  },
3011
2815
  },
3012
2816
  update: (cache, { data, errors }) => {
3013
- var _a, _b, _c;
2817
+ var _a, _b, _c, _d, _e, _f, _g;
3014
2818
  if (!data || errors) {
3015
2819
  setLoading(false);
3016
2820
  return;
3017
2821
  }
3018
- const responseMessage = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage;
2822
+ setPostThread((_a = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _a === void 0 ? void 0 : _a.data);
2823
+ const lastMessageId = (_c = (_b = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _b === void 0 ? void 0 : _b.lastMessage) === null || _c === void 0 ? void 0 : _c.id;
3019
2824
  if (!parentId || parentId == 0) {
3020
- setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3021
- // setChannelMessages((messages: any) => [
3022
- // ...messages,
3023
- // {
3024
- // ...responseMessage,
3025
- // files: {
3026
- // totalCount: uploadedFiles.length,
3027
- // data: uploadedFiles,
3028
- // },
3029
- // },
3030
- // ]);
3031
- // setTotalCount((t: any) => t + 1);
2825
+ setParentId((_e = (_d = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _d === void 0 ? void 0 : _d.lastMessage) === null || _e === void 0 ? void 0 : _e.id);
3032
2826
  }
3033
2827
  setChannelToTop(channelToTop + 1);
3034
2828
  setLoading(false);
3035
2829
  setMsg('');
3036
- // if (!parentId || parentId == 0) {
3037
- // setParentId(responseMessage?.id);
3038
- // }
3039
2830
  const msg = message == '' ? 'Send a file' : message;
3040
- sendPushNotification(responseMessage, channelId, parentId, (_c = (_b = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.id);
2831
+ sendPushNotification(lastMessageId, channelId, parentId, (_g = (_f = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.id);
3041
2832
  },
3042
2833
  });
3043
2834
  }
@@ -3047,6 +2838,7 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3047
2838
  await sendThreadMessage({
3048
2839
  variables: {
3049
2840
  channelId,
2841
+ postThreadId: postThread && (postThread === null || postThread === void 0 ? void 0 : postThread.id),
3050
2842
  postParentId: !parentId || parentId == 0 ? null : parentId,
3051
2843
  threadMessageInput: {
3052
2844
  content: message,
@@ -3054,30 +2846,26 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3054
2846
  },
3055
2847
  },
3056
2848
  update: (cache, { data, errors }) => {
3057
- var _a, _b, _c;
2849
+ var _a, _b, _c, _d, _e, _f;
3058
2850
  if (!data || errors) {
3059
2851
  setLoading(false);
3060
2852
  return;
3061
2853
  }
3062
- const responseMessage = (_a = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _a === void 0 ? void 0 : _a.lastMessage;
2854
+ setPostThread(data === null || data === void 0 ? void 0 : data.createPostThread.data);
2855
+ const lastMessageId = (_b = (_a = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _a === void 0 ? void 0 : _a.lastMessage) === null || _b === void 0 ? void 0 : _b.id;
3063
2856
  if (!parentId || parentId == 0) {
3064
- setParentId(responseMessage === null || responseMessage === void 0 ? void 0 : responseMessage.id);
3065
- // setChannelMessages((messages: any) => [...messages, responseMessage]);
3066
- // setTotalCount((t: any) => t + 1);
2857
+ setParentId((_d = (_c = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _c === void 0 ? void 0 : _c.lastMessage) === null || _d === void 0 ? void 0 : _d.id);
3067
2858
  }
3068
2859
  setChannelToTop(channelToTop + 1);
3069
2860
  setLoading(false);
3070
2861
  setMsg('');
3071
- // if (!parentId || parentId == 0) {
3072
- // setParentId(responseMessage?.id);
3073
- // }
3074
- sendPushNotification(responseMessage, channelId, parentId, (_c = (_b = data === null || data === void 0 ? void 0 : data.sendThreadMessage) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.id);
2862
+ sendPushNotification(lastMessageId, channelId, parentId, (_f = (_e = data === null || data === void 0 ? void 0 : data.createPostThread) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.id);
3075
2863
  },
3076
2864
  });
3077
2865
  }
3078
- }, [mongooseObjectId, setChannelMessages, channelId, images, parentId, expoTokens]);
3079
- const sendPushNotification = async (post, channelId, parentId, threadId) => {
3080
- var _a, _b;
2866
+ }, [setChannelMessages, channelId, images, parentId, expoTokens]);
2867
+ const sendPushNotification = async (messageId, channelId, parentId, threadId) => {
2868
+ var _a;
3081
2869
  const notificationData = {
3082
2870
  url: config_1.config.THREAD_MESSEGE_PATH,
3083
2871
  params: { channelId, title: (_a = params === null || params === void 0 ? void 0 : params.title) !== null && _a !== void 0 ? _a : 'Thread', postParentId: parentId, hideTabBar: true },
@@ -3088,53 +2876,12 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3088
2876
  if (parentId || parentId == 0) {
3089
2877
  await sendExpoNotificationOnPostMutation({
3090
2878
  variables: {
3091
- postId: (_b = post === null || post === void 0 ? void 0 : post.id) === null || _b === void 0 ? void 0 : _b.toString(),
2879
+ postId: messageId === null || messageId === void 0 ? void 0 : messageId.toString(),
3092
2880
  notificationData,
3093
2881
  },
3094
2882
  });
3095
2883
  }
3096
2884
  };
3097
- // const fetchTokenAndSendPushNotification = (message: any, channelId: any, parentId: any) => {
3098
- // const givenName = auth?.profile?.given_name ?? '';
3099
- // const familyName = auth?.profile?.family_name ?? '';
3100
- // const fullName = givenName ? givenName + ' ' + familyName : '';
3101
- // const title: String = fullName ? fullName : 'Message';
3102
- // const body: String = message;
3103
- // const notificationData: any = {
3104
- // url: config.THREAD_MESSEGE_PATH,
3105
- // params: { channelId, title: params?.title ?? 'Thread', postParentId: parentId, hideTabBar: true },
3106
- // screen: 'DialogThreadMessages',
3107
- // };
3108
- // if (parentId || parentId == 0) {
3109
- // refetchThreadMessages({
3110
- // channelId: !parentId || parentId == 0 ? null : channelId?.toString(),
3111
- // role: role?.toString(),
3112
- // postParentId: !parentId || parentId == 0 ? null : parentId?.toString(),
3113
- // })?.then((res: any) => {
3114
- // if (res?.data?.threadMessages?.data?.length > 0) {
3115
- // const participants =
3116
- // res?.data?.threadMessages?.data?.map((t: any) => t?.participants)?.flat(1) ?? [];
3117
- // const participantsTokens =
3118
- // participants?.length > 0
3119
- // ? participants
3120
- // ?.filter((u: any) => u?.id != auth?.id)
3121
- // ?.map((p: any) => p.tokens)
3122
- // ?.flat(1)
3123
- // : [];
3124
- // const expoTokens =
3125
- // participantsTokens?.length > 0
3126
- // ? participantsTokens
3127
- // ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
3128
- // ?.map((et: any) => et?.token)
3129
- // : [];
3130
- // if (expoTokens?.length > 0) {
3131
- // const to: any = expoTokens;
3132
- // sendPushNotification(title, body, notificationData, to);
3133
- // }
3134
- // }
3135
- // });
3136
- // }
3137
- // };
3138
2885
  const messageList = (0, react_1.useMemo)(() => {
3139
2886
  let currentDate = '';
3140
2887
  let res = [];
@@ -3328,40 +3075,16 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
3328
3075
  postParentId: !parentId || parentId == 0 ? null : parentId === null || parentId === void 0 ? void 0 : parentId.toString(),
3329
3076
  },
3330
3077
  updateQuery: (prev, { subscriptionData }) => {
3331
- var _a, _b, _c, _d, _e, _f, _g;
3078
+ var _a, _b, _c;
3332
3079
  if (!subscriptionData.data)
3333
3080
  return prev;
3334
3081
  const newMessage = (_a = subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data) === null || _a === void 0 ? void 0 : _a.threadChatMessageAdded;
3335
- const threadReplies = (_e = (_d = (_c = (_b = prev === null || prev === void 0 ? void 0 : prev.threadMessages) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.map((t) => t === null || t === void 0 ? void 0 : t.replies)) === null || _d === void 0 ? void 0 : _d.flat(1)) !== null && _e !== void 0 ? _e : [];
3336
- const replies = [...threadReplies, newMessage];
3337
- const previousData = (_g = (_f = prev === null || prev === void 0 ? void 0 : prev.threadMessages) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.map((t) => {
3338
- let thread = Object.assign({}, t);
3339
- thread.replies = replies;
3340
- return thread;
3082
+ const prevReplyCount = (_b = prev === null || prev === void 0 ? void 0 : prev.getPostThread) === null || _b === void 0 ? void 0 : _b.replyCount;
3083
+ const newReplyCount = prevReplyCount || 0 + 1;
3084
+ const replies = ((_c = prev === null || prev === void 0 ? void 0 : prev.getPostThread) === null || _c === void 0 ? void 0 : _c.replies) || [];
3085
+ return Object.assign({}, prev, {
3086
+ getPostThread: Object.assign(Object.assign({}, prev === null || prev === void 0 ? void 0 : prev.getPostThread), { lastReplyAt: newMessage.createdAt, replies: [newMessage, ...replies], replyCount: newReplyCount, updatedAt: newMessage.createdAt }),
3341
3087
  });
3342
- // const previousData = prev?.threadMessages?.data ? [...prev.threadMessages.data, newMessage] : [];
3343
- // const totalMsgCount = prev?.threadMessages?.totalCount + 1;
3344
- const merged = Object.assign(Object.assign({}, prev), { threadMessages: Object.assign(Object.assign({}, prev === null || prev === void 0 ? void 0 : prev.threadMessages), { data: previousData }) });
3345
- return merged;
3346
- // const mergedData = prev?.messages?.data
3347
- // ? [...prev.messages.data, newMessage]
3348
- // : [];
3349
- // const totalMsgCount = prev?.messages?.totalCount + 1;
3350
- // const merged = {
3351
- // ...prev?.messages,
3352
- // messages: {
3353
- // ...prev?.messages,
3354
- // data: mergedData,
3355
- // totalCount: totalMsgCount,
3356
- // },
3357
- // };
3358
- // return merged;
3359
- // return Object.assign({}, prev, {
3360
- // messages: {
3361
- // data: [...prev.messages.data, newMessage],
3362
- // totalCount: prev.messages.totalCount + 1,
3363
- // },
3364
- // });
3365
3088
  },
3366
3089
  }) }))), 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 && messageList && (messageList === null || messageList === void 0 ? void 0 : messageList.length) == 0 && (react_1.default.createElement(native_base_1.Box, { p: 5 },
3367
3090
  react_1.default.createElement(native_base_1.Center, { mt: 6 },
@@ -3432,11 +3155,12 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3432
3155
  const isFocused = (0, native_1.useIsFocused)();
3433
3156
  const [refreshing, setRefresh] = (0, react_1.useState)(false);
3434
3157
  const [threadData, setThreadsData] = (0, react_1.useState)([]);
3435
- const { data, loading: threadLoading, error, refetch, } = (0, platform_client_1.useThreadMessagesQuery)({
3158
+ const { data, loading: threadLoading, error, refetch, subscribeToMore, } = (0, platform_client_1.useThreadMessagesQuery)({
3436
3159
  variables: {
3437
3160
  channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3438
3161
  role: role === null || role === void 0 ? void 0 : role.toString(),
3439
3162
  limit: MESSAGES_PER_PAGE,
3163
+ repliesLimit2: 5,
3440
3164
  },
3441
3165
  fetchPolicy: 'cache-and-network',
3442
3166
  });
@@ -3451,28 +3175,27 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3451
3175
  channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3452
3176
  role: role === null || role === void 0 ? void 0 : role.toString(),
3453
3177
  limit: MESSAGES_PER_PAGE,
3454
- }).then(({ data }) => {
3455
- var _a, _b, _c;
3456
- if (!((_a = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _a === void 0 ? void 0 : _a.data)) {
3457
- return;
3458
- }
3459
- 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) {
3460
- const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3461
- setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
3462
- }
3463
3178
  });
3179
+ // .then(({ data }) => {
3180
+ // if (!data?.threadMessages?.data) {
3181
+ // return;
3182
+ // }
3183
+ // if (data?.threadMessages?.data?.length) {
3184
+ // const { data: newThreads } = data?.threadMessages;
3185
+ // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
3186
+ // }
3187
+ // });
3464
3188
  return () => {
3465
3189
  // Do something when the screen is unfocused
3466
3190
  // Useful for cleanup functions
3467
3191
  };
3468
3192
  }, [channelId]));
3469
- react_1.default.useEffect(() => {
3470
- var _a, _b;
3471
- 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) {
3472
- const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3473
- setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
3474
- }
3475
- }, [data]);
3193
+ // React.useEffect(() => {
3194
+ // if (data?.threadMessages?.data?.length) {
3195
+ // const { data: newThreads } = data?.threadMessages;
3196
+ // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
3197
+ // }
3198
+ // }, [data]);
3476
3199
  // React.useEffect(() => {
3477
3200
  // if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
3478
3201
  // const { data: newThreads } = threadCreatedUpdated?.threadCreatedUpdated;
@@ -3496,12 +3219,19 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3496
3219
  });
3497
3220
  // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
3498
3221
  }, []);
3222
+ // const threads = React.useMemo(() => {
3223
+ // if (!threadData?.length) return null;
3224
+ // return orderBy(threadData, ['updatedAt'], ['desc']) || [];
3225
+ // //return threadData || [];
3226
+ // }, [threadData]);
3499
3227
  const threads = react_1.default.useMemo(() => {
3500
- if (!(threadData === null || threadData === void 0 ? void 0 : threadData.length))
3228
+ var _a, _b;
3229
+ 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))
3501
3230
  return null;
3502
- return (0, lodash_1.orderBy)(threadData, ['updatedAt'], ['desc']) || [];
3503
- //return threadData || [];
3504
- }, [threadData]);
3231
+ const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3232
+ const threadsFiltered = newThreads ? (0, lodash_1.uniqBy)([...newThreads], ({ id }) => id) : [];
3233
+ return (0, lodash_1.orderBy)(threadsFiltered, ['updatedAt'], ['desc']) || [];
3234
+ }, [data]);
3505
3235
  const threadReplies = react_1.default.useMemo(() => {
3506
3236
  var _a;
3507
3237
  if (!(threads === null || threads === void 0 ? void 0 : threads.length))
@@ -3509,10 +3239,6 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3509
3239
  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)) || [];
3510
3240
  //return threadData || [];
3511
3241
  }, [threads]);
3512
- // const threads = React.useMemo(() => {
3513
- // if (!data?.threadMessages?.data?.length) return null;
3514
- // return data?.threadMessages?.data || [];
3515
- // }, [data]);
3516
3242
  const handleSelectThread = (0, react_1.useCallback)((id, title, postParentId) => {
3517
3243
  navigation.navigate(config_1.config.THREAD_MESSEGE_PATH, {
3518
3244
  channelId: id,
@@ -3542,16 +3268,16 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3542
3268
  channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3543
3269
  role: role === null || role === void 0 ? void 0 : role.toString(),
3544
3270
  limit: MESSAGES_PER_PAGE,
3545
- }).then(({ data }) => {
3546
- var _a, _b, _c;
3547
- if (!((_a = data === null || data === void 0 ? void 0 : data.threadMessages) === null || _a === void 0 ? void 0 : _a.data)) {
3548
- return;
3549
- }
3550
- 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) {
3551
- const { data: newThreads } = data === null || data === void 0 ? void 0 : data.threadMessages;
3552
- setThreadsData((oldThreads) => (0, lodash_1.uniqBy)([...oldThreads, ...newThreads], ({ id }) => id));
3553
- }
3554
3271
  });
3272
+ // .then(({ data }) => {
3273
+ // if (!data?.threadMessages?.data) {
3274
+ // return;
3275
+ // }
3276
+ // if (data?.threadMessages?.data?.length) {
3277
+ // const { data: newThreads } = data?.threadMessages;
3278
+ // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
3279
+ // }
3280
+ // });
3555
3281
  }, []);
3556
3282
  const fetchMoreThreads = (0, react_1.useCallback)(() => {
3557
3283
  refetch({
@@ -3581,7 +3307,32 @@ const ThreadsViewComponent = ({ channelId, role, channelsDetail, refetchChannelD
3581
3307
  react_1.default.createElement(native_base_1.Box, { p: 5 },
3582
3308
  react_1.default.createElement(native_base_1.Center, { mt: 6 },
3583
3309
  react_1.default.createElement(native_base_1.Icon, { as: vector_icons_1.Ionicons, name: "chatbubbles", size: 'xl' }),
3584
- 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 })));
3310
+ react_1.default.createElement(native_base_1.Text, null, "You don't have any message yet!"))))), ListFooterComponent: () => (react_1.default.createElement(react_1.default.Fragment, null,
3311
+ react_1.default.createElement(SubscriptionHandler, { channelId: channelId, subscribeToNewMessages: () => subscribeToMore({
3312
+ document: platform_client_1.OnThreadCreatedUpdatedDocument,
3313
+ variables: {
3314
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
3315
+ postParentId: null,
3316
+ },
3317
+ updateQuery: (prev, { subscriptionData }) => {
3318
+ var _a, _b, _c, _d, _e, _f;
3319
+ if (!subscriptionData.data)
3320
+ return prev;
3321
+ const newPostThreadData = (_b = (_a = subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data) === null || _a === void 0 ? void 0 : _a.threadCreatedUpdated) === null || _b === void 0 ? void 0 : _b.data;
3322
+ const newMessage = (_d = (_c = subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data) === null || _c === void 0 ? void 0 : _c.threadCreatedUpdated) === null || _d === void 0 ? void 0 : _d.lastMessage;
3323
+ const data = (_f = (_e = prev === null || prev === void 0 ? void 0 : prev.threadMessages) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.map((t) => t.id === (newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.id)
3324
+ ? Object.assign(Object.assign({}, t), { replies: [newMessage, ...t === null || t === void 0 ? void 0 : t.replies], replyCount: newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.replyCount, lastReplyAt: newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.lastReplyAt, updatedAt: newPostThreadData === null || newPostThreadData === void 0 ? void 0 : newPostThreadData.updatedAt }) : t);
3325
+ return Object.assign({}, prev, {
3326
+ threadMessages: Object.assign(Object.assign({}, prev === null || prev === void 0 ? void 0 : prev.threadMessages), {
3327
+ // totalCount: prev?.threadMessages?.totalCount + 1,
3328
+ data: data }),
3329
+ });
3330
+ },
3331
+ }) }))), keyExtractor: (item, index) => 'threads-view-key' + index, onEndReached: fetchMoreThreads, onEndReachedThreshold: 0.1 })));
3332
+ };
3333
+ const SubscriptionHandler = ({ subscribeToNewMessages, channelId }) => {
3334
+ (0, react_1.useEffect)(() => subscribeToNewMessages(), [channelId]);
3335
+ return react_1.default.createElement(react_1.default.Fragment, null);
3585
3336
  };
3586
3337
  exports.ThreadsView = react_1.default.memo(ThreadsViewComponent);
3587
3338
 
@@ -3648,6 +3399,16 @@ module.exports = require("@expo/vector-icons");
3648
3399
 
3649
3400
  /***/ }),
3650
3401
 
3402
+ /***/ "@messenger-box/core":
3403
+ /*!**************************************!*\
3404
+ !*** external "@messenger-box/core" ***!
3405
+ \**************************************/
3406
+ /***/ ((module) => {
3407
+
3408
+ module.exports = require("@messenger-box/core");
3409
+
3410
+ /***/ }),
3411
+
3651
3412
  /***/ "@messenger-box/platform-client":
3652
3413
  /*!*************************************************!*\
3653
3414
  !*** external "@messenger-box/platform-client" ***!