@messenger-box/platform-mobile 10.0.3-alpha.18 → 10.0.3-alpha.19

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.
@@ -1,4 +1,4 @@
1
- import React__default,{useState,useRef,useCallback,useEffect,useMemo}from'react';import {Button,Box,Spinner,Text,VStack,HStack,Avatar,AvatarFallbackText,AvatarImage,Center,Image}from'@admin-layout/gluestack-ui-mobile';import {Platform,SafeAreaView,Linking,View,TouchableHighlight}from'react-native';import {useRoute,useNavigation,useFocusEffect}from'@react-navigation/native';import {useSelector}from'react-redux';import {startCase,uniqBy}from'lodash-es';import*as ImagePicker from'expo-image-picker';import {MaterialIcons,Ionicons,MaterialCommunityIcons}from'@expo/vector-icons';import {GiftedChat,Actions as Actions$1,InputToolbar,Send}from'react-native-gifted-chat';import'common';import {useCreatePostThreadMutation,useSendExpoNotificationOnPostMutation,useGetPostThreadLazyQuery,OnThreadChatMessageAddedDocument}from'common/graphql';import {useUploadFilesNative}from'@messenger-box/platform-client';import {objectId}from'@messenger-box/core';import {format,isToday,isYesterday}from'date-fns';import {userSelector}from'@adminide-stack/user-auth0-client';import {config}from'../config/config.js';import Message from'../components/SlackMessageContainer/SlackMessage.js';import ImageViewerModal from'../components/SlackMessageContainer/ImageViewerModal.js';import CachedImage from'../components/CachedImage/index.js';import colors from'tailwindcss/colors';import {Actions,BaseState,MainState}from'./workflow/thread-conversation-xstate.js';var __defProp = Object.defineProperty;
1
+ import React__default,{useState,useRef,useCallback,useEffect,useMemo}from'react';import {Button,Box,Spinner,Text,HStack,VStack,Avatar,AvatarFallbackText,AvatarImage,Center,Image}from'@admin-layout/gluestack-ui-mobile';import {Platform,SafeAreaView,TouchableHighlight,Alert,Linking,View}from'react-native';import {useRoute,useNavigation,useFocusEffect}from'@react-navigation/native';import {useSelector}from'react-redux';import {orderBy,startCase,uniqBy}from'lodash-es';import*as ImagePicker from'expo-image-picker';import {MaterialIcons,Ionicons,MaterialCommunityIcons}from'@expo/vector-icons';import {GiftedChat,Actions as Actions$1,InputToolbar,Send}from'react-native-gifted-chat';import'common';import {useCreatePostThreadMutation,useSendExpoNotificationOnPostMutation,useGetPostThreadLazyQuery,OnThreadChatMessageAddedDocument}from'common/graphql';import {useUploadFilesNative}from'@messenger-box/platform-client';import {objectId}from'@messenger-box/core';import {format,isToday,isYesterday}from'date-fns';import {userSelector}from'@adminide-stack/user-auth0-client';import {config}from'../config/config.js';import Message from'../components/SlackMessageContainer/SlackMessage.js';import ImageViewerModal from'../components/SlackMessageContainer/ImageViewerModal.js';import CachedImage from'../components/CachedImage/index.js';import colors from'tailwindcss/colors';import {Actions,BaseState,MainState}from'./workflow/thread-conversation-xstate.js';var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -138,11 +138,15 @@ function useSafeMachine(machine) {
138
138
  })
139
139
  }));
140
140
  } else if (event.type === Actions.STOP_LOADING) {
141
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
142
- context: __spreadProps(__spreadValues({}, prev.context), {
143
- loading: false
144
- })
145
- }));
141
+ setState((prev) => {
142
+ var _a2;
143
+ return __spreadProps(__spreadValues({}, prev), {
144
+ context: __spreadProps(__spreadValues({}, prev.context), {
145
+ loading: false,
146
+ loadingOldMessages: ((_a2 = event.data) == null ? void 0 : _a2.loadingOldMessages) === false ? false : prev.context.loadingOldMessages
147
+ })
148
+ });
149
+ });
146
150
  } else if (event.type === Actions.SEND_THREAD_MESSAGE) {
147
151
  console.log("Sending message event with text:", (_a = event.data) == null ? void 0 : _a.messageText);
148
152
  setState((prev) => {
@@ -202,14 +206,37 @@ function useSafeMachine(machine) {
202
206
  });
203
207
  } else if (event.type === "FETCH_MORE_MESSAGES_SUCCESS") {
204
208
  setState((prev) => {
205
- var _a2;
209
+ var _a2, _b2;
206
210
  const newMessages = ((_a2 = event.data) == null ? void 0 : _a2.messages) || [];
211
+ const apiTotalCount = (_b2 = event.data) == null ? void 0 : _b2.totalCount;
212
+ console.log(`Merging ${newMessages.length} older messages with ${prev.context.threadMessages.length} existing messages`);
213
+ if (newMessages.length > 0) {
214
+ console.log("First new message date:", new Date(newMessages[0].createdAt).toISOString());
215
+ console.log("Last new message date:", new Date(newMessages[newMessages.length - 1].createdAt).toISOString());
216
+ }
217
+ if (prev.context.threadMessages.length > 0) {
218
+ console.log("First existing message date:", new Date(prev.context.threadMessages[0].createdAt).toISOString());
219
+ console.log("Last existing message date:", new Date(prev.context.threadMessages[prev.context.threadMessages.length - 1].createdAt).toISOString());
220
+ }
221
+ if (newMessages.length === 0 && prev.context.totalCount > prev.context.threadMessages.length) {
222
+ console.log("No new messages found despite totalCount indicating more should exist");
223
+ return __spreadProps(__spreadValues({}, prev), {
224
+ context: __spreadProps(__spreadValues({}, prev.context), {
225
+ loadingOldMessages: false,
226
+ totalCount: prev.context.threadMessages.length
227
+ }),
228
+ value: "active"
229
+ });
230
+ }
231
+ const combinedMessages = uniqBy([...prev.context.threadMessages, ...newMessages], "id");
232
+ const sortedMessages = orderBy(combinedMessages, [(msg) => new Date(msg.createdAt).getTime()], ["desc"]);
233
+ const newTotalCount = typeof apiTotalCount === "number" ? apiTotalCount : Math.max(sortedMessages.length, prev.context.totalCount);
234
+ console.log(`Total messages after merge and sort: ${sortedMessages.length}, totalCount: ${newTotalCount}`);
207
235
  return __spreadProps(__spreadValues({}, prev), {
208
236
  context: __spreadProps(__spreadValues({}, prev.context), {
209
237
  loadingOldMessages: false,
210
- threadMessages: uniqBy([...prev.context.threadMessages, ...newMessages], ({
211
- id
212
- }) => id)
238
+ threadMessages: sortedMessages,
239
+ totalCount: newTotalCount
213
240
  }),
214
241
  value: "active"
215
242
  });
@@ -314,11 +341,64 @@ const ThreadConversationViewComponent = ({
314
341
  }] = useGetPostThreadLazyQuery({
315
342
  fetchPolicy: "cache-and-network"
316
343
  });
344
+ const forceRefreshMessages = useCallback(() => {
345
+ console.log("Force refreshing all messages");
346
+ safeSend({
347
+ type: Actions.CLEAR_MESSAGES
348
+ });
349
+ if (channelId && parentId) {
350
+ safeSend({
351
+ type: Actions.START_LOADING,
352
+ data: {
353
+ loading: true
354
+ }
355
+ });
356
+ getThreadMessages({
357
+ variables: {
358
+ channelId: channelId == null ? void 0 : channelId.toString(),
359
+ role: role == null ? void 0 : role.toString(),
360
+ postParentId: !parentId || parentId == 0 ? null : parentId == null ? void 0 : parentId.toString(),
361
+ selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
362
+ limit: 50
363
+ }
364
+ }).then(({
365
+ data: data2
366
+ }) => {
367
+ var _a2, _b2, _c2;
368
+ if (data2 == null ? void 0 : data2.getPostThread) {
369
+ const threads = data2.getPostThread;
370
+ const threadPost = (_a2 = threads == null ? void 0 : threads.post) != null ? _a2 : [];
371
+ const threadReplies = (_b2 = threads == null ? void 0 : threads.replies) != null ? _b2 : [];
372
+ const messageTotalCount = (_c2 = threads == null ? void 0 : threads.replyCount) != null ? _c2 : 0;
373
+ const messages = [...threadReplies];
374
+ console.log(`Force refresh complete. Got ${messages.length} messages of ${messageTotalCount} total`);
375
+ safeSend({
376
+ type: Actions.SET_THREAD_MESSAGES,
377
+ data: {
378
+ messages,
379
+ totalCount: messageTotalCount,
380
+ threadPost,
381
+ postThread: threads
382
+ }
383
+ });
384
+ }
385
+ }).catch((error) => {
386
+ console.error("Error during force refresh:", error);
387
+ safeSend({
388
+ type: "ERROR",
389
+ data: {
390
+ message: error.message
391
+ }
392
+ });
393
+ });
394
+ }
395
+ }, [channelId, parentId, getThreadMessages, safeSend]);
317
396
  useFocusEffect(React__default.useCallback(() => {
318
397
  var _a2;
319
398
  navigation.setOptions({
320
399
  title: (_a2 = params == null ? void 0 : params.title) != null ? _a2 : "Thread",
321
- headerLeft: (props) => /* @__PURE__ */ React__default.createElement(Button, { className: "bg-transparent active:bg-gray-200 ", onPress: () => navigation.goBack() }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { size: 20, name: "arrow-back-ios", color: "black" }))
400
+ headerLeft: (props) => /* @__PURE__ */ React__default.createElement(Button, { className: "bg-transparent active:bg-gray-200 ", onPress: () => navigation.goBack() }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { size: 20, name: "arrow-back-ios", color: "black" })),
401
+ headerRight: () => /* @__PURE__ */ React__default.createElement(Button, { className: "bg-transparent active:bg-gray-200 mr-2", onPress: forceRefreshMessages }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { size: 20, name: "refresh", color: "black" }))
322
402
  });
323
403
  if (channelId && postParentId) {
324
404
  safeSend({
@@ -336,7 +416,7 @@ const ThreadConversationViewComponent = ({
336
416
  type: Actions.CLEAR_MESSAGES
337
417
  });
338
418
  };
339
- }, [postParentId]));
419
+ }, [postParentId, forceRefreshMessages]));
340
420
  useEffect(() => {
341
421
  if (safeMatches(BaseState.FetchThreadMessages)) {
342
422
  fetchThreadMessages();
@@ -363,13 +443,14 @@ const ThreadConversationViewComponent = ({
363
443
  }, [state.value]);
364
444
  const fetchThreadMessages = useCallback(() => {
365
445
  if (channelId && parentId) {
446
+ console.log("Initial fetch of thread messages using larger limit (50)");
366
447
  getThreadMessages({
367
448
  variables: {
368
449
  channelId: channelId == null ? void 0 : channelId.toString(),
369
450
  role: role == null ? void 0 : role.toString(),
370
451
  postParentId: !parentId || parentId == 0 ? null : parentId == null ? void 0 : parentId.toString(),
371
452
  selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
372
- limit: MESSAGES_PER_PAGE
453
+ limit: 50
373
454
  }
374
455
  }).then(({
375
456
  data: data2
@@ -381,6 +462,7 @@ const ThreadConversationViewComponent = ({
381
462
  const threadReplies = (_b2 = threads == null ? void 0 : threads.replies) != null ? _b2 : [];
382
463
  const messageTotalCount = (_c2 = threads == null ? void 0 : threads.replyCount) != null ? _c2 : 0;
383
464
  const messages = [...threadReplies];
465
+ console.log(`Initial fetch complete. Got ${messages.length} messages of ${messageTotalCount} total`);
384
466
  safeSend({
385
467
  type: Actions.SET_THREAD_MESSAGES,
386
468
  data: {
@@ -427,6 +509,54 @@ const ThreadConversationViewComponent = ({
427
509
  });
428
510
  }
429
511
  }, [safeContextProperty("selectedImage")]);
512
+ React__default.useEffect(() => {
513
+ const isLoading = safeContextProperty("loadingOldMessages", false);
514
+ if (isLoading) {
515
+ console.log("Message loading timeout safety started");
516
+ const timeoutId = setTimeout(() => {
517
+ if (safeContextProperty("loadingOldMessages", false)) {
518
+ console.log("Message loading timed out - resetting state");
519
+ safeSend({
520
+ type: Actions.STOP_LOADING,
521
+ data: {
522
+ loadingOldMessages: false
523
+ }
524
+ });
525
+ }
526
+ }, 1e4);
527
+ return () => clearTimeout(timeoutId);
528
+ }
529
+ }, [safeContextProperty("loadingOldMessages")]);
530
+ const failedLoadAttemptsRef = useRef(0);
531
+ const registerLoadAttemptResult = useCallback((success) => {
532
+ if (!success) {
533
+ failedLoadAttemptsRef.current += 1;
534
+ console.log(`Failed load attempt registered, count: ${failedLoadAttemptsRef.current}`);
535
+ } else {
536
+ failedLoadAttemptsRef.current = 0;
537
+ }
538
+ }, []);
539
+ React__default.useEffect(() => {
540
+ const isLoading = safeContextProperty("loadingOldMessages", false);
541
+ const totalCount = safeContextProperty("totalCount", 0);
542
+ const messagesCount = safeContextProperty("threadMessages", []).length;
543
+ if (!isLoading && totalCount > messagesCount) {
544
+ if (failedLoadAttemptsRef.current >= 2) {
545
+ console.log(`Auto-fixing incorrect message count after ${failedLoadAttemptsRef.current + 1} failed load attempts`);
546
+ console.log(`Adjusting totalCount from ${totalCount} to ${messagesCount}`);
547
+ safeSend({
548
+ type: Actions.SET_THREAD_MESSAGES,
549
+ data: {
550
+ messages: safeContextProperty("threadMessages", []),
551
+ totalCount: messagesCount,
552
+ threadPost: safeContextProperty("threadPost", []),
553
+ postThread: safeContextProperty("postThread", null)
554
+ }
555
+ });
556
+ failedLoadAttemptsRef.current = 0;
557
+ }
558
+ }
559
+ }, [safeContextProperty("loadingOldMessages"), safeContextProperty("threadMessages")]);
430
560
  React__default.useCallback(() => {
431
561
  if (threadMessageListRef == null ? void 0 : threadMessageListRef.current) {
432
562
  threadMessageListRef.current.scrollToBottom();
@@ -438,35 +568,72 @@ const ThreadConversationViewComponent = ({
438
568
  if (totalCount > threadMessages.length && !safeContextProperty("loadingOldMessages", false)) {
439
569
  console.log("Loading more messages - current count:", threadMessages.length, "of", totalCount);
440
570
  safeSend({
441
- type: Actions.START_LOADING,
571
+ type: Actions.FETCH_MORE_MESSAGES,
442
572
  data: {
443
573
  loadingOldMessages: true
444
574
  }
445
575
  });
576
+ console.log("Using proven approach: Skip=0, Limit=50");
577
+ const queryVariables = {
578
+ channelId: channelId == null ? void 0 : channelId.toString(),
579
+ role: role == null ? void 0 : role.toString(),
580
+ postParentId: !parentId || parentId == 0 ? null : parentId == null ? void 0 : parentId.toString(),
581
+ selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
582
+ limit: 50,
583
+ skip: 0
584
+ };
585
+ console.log("Query variables:", JSON.stringify(queryVariables));
446
586
  fetchMoreMessages({
447
- variables: {
448
- channelId: channelId == null ? void 0 : channelId.toString(),
449
- role: role == null ? void 0 : role.toString(),
450
- postParentId: parentId == null ? void 0 : parentId.toString(),
451
- selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
452
- limit: MESSAGES_PER_PAGE,
453
- skip: threadMessages.length
454
- }
587
+ variables: queryVariables
455
588
  }).then((res) => {
456
- var _a2, _b2, _c2;
589
+ var _a2, _b2, _c2, _d2;
590
+ console.log("API response received:", JSON.stringify(res == null ? void 0 : res.data, null, 2));
457
591
  if ((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.getPostThread) {
458
592
  const threads = (_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.getPostThread;
459
593
  const threadReplies = (_c2 = threads == null ? void 0 : threads.replies) != null ? _c2 : [];
460
- console.log("Successfully loaded more messages:", threadReplies.length);
594
+ const actualTotalCount = (_d2 = threads == null ? void 0 : threads.replyCount) != null ? _d2 : 0;
595
+ console.log("API response details:");
596
+ console.log("- replyCount:", threads == null ? void 0 : threads.replyCount);
597
+ console.log("- replies array length:", threadReplies.length);
598
+ console.log("- replies structure:", threadReplies.length > 0 ? `First item has fields: ${Object.keys(threadReplies[0]).join(", ")}` : "No items");
599
+ if (threadReplies.length > 0) {
600
+ console.log("- Sample message:", JSON.stringify(threadReplies[0], null, 2));
601
+ }
602
+ console.log("Successfully loaded more messages:", threadReplies.length, "of total:", actualTotalCount);
603
+ console.log("Thread reply IDs:", threadReplies.map((msg) => msg.id).join(", "));
604
+ const existingIds = new Set(threadMessages.map((msg) => msg.id));
605
+ const newUniqueMessages = threadReplies.filter((msg) => !existingIds.has(msg.id));
606
+ console.log(`Found ${newUniqueMessages.length} unique new messages out of ${threadReplies.length} received`);
607
+ if (actualTotalCount !== totalCount) {
608
+ console.log(`Updating totalCount from ${totalCount} to ${actualTotalCount} based on API response`);
609
+ }
610
+ if (newUniqueMessages.length === 0) {
611
+ console.log("No new unique messages found, adjusting total count");
612
+ registerLoadAttemptResult(false);
613
+ safeSend({
614
+ type: Actions.SET_THREAD_MESSAGES,
615
+ data: {
616
+ messages: threadMessages,
617
+ totalCount: threadMessages.length,
618
+ threadPost: safeContextProperty("threadPost", []),
619
+ postThread: safeContextProperty("postThread", null)
620
+ }
621
+ });
622
+ return;
623
+ }
624
+ registerLoadAttemptResult(true);
625
+ console.log(`Adding ${newUniqueMessages.length} new messages to thread`);
461
626
  safeSend({
462
627
  type: "FETCH_MORE_MESSAGES_SUCCESS",
463
628
  data: {
464
- messages: threadReplies,
629
+ messages: newUniqueMessages,
630
+ totalCount: actualTotalCount,
465
631
  loadingOldMessages: false
466
632
  }
467
633
  });
468
634
  } else {
469
635
  console.log("No thread data returned when loading more messages");
636
+ registerLoadAttemptResult(false);
470
637
  safeSend({
471
638
  type: Actions.STOP_LOADING,
472
639
  data: {
@@ -476,6 +643,7 @@ const ThreadConversationViewComponent = ({
476
643
  }
477
644
  }).catch((error) => {
478
645
  console.error("Error fetching more messages:", error);
646
+ registerLoadAttemptResult(false);
479
647
  safeSend({
480
648
  type: "ERROR",
481
649
  data: {
@@ -486,13 +654,26 @@ const ThreadConversationViewComponent = ({
486
654
  });
487
655
  } else {
488
656
  console.log("No more messages to load or already loading");
657
+ if (safeContextProperty("loadingOldMessages", false)) {
658
+ safeSend({
659
+ type: Actions.STOP_LOADING,
660
+ data: {
661
+ loadingOldMessages: false
662
+ }
663
+ });
664
+ }
489
665
  }
490
- }, [parentId, channelId, state.context]);
666
+ }, [parentId, channelId, state.context, registerLoadAttemptResult]);
491
667
  const handleScrollToTop = ({
492
668
  nativeEvent
493
669
  }) => {
494
670
  if (isCloseToTop(nativeEvent)) {
495
- if (!safeContextProperty("loadingOldMessages", false) && safeContextProperty("totalCount", 0) > safeContextProperty("threadMessages", []).length) {
671
+ const isLoading = safeContextProperty("loadingOldMessages", false);
672
+ const totalCount = safeContextProperty("totalCount", 0);
673
+ const currentCount = safeContextProperty("threadMessages", []).length;
674
+ const hasMoreMessages = totalCount > currentCount;
675
+ console.log(`Scroll near top - Loading state: ${isLoading}, Messages: ${currentCount}/${totalCount}, Has more: ${hasMoreMessages}`);
676
+ if (!isLoading && hasMoreMessages) {
496
677
  console.log("Near top of list - loading older messages");
497
678
  safeSend({
498
679
  type: Actions.FETCH_MORE_MESSAGES
@@ -508,8 +689,12 @@ const ThreadConversationViewComponent = ({
508
689
  contentOffset,
509
690
  contentSize
510
691
  }) => {
511
- const paddingToTop = 80;
512
- return contentOffset.y <= paddingToTop;
692
+ const visibleHeight = layoutMeasurement.height;
693
+ const topThreshold = Math.min(80, visibleHeight * 0.15);
694
+ const distanceFromTop = contentOffset.y;
695
+ const totalContentHeight = contentSize.height;
696
+ console.log(`Scroll position: ${distanceFromTop.toFixed(0)}px from top, threshold: ${topThreshold.toFixed(0)}px, content height: ${totalContentHeight.toFixed(0)}px`);
697
+ return contentOffset.y <= topThreshold;
513
698
  };
514
699
  const onSelectImages = async () => {
515
700
  var _a2;
@@ -812,7 +997,10 @@ const ThreadConversationViewComponent = ({
812
997
  return message;
813
998
  });
814
999
  }
815
- const sortedMessages = res.sort((a, b) => b.createdAt - a.createdAt);
1000
+ const sortedMessages = orderBy(res, [(msg) => new Date(msg.createdAt).getTime()], ["desc"]);
1001
+ if (sortedMessages.length > 0) {
1002
+ console.log("Message date range:", new Date(sortedMessages[sortedMessages.length - 1].createdAt).toISOString(), "to", new Date(sortedMessages[0].createdAt).toISOString());
1003
+ }
816
1004
  return sortedMessages;
817
1005
  }, [safeContextProperty("threadMessages"), auth]);
818
1006
  const renderSend = (props) => {
@@ -940,9 +1128,237 @@ const ThreadConversationViewComponent = ({
940
1128
  alignItems: "center"
941
1129
  } }));
942
1130
  };
1131
+ const forceLoadMessages = useCallback((skipValue) => {
1132
+ console.log(`Force loading messages with explicit skip=${skipValue}, limit=50`);
1133
+ if (channelId && parentId) {
1134
+ safeSend({
1135
+ type: Actions.START_LOADING,
1136
+ data: {
1137
+ loading: true
1138
+ }
1139
+ });
1140
+ getThreadMessages({
1141
+ variables: {
1142
+ channelId: channelId == null ? void 0 : channelId.toString(),
1143
+ role: role == null ? void 0 : role.toString(),
1144
+ postParentId: !parentId || parentId == 0 ? null : parentId == null ? void 0 : parentId.toString(),
1145
+ selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
1146
+ skip: skipValue,
1147
+ limit: 50
1148
+ }
1149
+ }).then(({
1150
+ data: data2
1151
+ }) => {
1152
+ var _a2, _b2, _c2;
1153
+ if (data2 == null ? void 0 : data2.getPostThread) {
1154
+ const threads = data2.getPostThread;
1155
+ const threadPost = (_a2 = threads == null ? void 0 : threads.post) != null ? _a2 : [];
1156
+ const threadReplies = (_b2 = threads == null ? void 0 : threads.replies) != null ? _b2 : [];
1157
+ const messageTotalCount = (_c2 = threads == null ? void 0 : threads.replyCount) != null ? _c2 : 0;
1158
+ const messages = [...threadReplies];
1159
+ console.log(`Force load with skip=${skipValue} complete. Got ${messages.length} messages of ${messageTotalCount} total`);
1160
+ safeSend({
1161
+ type: Actions.SET_THREAD_MESSAGES,
1162
+ data: {
1163
+ messages,
1164
+ totalCount: messageTotalCount,
1165
+ threadPost,
1166
+ postThread: threads
1167
+ }
1168
+ });
1169
+ }
1170
+ }).catch((error) => {
1171
+ console.error("Error during force load:", error);
1172
+ safeSend({
1173
+ type: "ERROR",
1174
+ data: {
1175
+ message: error.message
1176
+ }
1177
+ });
1178
+ });
1179
+ }
1180
+ }, [channelId, parentId, getThreadMessages, safeSend]);
943
1181
  return /* @__PURE__ */ React__default.createElement(SafeAreaView, { style: {
944
1182
  flex: 1
945
- } }, safeContextProperty("loadingOldMessages", false) && /* @__PURE__ */ React__default.createElement(Box, { className: "absolute top-10 left-0 right-0 z-10 items-center" }, /* @__PURE__ */ React__default.createElement(Box, { className: "bg-blue-500/20 rounded-full px-4 py-2 flex-row items-center" }, /* @__PURE__ */ React__default.createElement(Spinner, { color: colors.blue[500], size: "small" }), /* @__PURE__ */ React__default.createElement(Text, { className: "text-sm font-medium color-blue-600 ml-2" }, "Loading messages..."))), isPostParentIdThread && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, ((_a = safeContextProperty("threadPost", [])) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(VStack, { className: "px-2 pt-2 pb-0", space: "sm" }, /* @__PURE__ */ React__default.createElement(HStack, { space: "sm", className: "items-center" }, /* @__PURE__ */ React__default.createElement(Avatar, { className: "bg-transparent", size: "md" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_d = (_c = (_b = safeContextProperty("threadPost")[0]) == null ? void 0 : _b.author) == null ? void 0 : _c.username) == null ? void 0 : _d.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "image", style: {
1183
+ } }, safeContextProperty("loadingOldMessages", false) === true && /* @__PURE__ */ React__default.createElement(Box, { className: "absolute top-10 left-0 right-0 z-10 items-center" }, /* @__PURE__ */ React__default.createElement(Box, { className: "bg-blue-500/20 rounded-full px-4 py-2 flex-row items-center" }, /* @__PURE__ */ React__default.createElement(Spinner, { color: colors.blue[500], size: "small" }), /* @__PURE__ */ React__default.createElement(Text, { className: "text-sm font-medium color-blue-600 ml-2" }, "Loading messages..."))), !safeContextProperty("loadingOldMessages", false) && safeContextProperty("totalCount", 0) > safeContextProperty("threadMessages", []).length && /* @__PURE__ */ React__default.createElement(Box, { className: "absolute top-10 left-0 right-0 z-10 items-center" }, /* @__PURE__ */ React__default.createElement(HStack, { space: 2, className: "px-2" }, /* @__PURE__ */ React__default.createElement(TouchableHighlight, { onPress: () => {
1184
+ console.log("Manual load more pressed");
1185
+ Alert.alert("Load Options", "Choose loading method", [{
1186
+ text: "Normal Load",
1187
+ onPress: () => safeSend({
1188
+ type: Actions.FETCH_MORE_MESSAGES
1189
+ })
1190
+ }, {
1191
+ text: "Try Skip=0",
1192
+ onPress: () => forceLoadMessages(0)
1193
+ }, {
1194
+ text: "Try Skip=0, Limit=50",
1195
+ onPress: () => {
1196
+ console.log("Force loading with explicit skip=0, limit=50");
1197
+ safeSend({
1198
+ type: Actions.START_LOADING,
1199
+ data: {
1200
+ loadingOldMessages: true
1201
+ }
1202
+ });
1203
+ fetchMoreMessages({
1204
+ variables: {
1205
+ channelId: channelId == null ? void 0 : channelId.toString(),
1206
+ role: role == null ? void 0 : role.toString(),
1207
+ postParentId: !parentId || parentId == 0 ? null : parentId == null ? void 0 : parentId.toString(),
1208
+ selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
1209
+ limit: 50,
1210
+ skip: 0
1211
+ }
1212
+ }).then((res) => {
1213
+ var _a2, _b2, _c2, _d2;
1214
+ console.log("LARGE LIMIT response:", JSON.stringify(res == null ? void 0 : res.data, null, 2));
1215
+ if ((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.getPostThread) {
1216
+ const threads = (_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.getPostThread;
1217
+ const threadReplies = (_c2 = threads == null ? void 0 : threads.replies) != null ? _c2 : [];
1218
+ const actualTotalCount = (_d2 = threads == null ? void 0 : threads.replyCount) != null ? _d2 : 0;
1219
+ console.log(`Large limit load complete. Got ${threadReplies.length} messages of ${actualTotalCount} total`);
1220
+ if (threadReplies.length > 0) {
1221
+ safeSend({
1222
+ type: Actions.SET_THREAD_MESSAGES,
1223
+ data: {
1224
+ messages: threadReplies,
1225
+ totalCount: actualTotalCount,
1226
+ threadPost: safeContextProperty("threadPost", []),
1227
+ postThread: threads
1228
+ }
1229
+ });
1230
+ } else {
1231
+ safeSend({
1232
+ type: Actions.SET_THREAD_MESSAGES,
1233
+ data: {
1234
+ messages: safeContextProperty("threadMessages", []),
1235
+ totalCount: safeContextProperty("threadMessages", []).length,
1236
+ threadPost: safeContextProperty("threadPost", []),
1237
+ postThread: safeContextProperty("postThread", null)
1238
+ }
1239
+ });
1240
+ }
1241
+ } else {
1242
+ safeSend({
1243
+ type: Actions.STOP_LOADING,
1244
+ data: {
1245
+ loadingOldMessages: false
1246
+ }
1247
+ });
1248
+ }
1249
+ }).catch((error) => {
1250
+ console.error("Error in large limit load:", error);
1251
+ safeSend({
1252
+ type: Actions.STOP_LOADING,
1253
+ data: {
1254
+ loadingOldMessages: false
1255
+ }
1256
+ });
1257
+ });
1258
+ }
1259
+ }, {
1260
+ text: "Try Direct Fetch",
1261
+ onPress: () => {
1262
+ const currentCount = safeContextProperty("threadMessages", []).length;
1263
+ const totalCount = safeContextProperty("totalCount", 0);
1264
+ const missingCount = totalCount - currentCount;
1265
+ if (missingCount <= 0) {
1266
+ Alert.alert("Info", "No missing messages to fetch");
1267
+ return;
1268
+ }
1269
+ console.log(`Attempting direct fetch of missing ${missingCount} messages`);
1270
+ safeSend({
1271
+ type: Actions.START_LOADING,
1272
+ data: {
1273
+ loadingOldMessages: true
1274
+ }
1275
+ });
1276
+ getThreadMessages({
1277
+ variables: {
1278
+ channelId: channelId == null ? void 0 : channelId.toString(),
1279
+ role: role == null ? void 0 : role.toString(),
1280
+ postParentId: !parentId || parentId == 0 ? null : parentId == null ? void 0 : parentId.toString(),
1281
+ selectedFields: "id channel post replies replyCount lastReplyAt createdAt updatedAt",
1282
+ limit: missingCount,
1283
+ skip: 0
1284
+ }
1285
+ }).then(({
1286
+ data: data2
1287
+ }) => {
1288
+ var _a2, _b2;
1289
+ console.log("DIRECT FETCH response:", JSON.stringify(data2, null, 2));
1290
+ if (data2 == null ? void 0 : data2.getPostThread) {
1291
+ const threads = data2.getPostThread;
1292
+ const threadReplies = (_a2 = threads == null ? void 0 : threads.replies) != null ? _a2 : [];
1293
+ const actualTotalCount = (_b2 = threads == null ? void 0 : threads.replyCount) != null ? _b2 : 0;
1294
+ console.log(`Direct fetch complete. Got ${threadReplies.length} messages of ${actualTotalCount} total`);
1295
+ console.log("Message IDs:", threadReplies.map((msg) => msg.id).join(", "));
1296
+ const existingIds = new Set(safeContextProperty("threadMessages", []).map((msg) => msg.id));
1297
+ const newMessages = threadReplies.filter((msg) => !existingIds.has(msg.id));
1298
+ console.log(`Found ${newMessages.length} new messages that we didn't have before`);
1299
+ if (newMessages.length > 0) {
1300
+ safeSend({
1301
+ type: "FETCH_MORE_MESSAGES_SUCCESS",
1302
+ data: {
1303
+ messages: newMessages,
1304
+ totalCount: actualTotalCount,
1305
+ loadingOldMessages: false
1306
+ }
1307
+ });
1308
+ Alert.alert("Success", `Found ${newMessages.length} new messages`);
1309
+ } else {
1310
+ console.log("No new messages found, adjusting count");
1311
+ safeSend({
1312
+ type: Actions.SET_THREAD_MESSAGES,
1313
+ data: {
1314
+ messages: safeContextProperty("threadMessages", []),
1315
+ totalCount: safeContextProperty("threadMessages", []).length,
1316
+ threadPost: safeContextProperty("threadPost", []),
1317
+ postThread: safeContextProperty("postThread", null)
1318
+ }
1319
+ });
1320
+ Alert.alert("Info", "No new messages found. Count has been adjusted.");
1321
+ }
1322
+ } else {
1323
+ Alert.alert("Error", "Could not fetch thread messages");
1324
+ safeSend({
1325
+ type: Actions.STOP_LOADING,
1326
+ data: {
1327
+ loadingOldMessages: false
1328
+ }
1329
+ });
1330
+ }
1331
+ }).catch((error) => {
1332
+ console.error("Error in direct fetch:", error);
1333
+ Alert.alert("Error", "Failed to fetch messages: " + error.message);
1334
+ safeSend({
1335
+ type: Actions.STOP_LOADING,
1336
+ data: {
1337
+ loadingOldMessages: false
1338
+ }
1339
+ });
1340
+ });
1341
+ }
1342
+ }, {
1343
+ text: "Reset Count",
1344
+ style: "destructive",
1345
+ onPress: () => {
1346
+ console.log("Resetting message count to match reality");
1347
+ safeSend({
1348
+ type: Actions.SET_THREAD_MESSAGES,
1349
+ data: {
1350
+ messages: safeContextProperty("threadMessages", []),
1351
+ totalCount: safeContextProperty("threadMessages", []).length,
1352
+ threadPost: safeContextProperty("threadPost", []),
1353
+ postThread: safeContextProperty("postThread", null)
1354
+ }
1355
+ });
1356
+ }
1357
+ }, {
1358
+ text: "Cancel",
1359
+ style: "cancel"
1360
+ }]);
1361
+ }, underlayColor: "#e6e6e6" }, /* @__PURE__ */ React__default.createElement(Box, { className: "bg-gray-200 rounded-full px-4 py-2 flex-row items-center" }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { name: "arrow-upward", size: 16, color: colors.blue[500] }), /* @__PURE__ */ React__default.createElement(Text, { className: "text-sm font-medium color-blue-600 ml-2" }, "Load More (", safeContextProperty("totalCount", 0) - safeContextProperty("threadMessages", []).length, ")"))), /* @__PURE__ */ React__default.createElement(TouchableHighlight, { onPress: forceRefreshMessages, underlayColor: "#e6e6e6" }, /* @__PURE__ */ React__default.createElement(Box, { className: "bg-gray-200 rounded-full px-4 py-2 flex-row items-center" }, /* @__PURE__ */ React__default.createElement(MaterialIcons, { name: "refresh", size: 16, color: colors.blue[500] }), /* @__PURE__ */ React__default.createElement(Text, { className: "text-sm font-medium color-blue-600 ml-2" }, "Refresh All"))))), isPostParentIdThread && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, ((_a = safeContextProperty("threadPost", [])) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(VStack, { className: "px-2 pt-2 pb-0", space: "sm" }, /* @__PURE__ */ React__default.createElement(HStack, { space: "sm", className: "items-center" }, /* @__PURE__ */ React__default.createElement(Avatar, { className: "bg-transparent", size: "md" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, startCase((_d = (_c = (_b = safeContextProperty("threadPost")[0]) == null ? void 0 : _b.author) == null ? void 0 : _c.username) == null ? void 0 : _d.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "image", style: {
946
1362
  borderRadius: 6,
947
1363
  borderWidth: 2,
948
1364
  borderColor: "#fff"
@@ -959,7 +1375,7 @@ const ThreadConversationViewComponent = ({
959
1375
  minIndexForVisible: 0,
960
1376
  autoscrollToTopThreshold: 100
961
1377
  },
962
- scrollEventThrottle: 100,
1378
+ scrollEventThrottle: 16,
963
1379
  keyboardDismissMode: "on-drag",
964
1380
  keyboardShouldPersistTaps: "handled"
965
1381
  }, onSend: (messages) => {