Files
discord-decomp/modules/contact_sync/native/components/ContactSyncSettings.tsx
T
2026-11-01 12:12:55 +02:00

208 lines
7.0 KiB
TypeScript

// Metro module 13875 (f13876).
import UserStore from "../../../../stores/UserStore";
import { deleteStoredContacts, setStoredContacts } from "../ContactSyncPersistedStore";
import { AnalyticEvents, AnalyticsSections, FriendDiscoveryFlags } from "../../../../Constants";
import * as _ContactSyncUtils from "../ContactSyncUtils";
import { getContacts, uploadContacts, ContactSyncPermissionDenied, useContactSyncAccount, adminDeleteContactSync, handleOpenLearnMoreLink } from "../ContactSyncUtils";
import ToastActionCreators from "../../../toast/native/ToastActionCreators";
import { intl, t } from "../../../../intl/index.native";
import Module9172 from "../../../../_bundle/Module9172";
import ContactSyncActionCreators from "../ContactSyncActionCreators";
import AnalyticsUtils from "../../../../utils/AnalyticsUtils";
import { openContactSyncModal } from "../ContactSyncModalActionCreators";
import { useStateFromStores } from "../../../../_bundle/Module589";
import { FriendDiscoverySettings } from "../../../user_settings/UserSettings";
import * as _Module1384 from "../../../../_bundle/Module1384";
import { FormSection, FormSwitchRow, FormDivider, FormRow, FormHint } from "../../../../design/void/Form/native/index";
import ModalActionCreators from "../../../../actions/ModalActionCreators";
let updateFriendSync;
const syncContacts = async function syncContacts(c27584_0, c27584_1, c27584_2) {
let c27584_5;
let c27584_6 = 0;
let c30673_0, c30673_1, c30673_2;
L17: {
L16: {
try {
c30673_0 = void 0;
c30673_1 = void 0;
c30673_2 = void 0;
deleteStoredContacts();
if (!c27584_2) {
break L17;
}
if (c27584_0 == null) {
break L17;
}
if (c27584_1 != null) {
c27584_6 = 1;
c30673_0 = await getContacts(c27584_1);
c30673_1 = c30673_0.names;
c30673_2 = c30673_0.payload;
(0, setStoredContacts)(c30673_1);
await uploadContacts(c30673_2, true);
c27584_6 = 0;
break L16;
}
break L17;
} catch ($e) {
const r33 = $e;
let r8 = r33;
c27584_5 = r33;
if (c27584_6 !== 0) {
while (true) {
try {
const r102 = c27584_5;
c27584_6 = 0;
if (r102 !== ContactSyncPermissionDenied) {
break L16;
}
ToastActionCreators.open({
key: "CONTACT_SYNC_NEEDS_PERMISSIONS",
content: intl.string(t["h+jFOs"]),
icon: Module9172
});
break L16;
} catch (r99) {
r8 = r99;
c27584_5 = r99;
if (c27584_6 === 0) {
break;
}
}
}
}
throw r8;
}
}
return void 0;
}
};
updateFriendSync = async function updateFriendSync(c27585_0, c27585_1, enabled) {
let c27585_6 = 0;
let c30674_0, c30674_1, c30674_2;
L15: {
try {
c30674_0 = c27585_0;
c30674_1 = c27585_1;
c30674_2 = enabled;
if (c27585_0 != null) {
c27585_6 = 1;
await ContactSyncActionCreators.updateContactSyncEnabled({
enabled
});
await (0, syncContacts)(c30674_0, c30674_1, c30674_2);
c27585_6 = 0;
break L15;
}
} catch ($e) {
let r8 = $e;
if (c27585_6 !== 0) {
while (true) {
try {
c27585_6 = 0;
ToastActionCreators.open({
key: "CONTACT_SYNC_FAILED_ALERT_TITLE",
content: intl.string(t.GCwBtE),
icon: Module9172
});
break L15;
} catch ($e) {
r8 = $e;
if (c27585_6 === 0) {
break;
}
}
}
}
throw r8;
}
return void 0;
}
};
export default function ContactSyncSettings() {
let phone, hasFlag, hasFlag2;
const contactSyncAccount = useContactSyncAccount();
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
phone = stateFromStores?.phone;
const r7 = stateFromStores == null ? void 0 : stateFromStores.isStaff();
const isContactSyncEnabled = _ContactSyncUtils.isContactSyncEnabled(contactSyncAccount);
const setting = FriendDiscoverySettings.useSetting();
hasFlag = _Module1384.hasFlag(setting, FriendDiscoveryFlags.FIND_BY_PHONE);
hasFlag2 = _Module1384.hasFlag(setting, FriendDiscoveryFlags.FIND_BY_EMAIL);
return <>
<FormSection title={intl.string(t.bGSsnc)}>
{r7 ? <>
<FormSwitchRow label="STAFF ONLY - Find your friends deletion" value onValueChange={adminDeleteContactSync} />
<FormDivider />
</> : null}
<FormSwitchRow label={intl.string(t.uSvEy7)} value={isContactSyncEnabled} onValueChange={(value) => {
if (contactSyncAccount == null) {
AnalyticsUtils.track(AnalyticEvents.OPEN_MODAL, {
type: AnalyticsSections.CONTACT_SYNC_MODAL,
location: {
page: "User Settings"
}
});
openContactSyncModal({}, {
page: "User Settings"
});
} else {
updateFriendSync(contactSyncAccount, phone, value);
}
}} />
{contactSyncAccount != null ? <>
<FormDivider />
<FormRow label={intl.string(t.nAsWKy)} trailing={<FormRow.Arrow label={contactSyncAccount.name} />} onPress={function onPress() {
AnalyticsUtils.track(AnalyticEvents.OPEN_MODAL, {
type: "Change Name",
location: {
page: "User Settings"
}
});
ModalActionCreators.pushLazy(import("./ContactSyncNameUpdateModal"), "Contact Sync Name Update Modal");
}} />
</> : null}
</FormSection>
<FormHint>
{intl.format(t.BoR0dO, {
onClick: handleOpenLearnMoreLink
})}
</FormHint>
<FormHint>
{intl.string(t.cW1nr9)}
</FormHint>
<FormSection title={intl.string(t["0t2wRW"])}>
<FormSwitchRow label={intl.string(t["eJnn0+"])} subLabel={intl.string(t.X7pIKN)} value={hasFlag} onValueChange={function onValueChange(value) {
ContactSyncActionCreators.updateDiscoverability({
phone: value,
email: hasFlag2
});
}} />
<FormDivider />
<FormSwitchRow label={intl.string(t.dI4d4S)} subLabel={intl.string(t.ilGsHE)} value={hasFlag2} onValueChange={function onValueChange(value) {
ContactSyncActionCreators.updateDiscoverability({
phone: hasFlag,
email: value
});
}} />
</FormSection>
</>;
};
export { syncContacts };
export { updateFriendSync };
export function handleSyncContacts(a0, a1, a2) {
if (a0 == null) {
AnalyticsUtils.track(AnalyticEvents.OPEN_MODAL, {
type: AnalyticsSections.CONTACT_SYNC_MODAL,
location: {
page: "User Settings"
}
});
openContactSyncModal({}, {
page: "User Settings"
});
} else {
updateFriendSync(a0, a1, a2);
}
}