Skip to content

Commit

Permalink
add debug button + put back syncAllConversations + other clean up and…
Browse files Browse the repository at this point in the history
… fixes
  • Loading branch information
thierryskoda committed Jan 21, 2025
1 parent 6ca5f78 commit c0a7c6f
Show file tree
Hide file tree
Showing 25 changed files with 109 additions and 69 deletions.
6 changes: 4 additions & 2 deletions components/StateHandlers/HydrationStateHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prefetchConversationsQuery } from "@/queries/conversations-query";
import { prefetchConversationsQuery } from "@/queries/use-conversations-query";
import { prefetchInboxIdQuery } from "@/queries/use-inbox-id-query";
import { captureError } from "@/utils/capture-error";
import { getAccountsList } from "@data/store/accountsStore";
Expand Down Expand Up @@ -28,7 +28,9 @@ export default function HydrationStateHandler() {
for (const account of accounts) {
// Don't await because this is for performance but not critical
prefetchInboxIdQuery({ account }).catch(captureError);
prefetchConversationsQuery({ account }).catch(captureError);
prefetchConversationsQuery({
account,
}).catch(captureError);
}

useAppStore.getState().setHydrationDone(true);
Expand Down
9 changes: 6 additions & 3 deletions features/GroupInvites/joinGroup/JoinGroup.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AxiosInstance } from "axios";

import {} from "../groupInvites.utils";
import { JoinGroupResult } from "./joinGroup.types";
import { IConversationsQuery } from "@/queries/conversations-query";
import { IConversationsQuery } from "@/queries/use-conversations-query";
import { entify } from "@/queries/entify";
import { wait } from "@/utils/general";

Expand Down Expand Up @@ -94,11 +94,14 @@ export class JoinGroupClient {
account: string
): Promise<ConversationDataEntity> => {
const { fetchConversationsQuery } = await import(
"@/queries/conversations-query"
"@/queries/use-conversations-query"
);

const conversationList: IConversationsQuery =
await fetchConversationsQuery({ account });
await fetchConversationsQuery({
account,
caller: "liveFetchGroupsByAccount",
});

const conversationEntity: ConversationDataEntity = entify(
conversationList,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isConversationDenied } from "@/features/conversation/utils/is-conversation-denied";
import { getConversationMetadataQueryOptions } from "@/queries/conversation-metadata-query";
import { useConversationsQuery } from "@/queries/conversations-query";
import { useConversationsQuery } from "@/queries/use-conversations-query";
import { useCurrentAccount } from "@data/store/accountsStore";
import { useQueries } from "@tanstack/react-query";
import { useMemo } from "react";
Expand All @@ -10,6 +10,7 @@ export const useBlockedConversationsForCurrentAccount = () => {

const { data } = useConversationsQuery({
account: currentAccount!,
caller: "useBlockedConversationsForCurrentAccount",
});

const conversationsMetadataQueries = useQueries({
Expand Down
6 changes: 3 additions & 3 deletions features/consent/use-allow-group.mutation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { updateConversationInConversationsQueryData } from "@/queries/conversations-query";
import { updateConversationInConversationsQueryData } from "@/queries/use-conversations-query";
import { captureError } from "@/utils/capture-error";
import { GroupWithCodecsType } from "@/utils/xmtpRN/client.types";
import { queryClient } from "@queries/queryClient";
Expand All @@ -8,15 +8,15 @@ import {
useMutation,
} from "@tanstack/react-query";
import { getV3IdFromTopic } from "@utils/groupUtils/groupId";
import { updateInboxIdsConsentForAccount } from "./update-inbox-ids-consent-for-account";
import { updateConsentForGroupsForAccount } from "./update-consent-for-groups-for-account";
import {
ConsentState,
ConversationId,
ConversationTopic,
InboxId,
} from "@xmtp/react-native-sdk";
import { MutationKeys } from "../../queries/MutationKeys";
import { updateConsentForGroupsForAccount } from "./update-consent-for-groups-for-account";
import { updateInboxIdsConsentForAccount } from "./update-inbox-ids-consent-for-account";
import {
getGroupConsentQueryData,
setGroupConsentQueryData,
Expand Down
2 changes: 1 addition & 1 deletion features/consent/use-dm-consent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
getCurrentAccount,
useCurrentAccount,
} from "@/data/store/accountsStore";
import { updateConversationInConversationsQueryData } from "@/queries/conversations-query";
import { updateConversationInConversationsQueryData } from "@/queries/use-conversations-query";
import { getConversationQueryData } from "@/queries/useConversationQuery";
import { getDmQueryData, setDmQueryData } from "@/queries/useDmQuery";
import { updateObjectAndMethods } from "@/utils/update-object-and-methods";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const ConversationListPinnedConversations = memo(
if (!hasPinnedConversations) {
return null;
}

return (
<AnimatedVStack
style={themed($container)}
Expand Down Expand Up @@ -85,9 +86,7 @@ const PinnedConversationsSkeleton = memo(function () {
const { avatarSize } = useConversationListPinnedConversationsStyles();

return (
<AnimatedHStack
style={[themed($container), { justifyContent: "space-between" }]}
>
<AnimatedHStack style={themed($container)}>
<ConversationListItemAvatarSkeleton
color={hexToRGBA("#FF8080", 0.15)}
size={avatarSize}
Expand Down Expand Up @@ -135,6 +134,7 @@ const $container: ThemedStyle<ViewStyle> = ({ spacing }) => ({
paddingVertical: spacing.xs,
paddingHorizontal: spacing.lg,
rowGap: spacing.lg,
justifyContent: "space-between",
});

const $pinnedRow: ThemedStyle<ViewStyle> = ({ spacing }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { usePreferredName } from "@/hooks/usePreferredName";
import { translate } from "@/i18n";
import { useHeader } from "@/navigation/use-header";
import { ThemedStyle, useAppTheme } from "@/theme/useAppTheme";
import { converseEventEmitter } from "@/utils/events";
import { shortDisplayName } from "@/utils/str";
import { useAccountsProfiles } from "@/utils/useAccountsProfiles";
import { useNavigation } from "@react-navigation/native";
Expand Down Expand Up @@ -131,6 +132,10 @@ function ProfileAvatar() {
const preferredName = usePreferredInboxName(currentAccountInboxId);
const avatarUri = usePreferredInboxAvatar(currentAccountInboxId);

const showDebugMenu = useCallback(() => {
converseEventEmitter.emit("showDebugMenu");
}, []);

return (
<Pressable
onPress={() => {
Expand All @@ -139,6 +144,7 @@ function ProfileAvatar() {
});
}}
hitSlop={theme.spacing.sm}
onLongPress={showDebugMenu}
>
<Center style={themed($avatarContainer)}>
<Avatar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,19 @@ function useConversationContextMenuDeleteItem(args: {
const deleteDm = useDeleteDm({ topic: conversationTopic });

const handleDelete = useCallback(async () => {
if (!conversation) return;
try {
if (!conversation) {
throw new Error("Conversation not found");
}
if (isConversationGroup(conversation)) {
await deleteGroup();
} else {
await deleteDm();
}
} catch (error) {
captureErrorWithToast(error);
captureErrorWithToast(error, {
message: "Error deleting conversation",
});
}
}, [conversation, deleteGroup, deleteDm]);

Expand Down
3 changes: 2 additions & 1 deletion features/conversation-list/hooks/use-conversations-count.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getConversationsQueryOptions } from "@/queries/conversations-query";
import { getConversationsQueryOptions } from "@/queries/use-conversations-query";
import { useCurrentAccount } from "@data/store/accountsStore";
import { useQuery } from "@tanstack/react-query";

Expand All @@ -8,6 +8,7 @@ export const useConversationsCount = () => {
const { data: count, isLoading } = useQuery({
...getConversationsQueryOptions({
account: account!,
caller: "useConversationsCount",
}),
select: (data) => data?.length ?? 0,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getConversationMetadataQueryOptions } from "@/queries/conversation-metadata-query";
import { useConversationsQuery } from "@/queries/conversations-query";
import { useConversationsQuery } from "@/queries/use-conversations-query";
import { useCurrentAccount } from "@data/store/accountsStore";
import { useQueries } from "@tanstack/react-query";
import { useMemo } from "react";
Expand All @@ -10,6 +10,7 @@ export function usePinnedConversations() {
const { isLoading: isLoadingConversations, data: conversations } =
useConversationsQuery({
account: currentAccount!,
caller: "usePinnedConversations",
});

const conversationsDataQueries = useQueries({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { sentryTrackMessage } from "@utils/sentry";
import { useEffect, useRef } from "react";
import { useCurrentAccount } from "../../../data/store/accountsStore";
import { useConversationsQuery } from "@/queries/conversations-query";
import { useConversationsQuery } from "@/queries/use-conversations-query";
import { useShouldShowConnecting } from "./useShouldShowConnecting";

export const useShouldShowConnectingOrSyncing = () => {
const currentAccount = useCurrentAccount();
const { isLoading } = useConversationsQuery({
account: currentAccount!,
caller: "useShouldShowConnectingOrSyncing",
});
const initialLoadDoneOnce = !isLoading;
const shouldShowConnecting = useShouldShowConnecting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isConversationAllowed } from "@/features/conversation/utils/is-conversa
import { useScreenFocusEffectOnce } from "@/hooks/use-screen-focus-effect-once";
import { useAppStateHandlers } from "@/hooks/useAppStateHandlers";
import { getConversationMetadataQueryOptions } from "@/queries/conversation-metadata-query";
import { getConversationsQueryOptions } from "@/queries/conversations-query";
import { getConversationsQueryOptions } from "@/queries/use-conversations-query";
import { prefetchConversationMessages } from "@/queries/use-conversation-messages-query";
import { captureError } from "@/utils/capture-error";
import { useQueries, useQuery } from "@tanstack/react-query";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useConversationRequestsListItem() {
} = useQuery({
...getUnknownConsentConversationsQueryOptions({
account: currentAccount!,
context: "useConversationRequestsListItem",
caller: "useConversationRequestsListItem",
}),
});

Expand Down
2 changes: 1 addition & 1 deletion features/conversation/conversation-new-dm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { usePreferredName } from "@/hooks/usePreferredName";
import { translate } from "@/i18n";
import { useHeader } from "@/navigation/use-header";
import { useRouter } from "@/navigation/useNavigation";
import { addConversationToConversationsQuery } from "@/queries/conversations-query";
import { addConversationToConversationsQuery } from "@/queries/use-conversations-query";
import { setDmQueryData } from "@/queries/useDmQuery";
import { useAppTheme } from "@/theme/useAppTheme";
import { captureError } from "@/utils/capture-error";
Expand Down
2 changes: 1 addition & 1 deletion features/notifications/utils/accountTopicSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { currentAccount } from "@/data/store/accountsStore";
import { createConversationsQueryObserver } from "@/queries/conversations-query";
import { createConversationsQueryObserver } from "@/queries/use-conversations-query";
import { captureError } from "@/utils/capture-error";
import logger from "@/utils/logger";
import { resetNotifications } from "./resetNotifications";
Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AppCheckCore: cc8fd0a3a230ddd401f326489c99990b013f0c4f
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
boost: 4cb898d0bf20404aab1850c656dcea009429d6c1
CoinbaseWalletSDK: ea1f37512bbc69ebe07416e3b29bf840f5cc3152
CoinbaseWalletSDKExpo: 7488819c860868cd5fe117f6be43dd42c2e65919
ComputableLayout: c50faffac4ed9f8f05b0ce5e6f3a60df1f6042c8
Expand Down Expand Up @@ -2837,8 +2837,8 @@ SPEC CHECKSUMS:
FirebaseAppCheckInterop: 347aa09a805219a31249b58fc956888e9fcb314b
FirebaseCore: e0510f1523bc0eb21653cac00792e1e2bd6f1771
FirebaseCoreInternal: d98ab91e2d80a56d7b246856a8885443b302c0c2
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: 69ef571f3de08433d766d614c73a9838a06bf7eb
GoogleUtilities: 26a3abef001b6533cf678d3eb38fd3f614b7872d
hermes-engine: 06a9c6900587420b90accc394199527c64259db4
libavif: 84bbb62fb232c3018d6f1bab79beea87e35de7b7
Expand All @@ -2851,7 +2851,7 @@ SPEC CHECKSUMS:
MMKVCore: d26e4d3edd5cb8588c2569222cbd8be4231374e9
OpenSSL-Universal: b60a3702c9fea8b3145549d421fdb018e53ab7b4
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740
RCTDeprecation: fb7d408617e25d7f537940000d766d60149c5fea
RCTRequired: 9aaf0ffcc1f41f0c671af863970ef25c422a9920
RCTTypeSafety: e9a6e7d48184646eb0610295b74c0dd02768cbb2
Expand Down
13 changes: 5 additions & 8 deletions queries/unknown-consent-conversations-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ import { isConversationConsentUnknown } from "@/features/conversation/utils/is-c
import {
IConversationsQuery,
getConversationsQueryOptions,
} from "@/queries/conversations-query";
} from "@/queries/use-conversations-query";
import { UseQueryOptions } from "@tanstack/react-query";

function selectUnknownConsentConversations(conversations: IConversationsQuery) {
return (
conversations?.filter(
(conversation) =>
// Only the unknown conversations
isConversationConsentUnknown(conversation) &&
// Only the conversations with last message
conversation.lastMessage
conversations?.filter((conversation) =>
// Only the unknown conversations
isConversationConsentUnknown(conversation)
) ?? []
);
}

// For now just reuse the global conversations query
export const getUnknownConsentConversationsQueryOptions = (args: {
account: string;
context: string;
caller: string;
}): UseQueryOptions<IConversationsQuery> => {
return {
...getConversationsQueryOptions(args),
Expand Down
Loading

0 comments on commit c0a7c6f

Please sign in to comment.