@adminide-stack/yantra-mobile 12.0.103-alpha.0 → 12.0.103-alpha.2

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 (101) hide show
  1. package/lib/components/CustomDrawer.js +4 -2
  2. package/lib/components/CustomDrawer.js.map +1 -1
  3. package/lib/features/expenses/ExpensesExperience.js +11 -1
  4. package/lib/features/expenses/ExpensesExperience.js.map +1 -1
  5. package/lib/features/expenses/components/ClaimForm.js +144 -23
  6. package/lib/features/expenses/components/ClaimForm.js.map +1 -1
  7. package/lib/features/expenses/receiptScan.js +36 -5
  8. package/lib/features/expenses/receiptScan.js.map +1 -1
  9. package/lib/features/expenses/starterCategories.js +7 -0
  10. package/lib/features/expenses/starterCategories.js.map +1 -0
  11. package/lib/features/health/HealthSyncRunner.js +13 -13
  12. package/lib/features/health/HealthSyncRunner.js.map +1 -1
  13. package/lib/features/health/buildDays.js +188 -113
  14. package/lib/features/health/buildDays.js.map +1 -1
  15. package/lib/features/health/fitnessClient.js +5 -5
  16. package/lib/features/health/fitnessClient.js.map +1 -1
  17. package/lib/features/health/healthConnectMapping.js +57 -29
  18. package/lib/features/health/healthConnectMapping.js.map +1 -1
  19. package/lib/features/health/healthConnectReader.js +23 -5
  20. package/lib/features/health/healthConnectReader.js.map +1 -1
  21. package/lib/features/health/healthSyncStore.js +5 -1
  22. package/lib/features/health/healthSyncStore.js.map +1 -1
  23. package/lib/features/health/healthkitMapping.js +115 -25
  24. package/lib/features/health/healthkitMapping.js.map +1 -1
  25. package/lib/features/health/healthkitReader.js +49 -39
  26. package/lib/features/health/healthkitReader.js.map +1 -1
  27. package/lib/features/health/healthkitWriter.js +3 -6
  28. package/lib/features/health/healthkitWriter.js.map +1 -1
  29. package/lib/features/health/hostHealth.js +3 -1
  30. package/lib/features/health/hostHealth.js.map +1 -1
  31. package/lib/features/health/intraday.js +115 -0
  32. package/lib/features/health/intraday.js.map +1 -0
  33. package/lib/features/health/model.js +3 -0
  34. package/lib/features/health/model.js.map +1 -1
  35. package/lib/features/health/reader.js +15 -0
  36. package/lib/features/health/reader.js.map +1 -1
  37. package/lib/features/health/sleep.js +59 -3
  38. package/lib/features/health/sleep.js.map +1 -1
  39. package/lib/features/health/syncEngine.js +35 -31
  40. package/lib/features/health/syncEngine.js.map +1 -1
  41. package/lib/features/health/syncState.js.map +1 -1
  42. package/lib/features/health/time.js +52 -52
  43. package/lib/features/health/time.js.map +1 -1
  44. package/lib/features/health/types.js +21 -4
  45. package/lib/features/health/types.js.map +1 -1
  46. package/lib/features/health/writeMapping.js +12 -12
  47. package/lib/features/health/writeMapping.js.map +1 -1
  48. package/lib/features/health/zones.js +1 -2
  49. package/lib/features/health/zones.js.map +1 -1
  50. package/lib/features/messaging/ActionSheet.js +104 -0
  51. package/lib/features/messaging/ActionSheet.js.map +1 -0
  52. package/lib/features/messaging/ChatAttachments.js +2 -6
  53. package/lib/features/messaging/ChatAttachments.js.map +1 -1
  54. package/lib/features/messaging/ChatComponents.js +512 -244
  55. package/lib/features/messaging/ChatComponents.js.map +1 -1
  56. package/lib/features/messaging/ChatInfoScreen.js +314 -0
  57. package/lib/features/messaging/ChatInfoScreen.js.map +1 -0
  58. package/lib/features/messaging/ContactsScreen.js +28 -11
  59. package/lib/features/messaging/ContactsScreen.js.map +1 -1
  60. package/lib/features/messaging/ConversationListScreen.js +274 -14
  61. package/lib/features/messaging/ConversationListScreen.js.map +1 -1
  62. package/lib/features/messaging/ForwardScreen.js +203 -0
  63. package/lib/features/messaging/ForwardScreen.js.map +1 -0
  64. package/lib/features/messaging/InviteSheet.js +43 -39
  65. package/lib/features/messaging/InviteSheet.js.map +1 -1
  66. package/lib/features/messaging/LinkPreviewCard.js +52 -24
  67. package/lib/features/messaging/LinkPreviewCard.js.map +1 -1
  68. package/lib/features/messaging/MessageActions.js +11 -15
  69. package/lib/features/messaging/MessageActions.js.map +1 -1
  70. package/lib/features/messaging/MessageInfoScreen.js +218 -0
  71. package/lib/features/messaging/MessageInfoScreen.js.map +1 -0
  72. package/lib/features/messaging/NativeChatExperience.js +248 -28
  73. package/lib/features/messaging/NativeChatExperience.js.map +1 -1
  74. package/lib/features/messaging/NotificationSettingsScreen.js +288 -0
  75. package/lib/features/messaging/NotificationSettingsScreen.js.map +1 -0
  76. package/lib/features/messaging/StarredMessagesScreen.js +161 -0
  77. package/lib/features/messaging/StarredMessagesScreen.js.map +1 -0
  78. package/lib/features/messaging/TapRow.js +46 -0
  79. package/lib/features/messaging/TapRow.js.map +1 -0
  80. package/lib/features/messaging/ThreadScreen.js +704 -81
  81. package/lib/features/messaging/ThreadScreen.js.map +1 -1
  82. package/lib/features/messaging/chatModel.js +217 -11
  83. package/lib/features/messaging/chatModel.js.map +1 -1
  84. package/lib/features/messaging/chatNotificationPrefs.js +47 -0
  85. package/lib/features/messaging/chatNotificationPrefs.js.map +1 -0
  86. package/lib/features/messaging/chatOperations.js +102 -2
  87. package/lib/features/messaging/chatOperations.js.map +1 -1
  88. package/lib/features/messaging/chatPushToken.js +25 -0
  89. package/lib/features/messaging/chatPushToken.js.map +1 -0
  90. package/lib/features/messaging/nativeChatChannelQuery.js.map +1 -1
  91. package/lib/features/messaging/useChatData.js +364 -15
  92. package/lib/features/messaging/useChatData.js.map +1 -1
  93. package/lib/features/messaging/usePressed.js +8 -0
  94. package/lib/features/messaging/usePressed.js.map +1 -0
  95. package/lib/index.js +1 -1
  96. package/lib/index.js.map +1 -1
  97. package/lib/screens/ChatNative/index.js +2 -1
  98. package/lib/screens/ChatNative/index.js.map +1 -1
  99. package/lib/screens/Health/index.js +20 -5
  100. package/lib/screens/Health/index.js.map +1 -1
  101. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import*as React from'react';import {CHANNELS_QUERY,MESSAGE_ADDED_SUBSCRIPTION_WS,CREATE_DIRECT_CHANNEL_MUTATION,MESSAGES_QUERY,SEND_MESSAGE_MUTATION,CREATE_MESSAGE_UPLOAD_LINKS_MUTATION,ATTACH_UPLOADED_FILES_MUTATION,REACTION_CHANGED_SUBSCRIPTION_WS,SET_MESSAGE_REACTION_MUTATION,VIEW_CHANNEL_MUTATION}from'./chatOperations.js';import {mergeConversations,toConversation,patchConversationAfterPost,sortConversations,mergeMessages,toChatMessage,reconcileOptimistic,ATTACHMENT_LABELS,applyReactionSummary,withViewerReaction}from'./chatModel.js';import {NATIVE_CHAT_CHANNELS_QUERY_VARS,isNativeMessengerChannel,NATIVE_CHAT_LIST_PAGE_SIZE,isMongoAccountId}from'./nativeChatChannelQuery.js';var __defProp = Object.defineProperty;
1
+ import*as React from'react';import {CHANNELS_QUERY,SET_CHANNEL_LIST_STATE_MUTATION,MARK_CHANNEL_DELIVERED_MUTATION,MESSAGE_ADDED_SUBSCRIPTION_WS,CREATE_DIRECT_CHANNEL_MUTATION,MESSAGES_QUERY,SEND_MESSAGE_MUTATION,CREATE_MESSAGE_UPLOAD_LINKS_MUTATION,ATTACH_UPLOADED_FILES_MUTATION,REACTION_CHANGED_SUBSCRIPTION_WS,SET_MESSAGE_REACTION_MUTATION,MESSAGE_UPDATED_SUBSCRIPTION_WS,EDIT_MESSAGE_MUTATION,DELETE_MESSAGE_FOR_EVERYONE_MUTATION,SET_MESSAGE_STARRED_MUTATION,TYPING_SUBSCRIPTION_WS,SEND_TYPING_MUTATION,VIEW_CHANNEL_MUTATION,CHANNEL_READ_STATE_QUERY}from'./chatOperations.js';import {mergeConversations,toConversation,sortConversations,patchConversationAfterUpdate,patchConversationAfterPost,mergeMessages,toChatMessage,reconcileOptimistic,ATTACHMENT_LABELS,applyReactionSummary,withViewerReaction,readWatermarkOf,deliveredWatermarkOf}from'./chatModel.js';import {NATIVE_CHAT_CHANNELS_QUERY_VARS,isNativeMessengerChannel,NATIVE_CHAT_LIST_PAGE_SIZE,isMongoAccountId}from'./nativeChatChannelQuery.js';var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -24,6 +24,8 @@ function newPostId() {
24
24
  return seconds + rest;
25
25
  }
26
26
  const PAGE_SIZE = 20;
27
+ const MAX_PAGES_TO_FIND = 10;
28
+ const DELIVERED_THROTTLE_MS = 1e4;
27
29
  function firstErrorMessage(errors) {
28
30
  if (!(errors == null ? void 0 : errors.length)) return null;
29
31
  const raw = errors[0].message || "Something went wrong.";
@@ -132,6 +134,58 @@ function useConversations(services, viewer, opts) {
132
134
  unreadCount: 0
133
135
  }) : c));
134
136
  }, []);
137
+ const setMutedUntil = React.useCallback((channelId, mutedUntil) => {
138
+ setConversations((prev) => prev.map((c) => c.id === channelId ? __spreadProps(__spreadValues({}, c), {
139
+ mutedUntil
140
+ }) : c));
141
+ }, []);
142
+ const setDraft = React.useCallback((channelId, draft) => {
143
+ setConversations((prev) => prev.map((c) => c.id === channelId && c.draft !== draft ? __spreadProps(__spreadValues({}, c), {
144
+ draft
145
+ }) : c));
146
+ }, []);
147
+ const setListState = React.useCallback((channelId, state) => {
148
+ const before = conversationsRef.current.find((c) => c.id === channelId);
149
+ if (!before) return;
150
+ const now = Date.now();
151
+ const patch = {};
152
+ if (typeof state.archived === "boolean") {
153
+ patch.archivedAt = state.archived ? now : 0;
154
+ if (state.archived) patch.pinnedAt = 0;
155
+ }
156
+ if (typeof state.pinned === "boolean" && !state.archived) patch.pinnedAt = state.pinned ? now : 0;
157
+ setConversations((prev) => sortConversations(prev.map((c) => c.id === channelId ? __spreadValues(__spreadValues({}, c), patch) : c)));
158
+ void (async () => {
159
+ var _a2, _b, _c;
160
+ const res = await gql.mutate(SET_CHANNEL_LIST_STATE_MUTATION, __spreadValues({
161
+ channelId
162
+ }, state));
163
+ if (!mounted.current) return;
164
+ if (((_a2 = res.errors) == null ? void 0 : _a2.length) || !((_b = res.data) == null ? void 0 : _b.setChannelListState)) {
165
+ setConversations((prev) => sortConversations(prev.map((c) => c.id === channelId ? before : c)));
166
+ setError((_c = firstErrorMessage(res.errors)) != null ? _c : "Could not update the chat list.");
167
+ }
168
+ })();
169
+ }, [gql]);
170
+ const applyConversationUpdate = React.useCallback((channelId, post) => {
171
+ if (!viewerId) return;
172
+ setConversations((prev) => prev.map((c) => c.id === channelId ? patchConversationAfterUpdate(c, post, viewerId) : c));
173
+ }, [viewerId]);
174
+ const deliveredAt = React.useRef(/* @__PURE__ */ new Map());
175
+ const markDelivered = React.useCallback((channelId) => {
176
+ var _a2;
177
+ const last = (_a2 = deliveredAt.current.get(channelId)) != null ? _a2 : 0;
178
+ if (Date.now() - last < DELIVERED_THROTTLE_MS) return;
179
+ deliveredAt.current.set(channelId, Date.now());
180
+ void gql.mutate(MARK_CHANNEL_DELIVERED_MUTATION, {
181
+ channelId
182
+ });
183
+ }, [gql]);
184
+ const unreadKey = conversations.filter((c) => c.unreadCount > 0).map((c) => c.id).join("|");
185
+ React.useEffect(() => {
186
+ if (!unreadKey) return;
187
+ unreadKey.split("|").forEach((id) => markDelivered(id));
188
+ }, [unreadKey, markDelivered]);
135
189
  const applyConversationMessage = React.useCallback((channelId, post) => {
136
190
  if (!viewerId) return;
137
191
  setConversations((prev) => {
@@ -150,17 +204,19 @@ function useConversations(services, viewer, opts) {
150
204
  channelId
151
205
  }, {
152
206
  next: (data) => {
153
- var _a2;
207
+ var _a2, _b, _c, _d;
154
208
  const post = data == null ? void 0 : data.chatMessageAdded;
155
209
  if (!post || !mounted.current) return;
156
210
  applyConversationMessage(channelId, post);
157
211
  (_a2 = gql.patchChannelListAfterMessage) == null ? void 0 : _a2.call(gql, channelId, post);
212
+ const author = (_d = (_b = post.author) == null ? void 0 : _b.id) != null ? _d : (_c = post.creator) == null ? void 0 : _c.id;
213
+ if (author && String(author) !== viewerId) markDelivered(channelId);
158
214
  }
159
215
  }));
160
216
  return () => {
161
217
  unsubs.forEach((off) => off());
162
218
  };
163
- }, [gql, viewerId, listSyncKey, opts == null ? void 0 : opts.syncListRealtime, applyConversationMessage]);
219
+ }, [gql, viewerId, listSyncKey, opts == null ? void 0 : opts.syncListRealtime, applyConversationMessage, markDelivered]);
164
220
  React.useEffect(() => {
165
221
  mounted.current = true;
166
222
  return () => {
@@ -207,6 +263,11 @@ function useConversations(services, viewer, opts) {
207
263
  loadingMore,
208
264
  loadMore: () => void loadMore(),
209
265
  markRead,
266
+ setMutedUntil,
267
+ setDraft,
268
+ setListState,
269
+ applyConversationUpdate,
270
+ markDelivered,
210
271
  applyConversationMessage,
211
272
  openDirect
212
273
  };
@@ -298,7 +359,7 @@ function useThread(gql, channelId, viewer, opts) {
298
359
  error: (err) => mounted.current && setError(err.message)
299
360
  });
300
361
  }, [gql, channelId, viewerId, notifyList]);
301
- const send = React.useCallback(async (body) => {
362
+ const send = React.useCallback(async (body, replyTo) => {
302
363
  var _a2, _b, _c;
303
364
  const text = body.trim();
304
365
  if (!text || !channelId || !viewerId) return;
@@ -315,10 +376,12 @@ function useThread(gql, channelId, viewer, opts) {
315
376
  isEdited: false,
316
377
  attachments: [],
317
378
  reactions: [],
379
+ replyTo: replyTo != null ? replyTo : null,
318
380
  sendState: "sending"
319
381
  };
320
382
  pending.current.set(clientId, {
321
- body: text
383
+ body: text,
384
+ replyTo
322
385
  });
323
386
  setMessages((prev) => mergeMessages(prev, [optimistic]));
324
387
  onConversationMessage == null ? void 0 : onConversationMessage({
@@ -331,9 +394,14 @@ function useThread(gql, channelId, viewer, opts) {
331
394
  });
332
395
  const res = await gql.mutate(SEND_MESSAGE_MUTATION, {
333
396
  channelId,
334
- messageInput: {
397
+ // extraProps land in post.props, which every client reads the quote back from.
398
+ messageInput: __spreadValues({
335
399
  content: text
336
- }
400
+ }, replyTo ? {
401
+ extraProps: {
402
+ replyTo
403
+ }
404
+ } : {})
337
405
  });
338
406
  if (!mounted.current) return;
339
407
  const message = firstErrorMessage(res.errors);
@@ -349,7 +417,7 @@ function useThread(gql, channelId, viewer, opts) {
349
417
  setMessages((prev) => reconcileOptimistic(prev, toChatMessage(saved, viewerId)));
350
418
  notifyList(saved);
351
419
  }, [gql, channelId, viewerId, viewer, notifyList, onConversationMessage]);
352
- const sendAttachments = React.useCallback(async (files, caption, kind) => {
420
+ const sendAttachments = React.useCallback(async (files, caption, kind, replyTo) => {
353
421
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
354
422
  if (!media || !files.length || !channelId || !viewerId) return;
355
423
  const text = caption.trim();
@@ -382,13 +450,15 @@ function useThread(gql, channelId, viewer, opts) {
382
450
  isEdited: false,
383
451
  attachments: local,
384
452
  reactions: [],
453
+ replyTo: replyTo != null ? replyTo : null,
385
454
  sendState: "sending"
386
455
  }]);
387
456
  });
388
457
  pending.current.set(postId, {
389
458
  body: text,
390
459
  files,
391
- kind
460
+ kind,
461
+ replyTo
392
462
  });
393
463
  const fail = (message) => {
394
464
  if (!mounted.current) return;
@@ -436,10 +506,12 @@ function useThread(gql, channelId, viewer, opts) {
436
506
  // own carries its label; the bubble hides it again.
437
507
  content: text || ATTACHMENT_LABELS[kind],
438
508
  files: fileIds,
439
- extraProps: __spreadValues({
509
+ extraProps: __spreadValues(__spreadValues({
440
510
  attachmentKind: kind
441
511
  }, durationMs ? {
442
512
  voiceDurationMs: durationMs
513
+ } : {}), replyTo ? {
514
+ replyTo
443
515
  } : {})
444
516
  }
445
517
  });
@@ -462,8 +534,8 @@ function useThread(gql, channelId, viewer, opts) {
462
534
  if (!entry) return;
463
535
  pending.current.delete(messageId);
464
536
  setMessages((prev) => prev.filter((m) => m.id !== messageId));
465
- if (((_a2 = entry.files) == null ? void 0 : _a2.length) && entry.kind) void sendAttachments(entry.files, entry.body, entry.kind);
466
- else void send(entry.body);
537
+ if (((_a2 = entry.files) == null ? void 0 : _a2.length) && entry.kind) void sendAttachments(entry.files, entry.body, entry.kind, entry.replyTo);
538
+ else void send(entry.body, entry.replyTo);
467
539
  }, [send, sendAttachments]);
468
540
  const loadMore = React.useCallback(() => {
469
541
  if (loadingMore || !hasMore || loading) return;
@@ -516,8 +588,134 @@ function useThread(gql, channelId, viewer, opts) {
516
588
  });
517
589
  })();
518
590
  }, [gql, channelId, viewerId]);
591
+ const onConversationUpdate = opts == null ? void 0 : opts.onConversationUpdate;
592
+ React.useEffect(() => {
593
+ if (!channelId || !viewerId) return void 0;
594
+ return gql.subscribe(MESSAGE_UPDATED_SUBSCRIPTION_WS, {
595
+ channelId
596
+ }, {
597
+ next: (data) => {
598
+ const post = data == null ? void 0 : data.chatMessageUpdated;
599
+ if (!(post == null ? void 0 : post.id) || !mounted.current) return;
600
+ const updated = toChatMessage(post, viewerId);
601
+ setMessages((prev) => prev.map((m) => m.id === updated.id ? __spreadProps(__spreadValues({}, updated), {
602
+ sendState: m.sendState
603
+ }) : m));
604
+ onConversationUpdate == null ? void 0 : onConversationUpdate(post);
605
+ }
606
+ });
607
+ }, [gql, channelId, viewerId, onConversationUpdate]);
608
+ const messageIdOf = React.useCallback((messageId) => ({
609
+ channelId: String(channelId),
610
+ messageId
611
+ }), [channelId]);
612
+ const edit = React.useCallback((messageId, body) => {
613
+ const text = body.trim();
614
+ if (!channelId || !viewerId || !text) return;
615
+ const before = messagesRef.current.find((m) => m.id === messageId);
616
+ if (!before || before.body === text) return;
617
+ setMessages((prev) => prev.map((m) => m.id === messageId ? __spreadProps(__spreadValues({}, m), {
618
+ body: text,
619
+ isEdited: true
620
+ }) : m));
621
+ void (async () => {
622
+ var _a2, _b, _c;
623
+ const res = await gql.mutate(EDIT_MESSAGE_MUTATION, {
624
+ messageId: messageIdOf(messageId),
625
+ messageInput: {
626
+ content: text
627
+ }
628
+ });
629
+ if (!mounted.current) return;
630
+ const saved = (_a2 = res.data) == null ? void 0 : _a2.editMessage;
631
+ if (((_b = res.errors) == null ? void 0 : _b.length) || !saved) {
632
+ setMessages((prev) => prev.map((m) => m.id === messageId ? before : m));
633
+ setError((_c = firstErrorMessage(res.errors)) != null ? _c : "Could not edit the message.");
634
+ return;
635
+ }
636
+ setMessages((prev) => prev.map((m) => m.id === messageId ? toChatMessage(saved, viewerId) : m));
637
+ onConversationUpdate == null ? void 0 : onConversationUpdate(saved);
638
+ })();
639
+ }, [gql, channelId, viewerId, messageIdOf, onConversationUpdate]);
640
+ const deleteForEveryone = React.useCallback((messageId) => {
641
+ if (!channelId || !viewerId) return;
642
+ const before = messagesRef.current.find((m) => m.id === messageId);
643
+ if (!before) return;
644
+ setMessages((prev) => prev.map((m) => m.id === messageId ? __spreadProps(__spreadValues({}, m), {
645
+ isDeleted: true,
646
+ body: "",
647
+ attachments: [],
648
+ replyTo: null
649
+ }) : m));
650
+ void (async () => {
651
+ var _a2, _b, _c;
652
+ const res = await gql.mutate(DELETE_MESSAGE_FOR_EVERYONE_MUTATION, {
653
+ messageId: messageIdOf(messageId)
654
+ });
655
+ if (!mounted.current) return;
656
+ const saved = (_a2 = res.data) == null ? void 0 : _a2.deleteMessageForEveryone;
657
+ if (((_b = res.errors) == null ? void 0 : _b.length) || !saved) {
658
+ setMessages((prev) => prev.map((m) => m.id === messageId ? before : m));
659
+ setError((_c = firstErrorMessage(res.errors)) != null ? _c : "Could not delete the message.");
660
+ return;
661
+ }
662
+ onConversationUpdate == null ? void 0 : onConversationUpdate(saved);
663
+ })();
664
+ }, [gql, channelId, viewerId, messageIdOf, onConversationUpdate]);
665
+ const storage = opts == null ? void 0 : opts.storage;
666
+ const hiddenKey = channelId ? `chat-hidden:${channelId}` : null;
667
+ const [hidden, setHidden] = React.useState(() => /* @__PURE__ */ new Set());
668
+ React.useEffect(() => {
669
+ setHidden(/* @__PURE__ */ new Set());
670
+ if (!storage || !hiddenKey) return;
671
+ storage.get(hiddenKey).then((raw) => {
672
+ const ids = raw ? JSON.parse(raw) : [];
673
+ if (mounted.current && Array.isArray(ids)) setHidden(new Set(ids.filter((i) => typeof i === "string")));
674
+ }).catch(() => void 0);
675
+ }, [storage, hiddenKey]);
676
+ const deleteForMe = React.useCallback((messageId) => {
677
+ setHidden((prev) => {
678
+ const next = new Set(prev);
679
+ next.add(messageId);
680
+ if (storage && hiddenKey) {
681
+ storage.set(hiddenKey, JSON.stringify(Array.from(next).slice(-500))).catch(() => void 0);
682
+ }
683
+ return next;
684
+ });
685
+ }, [storage, hiddenKey]);
686
+ const star = React.useCallback((messageId, starred) => {
687
+ if (!channelId || !viewerId) return;
688
+ setMessages((prev) => prev.map((m) => m.id === messageId ? __spreadProps(__spreadValues({}, m), {
689
+ starred
690
+ }) : m));
691
+ void (async () => {
692
+ var _a2, _b, _c;
693
+ const res = await gql.mutate(SET_MESSAGE_STARRED_MUTATION, {
694
+ messageId: messageIdOf(messageId),
695
+ starred
696
+ });
697
+ if (!mounted.current) return;
698
+ if (((_a2 = res.errors) == null ? void 0 : _a2.length) || !((_b = res.data) == null ? void 0 : _b.setMessageStarred)) {
699
+ setMessages((prev) => prev.map((m) => m.id === messageId ? __spreadProps(__spreadValues({}, m), {
700
+ starred: !starred
701
+ }) : m));
702
+ setError((_c = firstErrorMessage(res.errors)) != null ? _c : "Could not update the star.");
703
+ }
704
+ })();
705
+ }, [gql, channelId, viewerId, messageIdOf]);
706
+ const loadUntil = React.useCallback(async (messageId) => {
707
+ for (let page = 0; page < MAX_PAGES_TO_FIND; page += 1) {
708
+ if (messagesRef.current.some((m) => m.id === messageId)) return true;
709
+ const served = messagesRef.current.filter((m) => !m.sendState || m.sendState === "sent").length;
710
+ const before = messagesRef.current.length;
711
+ await fetchPage(served);
712
+ if (messagesRef.current.length === before) break;
713
+ }
714
+ return messagesRef.current.some((m) => m.id === messageId);
715
+ }, [fetchPage]);
716
+ const visibleMessages = React.useMemo(() => hidden.size ? messages.filter((m) => !hidden.has(m.id)) : messages, [messages, hidden]);
519
717
  return {
520
- messages,
718
+ messages: visibleMessages,
521
719
  loading,
522
720
  loadingMore,
523
721
  hasMore,
@@ -526,9 +724,52 @@ function useThread(gql, channelId, viewer, opts) {
526
724
  sendAttachments: media ? sendAttachments : void 0,
527
725
  loadMore,
528
726
  retry,
529
- react
727
+ react,
728
+ edit,
729
+ deleteForEveryone,
730
+ deleteForMe,
731
+ star,
732
+ loadUntil
530
733
  };
531
734
  }
735
+ const READ_STATE_POLL_MS = 8e3;
736
+ function useReadWatermark(gql, channelId, viewerId, waiting) {
737
+ const [watermark, setWatermark] = React.useState({
738
+ read: 0,
739
+ delivered: 0
740
+ });
741
+ React.useEffect(() => setWatermark({
742
+ read: 0,
743
+ delivered: 0
744
+ }), [channelId]);
745
+ React.useEffect(() => {
746
+ if (!channelId || !viewerId || !waiting) return void 0;
747
+ let alive = true;
748
+ const read = async () => {
749
+ var _a;
750
+ const res = await gql.query(CHANNEL_READ_STATE_QUERY, {
751
+ id: channelId
752
+ }, {
753
+ fetchPolicy: "no-cache"
754
+ });
755
+ const channel = (_a = res.data) == null ? void 0 : _a.viewChannelDetail;
756
+ if (!alive || !channel) return;
757
+ const read2 = readWatermarkOf(channel, viewerId);
758
+ const delivered = deliveredWatermarkOf(channel, viewerId);
759
+ setWatermark((prev) => read2 <= prev.read && delivered <= prev.delivered ? prev : {
760
+ read: Math.max(prev.read, read2),
761
+ delivered: Math.max(prev.delivered, delivered)
762
+ });
763
+ };
764
+ void read();
765
+ const timer = setInterval(read, READ_STATE_POLL_MS);
766
+ return () => {
767
+ alive = false;
768
+ clearInterval(timer);
769
+ };
770
+ }, [gql, channelId, viewerId, waiting, gql.reconnectEpoch]);
771
+ return watermark;
772
+ }
532
773
  function useMarkRead(gql, channelId, onMarked) {
533
774
  React.useEffect(() => {
534
775
  if (!channelId) return;
@@ -537,4 +778,112 @@ function useMarkRead(gql, channelId, onMarked) {
537
778
  id: channelId
538
779
  });
539
780
  }, [channelId]);
540
- }export{useConversations,useMarkRead,useThread};//# sourceMappingURL=useChatData.js.map
781
+ }
782
+ const TYPING_REFRESH_MS = 4e3;
783
+ const TYPING_IDLE_MS = 5e3;
784
+ const TYPING_EXPIRE_MS = 7e3;
785
+ function useTyping(gql, channelId, viewerId) {
786
+ const [typing, setTyping] = React.useState({});
787
+ const lastStart = React.useRef(0);
788
+ const idleTimer = React.useRef(null);
789
+ const active = React.useRef(false);
790
+ React.useEffect(() => {
791
+ setTyping({});
792
+ if (!channelId || !viewerId) return void 0;
793
+ const off = gql.subscribe(TYPING_SUBSCRIPTION_WS, {
794
+ channelId
795
+ }, {
796
+ next: (data) => {
797
+ const event = data == null ? void 0 : data.typingIndicator;
798
+ const who = (event == null ? void 0 : event.userId) ? String(event.userId) : "";
799
+ if (!who || who === viewerId) return;
800
+ setTyping((prev) => {
801
+ const next = __spreadValues({}, prev);
802
+ if ((event == null ? void 0 : event.action) === "start") next[who] = Date.now();
803
+ else delete next[who];
804
+ return next;
805
+ });
806
+ }
807
+ });
808
+ const sweep = setInterval(() => {
809
+ setTyping((prev) => {
810
+ const now = Date.now();
811
+ const kept = Object.entries(prev).filter(([, at]) => now - at < TYPING_EXPIRE_MS);
812
+ return kept.length === Object.keys(prev).length ? prev : Object.fromEntries(kept);
813
+ });
814
+ }, 1e3);
815
+ return () => {
816
+ off();
817
+ clearInterval(sweep);
818
+ };
819
+ }, [gql, channelId, viewerId]);
820
+ const send = React.useCallback((action) => {
821
+ if (!channelId) return;
822
+ void gql.mutate(SEND_TYPING_MUTATION, {
823
+ channelId,
824
+ action
825
+ });
826
+ }, [gql, channelId]);
827
+ const stop = React.useCallback(() => {
828
+ if (idleTimer.current) clearTimeout(idleTimer.current);
829
+ idleTimer.current = null;
830
+ if (!active.current) return;
831
+ active.current = false;
832
+ lastStart.current = 0;
833
+ send("stop");
834
+ }, [send]);
835
+ const onDraftChange = React.useCallback((text) => {
836
+ if (!text.trim()) {
837
+ stop();
838
+ return;
839
+ }
840
+ const now = Date.now();
841
+ if (!active.current || now - lastStart.current > TYPING_REFRESH_MS) {
842
+ active.current = true;
843
+ lastStart.current = now;
844
+ send("start");
845
+ }
846
+ if (idleTimer.current) clearTimeout(idleTimer.current);
847
+ idleTimer.current = setTimeout(stop, TYPING_IDLE_MS);
848
+ }, [send, stop]);
849
+ React.useEffect(() => stop, [channelId, stop]);
850
+ const typingUserIds = React.useMemo(() => Object.entries(typing).sort((a, b) => a[1] - b[1]).map(([id]) => id), [typing]);
851
+ return {
852
+ typingUserIds,
853
+ onDraftChange,
854
+ onSent: stop
855
+ };
856
+ }
857
+ async function forwardMessage(gql, body, channelIds) {
858
+ const text = body.trim();
859
+ const sent = [];
860
+ const posts = [];
861
+ if (!text) return {
862
+ sent,
863
+ posts
864
+ };
865
+ await Promise.all(channelIds.map(async (channelId) => {
866
+ var _a, _b;
867
+ const res = await gql.mutate(SEND_MESSAGE_MUTATION, {
868
+ channelId,
869
+ messageInput: {
870
+ content: text,
871
+ extraProps: {
872
+ forwarded: true
873
+ }
874
+ }
875
+ });
876
+ const post = (_a = res.data) == null ? void 0 : _a.sendMessage;
877
+ if (post && !((_b = res.errors) == null ? void 0 : _b.length)) {
878
+ sent.push(channelId);
879
+ posts.push({
880
+ channelId,
881
+ post
882
+ });
883
+ }
884
+ }));
885
+ return {
886
+ sent,
887
+ posts
888
+ };
889
+ }export{forwardMessage,useConversations,useMarkRead,useReadWatermark,useThread,useTyping};//# sourceMappingURL=useChatData.js.map