@messenger-box/platform-mobile 10.0.3-alpha.20 → 10.0.3-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/screens/inbox/DialogThreads.js +52 -12
  3. package/lib/screens/inbox/DialogThreads.js.map +1 -1
  4. package/lib/screens/inbox/components/CachedImage/index.js +0 -19
  5. package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
  6. package/lib/screens/inbox/components/ThreadsViewItem.js +66 -44
  7. package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
  8. package/lib/screens/inbox/containers/ConversationView.js +36 -34
  9. package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
  10. package/lib/screens/inbox/containers/Dialogs.js +82 -37
  11. package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
  12. package/lib/screens/inbox/containers/ThreadConversationView.js +282 -219
  13. package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
  14. package/lib/screens/inbox/containers/ThreadsView.js +83 -50
  15. package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
  16. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
  17. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
  18. package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
  19. package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
  20. package/package.json +2 -2
  21. package/src/screens/inbox/DialogThreads.tsx +49 -53
  22. package/src/screens/inbox/components/CachedImage/index.tsx +9 -9
  23. package/src/screens/inbox/components/SmartLoader.tsx +61 -0
  24. package/src/screens/inbox/components/ThreadsViewItem.tsx +177 -265
  25. package/src/screens/inbox/containers/ConversationView.tsx +32 -30
  26. package/src/screens/inbox/containers/Dialogs.tsx +57 -22
  27. package/src/screens/inbox/containers/ThreadConversationView.tsx +467 -484
  28. package/src/screens/inbox/containers/ThreadsView.tsx +102 -183
  29. package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +136 -0
  30. package/src/screens/inbox/index.ts +37 -0
  31. package/src/screens/inbox/machines/threadsMachine.ts +147 -0
  32. package/src/screens/inbox/workflow/dialog-threads-xstate.ts +163 -0
@@ -236,7 +236,7 @@ const ConversationViewComponent = (_a) => {
236
236
  "role",
237
237
  "isShowThreadMessage"
238
238
  ]);
239
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
239
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
240
240
  const [channelToTop, setChannelToTop] = useState(0);
241
241
  const isMountedRef = useRef(true);
242
242
  const [state, send] = useSafeMachine();
@@ -895,20 +895,12 @@ const ConversationViewComponent = (_a) => {
895
895
  };
896
896
  }, [state.context.channelId, state.context.channelMessages, fetchMessagesWithFallback]);
897
897
  const messageList = useMemo(() => {
898
- var _a3, _b3, _c2, _d2, _e2, _f2;
898
+ var _a3;
899
899
  console.log("\u{1F504} CALCULATING MESSAGE LIST - Optimized version");
900
900
  if (!((_a3 = state == null ? void 0 : state.context) == null ? void 0 : _a3.channelMessages) || state.context.channelMessages.length === 0) {
901
901
  console.log("No messages to process");
902
902
  return [];
903
903
  }
904
- if (state.context.channelMessages[0]) {
905
- const sampleMsg = state.context.channelMessages[0];
906
- console.log("\u{1F4F7} Sample message files:", JSON.stringify({
907
- hasFiles: !!sampleMsg.files,
908
- fileCount: ((_c2 = (_b3 = sampleMsg.files) == null ? void 0 : _b3.data) == null ? void 0 : _c2.length) || 0,
909
- fileUrl: ((_f2 = (_e2 = (_d2 = sampleMsg.files) == null ? void 0 : _d2.data) == null ? void 0 : _e2[0]) == null ? void 0 : _f2.url) || "none"
910
- }));
911
- }
912
904
  const filteredMessages = uniqBy(state.context.channelMessages, ({
913
905
  id
914
906
  }) => id);
@@ -916,14 +908,13 @@ const ConversationViewComponent = (_a) => {
916
908
  return [];
917
909
  }
918
910
  return orderBy(filteredMessages, ["createdAt"], ["desc"]).map((msg) => {
919
- var _a4, _b4, _c3, _d3, _e3, _f3;
911
+ var _a4, _b3, _c2, _d2, _e2, _f2;
920
912
  const date = new Date(msg.createdAt);
921
913
  let imageUrl = null;
922
914
  if (((_a4 = msg.files) == null ? void 0 : _a4.data) && msg.files.data.length > 0) {
923
915
  const fileData = msg.files.data[0];
924
916
  if (fileData && fileData.url) {
925
917
  imageUrl = fileData.url;
926
- console.log("\u{1F4F7} Found image URL for message", msg.id, ":", imageUrl);
927
918
  }
928
919
  }
929
920
  return {
@@ -931,22 +922,22 @@ const ConversationViewComponent = (_a) => {
931
922
  text: msg.message,
932
923
  createdAt: date,
933
924
  user: {
934
- _id: ((_b4 = msg.author) == null ? void 0 : _b4.id) || "",
935
- name: `${((_c3 = msg.author) == null ? void 0 : _c3.givenName) || ""} ${((_d3 = msg.author) == null ? void 0 : _d3.familyName) || ""}`,
936
- avatar: ((_e3 = msg.author) == null ? void 0 : _e3.picture) || ""
925
+ _id: ((_b3 = msg.author) == null ? void 0 : _b3.id) || "",
926
+ name: `${((_c2 = msg.author) == null ? void 0 : _c2.givenName) || ""} ${((_d2 = msg.author) == null ? void 0 : _d2.familyName) || ""}`,
927
+ avatar: ((_e2 = msg.author) == null ? void 0 : _e2.picture) || ""
937
928
  },
938
929
  image: imageUrl,
939
930
  sent: msg == null ? void 0 : msg.isDelivered,
940
931
  received: msg == null ? void 0 : msg.isRead,
941
932
  type: msg == null ? void 0 : msg.type,
942
933
  propsConfiguration: msg == null ? void 0 : msg.propsConfiguration,
943
- replies: (_f3 = msg == null ? void 0 : msg.replies) != null ? _f3 : [],
934
+ replies: (_f2 = msg == null ? void 0 : msg.replies) != null ? _f2 : [],
944
935
  isShowThreadMessage
945
936
  };
946
937
  });
947
- }, [(_i = state == null ? void 0 : state.context) == null ? void 0 : _i.channelMessages, (_j = state == null ? void 0 : state.context) == null ? void 0 : _j.channelId, isShowThreadMessage]);
938
+ }, [(_i = state == null ? void 0 : state.context) == null ? void 0 : _i.channelMessages, isShowThreadMessage]);
948
939
  const renderMessageText = useCallback((props) => {
949
- var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2, _q2, _r2, _s2, _t2, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U;
940
+ var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2, _q2, _r2, _s2, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U;
950
941
  const {
951
942
  currentMessage
952
943
  } = props;
@@ -966,7 +957,7 @@ const ConversationViewComponent = (_a) => {
966
957
  param = ((_m2 = route == null ? void 0 : route.guest) == null ? void 0 : _m2.params) ? (_o2 = (_n2 = route == null ? void 0 : route.guest) == null ? void 0 : _n2.params) != null ? _o2 : null : null;
967
958
  } else if (role && role == PreDefinedRole.Owner) {
968
959
  path = ((_p2 = route == null ? void 0 : route.host) == null ? void 0 : _p2.name) ? (_r2 = (_q2 = route == null ? void 0 : route.host) == null ? void 0 : _q2.name) != null ? _r2 : null : null;
969
- param = ((_s2 = route == null ? void 0 : route.host) == null ? void 0 : _s2.params) ? (_u = (_t2 = route == null ? void 0 : route.host) == null ? void 0 : _t2.params) != null ? _u : null : null;
960
+ param = ((_s2 = route == null ? void 0 : route.host) == null ? void 0 : _s2.params) ? (_u = (_t = route == null ? void 0 : route.host) == null ? void 0 : _t.params) != null ? _u : null : null;
970
961
  } else {
971
962
  path = ((_v = route == null ? void 0 : route.host) == null ? void 0 : _v.name) ? (_x = (_w = route == null ? void 0 : route.host) == null ? void 0 : _w.name) != null ? _x : null : null;
972
963
  param = ((_y = route == null ? void 0 : route.host) == null ? void 0 : _y.params) ? (_A = (_z = route == null ? void 0 : route.host) == null ? void 0 : _z.params) != null ? _A : null : null;
@@ -1052,7 +1043,7 @@ const ConversationViewComponent = (_a) => {
1052
1043
  fontSize: 12
1053
1044
  }, className: "font-bold color-gray-500" }, lastReply ? createdAtText(lastReply == null ? void 0 : lastReply.createdAt) : ""))));
1054
1045
  }
1055
- }, [navigation, (_k = state == null ? void 0 : state.context) == null ? void 0 : _k.channelId, role]);
1046
+ }, [navigation, (_j = state == null ? void 0 : state.context) == null ? void 0 : _j.channelId, role]);
1056
1047
  const renderActions = (props) => {
1057
1048
  return /* @__PURE__ */ React__default.createElement(
1058
1049
  Actions$1,
@@ -1133,7 +1124,7 @@ const ConversationViewComponent = (_a) => {
1133
1124
  color: "white",
1134
1125
  fontWeight: "bold"
1135
1126
  } }, "X"))));
1136
- }, [(_l = state == null ? void 0 : state.context) == null ? void 0 : _l.selectedImage, safeSend]);
1127
+ }, [(_k = state == null ? void 0 : state.context) == null ? void 0 : _k.selectedImage, safeSend]);
1137
1128
  const setImageViewerObject = (obj, v) => {
1138
1129
  setImageObject(obj);
1139
1130
  setImageViewer(v);
@@ -1302,7 +1293,7 @@ const ConversationViewComponent = (_a) => {
1302
1293
  return prev;
1303
1294
  }
1304
1295
  lastProcessedMessageRef.current = newMessage.id;
1305
- setTimeout(() => {
1296
+ queueMicrotask(() => {
1306
1297
  var _a6;
1307
1298
  safeSend({
1308
1299
  type: Actions.SET_CHANNEL_MESSAGES,
@@ -1313,7 +1304,7 @@ const ConversationViewComponent = (_a) => {
1313
1304
  totalCount: (((_a6 = prev == null ? void 0 : prev.messages) == null ? void 0 : _a6.totalCount) || 0) + 1
1314
1305
  }
1315
1306
  });
1316
- }, 0);
1307
+ });
1317
1308
  return __spreadProps(__spreadValues({}, prev), {
1318
1309
  messages: __spreadProps(__spreadValues({}, prev == null ? void 0 : prev.messages), {
1319
1310
  data: [...currentMessages, newMessage],
@@ -1323,7 +1314,7 @@ const ConversationViewComponent = (_a) => {
1323
1314
  }
1324
1315
  });
1325
1316
  } }));
1326
- }, [isShowImageViewer, modalContent, (_m = state == null ? void 0 : state.context) == null ? void 0 : _m.channelId, (_n = state == null ? void 0 : state.context) == null ? void 0 : _n.channelMessages, subscribeToMore, safeSend]);
1317
+ }, [isShowImageViewer, modalContent, (_l = state == null ? void 0 : state.context) == null ? void 0 : _l.channelId, (_m = state == null ? void 0 : state.context) == null ? void 0 : _m.channelMessages, subscribeToMore, safeSend]);
1327
1318
  const lastProcessedMessageRef = useRef(null);
1328
1319
  const listViewProps = useMemo(() => ({
1329
1320
  onEndReached,
@@ -1331,8 +1322,10 @@ const ConversationViewComponent = (_a) => {
1331
1322
  onMomentumScrollBegin,
1332
1323
  removeClippedSubviews: true,
1333
1324
  initialNumToRender: 10,
1334
- maxToRenderPerBatch: 10,
1335
- windowSize: 10
1325
+ maxToRenderPerBatch: 7,
1326
+ windowSize: 7,
1327
+ updateCellsBatchingPeriod: 50,
1328
+ keyExtractor: (item) => item._id
1336
1329
  }), [onEndReached, onMomentumScrollBegin]);
1337
1330
  const renderLoadEarlier = useCallback(() => {
1338
1331
  var _a3;
@@ -1342,7 +1335,7 @@ const ConversationViewComponent = (_a) => {
1342
1335
  borderRadius: 10,
1343
1336
  marginTop: 10
1344
1337
  } }, /* @__PURE__ */ React__default.createElement(Spinner, { size: "small", color: "#3b82f6" })) : null;
1345
- }, [(_o = state == null ? void 0 : state.context) == null ? void 0 : _o.loadingOldMessages]);
1338
+ }, [(_n = state == null ? void 0 : state.context) == null ? void 0 : _n.loadingOldMessages]);
1346
1339
  const renderInputToolbar = useCallback((props) => {
1347
1340
  return /* @__PURE__ */ React__default.createElement(InputToolbar, __spreadProps(__spreadValues({}, props), { containerStyle: {
1348
1341
  backgroundColor: "white",
@@ -1381,7 +1374,7 @@ const ConversationViewComponent = (_a) => {
1381
1374
  messageText: text
1382
1375
  }
1383
1376
  }),
1384
- renderFooter: () => safeContextProperty("loading") ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : safeContextProperty("imageLoading") ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : "",
1377
+ renderFooter: () => safeContextProperty("loading") || safeContextProperty("imageLoading") ? /* @__PURE__ */ React__default.createElement(Spinner, { color: "#3b82f6" }) : null,
1385
1378
  scrollToBottom: true,
1386
1379
  user: {
1387
1380
  _id: (auth == null ? void 0 : auth.id) || ""
@@ -1393,12 +1386,12 @@ const ConversationViewComponent = (_a) => {
1393
1386
  renderInputToolbar,
1394
1387
  minInputToolbarHeight: 50,
1395
1388
  renderActions: safeContextProperty("channelId") && renderActions,
1396
- renderAccessory: !!((_p = state == null ? void 0 : state.context) == null ? void 0 : _p.selectedImage) ? renderAccessory : void 0,
1389
+ renderAccessory: !!((_o = state == null ? void 0 : state.context) == null ? void 0 : _o.selectedImage) ? renderAccessory : void 0,
1397
1390
  renderMessage,
1398
1391
  renderChatFooter,
1399
1392
  renderLoadEarlier,
1400
- loadEarlier: ((_q = state == null ? void 0 : state.context) == null ? void 0 : _q.totalCount) > ((_s = (_r = state == null ? void 0 : state.context) == null ? void 0 : _r.channelMessages) == null ? void 0 : _s.length),
1401
- isLoadingEarlier: (_t = state == null ? void 0 : state.context) == null ? void 0 : _t.loadingOldMessages,
1393
+ loadEarlier: ((_p = state == null ? void 0 : state.context) == null ? void 0 : _p.totalCount) > ((_r = (_q = state == null ? void 0 : state.context) == null ? void 0 : _q.channelMessages) == null ? void 0 : _r.length),
1394
+ isLoadingEarlier: (_s = state == null ? void 0 : state.context) == null ? void 0 : _s.loadingOldMessages,
1402
1395
  bottomOffset: Platform.OS === "ios" ? 10 : 0,
1403
1396
  textInputProps: {
1404
1397
  style: {
@@ -1441,7 +1434,16 @@ const SubscriptionHandler = ({
1441
1434
  subscribeToNewMessages,
1442
1435
  channelId
1443
1436
  }) => {
1444
- useEffect(() => subscribeToNewMessages(), [channelId]);
1445
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
1437
+ const channelIdRef = useRef(channelId);
1438
+ useEffect(() => {
1439
+ if (channelId && channelId !== channelIdRef.current) {
1440
+ channelIdRef.current = channelId;
1441
+ console.log("Setting up subscription for channel:", channelId);
1442
+ return subscribeToNewMessages();
1443
+ }
1444
+ }, [channelId, subscribeToNewMessages]);
1445
+ return null;
1446
1446
  };
1447
- const ConversationView = React__default.memo(ConversationViewComponent);export{ConversationView};//# sourceMappingURL=ConversationView.js.map
1447
+ const ConversationView = React__default.memo(ConversationViewComponent, (prevProps, nextProps) => {
1448
+ return prevProps.channelId === nextProps.channelId && prevProps.role === nextProps.role && prevProps.isShowThreadMessage === nextProps.isShowThreadMessage;
1449
+ });export{ConversationView};//# sourceMappingURL=ConversationView.js.map