Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Requests list items #1567

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/XmtpEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "react-native";
import { getAccountsList, useAccountsStore } from "../data/store/accountsStore";
import { useAppStore } from "../data/store/appStore";
import { stopStreamingConversations } from "../utils/xmtpRN/conversations";
import { stopStreamingConversations } from "@/utils/xmtpRN/xmtp-conversations/xmtp-conversations-stream";
import { syncConversationListXmtpClient } from "../utils/xmtpRN/sync";
import { stopStreamingConsent } from "@/utils/xmtpRN/xmtp-preferences/xmtp-preferences-stream";

Expand Down
4 changes: 2 additions & 2 deletions containers/GroupPendingRequestsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useGroupPendingRequests } from "@hooks/useGroupPendingRequests";
import { usePreferredNames } from "@hooks/usePreferredNames";
import { translate } from "@i18n";
import { useAddToGroupMutation } from "@queries/useAddToGroupMutation";
import { invalidatePendingJoinRequestsQuery } from "@queries/usePendingRequestsQuery";
import { invalidateGroupPendingJoinRequestsQuery } from "@/queries/useGroupPendingRequestsQuery";
import { actionSheetColors, textSecondaryColor } from "@styles/colors";
import { updateGroupJoinRequestStatus } from "@/utils/api/api-groups/api-groups";
import { FC, useMemo } from "react";
Expand Down Expand Up @@ -71,7 +71,7 @@ export const GroupPendingRequestsTable: FC<GroupPendingRequestsTableProps> = ({
request.id,
"ACCEPTED"
);
invalidatePendingJoinRequestsQuery(currentAccount);
invalidateGroupPendingJoinRequestsQuery(currentAccount);
break;
case 1:
// deny
Expand Down
13 changes: 6 additions & 7 deletions containers/GroupScreenConsentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { dangerColor, primaryColor } from "@styles/colors";
import { groupRemoveRestoreHandler } from "@utils/groupUtils/groupActionHandlers";
import { FC, useMemo } from "react";
import { useColorScheme } from "react-native";

import { GroupWithCodecsType } from "@/utils/xmtpRN/client.types";
import type { ConversationTopic } from "@xmtp/react-native-sdk";
import TableView, {
TableViewItemType,
} from "../components/TableView/TableView";
import type { ConversationTopic } from "@xmtp/react-native-sdk";
import { GroupWithCodecsType } from "@/utils/xmtpRN/client.types";

type GroupScreenConsentTableProps = {
topic: ConversationTopic;
Expand All @@ -21,7 +20,7 @@ export const GroupScreenConsentTable: FC<GroupScreenConsentTableProps> = ({
group,
}) => {
const colorScheme = useColorScheme();
const { consent, allowGroup, blockGroup } =
const { consent, allowGroup, denyGroup } =
useGroupConsentForCurrentAccount(topic);

const consentTableViewItems = useMemo(() => {
Expand All @@ -39,7 +38,7 @@ export const GroupScreenConsentTable: FC<GroupScreenConsentTableProps> = ({
colorScheme,
groupName,
allowGroup,
blockGroup
denyGroup
)((success: boolean) => {
// If not successful, do nothing (user canceled)
});
Expand All @@ -58,7 +57,7 @@ export const GroupScreenConsentTable: FC<GroupScreenConsentTableProps> = ({
colorScheme,
groupName,
allowGroup,
blockGroup
denyGroup
)((success: boolean) => {
// If not successful, do nothing (user canceled)
});
Expand All @@ -67,7 +66,7 @@ export const GroupScreenConsentTable: FC<GroupScreenConsentTableProps> = ({
}

return items;
}, [consent, allowGroup, blockGroup, colorScheme, group]);
}, [consent, allowGroup, denyGroup, colorScheme, group]);

return (
<TableView
Expand Down
11 changes: 4 additions & 7 deletions containers/GroupScreenMembersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import { navigate } from "@utils/navigation";
import { getPreferredInboxName } from "@utils/profile";
import { FC, memo, useMemo } from "react";
import { StyleSheet, Text, View, useColorScheme } from "react-native";

import { IProfileSocials } from "@/features/profiles/profile-types";
import { useInboxProfilesSocials } from "@/hooks/useInboxProfilesSocials";
import { useGroupMembersConversationScreenQuery } from "@/queries/useGroupMembersQuery";
import { captureErrorWithFriendlyToast } from "@/utils/capture-error";
import { GroupWithCodecsType } from "@/utils/xmtpRN/client.types";
import { useGroupPermissionPolicyQuery } from "@queries/useGroupPermissionPolicyQuery";
Expand All @@ -39,10 +37,7 @@ export const GroupScreenMembersTable: FC<GroupScreenMembersTableProps> = memo(
const colorScheme = useColorScheme();
const currentAccount = useCurrentAccount() as string;
const styles = useStyles();
const { data: members } = useGroupMembersConversationScreenQuery({
account: currentAccount,
topic,
});
const { members } = useGroupMembers(topic);
const {
promoteToSuperAdmin,
promoteToAdmin,
Expand Down Expand Up @@ -98,7 +93,9 @@ export const GroupScreenMembersTable: FC<GroupScreenMembersTableProps> = memo(
const preferredName = getPreferredInboxName(mappedData[a.inboxId]);
items.push({
id: a.inboxId,
title: `${preferredName}${isCurrentUser ? translate("you_parentheses") : ""}`,
title: `${preferredName}${
isCurrentUser ? translate("you_parentheses") : ""
}`,
action: () => {
const {
options,
Expand Down
3 changes: 1 addition & 2 deletions features/GroupInvites/joinGroup/JoinGroup.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,10 @@ export class JoinGroupClient {
const allowGroupMutationObserver = createAllowGroupMutationObserver({
account,
topic,
groupId,
});
await allowGroupMutationObserver.mutate({
group: conversation as GroupWithCodecsType,
account,
topic,
});

// Dynamically import setGroupStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import {
getCurrentAccount,
useCurrentAccount,
} from "@/data/store/accountsStore";
import { updateConversationInConversationsQueryData } from "@/queries/use-conversations-query";
import {
addConversationToUnknownConsentConversationsQuery,
removeConversationFromUnknownConsentConversationsQueryData,
} from "@/queries/unknown-consent-conversations-query";
import {
addConversationToConversationsQuery,
removeConversationFromConversationsQuery,
} from "@/queries/use-conversations-query";
import { getConversationQueryData } from "@/queries/useConversationQuery";
import { getDmQueryData, setDmQueryData } from "@/queries/useDmQuery";
import { updateObjectAndMethods } from "@/utils/update-object-and-methods";
import { DmWithCodecsType } from "@/utils/xmtpRN/client.types";
import {
ConversationWithCodecsType,
DmWithCodecsType,
} from "@/utils/xmtpRN/client.types";
import { useMutation } from "@tanstack/react-query";
import {
ConversationId,
Expand All @@ -16,17 +26,16 @@ import {
import { updateConsentForGroupsForAccount } from "./update-consent-for-groups-for-account";
import { updateInboxIdsConsentForAccount } from "./update-inbox-ids-consent-for-account";

export function useDmConsentForCurrentAccount() {
export function useAllowDmMutation() {
const currentAccount = useCurrentAccount()!;

return useMutation({
mutationFn: async (args: {
consent: "allow" | "deny";
peerInboxId: InboxId;
conversationId: ConversationId;
topic: ConversationTopic;
}) => {
const { peerInboxId, conversationId, topic } = args;
const { peerInboxId, conversationId } = args;
if (!peerInboxId) {
throw new Error("Peer inbox id not found");
}
Expand All @@ -35,24 +44,23 @@ export function useDmConsentForCurrentAccount() {
updateConsentForGroupsForAccount({
account: currentAccount,
groupIds: [conversationId],
consent: args.consent,
consent: "allow",
}),
updateInboxIdsConsentForAccount({
account: currentAccount,
inboxIds: [peerInboxId],
consent: args.consent,
consent: "allow",
}),
]);
},
onMutate: (args) => {
const { peerInboxId, conversationId, topic } = args;
onMutate: ({ topic }) => {
const conversation = getConversationQueryData({
account: currentAccount,
topic,
});
if (conversation) {
const updatedDm = updateObjectAndMethods(conversation, {
state: args.consent === "allow" ? "allowed" : "denied",
state: "allowed",
});

setDmQueryData({
Expand All @@ -61,41 +69,53 @@ export function useDmConsentForCurrentAccount() {
dm: updatedDm as DmWithCodecsType,
});

updateConversationInConversationsQueryData({
// Add to main conversations list
addConversationToConversationsQuery({
account: currentAccount,
conversation: updatedDm as ConversationWithCodecsType,
});

// Remove from requests
removeConversationFromUnknownConsentConversationsQueryData({
account: currentAccount,
topic,
conversationUpdate: {
state: args.consent === "allow" ? "allowed" : "denied",
},
});

return { previousDmConsent: conversation.state };
}
},
onError: (error, variables, context) => {
const { topic } = variables;
onError: (error, { topic }, context) => {
const { previousDmConsent } = context || {};
if (previousDmConsent) {
const dm = getDmQueryData({
account: currentAccount,
peer: topic,
});

if (!dm) {
return;
}
const updatedDm = updateObjectAndMethods(dm, {

const previousDm = updateObjectAndMethods(dm, {
state: previousDmConsent,
});

setDmQueryData({
account: currentAccount,
peer: topic,
dm: updatedDm,
dm: previousDm,
});
updateConversationInConversationsQueryData({

// Add back in requests
addConversationToUnknownConsentConversationsQuery({
account: currentAccount,
conversation: previousDm as ConversationWithCodecsType,
});

// Remove from main conversations list
removeConversationFromConversationsQuery({
account: currentAccount,
topic,
conversationUpdate: {
state: previousDmConsent,
},
});
}
},
Expand Down
Loading
Loading