@planningcenter/chat-react-native 4.2.1-qa-staging.7 → 4.2.1-qa-staging.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/conversation/message_form.d.ts +1 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +167 -373
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts +4 -2
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +115 -81
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/missing_message.d.ts +2 -0
- package/build/components/conversation/missing_message.d.ts.map +1 -0
- package/build/components/conversation/missing_message.js +139 -0
- package/build/components/conversation/missing_message.js.map +1 -0
- package/build/contexts/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +1 -2
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/conversation_context.d.ts +1 -3
- package/build/contexts/conversation_context.d.ts.map +1 -1
- package/build/contexts/conversation_context.js +18 -23
- package/build/contexts/conversation_context.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +4 -3
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/paginator_meta.d.ts +1 -3
- package/build/hooks/paginator_meta.d.ts.map +1 -1
- package/build/hooks/paginator_meta.js +8 -25
- package/build/hooks/paginator_meta.js.map +1 -1
- package/build/hooks/use_api.d.ts.map +1 -1
- package/build/hooks/use_api.js +8 -5
- package/build/hooks/use_api.js.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts +10 -8
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +218 -81
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts +1 -17
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +90 -83
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/hooks/use_message_create_or_update.d.ts.map +1 -1
- package/build/hooks/use_message_create_or_update.js +80 -91
- package/build/hooks/use_message_create_or_update.js.map +1 -1
- package/build/hooks/use_message_reaction_toggle.d.ts.map +1 -1
- package/build/hooks/use_message_reaction_toggle.js +40 -45
- package/build/hooks/use_message_reaction_toggle.js.map +1 -1
- package/build/hooks/use_read_receipts.d.ts +4 -3
- package/build/hooks/use_read_receipts.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.d.ts +10 -6
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +88 -65
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/screens/conversation_screen.d.ts +1 -1
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +338 -463
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +26 -21
- package/build/screens/message_actions_screen.js.map +1 -1
- package/build/screens/message_report_screen.d.ts.map +1 -1
- package/build/screens/message_report_screen.js +44 -17
- package/build/screens/message_report_screen.js.map +1 -1
- package/build/screens/notification_settings/hooks/groups.d.ts +4 -3
- package/build/screens/notification_settings/hooks/groups.d.ts.map +1 -1
- package/build/screens/reactions_screen.d.ts.map +1 -1
- package/build/screens/reactions_screen.js +88 -70
- package/build/screens/reactions_screen.js.map +1 -1
- package/build/types/api_primitives.d.ts +0 -1
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/utils/cache/messages_cache.d.ts +0 -1
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +0 -3
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/cache/messages_window.d.ts +11 -0
- package/build/utils/cache/messages_window.d.ts.map +1 -0
- package/build/utils/cache/messages_window.js +51 -0
- package/build/utils/cache/messages_window.js.map +1 -0
- package/build/utils/cache/optimistically_update_message.d.ts +1 -2
- package/build/utils/cache/optimistically_update_message.d.ts.map +1 -1
- package/build/utils/cache/optimistically_update_message.js +4 -4
- package/build/utils/cache/optimistically_update_message.js.map +1 -1
- package/build/utils/generate_placeholder_ulid.d.ts +6 -0
- package/build/utils/generate_placeholder_ulid.d.ts.map +1 -1
- package/build/utils/generate_placeholder_ulid.js +2 -2
- package/build/utils/generate_placeholder_ulid.js.map +1 -1
- package/build/utils/request/get_messages.d.ts +6 -18
- package/build/utils/request/get_messages.d.ts.map +1 -1
- package/build/utils/request/get_messages.js +12 -10
- package/build/utils/request/get_messages.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/hooks/paginator_meta.test.ts +2 -73
- package/src/components/conversation/__tests__/message_list.test.tsx +0 -42
- package/src/components/conversation/message_form.tsx +30 -5
- package/src/components/conversation/message_list.tsx +44 -14
- package/src/components/conversation/missing_message.tsx +66 -0
- package/src/contexts/api_provider.tsx +1 -2
- package/src/contexts/conversation_context.tsx +1 -6
- package/src/hooks/__tests__/use_conversation_messages.test.tsx +333 -0
- package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +87 -0
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +33 -0
- package/src/hooks/paginator_meta.ts +5 -29
- package/src/hooks/use_api.ts +5 -4
- package/src/hooks/use_conversation_messages.ts +88 -43
- package/src/hooks/use_conversation_messages_jolt_events.ts +53 -62
- package/src/hooks/use_message_create_or_update.ts +8 -8
- package/src/hooks/use_message_reaction_toggle.ts +1 -3
- package/src/hooks/use_suspense_api.ts +17 -8
- package/src/screens/conversation_screen.tsx +63 -123
- package/src/screens/message_actions_screen.tsx +5 -3
- package/src/screens/message_report_screen.tsx +3 -2
- package/src/screens/reactions_screen.tsx +4 -2
- package/src/types/api_primitives.ts +0 -1
- package/src/utils/cache/__tests__/messages_cache.test.ts +1 -14
- package/src/utils/cache/__tests__/messages_window.test.ts +78 -0
- package/src/utils/cache/messages_cache.ts +0 -3
- package/src/utils/cache/messages_window.ts +55 -0
- package/src/utils/cache/optimistically_update_message.ts +5 -2
- package/src/utils/generate_placeholder_ulid.ts +2 -2
- package/src/utils/request/get_messages.ts +14 -12
- package/build/components/conversation/anchor_not_found_boundary.d.ts +0 -18
- package/build/components/conversation/anchor_not_found_boundary.d.ts.map +0 -1
- package/build/components/conversation/anchor_not_found_boundary.js +0 -20
- package/build/components/conversation/anchor_not_found_boundary.js.map +0 -1
- package/build/hooks/use_conversation_message_lookup.d.ts +0 -7
- package/build/hooks/use_conversation_message_lookup.d.ts.map +0 -1
- package/build/hooks/use_conversation_message_lookup.js +0 -52
- package/build/hooks/use_conversation_message_lookup.js.map +0 -1
- package/build/hooks/use_fetch_newer_messages.d.ts +0 -9
- package/build/hooks/use_fetch_newer_messages.d.ts.map +0 -1
- package/build/hooks/use_fetch_newer_messages.js +0 -69
- package/build/hooks/use_fetch_newer_messages.js.map +0 -1
- package/build/hooks/use_fetch_newer_on_foreground.d.ts +0 -8
- package/build/hooks/use_fetch_newer_on_foreground.d.ts.map +0 -1
- package/build/hooks/use_fetch_newer_on_foreground.js +0 -42
- package/build/hooks/use_fetch_newer_on_foreground.js.map +0 -1
- package/build/hooks/use_held_back_messages.d.ts +0 -11
- package/build/hooks/use_held_back_messages.d.ts.map +0 -1
- package/build/hooks/use_held_back_messages.js +0 -24
- package/build/hooks/use_held_back_messages.js.map +0 -1
- package/build/utils/cache/find_message_in_caches.d.ts +0 -4
- package/build/utils/cache/find_message_in_caches.d.ts.map +0 -1
- package/build/utils/cache/find_message_in_caches.js +0 -16
- package/build/utils/cache/find_message_in_caches.js.map +0 -1
- package/build/utils/cache/invalidate_refetchable_queries.d.ts +0 -3
- package/build/utils/cache/invalidate_refetchable_queries.d.ts.map +0 -1
- package/build/utils/cache/invalidate_refetchable_queries.js +0 -8
- package/build/utils/cache/invalidate_refetchable_queries.js.map +0 -1
- package/build/utils/cache/prepend_newer_page.d.ts +0 -7
- package/build/utils/cache/prepend_newer_page.d.ts.map +0 -1
- package/build/utils/cache/prepend_newer_page.js +0 -15
- package/build/utils/cache/prepend_newer_page.js.map +0 -1
- package/build/utils/gated_message_cache.d.ts +0 -7
- package/build/utils/gated_message_cache.d.ts.map +0 -1
- package/build/utils/gated_message_cache.js +0 -13
- package/build/utils/gated_message_cache.js.map +0 -1
- package/build/utils/ulid.d.ts +0 -3
- package/build/utils/ulid.d.ts.map +0 -1
- package/build/utils/ulid.js +0 -7
- package/build/utils/ulid.js.map +0 -1
- package/src/__tests__/hooks/use_conversation_messages.test.ts +0 -22
- package/src/__tests__/hooks/use_conversation_messages_jolt_events.test.ts +0 -33
- package/src/__tests__/utils/gated_message_cache.test.ts +0 -26
- package/src/__tests__/utils/request/get_messages.test.ts +0 -24
- package/src/__tests__/utils/ulid.test.ts +0 -15
- package/src/components/conversation/__tests__/anchor_not_found_boundary.test.tsx +0 -51
- package/src/components/conversation/anchor_not_found_boundary.tsx +0 -21
- package/src/hooks/__tests__/use_fetch_newer_messages.test.tsx +0 -95
- package/src/hooks/__tests__/use_held_back_messages.test.tsx +0 -60
- package/src/hooks/__tests__/use_message_reaction_toggle.test.tsx +0 -73
- package/src/hooks/use_conversation_message_lookup.ts +0 -29
- package/src/hooks/use_fetch_newer_messages.ts +0 -52
- package/src/hooks/use_fetch_newer_on_foreground.ts +0 -25
- package/src/hooks/use_held_back_messages.ts +0 -33
- package/src/utils/cache/__tests__/find_message_in_caches.test.ts +0 -37
- package/src/utils/cache/__tests__/invalidate_refetchable_queries.test.ts +0 -23
- package/src/utils/cache/__tests__/prepend_newer_page.test.ts +0 -34
- package/src/utils/cache/find_message_in_caches.ts +0 -20
- package/src/utils/cache/invalidate_refetchable_queries.ts +0 -9
- package/src/utils/cache/prepend_newer_page.ts +0 -19
- package/src/utils/gated_message_cache.ts +0 -19
- package/src/utils/ulid.ts +0 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InfiniteData } from '@tanstack/react-query';
|
|
2
|
+
import { ApiCollection, MessageResource } from '../../types';
|
|
3
|
+
import { RequestData } from '../client';
|
|
4
|
+
export type MessagesWindow = InfiniteData<ApiCollection<MessageResource>, Partial<RequestData> | undefined>;
|
|
5
|
+
export declare const livePageParam: Partial<RequestData>;
|
|
6
|
+
export declare const anchoredPageParam: (anchor: string) => Partial<RequestData>;
|
|
7
|
+
export declare function isBehindLiveEdge(data: MessagesWindow | undefined): boolean;
|
|
8
|
+
export declare function newerPageParam(firstPage: ApiCollection<MessageResource>): Partial<RequestData> | undefined;
|
|
9
|
+
export declare function newestFirst<Page extends ApiCollection<MessageResource>>(page: Page, pageParam: Partial<RequestData> | undefined): Page;
|
|
10
|
+
export declare function markLiveIfCaughtUp(data: MessagesWindow | undefined): MessagesWindow | undefined;
|
|
11
|
+
//# sourceMappingURL=messages_window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages_window.d.ts","sourceRoot":"","sources":["../../../src/utils/cache/messages_window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,MAAM,cAAc,GAAG,YAAY,CACvC,aAAa,CAAC,eAAe,CAAC,EAC9B,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CACjC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,WAAW,CAAM,CAAA;AAErD,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,OAAO,CAAC,WAAW,CAEpE,CAAA;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAE1E;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,aAAa,CAAC,eAAe,CAAC,GACxC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAMlC;AAKD,wBAAgB,WAAW,CAAC,IAAI,SAAS,aAAa,CAAC,eAAe,CAAC,EACrE,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAC1C,IAAI,CAUN;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAO/F"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const livePageParam = {};
|
|
2
|
+
export const anchoredPageParam = anchor => ({
|
|
3
|
+
where: {
|
|
4
|
+
id_around: anchor
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
export function isBehindLiveEdge(data) {
|
|
8
|
+
return !!data?.pages[0]?.meta?.prev;
|
|
9
|
+
}
|
|
10
|
+
export function newerPageParam(firstPage) {
|
|
11
|
+
const newestId = firstPage.meta?.prev?.idGt;
|
|
12
|
+
if (!newestId) return undefined;
|
|
13
|
+
|
|
14
|
+
// Without asc the server hands back the newest page instead, leaving a gap.
|
|
15
|
+
return {
|
|
16
|
+
where: {
|
|
17
|
+
id_gt: newestId
|
|
18
|
+
},
|
|
19
|
+
order: 'asc'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The server returns newer pages oldest first, linking only to the next newer page.
|
|
24
|
+
// Storing them newest first with an older link lets a refetch replay the window
|
|
25
|
+
// forward from its top page like any other.
|
|
26
|
+
export function newestFirst(page, pageParam) {
|
|
27
|
+
if (pageParam?.order !== 'asc') return page;
|
|
28
|
+
const data = [...page.data].reverse();
|
|
29
|
+
const oldest = data[data.length - 1];
|
|
30
|
+
return {
|
|
31
|
+
...page,
|
|
32
|
+
data,
|
|
33
|
+
meta: {
|
|
34
|
+
...page.meta,
|
|
35
|
+
prev: page.meta?.next,
|
|
36
|
+
next: oldest && {
|
|
37
|
+
idLt: oldest.id
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function markLiveIfCaughtUp(data) {
|
|
43
|
+
if (!data) return data;
|
|
44
|
+
const topIsLive = !data.pageParams[0]?.where;
|
|
45
|
+
if (topIsLive || isBehindLiveEdge(data)) return data;
|
|
46
|
+
return {
|
|
47
|
+
...data,
|
|
48
|
+
pageParams: [livePageParam, ...data.pageParams.slice(1)]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=messages_window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages_window.js","names":["livePageParam","anchoredPageParam","anchor","where","id_around","isBehindLiveEdge","data","pages","meta","prev","newerPageParam","firstPage","newestId","idGt","undefined","id_gt","order","newestFirst","page","pageParam","reverse","oldest","length","next","idLt","id","markLiveIfCaughtUp","topIsLive","pageParams","slice"],"sources":["../../../src/utils/cache/messages_window.ts"],"sourcesContent":["import { InfiniteData } from '@tanstack/react-query'\nimport { ApiCollection, MessageResource } from '../../types'\nimport { RequestData } from '../client'\n\nexport type MessagesWindow = InfiniteData<\n ApiCollection<MessageResource>,\n Partial<RequestData> | undefined\n>\n\nexport const livePageParam: Partial<RequestData> = {}\n\nexport const anchoredPageParam = (anchor: string): Partial<RequestData> => ({\n where: { id_around: anchor },\n})\n\nexport function isBehindLiveEdge(data: MessagesWindow | undefined): boolean {\n return !!data?.pages[0]?.meta?.prev\n}\n\nexport function newerPageParam(\n firstPage: ApiCollection<MessageResource>\n): Partial<RequestData> | undefined {\n const newestId = firstPage.meta?.prev?.idGt\n if (!newestId) return undefined\n\n // Without asc the server hands back the newest page instead, leaving a gap.\n return { where: { id_gt: newestId }, order: 'asc' }\n}\n\n// The server returns newer pages oldest first, linking only to the next newer page.\n// Storing them newest first with an older link lets a refetch replay the window\n// forward from its top page like any other.\nexport function newestFirst<Page extends ApiCollection<MessageResource>>(\n page: Page,\n pageParam: Partial<RequestData> | undefined\n): Page {\n if (pageParam?.order !== 'asc') return page\n\n const data = [...page.data].reverse()\n const oldest = data[data.length - 1]\n return {\n ...page,\n data,\n meta: { ...page.meta, prev: page.meta?.next, next: oldest && { idLt: oldest.id } },\n }\n}\n\nexport function markLiveIfCaughtUp(data: MessagesWindow | undefined): MessagesWindow | undefined {\n if (!data) return data\n\n const topIsLive = !data.pageParams[0]?.where\n if (topIsLive || isBehindLiveEdge(data)) return data\n\n return { ...data, pageParams: [livePageParam, ...data.pageParams.slice(1)] }\n}\n"],"mappings":"AASA,OAAO,MAAMA,aAAmC,GAAG,CAAC,CAAC;AAErD,OAAO,MAAMC,iBAAiB,GAAIC,MAAc,KAA4B;EAC1EC,KAAK,EAAE;IAAEC,SAAS,EAAEF;EAAO;AAC7B,CAAC,CAAC;AAEF,OAAO,SAASG,gBAAgBA,CAACC,IAAgC,EAAW;EAC1E,OAAO,CAAC,CAACA,IAAI,EAAEC,KAAK,CAAC,CAAC,CAAC,EAAEC,IAAI,EAAEC,IAAI;AACrC;AAEA,OAAO,SAASC,cAAcA,CAC5BC,SAAyC,EACP;EAClC,MAAMC,QAAQ,GAAGD,SAAS,CAACH,IAAI,EAAEC,IAAI,EAAEI,IAAI;EAC3C,IAAI,CAACD,QAAQ,EAAE,OAAOE,SAAS;;EAE/B;EACA,OAAO;IAAEX,KAAK,EAAE;MAAEY,KAAK,EAAEH;IAAS,CAAC;IAAEI,KAAK,EAAE;EAAM,CAAC;AACrD;;AAEA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CACzBC,IAAU,EACVC,SAA2C,EACrC;EACN,IAAIA,SAAS,EAAEH,KAAK,KAAK,KAAK,EAAE,OAAOE,IAAI;EAE3C,MAAMZ,IAAI,GAAG,CAAC,GAAGY,IAAI,CAACZ,IAAI,CAAC,CAACc,OAAO,CAAC,CAAC;EACrC,MAAMC,MAAM,GAAGf,IAAI,CAACA,IAAI,CAACgB,MAAM,GAAG,CAAC,CAAC;EACpC,OAAO;IACL,GAAGJ,IAAI;IACPZ,IAAI;IACJE,IAAI,EAAE;MAAE,GAAGU,IAAI,CAACV,IAAI;MAAEC,IAAI,EAAES,IAAI,CAACV,IAAI,EAAEe,IAAI;MAAEA,IAAI,EAAEF,MAAM,IAAI;QAAEG,IAAI,EAAEH,MAAM,CAACI;MAAG;IAAE;EACnF,CAAC;AACH;AAEA,OAAO,SAASC,kBAAkBA,CAACpB,IAAgC,EAA8B;EAC/F,IAAI,CAACA,IAAI,EAAE,OAAOA,IAAI;EAEtB,MAAMqB,SAAS,GAAG,CAACrB,IAAI,CAACsB,UAAU,CAAC,CAAC,CAAC,EAAEzB,KAAK;EAC5C,IAAIwB,SAAS,IAAItB,gBAAgB,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;EAEpD,OAAO;IAAE,GAAGA,IAAI;IAAEsB,UAAU,EAAE,CAAC5B,aAAa,EAAE,GAAGM,IAAI,CAACsB,UAAU,CAACC,KAAK,CAAC,CAAC,CAAC;EAAE,CAAC;AAC9E","ignoreList":[]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MessageResource } from '../../types';
|
|
2
|
-
export declare function optimisticallyUpdateMessage({ conversationId, message, text, replyRootId,
|
|
2
|
+
export declare function optimisticallyUpdateMessage({ conversationId, message, text, replyRootId, }: {
|
|
3
3
|
conversationId: number;
|
|
4
4
|
message: MessageResource;
|
|
5
5
|
text: string;
|
|
6
6
|
replyRootId?: string | null;
|
|
7
|
-
queryKey?: unknown[];
|
|
8
7
|
}): MessageResource;
|
|
9
8
|
//# sourceMappingURL=optimistically_update_message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimistically_update_message.d.ts","sourceRoot":"","sources":["../../../src/utils/cache/optimistically_update_message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,eAAe,EAAE,MAAM,aAAa,CAAA;AAI5D,wBAAgB,2BAA2B,CAAC,EAC1C,cAAc,EACd,OAAO,EACP,IAAI,EACJ,WAAW,
|
|
1
|
+
{"version":3,"file":"optimistically_update_message.d.ts","sourceRoot":"","sources":["../../../src/utils/cache/optimistically_update_message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,eAAe,EAAE,MAAM,aAAa,CAAA;AAI5D,wBAAgB,2BAA2B,CAAC,EAC1C,cAAc,EACd,OAAO,EACP,IAAI,EACJ,WAAW,GACZ,EAAE;IACD,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B,mBA0BA"}
|
|
@@ -5,12 +5,12 @@ export function optimisticallyUpdateMessage({
|
|
|
5
5
|
conversationId,
|
|
6
6
|
message,
|
|
7
7
|
text,
|
|
8
|
-
replyRootId
|
|
9
|
-
|
|
8
|
+
replyRootId
|
|
9
|
+
}) {
|
|
10
|
+
const queryKey = getMessagesQueryKey({
|
|
10
11
|
conversation_id: conversationId,
|
|
11
12
|
reply_root_id: replyRootId
|
|
12
|
-
})
|
|
13
|
-
}) {
|
|
13
|
+
});
|
|
14
14
|
let optimisticMessage = message;
|
|
15
15
|
chatQueryClient.setQueryData(queryKey, data => updateOrCreateRecordInPagesData({
|
|
16
16
|
data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimistically_update_message.js","names":["chatQueryClient","getMessagesQueryKey","updateOrCreateRecordInPagesData","optimisticallyUpdateMessage","conversationId","message","text","replyRootId","queryKey","conversation_id","reply_root_id","optimisticMessage","setQueryData","data","record","processRecord","next","prev","pending"],"sources":["../../../src/utils/cache/optimistically_update_message.ts"],"sourcesContent":["import { InfiniteData } from '@tanstack/react-query'\nimport { chatQueryClient } from '../../contexts/api_provider'\nimport { ApiCollection, MessageResource } from '../../types'\nimport { getMessagesQueryKey } from '../../utils/request/get_messages'\nimport { updateOrCreateRecordInPagesData } from './page_mutations'\n\nexport function optimisticallyUpdateMessage({\n conversationId,\n message,\n text,\n replyRootId,\n
|
|
1
|
+
{"version":3,"file":"optimistically_update_message.js","names":["chatQueryClient","getMessagesQueryKey","updateOrCreateRecordInPagesData","optimisticallyUpdateMessage","conversationId","message","text","replyRootId","queryKey","conversation_id","reply_root_id","optimisticMessage","setQueryData","data","record","processRecord","next","prev","pending"],"sources":["../../../src/utils/cache/optimistically_update_message.ts"],"sourcesContent":["import { InfiniteData } from '@tanstack/react-query'\nimport { chatQueryClient } from '../../contexts/api_provider'\nimport { ApiCollection, MessageResource } from '../../types'\nimport { getMessagesQueryKey } from '../../utils/request/get_messages'\nimport { updateOrCreateRecordInPagesData } from './page_mutations'\n\nexport function optimisticallyUpdateMessage({\n conversationId,\n message,\n text,\n replyRootId,\n}: {\n conversationId: number\n message: MessageResource\n text: string\n replyRootId?: string | null\n}) {\n type QueryData = InfiniteData<ApiCollection<MessageResource>>\n\n const queryKey = getMessagesQueryKey({\n conversation_id: conversationId,\n reply_root_id: replyRootId,\n })\n\n let optimisticMessage = message\n\n chatQueryClient.setQueryData<QueryData>(queryKey, data =>\n updateOrCreateRecordInPagesData({\n data,\n record: message,\n processRecord: (next, prev) => {\n optimisticMessage = {\n ...(prev || next),\n text,\n pending: true,\n }\n return optimisticMessage\n },\n })\n )\n\n return optimisticMessage\n}\n"],"mappings":"AACA,SAASA,eAAe,QAAQ,6BAA6B;AAE7D,SAASC,mBAAmB,QAAQ,kCAAkC;AACtE,SAASC,+BAA+B,QAAQ,kBAAkB;AAElE,OAAO,SAASC,2BAA2BA,CAAC;EAC1CC,cAAc;EACdC,OAAO;EACPC,IAAI;EACJC;AAMF,CAAC,EAAE;EAGD,MAAMC,QAAQ,GAAGP,mBAAmB,CAAC;IACnCQ,eAAe,EAAEL,cAAc;IAC/BM,aAAa,EAAEH;EACjB,CAAC,CAAC;EAEF,IAAII,iBAAiB,GAAGN,OAAO;EAE/BL,eAAe,CAACY,YAAY,CAAYJ,QAAQ,EAAEK,IAAI,IACpDX,+BAA+B,CAAC;IAC9BW,IAAI;IACJC,MAAM,EAAET,OAAO;IACfU,aAAa,EAAEA,CAACC,IAAI,EAAEC,IAAI,KAAK;MAC7BN,iBAAiB,GAAG;QAClB,IAAIM,IAAI,IAAID,IAAI,CAAC;QACjBV,IAAI;QACJY,OAAO,EAAE;MACX,CAAC;MACD,OAAOP,iBAAiB;IAC1B;EACF,CAAC,CACH,CAAC;EAED,OAAOA,iBAAiB;AAC1B","ignoreList":[]}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The actual `ulid` library depends on a secure random number generator, which looks like it
|
|
3
|
+
* may require a native dependency to polyfill in React Native.
|
|
4
|
+
* Since this is only used as a local temporary ID, I think we can get away with a simpler
|
|
5
|
+
* implementation that doesn't require any native dependencies.
|
|
6
|
+
*/
|
|
1
7
|
export declare function generatePlaceholderUlid({ offsetMs }?: {
|
|
2
8
|
offsetMs?: number;
|
|
3
9
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_placeholder_ulid.d.ts","sourceRoot":"","sources":["../../src/utils/generate_placeholder_ulid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate_placeholder_ulid.d.ts","sourceRoot":"","sources":["../../src/utils/generate_placeholder_ulid.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,wBAAgB,uBAAuB,CAAC,EAAE,QAAY,EAAE,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAa5F"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ULID_CHARS } from './ulid';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* The actual `ulid` library depends on a secure random number generator, which looks like it
|
|
5
3
|
* may require a native dependency to polyfill in React Native.
|
|
@@ -7,6 +5,8 @@ import { ULID_CHARS } from './ulid';
|
|
|
7
5
|
* implementation that doesn't require any native dependencies.
|
|
8
6
|
*/
|
|
9
7
|
|
|
8
|
+
const ULID_CHARS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'; // Crockford's Base32
|
|
9
|
+
|
|
10
10
|
function encodeBase32(value, length) {
|
|
11
11
|
let result = '';
|
|
12
12
|
for (let i = 0; i < length; i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_placeholder_ulid.js","names":["ULID_CHARS","encodeBase32","value","length","result","i","Math","floor","generatePlaceholderUlid","offsetMs","timestamp","Date","now","timeComponent","randomComponent","random"],"sources":["../../src/utils/generate_placeholder_ulid.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"generate_placeholder_ulid.js","names":["ULID_CHARS","encodeBase32","value","length","result","i","Math","floor","generatePlaceholderUlid","offsetMs","timestamp","Date","now","timeComponent","randomComponent","random"],"sources":["../../src/utils/generate_placeholder_ulid.ts"],"sourcesContent":["/**\n * The actual `ulid` library depends on a secure random number generator, which looks like it\n * may require a native dependency to polyfill in React Native.\n * Since this is only used as a local temporary ID, I think we can get away with a simpler\n * implementation that doesn't require any native dependencies.\n */\n\nconst ULID_CHARS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ' // Crockford's Base32\n\nfunction encodeBase32(value: number, length: number) {\n let result = ''\n for (let i = 0; i < length; i++) {\n result = ULID_CHARS[value % 32] + result\n value = Math.floor(value / 32)\n }\n return result\n}\n\nexport function generatePlaceholderUlid({ offsetMs = 0 }: { offsetMs?: number } = {}): string {\n const timestamp = Date.now() + offsetMs // Milliseconds since epoch\n // 48 bits for timestamp (6 Base32 characters)\n const timeComponent = encodeBase32(timestamp, 10) // 48 bits = 6 bytes = 10 Base32 characters (approx, needs more precise bit shifting)\n\n // 80 bits for randomness (16 Base32 characters)\n let randomComponent = ''\n for (let i = 0; i < 16; i++) {\n // Generate 16 random Base32 chars\n randomComponent += ULID_CHARS[Math.floor(Math.random() * 32)]\n }\n\n return timeComponent + randomComponent\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,UAAU,GAAG,kCAAkC,EAAC;;AAEtD,SAASC,YAAYA,CAACC,KAAa,EAAEC,MAAc,EAAE;EACnD,IAAIC,MAAM,GAAG,EAAE;EACf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,EAAEE,CAAC,EAAE,EAAE;IAC/BD,MAAM,GAAGJ,UAAU,CAACE,KAAK,GAAG,EAAE,CAAC,GAAGE,MAAM;IACxCF,KAAK,GAAGI,IAAI,CAACC,KAAK,CAACL,KAAK,GAAG,EAAE,CAAC;EAChC;EACA,OAAOE,MAAM;AACf;AAEA,OAAO,SAASI,uBAAuBA,CAAC;EAAEC,QAAQ,GAAG;AAAyB,CAAC,GAAG,CAAC,CAAC,EAAU;EAC5F,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGH,QAAQ,EAAC;EACxC;EACA,MAAMI,aAAa,GAAGZ,YAAY,CAACS,SAAS,EAAE,EAAE,CAAC,EAAC;;EAElD;EACA,IAAII,eAAe,GAAG,EAAE;EACxB,KAAK,IAAIT,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,EAAE,EAAEA,CAAC,EAAE,EAAE;IAC3B;IACAS,eAAe,IAAId,UAAU,CAACM,IAAI,CAACC,KAAK,CAACD,IAAI,CAACS,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;EAC/D;EAEA,OAAOF,aAAa,GAAGC,eAAe;AACxC","ignoreList":[]}
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export declare const getMessagesRequestArgs: ({ conversation_id, reply_root_id, }: {
|
|
2
2
|
conversation_id: number;
|
|
3
3
|
reply_root_id?: string | null;
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export declare const getMessagesRequestArgs: ({ conversation_id, reply_root_id, anchor, }: MessagesRequestOptions) => {
|
|
4
|
+
}) => {
|
|
7
5
|
url: string;
|
|
8
6
|
data: {
|
|
9
|
-
where: {
|
|
10
|
-
id_around: string;
|
|
11
|
-
};
|
|
12
|
-
perPage: number;
|
|
13
|
-
fields: {
|
|
14
|
-
Message: string[];
|
|
15
|
-
Person: string[];
|
|
16
|
-
ReactionCount: string[];
|
|
17
|
-
};
|
|
18
|
-
include: string[];
|
|
19
|
-
} | {
|
|
20
|
-
where?: undefined;
|
|
21
7
|
perPage: number;
|
|
22
8
|
fields: {
|
|
23
9
|
Message: string[];
|
|
@@ -28,6 +14,8 @@ export declare const getMessagesRequestArgs: ({ conversation_id, reply_root_id,
|
|
|
28
14
|
};
|
|
29
15
|
reply_root_id: string | null;
|
|
30
16
|
};
|
|
31
|
-
export declare const getMessagesQueryKey: (
|
|
32
|
-
|
|
17
|
+
export declare const getMessagesQueryKey: ({ conversation_id, reply_root_id, }: {
|
|
18
|
+
conversation_id: number;
|
|
19
|
+
reply_root_id?: string | null;
|
|
20
|
+
}) => import("../..").RequestQueryKey;
|
|
33
21
|
//# sourceMappingURL=get_messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_messages.d.ts","sourceRoot":"","sources":["../../../src/utils/request/get_messages.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"get_messages.d.ts","sourceRoot":"","sources":["../../../src/utils/request/get_messages.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,GAAI,qCAGpC;IACD,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;;;;;;;;;;;;CAeA,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,qCAGjC;IACD,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B,oCAGA,CAAA"}
|
|
@@ -2,26 +2,28 @@ import { getRequestQueryKey } from '../../hooks/use_suspense_api';
|
|
|
2
2
|
import { getMessageFields, getMessagesInclude } from './messages_data_options';
|
|
3
3
|
export const getMessagesRequestArgs = ({
|
|
4
4
|
conversation_id,
|
|
5
|
-
reply_root_id
|
|
6
|
-
anchor
|
|
5
|
+
reply_root_id
|
|
7
6
|
}) => {
|
|
8
7
|
const normalizedReplyRootId = reply_root_id ?? null;
|
|
9
8
|
const url = normalizedReplyRootId ? `/me/conversations/${conversation_id}/messages/${normalizedReplyRootId}/replies` : `/me/conversations/${conversation_id}/messages`;
|
|
10
|
-
const anchored = anchor ? {
|
|
11
|
-
where: {
|
|
12
|
-
id_around: anchor
|
|
13
|
-
}
|
|
14
|
-
} : {};
|
|
15
9
|
return {
|
|
16
10
|
url,
|
|
17
11
|
data: {
|
|
18
12
|
perPage: 25,
|
|
19
13
|
fields: getMessageFields,
|
|
20
|
-
include: getMessagesInclude
|
|
21
|
-
...anchored
|
|
14
|
+
include: getMessagesInclude
|
|
22
15
|
},
|
|
23
16
|
reply_root_id: normalizedReplyRootId
|
|
24
17
|
};
|
|
25
18
|
};
|
|
26
|
-
export const getMessagesQueryKey =
|
|
19
|
+
export const getMessagesQueryKey = ({
|
|
20
|
+
conversation_id,
|
|
21
|
+
reply_root_id
|
|
22
|
+
}) => {
|
|
23
|
+
const requestArgs = getMessagesRequestArgs({
|
|
24
|
+
conversation_id,
|
|
25
|
+
reply_root_id
|
|
26
|
+
});
|
|
27
|
+
return getRequestQueryKey(requestArgs);
|
|
28
|
+
};
|
|
27
29
|
//# sourceMappingURL=get_messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_messages.js","names":["getRequestQueryKey","getMessageFields","getMessagesInclude","getMessagesRequestArgs","conversation_id","reply_root_id","
|
|
1
|
+
{"version":3,"file":"get_messages.js","names":["getRequestQueryKey","getMessageFields","getMessagesInclude","getMessagesRequestArgs","conversation_id","reply_root_id","normalizedReplyRootId","url","data","perPage","fields","include","getMessagesQueryKey","requestArgs"],"sources":["../../../src/utils/request/get_messages.ts"],"sourcesContent":["import { getRequestQueryKey } from '../../hooks/use_suspense_api'\nimport { getMessageFields, getMessagesInclude } from './messages_data_options'\n\nexport const getMessagesRequestArgs = ({\n conversation_id,\n reply_root_id,\n}: {\n conversation_id: number\n reply_root_id?: string | null\n}) => {\n const normalizedReplyRootId = reply_root_id ?? null\n const url = normalizedReplyRootId\n ? `/me/conversations/${conversation_id}/messages/${normalizedReplyRootId}/replies`\n : `/me/conversations/${conversation_id}/messages`\n\n return {\n url,\n data: {\n perPage: 25,\n fields: getMessageFields,\n include: getMessagesInclude,\n },\n reply_root_id: normalizedReplyRootId,\n }\n}\n\nexport const getMessagesQueryKey = ({\n conversation_id,\n reply_root_id,\n}: {\n conversation_id: number\n reply_root_id?: string | null\n}) => {\n const requestArgs = getMessagesRequestArgs({ conversation_id, reply_root_id })\n return getRequestQueryKey(requestArgs)\n}\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,yBAAyB;AAE9E,OAAO,MAAMC,sBAAsB,GAAGA,CAAC;EACrCC,eAAe;EACfC;AAIF,CAAC,KAAK;EACJ,MAAMC,qBAAqB,GAAGD,aAAa,IAAI,IAAI;EACnD,MAAME,GAAG,GAAGD,qBAAqB,GAC7B,qBAAqBF,eAAe,aAAaE,qBAAqB,UAAU,GAChF,qBAAqBF,eAAe,WAAW;EAEnD,OAAO;IACLG,GAAG;IACHC,IAAI,EAAE;MACJC,OAAO,EAAE,EAAE;MACXC,MAAM,EAAET,gBAAgB;MACxBU,OAAO,EAAET;IACX,CAAC;IACDG,aAAa,EAAEC;EACjB,CAAC;AACH,CAAC;AAED,OAAO,MAAMM,mBAAmB,GAAGA,CAAC;EAClCR,eAAe;EACfC;AAIF,CAAC,KAAK;EACJ,MAAMQ,WAAW,GAAGV,sBAAsB,CAAC;IAAEC,eAAe;IAAEC;EAAc,CAAC,CAAC;EAC9E,OAAOL,kBAAkB,CAACa,WAAW,CAAC;AACxC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.2.1-qa-staging.
|
|
3
|
+
"version": "4.2.1-qa-staging.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
35
35
|
"@fortawesome/react-native-fontawesome": "^0.3.2",
|
|
36
|
-
"@planningcenter/emoji-keyboard": "4.2.1-qa-staging.
|
|
36
|
+
"@planningcenter/emoji-keyboard": "4.2.1-qa-staging.8",
|
|
37
37
|
"lodash-inflection": "^1.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "79a6fab28e0ddadba0af22642a2d97eb9609f1cc"
|
|
88
88
|
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getNewerPageParam,
|
|
3
|
-
getNextPageParamFromMeta,
|
|
4
|
-
mergePageWhere,
|
|
5
|
-
} from '../../hooks/paginator_meta'
|
|
6
|
-
import { NextPageCursor } from '../../types/api_primitives'
|
|
7
|
-
import { RequestData } from '../../utils/client'
|
|
1
|
+
import { getNextPageParamFromMeta } from '../../hooks/paginator_meta'
|
|
8
2
|
|
|
9
3
|
describe('getNextPageParamFromMeta', () => {
|
|
10
|
-
it.each
|
|
4
|
+
it.each([
|
|
11
5
|
[undefined, undefined],
|
|
12
6
|
[{}, undefined],
|
|
13
7
|
[{ idLt: '01ABC' }, { where: { id_lt: '01ABC' } }],
|
|
@@ -15,72 +9,7 @@ describe('getNextPageParamFromMeta', () => {
|
|
|
15
9
|
[{ idGt: '01ABC' }, { where: { id_gt: '01ABC' } }],
|
|
16
10
|
[{ idGte: '01ABC' }, { where: { id_gte: '01ABC' } }],
|
|
17
11
|
[{ offset: '40' }, { offset: 40 }],
|
|
18
|
-
[
|
|
19
|
-
{ idLt: '01ABC', order: 'desc' },
|
|
20
|
-
{ where: { id_lt: '01ABC' }, order: 'desc' },
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
{ idGt: '01ABC', order: 'asc' },
|
|
24
|
-
{ where: { id_gt: '01ABC' }, order: 'asc' },
|
|
25
|
-
],
|
|
26
12
|
])('maps %p to %p', (input, expected) => {
|
|
27
13
|
expect(getNextPageParamFromMeta(input)).toEqual(expected)
|
|
28
14
|
})
|
|
29
15
|
})
|
|
30
|
-
|
|
31
|
-
describe('getNewerPageParam', () => {
|
|
32
|
-
const page = (meta: { next?: NextPageCursor; prev?: NextPageCursor }) => ({
|
|
33
|
-
data: [],
|
|
34
|
-
links: {},
|
|
35
|
-
meta: { count: 0, totalCount: 0, ...meta },
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('follows meta.prev on the anchored page', () => {
|
|
39
|
-
const anchored = page({
|
|
40
|
-
next: { idLt: '01A', order: 'desc' },
|
|
41
|
-
prev: { idGt: '01E', order: 'asc' },
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
expect(getNewerPageParam(anchored, {})).toEqual({ where: { id_gt: '01E' }, order: 'asc' })
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('stops when the anchored page has no newer side', () => {
|
|
48
|
-
expect(getNewerPageParam(page({ next: { idLt: '01A', order: 'desc' } }), {})).toBeUndefined()
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('follows meta.next on an ascending page', () => {
|
|
52
|
-
const newer = page({ next: { idGt: '01H', order: 'asc' } })
|
|
53
|
-
|
|
54
|
-
expect(getNewerPageParam(newer, { order: 'asc' })).toEqual({
|
|
55
|
-
where: { id_gt: '01H' },
|
|
56
|
-
order: 'asc',
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('stops once an ascending page has no meta.next', () => {
|
|
61
|
-
expect(getNewerPageParam(page({}), { order: 'asc' })).toBeUndefined()
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
describe('mergePageWhere', () => {
|
|
66
|
-
it('lets a page cursor replace the request bound instead of stacking bounds', () => {
|
|
67
|
-
expect(mergePageWhere({ id_around: '01ANCHOR' }, { id_gt: '01NEWER' })).toEqual({
|
|
68
|
-
id_gt: '01NEWER',
|
|
69
|
-
})
|
|
70
|
-
expect(mergePageWhere({ id_around: '01ANCHOR' }, { id_lt: '01OLDER' })).toEqual({
|
|
71
|
-
id_lt: '01OLDER',
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('keeps non-cursor filters alongside the cursor', () => {
|
|
76
|
-
expect(mergePageWhere({ source_type: 'Group' }, { id_lt: '01OLDER' })).toEqual({
|
|
77
|
-
source_type: 'Group',
|
|
78
|
-
id_lt: '01OLDER',
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('leaves the request where alone when the page has no cursor', () => {
|
|
83
|
-
expect(mergePageWhere({ id_around: '01ANCHOR' }, {})).toEqual({ id_around: '01ANCHOR' })
|
|
84
|
-
expect(mergePageWhere(undefined, undefined)).toEqual({})
|
|
85
|
-
})
|
|
86
|
-
})
|
|
@@ -104,7 +104,6 @@ let queryClient: QueryClient
|
|
|
104
104
|
|
|
105
105
|
// A top-level rerender would rebuild the wrapper context and redraw every row.
|
|
106
106
|
let setHarnessConversation: (next: ConversationResource) => void = () => {}
|
|
107
|
-
let harnessAnchorMessageId: string | null = null
|
|
108
107
|
|
|
109
108
|
function Harness() {
|
|
110
109
|
const [current, setCurrent] = React.useState(conversation)
|
|
@@ -118,7 +117,6 @@ function Harness() {
|
|
|
118
117
|
conversation={current}
|
|
119
118
|
conversationId={CONVERSATION_ID}
|
|
120
119
|
messages={loaded}
|
|
121
|
-
anchorMessageId={harnessAnchorMessageId}
|
|
122
120
|
hasNextPage
|
|
123
121
|
onEndReached={() => {}}
|
|
124
122
|
/>
|
|
@@ -178,49 +176,9 @@ beforeEach(() => {
|
|
|
178
176
|
afterEach(() => {
|
|
179
177
|
queryClient.clear()
|
|
180
178
|
jest.clearAllMocks()
|
|
181
|
-
harnessAnchorMessageId = null
|
|
182
179
|
})
|
|
183
180
|
|
|
184
181
|
describe('MessageList', () => {
|
|
185
|
-
it('pins the anchor row to the bottom edge as content lays out, until the user drags', () => {
|
|
186
|
-
const scrollToIndex = jest.spyOn(FlatList.prototype, 'scrollToIndex').mockImplementation()
|
|
187
|
-
harnessAnchorMessageId = messages[3].id
|
|
188
|
-
renderList()
|
|
189
|
-
const list = screen.UNSAFE_getByType(FlatList)
|
|
190
|
-
const anchorIndex = list.props.data.findIndex(
|
|
191
|
-
(item: { id: string }) => item.id === messages[3].id
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
act(() => list.props.onLayout({ nativeEvent: { layout: { height: 600 } } }))
|
|
195
|
-
act(() => list.props.onContentSizeChange(0, 400))
|
|
196
|
-
expect(scrollToIndex).not.toHaveBeenCalled()
|
|
197
|
-
|
|
198
|
-
act(() => list.props.onContentSizeChange(0, 1000))
|
|
199
|
-
act(() => list.props.onContentSizeChange(0, 2000))
|
|
200
|
-
expect(anchorIndex).toBeGreaterThan(0)
|
|
201
|
-
expect(scrollToIndex).toHaveBeenCalledTimes(2)
|
|
202
|
-
expect(scrollToIndex).toHaveBeenLastCalledWith({
|
|
203
|
-
index: anchorIndex,
|
|
204
|
-
viewPosition: 0,
|
|
205
|
-
animated: false,
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
act(() => list.props.onScrollBeginDrag({ nativeEvent: {} }))
|
|
209
|
-
act(() => list.props.onContentSizeChange(0, 3000))
|
|
210
|
-
expect(scrollToIndex).toHaveBeenCalledTimes(2)
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
it('leaves the offset alone when there is no anchor', () => {
|
|
214
|
-
const scrollToIndex = jest.spyOn(FlatList.prototype, 'scrollToIndex').mockImplementation()
|
|
215
|
-
renderList()
|
|
216
|
-
const list = screen.UNSAFE_getByType(FlatList)
|
|
217
|
-
|
|
218
|
-
act(() => list.props.onLayout({ nativeEvent: { layout: { height: 600 } } }))
|
|
219
|
-
act(() => list.props.onContentSizeChange(0, 1000))
|
|
220
|
-
|
|
221
|
-
expect(scrollToIndex).not.toHaveBeenCalled()
|
|
222
|
-
})
|
|
223
|
-
|
|
224
182
|
it('redraws only the reacted row when a reaction arrives', () => {
|
|
225
183
|
renderList()
|
|
226
184
|
const target = messages[3]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'
|
|
2
|
-
import React, { useCallback, useContext, useEffect, useState } from 'react'
|
|
2
|
+
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
|
|
3
3
|
import {
|
|
4
4
|
Linking,
|
|
5
5
|
Platform,
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
FileAttachment,
|
|
35
35
|
} from '../../types/resources/denormalized_attachment_resource_for_create'
|
|
36
36
|
import {
|
|
37
|
+
Log,
|
|
37
38
|
MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
|
|
38
39
|
platformFontWeightMedium,
|
|
39
40
|
platformPressedOpacityStyle,
|
|
@@ -71,7 +72,7 @@ interface MessagesFormRootProps extends ViewProps {
|
|
|
71
72
|
replyRootId?: string | null
|
|
72
73
|
replyRootAuthorFirstName?: string | null
|
|
73
74
|
onFlaggedInMessageForm?: (id: string) => void
|
|
74
|
-
onBeforeSubmit?: () => void
|
|
75
|
+
onBeforeSubmit?: () => void | Promise<void>
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
const MessageFormContext = React.createContext<{
|
|
@@ -226,10 +227,31 @@ function MessageFormRoot({
|
|
|
226
227
|
}
|
|
227
228
|
}, [conversation.id, navigation, text])
|
|
228
229
|
|
|
229
|
-
const
|
|
230
|
+
const catchingUp = useRef(false)
|
|
231
|
+
|
|
232
|
+
// A send from a window behind the live edge would leave a gap above it, so a failed
|
|
233
|
+
// catch-up stops the send and keeps what was typed.
|
|
234
|
+
const catchUpBeforeSend = async () => {
|
|
235
|
+
if (catchingUp.current) return false
|
|
236
|
+
|
|
237
|
+
catchingUp.current = true
|
|
238
|
+
try {
|
|
239
|
+
await onBeforeSubmit?.()
|
|
240
|
+
return true
|
|
241
|
+
} catch (error) {
|
|
242
|
+
Log.error('send stopped: live window fetch failed', error)
|
|
243
|
+
return false
|
|
244
|
+
} finally {
|
|
245
|
+
catchingUp.current = false
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const handleSubmit = async () => {
|
|
230
250
|
if (!canSubmit) return
|
|
231
251
|
|
|
232
252
|
if (canGiphy && usingGiphy) {
|
|
253
|
+
if (!(await catchUpBeforeSend())) return
|
|
254
|
+
|
|
233
255
|
TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput())
|
|
234
256
|
Haptic.impactLight()
|
|
235
257
|
navigateToSendGiphyAfterKeyboardHides()
|
|
@@ -250,9 +272,12 @@ function MessageFormRoot({
|
|
|
250
272
|
mutateAsync({ text: messageText })
|
|
251
273
|
reset()
|
|
252
274
|
} else {
|
|
253
|
-
|
|
254
|
-
|
|
275
|
+
// The live-window fetch replaces the cache, which would wipe an optimistic row
|
|
276
|
+
// added earlier.
|
|
277
|
+
if (!(await catchUpBeforeSend())) return
|
|
278
|
+
|
|
255
279
|
reset()
|
|
280
|
+
mutateAsync({ text: messageText, attachments: attachmentsForSubmit })
|
|
256
281
|
}
|
|
257
282
|
}
|
|
258
283
|
}
|