106 lines
3.6 KiB
TypeScript
106 lines
3.6 KiB
TypeScript
// Metro module 11772 (f11773).
|
|
import ConnectedAccountsStore from "../../../stores/ConnectedAccountsStore";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import { deleteStoredContacts, setStoredContacts, useContactSyncStore } from "./ContactSyncPersistedStore";
|
|
import { ContactPermissions } from "./ContactSyncConstants";
|
|
import { PlatformTypes } from "../../../Constants";
|
|
import { Storage } from "../../../_bundle/Module595";
|
|
import { getContacts, uploadContacts, isContactSyncEnabled, checkContactPermissions } from "./ContactSyncUtils";
|
|
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
|
|
import { runAfterInteractions } from "../../../utils/native/RunAfterInteractionsUtils";
|
|
let c8065_10;
|
|
let _requestAndSyncContacts = function _requestAndSyncContacts() {
|
|
const r8 = async () => {
|
|
let c27157_0;
|
|
let c27157_4 = 0;
|
|
let c30444_0, c30444_1, c30444_2, c30444_3;
|
|
L25: {
|
|
L23: {
|
|
try {
|
|
c30444_0 = void 0;
|
|
c30444_1 = void 0;
|
|
c30444_2 = void 0;
|
|
c30444_3 = void 0;
|
|
const r37 = Storage.get(c8065_10, 0);
|
|
c27157_0 = r37;
|
|
if (r37 == null) {
|
|
c27157_0 = 0;
|
|
}
|
|
const r38 = c27157_0;
|
|
const r41 = Date.now();
|
|
c30444_0 = r41;
|
|
c27157_4 = 1;
|
|
if (r38 + 86400000 <= r41) {
|
|
const phone = UserStore.getCurrentUser()?.phone;
|
|
if (phone == null) {
|
|
c27157_4 = 0;
|
|
break L25;
|
|
}
|
|
c30444_1 = await getContacts(phone, useContactSyncStore.getState().storedContacts);
|
|
c30444_2 = c30444_1.names;
|
|
c30444_3 = c30444_1.payload;
|
|
(0, setStoredContacts)(c30444_2);
|
|
if (c30444_3 != null) {
|
|
await uploadContacts(c30444_3, true);
|
|
}
|
|
Storage.set(c8065_10, c30444_0);
|
|
c27157_4 = 0;
|
|
break L23;
|
|
}
|
|
c27157_4 = 0;
|
|
} catch ($e) {
|
|
let r7 = $e;
|
|
if (c27157_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c27157_4 = 0;
|
|
(0, deleteStoredContacts)();
|
|
break L23;
|
|
} catch ($e) {
|
|
r7 = $e;
|
|
if (c27157_4 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
_requestAndSyncContacts = r8;
|
|
return r8.apply(this, arguments);
|
|
};
|
|
c8065_10 = "LAST_USER_CONTACTS_REQUEST_TIMESTAMP_KEY";
|
|
class ContactSyncLifecycleManager extends AutomaticLifecycleManager {
|
|
constructor() {
|
|
super(...arguments);
|
|
const _this = this;
|
|
this.actions = {
|
|
POST_CONNECTION_OPEN: () => _this.handleConnectionOpen()
|
|
};
|
|
this.handleConnectionOpen = () => {
|
|
if (UserStore.getCurrentUser() != null) {
|
|
if (isContactSyncEnabled(ConnectedAccountsStore.getLocalAccount(PlatformTypes.CONTACTS))) {
|
|
checkContactPermissions().then((result) => {
|
|
if (result === ContactPermissions.AUTHORIZED) {
|
|
runAfterInteractions(() => (function requestAndSyncContacts() {
|
|
return _requestAndSyncContacts.apply(this, arguments);
|
|
})());
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
const contactSyncLifecycleManager = new ContactSyncLifecycleManager();
|
|
export default contactSyncLifecycleManager;
|
|
export const LAST_USER_CONTACTS_REQUEST_TIMESTAMP_KEY = "LAST_USER_CONTACTS_REQUEST_TIMESTAMP_KEY";
|
|
export function removeLastUserContactsUpload() {
|
|
Storage.remove(c8065_10);
|
|
}
|