@planningcenter/chat-react-native 4.3.0-rc.1 → 4.3.0-rc.10

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 (140) hide show
  1. package/build/components/conversation/message_form.d.ts +2 -1
  2. package/build/components/conversation/message_form.d.ts.map +1 -1
  3. package/build/components/conversation/message_form.js +167 -370
  4. package/build/components/conversation/message_form.js.map +1 -1
  5. package/build/components/conversation/message_list.d.ts +5 -2
  6. package/build/components/conversation/message_list.d.ts.map +1 -1
  7. package/build/components/conversation/message_list.js +187 -67
  8. package/build/components/conversation/message_list.js.map +1 -1
  9. package/build/components/conversation/missing_message.d.ts +2 -0
  10. package/build/components/conversation/missing_message.d.ts.map +1 -0
  11. package/build/components/conversation/missing_message.js +139 -0
  12. package/build/components/conversation/missing_message.js.map +1 -0
  13. package/build/components/display/conversation_avatar.d.ts +1 -2
  14. package/build/components/display/conversation_avatar.d.ts.map +1 -1
  15. package/build/components/display/conversation_avatar.js.map +1 -1
  16. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +4 -3
  17. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
  18. package/build/hooks/use_conversation_messages.d.ts +14 -5
  19. package/build/hooks/use_conversation_messages.d.ts.map +1 -1
  20. package/build/hooks/use_conversation_messages.js +218 -42
  21. package/build/hooks/use_conversation_messages.js.map +1 -1
  22. package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
  23. package/build/hooks/use_conversation_messages_jolt_events.js +58 -42
  24. package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
  25. package/build/hooks/use_features.d.ts +2 -1
  26. package/build/hooks/use_features.d.ts.map +1 -1
  27. package/build/hooks/use_features.js +2 -1
  28. package/build/hooks/use_features.js.map +1 -1
  29. package/build/hooks/use_mark_latest_message_read.d.ts +2 -1
  30. package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
  31. package/build/hooks/use_mark_latest_message_read.js +4 -3
  32. package/build/hooks/use_mark_latest_message_read.js.map +1 -1
  33. package/build/hooks/use_read_receipts.d.ts +4 -3
  34. package/build/hooks/use_read_receipts.d.ts.map +1 -1
  35. package/build/hooks/use_search_results.d.ts +19 -0
  36. package/build/hooks/use_search_results.d.ts.map +1 -0
  37. package/build/hooks/use_search_results.js +145 -0
  38. package/build/hooks/use_search_results.js.map +1 -0
  39. package/build/hooks/use_suspense_api.d.ts +10 -6
  40. package/build/hooks/use_suspense_api.d.ts.map +1 -1
  41. package/build/hooks/use_suspense_api.js +83 -63
  42. package/build/hooks/use_suspense_api.js.map +1 -1
  43. package/build/navigation/index.d.ts +5 -0
  44. package/build/navigation/index.d.ts.map +1 -1
  45. package/build/navigation/index.js +5 -0
  46. package/build/navigation/index.js.map +1 -1
  47. package/build/screens/conversation_screen.d.ts +1 -0
  48. package/build/screens/conversation_screen.d.ts.map +1 -1
  49. package/build/screens/conversation_screen.js +305 -203
  50. package/build/screens/conversation_screen.js.map +1 -1
  51. package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
  52. package/build/screens/conversations/components/search_list_header_component.js +159 -133
  53. package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
  54. package/build/screens/message_actions_screen.d.ts.map +1 -1
  55. package/build/screens/message_actions_screen.js +103 -92
  56. package/build/screens/message_actions_screen.js.map +1 -1
  57. package/build/screens/notification_settings/hooks/groups.d.ts +4 -3
  58. package/build/screens/notification_settings/hooks/groups.d.ts.map +1 -1
  59. package/build/screens/search/components/search_blank_states.d.ts +7 -0
  60. package/build/screens/search/components/search_blank_states.d.ts.map +1 -0
  61. package/build/screens/search/components/search_blank_states.js +72 -0
  62. package/build/screens/search/components/search_blank_states.js.map +1 -0
  63. package/build/screens/search/components/search_field.d.ts +7 -0
  64. package/build/screens/search/components/search_field.d.ts.map +1 -0
  65. package/build/screens/search/components/search_field.js +152 -0
  66. package/build/screens/search/components/search_field.js.map +1 -0
  67. package/build/screens/search/search_screen.d.ts +5 -0
  68. package/build/screens/search/search_screen.d.ts.map +1 -0
  69. package/build/screens/search/search_screen.js +59 -0
  70. package/build/screens/search/search_screen.js.map +1 -0
  71. package/build/types/api_primitives.d.ts +1 -0
  72. package/build/types/api_primitives.d.ts.map +1 -1
  73. package/build/types/api_primitives.js.map +1 -1
  74. package/build/types/resources/conversation.d.ts +1 -0
  75. package/build/types/resources/conversation.d.ts.map +1 -1
  76. package/build/types/resources/conversation.js.map +1 -1
  77. package/build/types/resources/index.d.ts +1 -0
  78. package/build/types/resources/index.d.ts.map +1 -1
  79. package/build/types/resources/index.js +1 -0
  80. package/build/types/resources/index.js.map +1 -1
  81. package/build/types/resources/search_result.d.ts +29 -0
  82. package/build/types/resources/search_result.d.ts.map +1 -0
  83. package/build/types/resources/search_result.js +2 -0
  84. package/build/types/resources/search_result.js.map +1 -0
  85. package/build/utils/cache/messages_cache.d.ts +1 -0
  86. package/build/utils/cache/messages_cache.d.ts.map +1 -1
  87. package/build/utils/cache/messages_cache.js +37 -1
  88. package/build/utils/cache/messages_cache.js.map +1 -1
  89. package/build/utils/cache/messages_window.d.ts +11 -0
  90. package/build/utils/cache/messages_window.d.ts.map +1 -0
  91. package/build/utils/cache/messages_window.js +51 -0
  92. package/build/utils/cache/messages_window.js.map +1 -0
  93. package/build/utils/client/types.d.ts +1 -0
  94. package/build/utils/client/types.d.ts.map +1 -1
  95. package/build/utils/client/types.js.map +1 -1
  96. package/build/utils/request/get_search_results.d.ts +13 -0
  97. package/build/utils/request/get_search_results.d.ts.map +1 -0
  98. package/build/utils/request/get_search_results.js +20 -0
  99. package/build/utils/request/get_search_results.js.map +1 -0
  100. package/package.json +2 -2
  101. package/src/__tests__/hooks/use_features.test.ts +10 -2
  102. package/src/__utils__/query_client.ts +3 -0
  103. package/src/components/conversation/message_form.tsx +31 -3
  104. package/src/components/conversation/message_list.tsx +88 -4
  105. package/src/components/conversation/missing_message.tsx +66 -0
  106. package/src/components/display/conversation_avatar.tsx +1 -10
  107. package/src/hooks/__tests__/use_conversation_messages.test.tsx +333 -0
  108. package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +87 -0
  109. package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +33 -0
  110. package/src/hooks/__tests__/use_message_create_or_update.test.tsx +2 -7
  111. package/src/hooks/__tests__/use_search_results.test.tsx +76 -0
  112. package/src/hooks/use_conversation_messages.ts +103 -17
  113. package/src/hooks/use_conversation_messages_jolt_events.ts +12 -2
  114. package/src/hooks/use_features.ts +3 -2
  115. package/src/hooks/use_mark_latest_message_read.ts +4 -3
  116. package/src/hooks/use_search_results.ts +77 -0
  117. package/src/hooks/use_suspense_api.ts +14 -6
  118. package/src/navigation/index.tsx +5 -0
  119. package/src/screens/conversation_screen.tsx +62 -13
  120. package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +62 -0
  121. package/src/screens/conversations/components/search_list_header_component.tsx +11 -0
  122. package/src/screens/message_actions_screen.tsx +12 -1
  123. package/src/screens/search/components/__tests__/search_blank_states.test.tsx +20 -0
  124. package/src/screens/search/components/__tests__/search_field.test.tsx +29 -0
  125. package/src/screens/search/components/search_blank_states.tsx +34 -0
  126. package/src/screens/search/components/search_field.tsx +81 -0
  127. package/src/screens/search/search_screen.tsx +41 -0
  128. package/src/types/api_primitives.ts +1 -0
  129. package/src/types/resources/conversation.ts +9 -0
  130. package/src/types/resources/index.ts +1 -0
  131. package/src/types/resources/search_result.ts +32 -0
  132. package/src/utils/__tests__/get_search_results.test.ts +24 -0
  133. package/src/utils/cache/__tests__/messages_cache.test.ts +2 -1
  134. package/src/utils/cache/__tests__/messages_cache_deletion.test.ts +97 -0
  135. package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +3 -2
  136. package/src/utils/cache/__tests__/messages_window.test.ts +78 -0
  137. package/src/utils/cache/messages_cache.ts +45 -1
  138. package/src/utils/cache/messages_window.ts +55 -0
  139. package/src/utils/client/types.ts +1 -0
  140. package/src/utils/request/get_search_results.ts +23 -0
@@ -13,8 +13,9 @@ interface MessagesFormRootProps extends ViewProps {
13
13
  replyRootId?: string | null;
14
14
  replyRootAuthorFirstName?: string | null;
15
15
  onFlaggedInMessageForm?: (id: string) => void;
16
+ onBeforeSubmit?: () => void | Promise<void>;
16
17
  }
17
- declare function MessageFormRoot({ conversation, currentlyEditingMessage, children, replyRootId, replyRootAuthorFirstName, onFlaggedInMessageForm, }: MessagesFormRootProps): import("react/jsx-runtime").JSX.Element;
18
+ declare function MessageFormRoot({ conversation, currentlyEditingMessage, children, replyRootId, replyRootAuthorFirstName, onFlaggedInMessageForm, onBeforeSubmit, }: MessagesFormRootProps): import("react/jsx-runtime").JSX.Element;
18
19
  declare function MessageFormInput(): import("react/jsx-runtime").JSX.Element;
19
20
  declare function MessageFormSubmitBtn(): import("react/jsx-runtime").JSX.Element;
20
21
  declare function MessageFormAttachmentPicker(): import("react/jsx-runtime").JSX.Element | null;
@@ -1 +1 @@
1
- {"version":3,"file":"message_form.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAQL,SAAS,EAEV,MAAM,cAAc,CAAA;AAiBrB,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA6BnE,eAAO,MAAM,WAAW;;;;;;CAOvB,CAAA;AAED,UAAU,qBAAsB,SAAQ,SAAS;IAC/C,YAAY,EAAE,oBAAoB,CAAA;IAClC,uBAAuB,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAChD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxC,sBAAsB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9C;AAmCD,iBAAS,eAAe,CAAC,EACvB,YAAY,EACZ,uBAAuB,EACvB,QAAQ,EACR,WAAW,EACX,wBAAwB,EACxB,sBAAsB,GACvB,EAAE,qBAAqB,2CA6KvB;AAyID,iBAAS,gBAAgB,4CAyDxB;AAcD,iBAAS,oBAAoB,4CAgD5B;AAED,iBAAS,2BAA2B,mDAuHnC;AAED,iBAAS,mBAAmB,mDAkC3B"}
1
+ {"version":3,"file":"message_form.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAQL,SAAS,EAEV,MAAM,cAAc,CAAA;AAiBrB,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA8BnE,eAAO,MAAM,WAAW;;;;;;CAOvB,CAAA;AAED,UAAU,qBAAsB,SAAQ,SAAS;IAC/C,YAAY,EAAE,oBAAoB,CAAA;IAClC,uBAAuB,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAChD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxC,sBAAsB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5C;AAmCD,iBAAS,eAAe,CAAC,EACvB,YAAY,EACZ,uBAAuB,EACvB,QAAQ,EACR,WAAW,EACX,wBAAwB,EACxB,sBAAsB,EACtB,cAAc,GACf,EAAE,qBAAqB,2CAsMvB;AAyID,iBAAS,gBAAgB,4CAyDxB;AAcD,iBAAS,oBAAoB,4CAgD5B;AAED,iBAAS,2BAA2B,mDAuHnC;AAED,iBAAS,mBAAmB,mDAkC3B"}
@@ -1,6 +1,6 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native';
3
- import React, { useCallback, useContext, useEffect, useState } from 'react';
3
+ import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
4
4
  import { Linking, Platform, Pressable, ScrollView, StyleSheet, TextInput, View, Keyboard } from 'react-native';
5
5
  import LinearGradient from 'react-native-linear-gradient';
6
6
  import { Heading, Icon, IconButton, Text, TextButton } from '../../components';
@@ -11,7 +11,7 @@ import { useBroadcastTypingStatus } from '../../hooks/use_broadcast_typing_statu
11
11
  import { useChatConfiguration } from '../../hooks/use_chat_configuration';
12
12
  import { useMessageCreateOrUpdate } from '../../hooks/use_message_create_or_update';
13
13
  import { useMessageDraft } from '../../hooks/use_message_draft';
14
- import { MAX_FONT_SIZE_MULTIPLIER_LANDMARK, platformFontWeightMedium, platformPressedOpacityStyle } from '../../utils';
14
+ import { Log, MAX_FONT_SIZE_MULTIPLIER_LANDMARK, platformFontWeightMedium, platformPressedOpacityStyle } from '../../utils';
15
15
  import { pickAttachmentPreviewKind } from '../../utils/attachment_kind';
16
16
  import { canSubmitMessage } from '../../utils/can_submit_message';
17
17
  import { isInputEditable } from '../../utils/is_input_editable';
@@ -48,16 +48,15 @@ const MessageFormContext = React.createContext({
48
48
  const GIPHY_MAX_LENGTH = 50;
49
49
  const MAX_MESSAGE_LENGTH = 5000;
50
50
  const PLACEHOLDER_FONT_SCALE_THRESHOLD = 1.7;
51
- function MessageFormRoot(t0) {
52
- const $ = _c(88);
53
- const {
54
- conversation,
55
- currentlyEditingMessage,
56
- children,
57
- replyRootId,
58
- replyRootAuthorFirstName,
59
- onFlaggedInMessageForm
60
- } = t0;
51
+ function MessageFormRoot({
52
+ conversation,
53
+ currentlyEditingMessage,
54
+ children,
55
+ replyRootId,
56
+ replyRootAuthorFirstName,
57
+ onFlaggedInMessageForm,
58
+ onBeforeSubmit
59
+ }) {
61
60
  const {
62
61
  giphyApiKey
63
62
  } = useContext(ChatContext);
@@ -68,295 +67,162 @@ function MessageFormRoot(t0) {
68
67
  saveDraft,
69
68
  clearDraft
70
69
  } = useMessageDraft();
71
- let t1;
72
- if ($[0] !== currentlyEditingMessage || $[1] !== draft?.text) {
73
- t1 = () => currentlyEditingMessage ? "" : draft?.text || "";
74
- $[0] = currentlyEditingMessage;
75
- $[1] = draft?.text;
76
- $[2] = t1;
77
- } else {
78
- t1 = $[2];
79
- }
80
- const [text, setText] = React.useState(t1);
70
+ const [text, setText] = React.useState(() => {
71
+ // Initialize from draft only when not editing a message
72
+ return currentlyEditingMessage ? '' : draft?.text || '';
73
+ });
81
74
  const [usingGiphy, setUsingGiphy] = useState(false);
82
75
  const navigation = useNavigation();
83
76
  const route = useRoute();
84
- const t2 = currentlyEditingMessage || undefined;
85
- let t3;
86
- if ($[3] !== conversation.id || $[4] !== replyRootId || $[5] !== t2) {
87
- t3 = {
88
- conversationId: conversation.id,
89
- message: t2,
90
- replyRootId
91
- };
92
- $[3] = conversation.id;
93
- $[4] = replyRootId;
94
- $[5] = t2;
95
- $[6] = t3;
96
- } else {
97
- t3 = $[6];
98
- }
99
77
  const {
100
78
  status,
101
79
  isPending,
102
80
  reset: resetMutation,
103
81
  mutateAsync
104
- } = useMessageCreateOrUpdate(t3);
105
- const t4 = currentlyEditingMessage ? undefined : draft?.attachments;
106
- let t5;
107
- if ($[7] !== conversation.id || $[8] !== onFlaggedInMessageForm || $[9] !== t4) {
108
- t5 = {
109
- conversationId: conversation.id,
110
- draftAttachments: t4,
111
- onFlaggedInMessageForm
112
- };
113
- $[7] = conversation.id;
114
- $[8] = onFlaggedInMessageForm;
115
- $[9] = t4;
116
- $[10] = t5;
117
- } else {
118
- t5 = $[10];
119
- }
120
- const attachmentUploader = useAttachmentUploader(t5);
82
+ } = useMessageCreateOrUpdate({
83
+ conversationId: conversation.id,
84
+ message: currentlyEditingMessage || undefined,
85
+ replyRootId
86
+ });
87
+ const attachmentUploader = useAttachmentUploader({
88
+ conversationId: conversation.id,
89
+ draftAttachments: currentlyEditingMessage ? undefined : draft?.attachments,
90
+ onFlaggedInMessageForm
91
+ });
121
92
  const resetAttachmentUploader = attachmentUploader.reset;
122
- let t6;
123
- if ($[11] !== clearDraft || $[12] !== currentlyEditingMessage || $[13] !== navigation || $[14] !== resetAttachmentUploader || $[15] !== resetMutation) {
124
- t6 = () => {
125
- resetAttachmentUploader();
126
- resetMutation();
127
- setText("");
128
- setUsingGiphy(false);
129
- if (!currentlyEditingMessage) {
130
- clearDraft();
131
- }
93
+ const reset = useCallback(() => {
94
+ resetAttachmentUploader();
95
+ resetMutation();
96
+ setText('');
97
+ setUsingGiphy(false);
98
+ if (!currentlyEditingMessage) {
99
+ clearDraft();
100
+ }
101
+ navigation.setParams({
102
+ editing_message_id: null
103
+ });
104
+ }, [resetAttachmentUploader, resetMutation, navigation, currentlyEditingMessage, clearDraft]);
105
+ useEffect(() => {
106
+ if (canGiphy && !usingGiphy && text.startsWith('/giphy ')) {
107
+ setUsingGiphy(true);
108
+ setText('');
109
+ }
110
+ }, [canGiphy, text, usingGiphy]);
111
+ useEffect(() => {
112
+ switch (status) {
113
+ case 'success':
114
+ reset();
115
+ break;
116
+ }
117
+ }, [reset, status]);
118
+ useEffect(() => {
119
+ if (route.params.clear_input) {
120
+ reset();
132
121
  navigation.setParams({
133
- editing_message_id: null
122
+ ...route.params,
123
+ clear_input: false
134
124
  });
135
- };
136
- $[11] = clearDraft;
137
- $[12] = currentlyEditingMessage;
138
- $[13] = navigation;
139
- $[14] = resetAttachmentUploader;
140
- $[15] = resetMutation;
141
- $[16] = t6;
142
- } else {
143
- t6 = $[16];
144
- }
145
- const reset = t6;
146
- let t7;
147
- let t8;
148
- if ($[17] !== canGiphy || $[18] !== text || $[19] !== usingGiphy) {
149
- t7 = () => {
150
- if (canGiphy && !usingGiphy && text.startsWith("/giphy ")) {
151
- setUsingGiphy(true);
152
- setText("");
153
- }
154
- };
155
- t8 = [canGiphy, text, usingGiphy];
156
- $[17] = canGiphy;
157
- $[18] = text;
158
- $[19] = usingGiphy;
159
- $[20] = t7;
160
- $[21] = t8;
161
- } else {
162
- t7 = $[20];
163
- t8 = $[21];
164
- }
165
- useEffect(t7, t8);
166
- let t10;
167
- let t9;
168
- if ($[22] !== reset || $[23] !== status) {
169
- t9 = () => {
170
- switch (status) {
171
- case "success":
172
- {
173
- reset();
174
- }
175
- }
176
- };
177
- t10 = [reset, status];
178
- $[22] = reset;
179
- $[23] = status;
180
- $[24] = t10;
181
- $[25] = t9;
182
- } else {
183
- t10 = $[24];
184
- t9 = $[25];
185
- }
186
- useEffect(t9, t10);
187
- let t11;
188
- let t12;
189
- if ($[26] !== navigation || $[27] !== reset || $[28] !== route.params) {
190
- t11 = () => {
191
- if (route.params.clear_input) {
192
- reset();
193
- navigation.setParams({
194
- ...route.params,
195
- clear_input: false
196
- });
197
- }
198
- };
199
- t12 = [reset, navigation, route.params];
200
- $[26] = navigation;
201
- $[27] = reset;
202
- $[28] = route.params;
203
- $[29] = t11;
204
- $[30] = t12;
205
- } else {
206
- t11 = $[29];
207
- t12 = $[30];
208
- }
209
- useEffect(t11, t12);
210
- let t13;
211
- let t14;
212
- if ($[31] !== attachmentUploader.attachments || $[32] !== currentlyEditingMessage || $[33] !== saveDraft || $[34] !== text) {
213
- t13 = () => {
214
- if (currentlyEditingMessage) {
215
- return;
216
- }
217
- const timeoutId = setTimeout(() => {
218
- saveDraft(text, attachmentUploader.attachments);
219
- }, 500);
220
- return () => clearTimeout(timeoutId);
221
- };
222
- t14 = [text, attachmentUploader.attachments, saveDraft, currentlyEditingMessage];
223
- $[31] = attachmentUploader.attachments;
224
- $[32] = currentlyEditingMessage;
225
- $[33] = saveDraft;
226
- $[34] = text;
227
- $[35] = t13;
228
- $[36] = t14;
229
- } else {
230
- t13 = $[35];
231
- t14 = $[36];
232
- }
233
- useEffect(t13, t14);
234
- const t15 = conversation.disabled ?? false;
235
- const t16 = !!attachmentUploader?.pendingUploads;
236
- const t17 = !!attachmentUploader?.flaggedAttachmentCount;
237
- let t18;
238
- if ($[37] !== attachmentUploader.attachmentIds?.length || $[38] !== isPending || $[39] !== t15 || $[40] !== t16 || $[41] !== t17 || $[42] !== text) {
239
- t18 = canSubmitMessage({
240
- isPending,
241
- conversationDisabled: t15,
242
- pendingUploads: t16,
243
- hasFlaggedAttachments: t17,
244
- hasText: hasMessageText(text),
245
- hasSendableAttachments: !!attachmentUploader?.attachmentIds?.length
246
- });
247
- $[37] = attachmentUploader.attachmentIds?.length;
248
- $[38] = isPending;
249
- $[39] = t15;
250
- $[40] = t16;
251
- $[41] = t17;
252
- $[42] = text;
253
- $[43] = t18;
254
- } else {
255
- t18 = $[43];
256
- }
257
- const canSubmit = t18;
125
+ }
126
+ }, [reset, navigation, route.params]);
127
+
128
+ // Save draft when text or attachments change (debounced)
129
+ useEffect(() => {
130
+ // Don't save drafts when editing a message
131
+ if (currentlyEditingMessage) return;
132
+ const timeoutId = setTimeout(() => {
133
+ saveDraft(text, attachmentUploader.attachments);
134
+ }, 500);
135
+ return () => clearTimeout(timeoutId);
136
+ }, [text, attachmentUploader.attachments, saveDraft, currentlyEditingMessage]);
137
+ const canSubmit = canSubmitMessage({
138
+ isPending,
139
+ conversationDisabled: conversation.disabled ?? false,
140
+ pendingUploads: !!attachmentUploader?.pendingUploads,
141
+ hasFlaggedAttachments: !!attachmentUploader?.flaggedAttachmentCount,
142
+ hasText: hasMessageText(text),
143
+ hasSendableAttachments: !!attachmentUploader?.attachmentIds?.length
144
+ });
258
145
  const disabled = !canSubmit;
259
- const t19 = conversation.disabled ?? false;
260
- let t20;
261
- if ($[44] !== isPending || $[45] !== t19) {
262
- t20 = isInputEditable({
263
- isPending,
264
- conversationDisabled: t19
265
- });
266
- $[44] = isPending;
267
- $[45] = t19;
268
- $[46] = t20;
269
- } else {
270
- t20 = $[46];
271
- }
272
- const inputEditable = t20;
273
- let t21;
274
- if ($[47] !== conversation.id || $[48] !== navigation || $[49] !== text) {
275
- t21 = () => {
276
- if (!Keyboard.isVisible() || Platform.OS === "ios") {
277
- navigation.navigate("SendGiphy", {
146
+ const inputEditable = isInputEditable({
147
+ isPending,
148
+ conversationDisabled: conversation.disabled ?? false
149
+ });
150
+
151
+ /*
152
+ Opening a FormSheet on Android while the keyboard is visible breaks the FormSheet's height & position.
153
+ This is a workaround to ensure we don't open the FormSheet while the keyboard is visible.
154
+ */
155
+ const navigateToSendGiphyAfterKeyboardHides = useCallback(() => {
156
+ if (!Keyboard.isVisible() || Platform.OS === 'ios') {
157
+ navigation.navigate('SendGiphy', {
158
+ conversation_id: conversation.id,
159
+ search_term: text
160
+ });
161
+ } else {
162
+ const keyboardListener = Keyboard.addListener('keyboardDidHide', () => {
163
+ navigation.navigate('SendGiphy', {
278
164
  conversation_id: conversation.id,
279
165
  search_term: text
280
166
  });
281
- } else {
282
- const keyboardListener = Keyboard.addListener("keyboardDidHide", () => {
283
- navigation.navigate("SendGiphy", {
284
- conversation_id: conversation.id,
285
- search_term: text
286
- });
287
- keyboardListener?.remove();
167
+ keyboardListener?.remove();
168
+ });
169
+ }
170
+ }, [conversation.id, navigation, text]);
171
+ const catchingUp = useRef(false);
172
+
173
+ // A send from a window behind the live edge would leave a gap above it, so a failed
174
+ // catch-up stops the send and keeps what was typed.
175
+ const catchUpBeforeSend = async () => {
176
+ if (catchingUp.current) return false;
177
+ catchingUp.current = true;
178
+ try {
179
+ await onBeforeSubmit?.();
180
+ return true;
181
+ } catch (error) {
182
+ Log.error('send stopped: live window fetch failed', error);
183
+ return false;
184
+ } finally {
185
+ catchingUp.current = false;
186
+ }
187
+ };
188
+ const handleSubmit = async () => {
189
+ if (!canSubmit) return;
190
+ if (canGiphy && usingGiphy) {
191
+ if (!(await catchUpBeforeSend())) return;
192
+ TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput());
193
+ Haptic.impactLight();
194
+ navigateToSendGiphyAfterKeyboardHides();
195
+ } else {
196
+ let attachmentsForSubmit = attachmentUploader.attachments.filter(a => a.status === 'success' && a.id).map(attachment => ({
197
+ type: 'MessageAttachment',
198
+ id: attachment.id,
199
+ file: attachment.file
200
+ }));
201
+ const messageText = stripEmptyTextCharacters(text);
202
+ if (currentlyEditingMessage) {
203
+ mutateAsync({
204
+ text: messageText
288
205
  });
289
- }
290
- };
291
- $[47] = conversation.id;
292
- $[48] = navigation;
293
- $[49] = text;
294
- $[50] = t21;
295
- } else {
296
- t21 = $[50];
297
- }
298
- const navigateToSendGiphyAfterKeyboardHides = t21;
299
- let t22;
300
- if ($[51] !== attachmentUploader.attachments || $[52] !== canGiphy || $[53] !== canSubmit || $[54] !== currentlyEditingMessage || $[55] !== mutateAsync || $[56] !== navigateToSendGiphyAfterKeyboardHides || $[57] !== reset || $[58] !== text || $[59] !== usingGiphy) {
301
- t22 = () => {
302
- if (!canSubmit) {
303
- return;
304
- }
305
- if (canGiphy && usingGiphy) {
306
- TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput());
307
- Haptic.impactLight();
308
- navigateToSendGiphyAfterKeyboardHides();
206
+ reset();
309
207
  } else {
310
- const attachmentsForSubmit = attachmentUploader.attachments.filter(_temp).map(_temp2);
311
- const messageText = stripEmptyTextCharacters(text);
312
- if (currentlyEditingMessage) {
313
- mutateAsync({
314
- text: messageText
315
- });
316
- reset();
317
- } else {
318
- mutateAsync({
319
- text: messageText,
320
- attachments: attachmentsForSubmit
321
- });
322
- reset();
323
- }
324
- }
325
- };
326
- $[51] = attachmentUploader.attachments;
327
- $[52] = canGiphy;
328
- $[53] = canSubmit;
329
- $[54] = currentlyEditingMessage;
330
- $[55] = mutateAsync;
331
- $[56] = navigateToSendGiphyAfterKeyboardHides;
332
- $[57] = reset;
333
- $[58] = text;
334
- $[59] = usingGiphy;
335
- $[60] = t22;
336
- } else {
337
- t22 = $[60];
338
- }
339
- const handleSubmit = t22;
340
- let t23;
341
- let t24;
342
- if ($[61] !== currentlyEditingMessage) {
343
- t23 = () => {
344
- if (currentlyEditingMessage) {
345
- setText(currentlyEditingMessage.text || "");
208
+ // The live-window fetch replaces the cache, which would wipe an optimistic row
209
+ // added earlier.
210
+ if (!(await catchUpBeforeSend())) return;
211
+ reset();
212
+ mutateAsync({
213
+ text: messageText,
214
+ attachments: attachmentsForSubmit
215
+ });
346
216
  }
347
- };
348
- t24 = [currentlyEditingMessage];
349
- $[61] = currentlyEditingMessage;
350
- $[62] = t23;
351
- $[63] = t24;
352
- } else {
353
- t23 = $[62];
354
- t24 = $[63];
355
- }
356
- useEffect(t23, t24);
357
- let t25;
358
- if ($[64] !== attachmentUploader || $[65] !== canGiphy || $[66] !== currentlyEditingMessage || $[67] !== disabled || $[68] !== handleSubmit || $[69] !== inputEditable || $[70] !== replyRootAuthorFirstName || $[71] !== replyRootId || $[72] !== reset || $[73] !== text || $[74] !== usingGiphy) {
359
- t25 = {
217
+ }
218
+ };
219
+ useEffect(() => {
220
+ if (currentlyEditingMessage) {
221
+ setText(currentlyEditingMessage.text || '');
222
+ }
223
+ }, [currentlyEditingMessage]);
224
+ return /*#__PURE__*/_jsx(MessageFormContext.Provider, {
225
+ value: {
360
226
  text,
361
227
  setText,
362
228
  onSubmit: handleSubmit,
@@ -370,84 +236,15 @@ function MessageFormRoot(t0) {
370
236
  reset,
371
237
  replyRootId,
372
238
  replyRootAuthorFirstName
373
- };
374
- $[64] = attachmentUploader;
375
- $[65] = canGiphy;
376
- $[66] = currentlyEditingMessage;
377
- $[67] = disabled;
378
- $[68] = handleSubmit;
379
- $[69] = inputEditable;
380
- $[70] = replyRootAuthorFirstName;
381
- $[71] = replyRootId;
382
- $[72] = reset;
383
- $[73] = text;
384
- $[74] = usingGiphy;
385
- $[75] = t25;
386
- } else {
387
- t25 = $[75];
388
- }
389
- let t26;
390
- let t27;
391
- let t28;
392
- if ($[76] === Symbol.for("react.memo_cache_sentinel")) {
393
- t26 = /*#__PURE__*/_jsx(EditingIndicator, {});
394
- t27 = /*#__PURE__*/_jsx(ReplyIndicator, {});
395
- t28 = /*#__PURE__*/_jsx(FlaggedContentBanner, {});
396
- $[76] = t26;
397
- $[77] = t27;
398
- $[78] = t28;
399
- } else {
400
- t26 = $[76];
401
- t27 = $[77];
402
- t28 = $[78];
403
- }
404
- let t29;
405
- if ($[79] !== children || $[80] !== styles.textInputContainer) {
406
- t29 = /*#__PURE__*/_jsx(View, {
407
- style: styles.textInputContainer,
408
- children: children
409
- });
410
- $[79] = children;
411
- $[80] = styles.textInputContainer;
412
- $[81] = t29;
413
- } else {
414
- t29 = $[81];
415
- }
416
- let t30;
417
- if ($[82] !== styles.container || $[83] !== t29) {
418
- t30 = /*#__PURE__*/_jsxs(View, {
239
+ },
240
+ children: /*#__PURE__*/_jsxs(View, {
419
241
  style: styles.container,
420
- children: [t26, t27, t28, t29]
421
- });
422
- $[82] = styles.container;
423
- $[83] = t29;
424
- $[84] = t30;
425
- } else {
426
- t30 = $[84];
427
- }
428
- let t31;
429
- if ($[85] !== t25 || $[86] !== t30) {
430
- t31 = /*#__PURE__*/_jsx(MessageFormContext.Provider, {
431
- value: t25,
432
- children: t30
433
- });
434
- $[85] = t25;
435
- $[86] = t30;
436
- $[87] = t31;
437
- } else {
438
- t31 = $[87];
439
- }
440
- return t31;
441
- }
442
- function _temp2(attachment) {
443
- return {
444
- type: "MessageAttachment",
445
- id: attachment.id,
446
- file: attachment.file
447
- };
448
- }
449
- function _temp(a) {
450
- return a.status === "success" && a.id;
242
+ children: [/*#__PURE__*/_jsx(EditingIndicator, {}), /*#__PURE__*/_jsx(ReplyIndicator, {}), /*#__PURE__*/_jsx(FlaggedContentBanner, {}), /*#__PURE__*/_jsx(View, {
243
+ style: styles.textInputContainer,
244
+ children: children
245
+ })]
246
+ })
247
+ });
451
248
  }
452
249
  function MessageFormAttachments() {
453
250
  const $ = _c(10);
@@ -550,7 +347,7 @@ function FlaggedContentBanner() {
550
347
  if ($[0] !== attachmentUploader?.attachments) {
551
348
  t1 = Symbol.for("react.early_return_sentinel");
552
349
  bb0: {
553
- const flaggedAttachments = attachmentUploader?.attachments.filter(_temp3) ?? [];
350
+ const flaggedAttachments = attachmentUploader?.attachments.filter(_temp) ?? [];
554
351
  const flaggedCount = flaggedAttachments.length;
555
352
  if (flaggedCount === 0) {
556
353
  t1 = null;
@@ -657,7 +454,7 @@ function FlaggedContentBanner() {
657
454
  }
658
455
  return t8;
659
456
  }
660
- function _temp3(a) {
457
+ function _temp(a) {
661
458
  return a.flagged;
662
459
  }
663
460
  function BannerMessage(t0) {
@@ -671,7 +468,7 @@ function BannerMessage(t0) {
671
468
  if ($[0] !== styles.flaggedBannerLink) {
672
469
  t1 = /*#__PURE__*/_jsx(Text, {
673
470
  style: styles.flaggedBannerLink,
674
- onPress: _temp4,
471
+ onPress: _temp2,
675
472
  accessibilityRole: "link",
676
473
  children: "content guidelines"
677
474
  });
@@ -700,7 +497,7 @@ function BannerMessage(t0) {
700
497
  }
701
498
  return t2;
702
499
  }
703
- function _temp4() {
500
+ function _temp2() {
704
501
  return Linking.openURL("https://www.planningcenter.com/terms#:~:text=4.%20Acceptable%20Use%20of%20Planning%20Center");
705
502
  }
706
503
  function MessageFormInput() {
@@ -1044,7 +841,7 @@ function MessageFormAttachmentPicker() {
1044
841
  if (result.canceled) {
1045
842
  return;
1046
843
  }
1047
- const filteredAssets = result.assets.filter(_temp5).map(_temp6);
844
+ const filteredAssets = result.assets.filter(_temp3).map(_temp4);
1048
845
  attachmentUploader?.handleFilesAttached(filteredAssets);
1049
846
  };
1050
847
  $[0] = attachmentUploader;
@@ -1059,7 +856,7 @@ function MessageFormAttachmentPicker() {
1059
856
  if (result_0.canceled) {
1060
857
  return;
1061
858
  }
1062
- const filteredAssets_0 = result_0.assets.filter(_temp7).map(_temp8);
859
+ const filteredAssets_0 = result_0.assets.filter(_temp5).map(_temp6);
1063
860
  attachmentUploader?.handleFilesAttached(filteredAssets_0);
1064
861
  };
1065
862
  $[2] = attachmentUploader;
@@ -1199,7 +996,7 @@ function MessageFormAttachmentPicker() {
1199
996
  }
1200
997
  return t8;
1201
998
  }
1202
- function _temp8(asset_2) {
999
+ function _temp6(asset_2) {
1203
1000
  return {
1204
1001
  uri: asset_2.uri,
1205
1002
  name: asset_2.name,
@@ -1207,10 +1004,10 @@ function _temp8(asset_2) {
1207
1004
  size: asset_2.size
1208
1005
  };
1209
1006
  }
1210
- function _temp7(asset_1) {
1007
+ function _temp5(asset_1) {
1211
1008
  return asset_1.size != null && asset_1.uri;
1212
1009
  }
1213
- function _temp6(asset_0) {
1010
+ function _temp4(asset_0) {
1214
1011
  return {
1215
1012
  uri: asset_0.uri,
1216
1013
  name: asset_0.fileName || asset_0.uri.split("/").pop() || "attachment",
@@ -1220,7 +1017,7 @@ function _temp6(asset_0) {
1220
1017
  width: asset_0.width
1221
1018
  };
1222
1019
  }
1223
- function _temp5(asset) {
1020
+ function _temp3(asset) {
1224
1021
  return asset.fileSize && asset.mimeType && asset.uri;
1225
1022
  }
1226
1023
  function MessageFormCommands() {