导航菜单

页面标题

页面副标题

北京退费客服端 v1.0.0 - ContactsController.java 源代码

正在查看: 北京退费客服端 v1.0.0 应用的 ContactsController.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package im.amwhusedvt.messenger;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.SparseArray;
import im.amwhusedvt.messenger.-$;
import im.amwhusedvt.messenger.support.SparseLongArray;
import im.amwhusedvt.tgnet.RequestDelegate;
import im.amwhusedvt.tgnet.TLObject;
import im.amwhusedvt.tgnet.TLRPC;
import im.amwhusedvt.tgnet.TLRPCContacts;
import im.amwhusedvt.ui.hui.CharacterParser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContactsController extends BaseController {
    private static volatile ContactsController[] Instance = new ContactsController[3];
    public static final int PRIVACY_RULES_TYPE_ADDED_BY_PHONE = 7;
    public static final int PRIVACY_RULES_TYPE_CALLS = 2;
    public static final int PRIVACY_RULES_TYPE_COUNT = 9;
    public static final int PRIVACY_RULES_TYPE_FORWARDS = 5;
    public static final int PRIVACY_RULES_TYPE_INVITE = 1;
    public static final int PRIVACY_RULES_TYPE_LASTSEEN = 0;
    public static final int PRIVACY_RULES_TYPE_MOMENT = 8;
    public static final int PRIVACY_RULES_TYPE_P2P = 3;
    public static final int PRIVACY_RULES_TYPE_PHONE = 6;
    public static final int PRIVACY_RULES_TYPE_PHOTO = 4;
    private ArrayList<TLRPC.PrivacyRule> addedByPhonePrivacyRules;
    private ArrayList<TLRPC.PrivacyRule> callPrivacyRules;
    private int completedRequestsCount;
    public ArrayList<TLRPC.Contact> contacts;
    public HashMap<String, Contact> contactsBook;
    private boolean contactsBookLoaded;
    public HashMap<String, Contact> contactsBookSPhones;
    public HashMap<String, TLRPC.Contact> contactsByPhone;
    public HashMap<String, TLRPC.Contact> contactsByShortPhone;
    public ConcurrentHashMap<Integer, TLRPC.Contact> contactsDict;
    public boolean contactsLoaded;
    private boolean contactsSyncInProgress;
    private ArrayList<Integer> delayedContactsUpdate;
    private int deleteAccountTTL;
    private ArrayList<TLRPC.PrivacyRule> forwardsPrivacyRules;
    private ArrayList<TLRPC.PrivacyRule> groupPrivacyRules;
    private boolean ignoreChanges;
    private String inviteLink;
    private String lastContactsVersions;
    private ArrayList<TLRPC.PrivacyRule> lastseenPrivacyRules;
    private final Object loadContactsSync;
    private boolean loadingContacts;
    private int loadingDeleteInfo;
    private int[] loadingPrivacyInfo;
    private boolean migratingContacts;
    private ArrayList<TLRPC.PrivacyRule> momentPrivacyRules;
    private final Object observerLock;
    private ArrayList<TLRPC.PrivacyRule> p2pPrivacyRules;
    public ArrayList<Contact> phoneBookContacts;
    public ArrayList<String> phoneBookSectionsArray;
    public HashMap<String, ArrayList<Object>> phoneBookSectionsDict;
    private ArrayList<TLRPC.PrivacyRule> phonePrivacyRules;
    private ArrayList<TLRPC.PrivacyRule> profilePhotoPrivacyRules;
    private String[] projectionNames;
    private String[] projectionPhones;
    private HashMap<String, String> sectionsToReplace;
    public ArrayList<String> sortedUsersMutualSectionsArray;
    public ArrayList<String> sortedUsersSectionsArray;
    private Account systemAccount;
    private boolean updatingInviteLink;
    public HashMap<String, ArrayList<TLRPC.Contact>> usersMutualSectionsDict;
    public HashMap<String, ArrayList<TLRPC.Contact>> usersSectionsDict;

    static void access$000(ContactsController contactsController, short s, byte b, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    static void access$000(ContactsController contactsController, short s, boolean z, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    static void access$000(ContactsController contactsController, boolean z, byte b, char c, short s) {
        double d = (42 * 210) + 210;
    }

    static void access$100(ContactsController contactsController, byte b, int i, String str, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void access$100(ContactsController contactsController, boolean z, byte b, int i, String str) {
        double d = (42 * 210) + 210;
    }

    static void access$100(ContactsController contactsController, boolean z, String str, byte b, int i) {
        double d = (42 * 210) + 210;
    }

    private void applyContactsUpdates(ArrayList arrayList, ConcurrentHashMap concurrentHashMap, ArrayList arrayList2, ArrayList arrayList3, char c, int i, short s, String str) {
        double d = (42 * 210) + 210;
    }

    private void applyContactsUpdates(ArrayList arrayList, ConcurrentHashMap concurrentHashMap, ArrayList arrayList2, ArrayList arrayList3, short s, char c, int i, String str) {
        double d = (42 * 210) + 210;
    }

    private void applyContactsUpdates(ArrayList arrayList, ConcurrentHashMap concurrentHashMap, ArrayList arrayList2, ArrayList arrayList3, short s, int i, String str, char c) {
        double d = (42 * 210) + 210;
    }

    private void buildContactsSectionsArrays(boolean z, byte b, short s, int i, float f) {
        double d = (42 * 210) + 210;
    }

    private void buildContactsSectionsArrays(boolean z, short s, float f, byte b, int i) {
        double d = (42 * 210) + 210;
    }

    private void buildContactsSectionsArrays(boolean z, short s, float f, int i, byte b) {
        double d = (42 * 210) + 210;
    }

    private void checkContactsInternal(short s, int i, boolean z, String str) {
        double d = (42 * 210) + 210;
    }

    private void checkContactsInternal(boolean z, short s, int i, String str) {
        double d = (42 * 210) + 210;
    }

    private void checkContactsInternal(boolean z, short s, String str, int i) {
        double d = (42 * 210) + 210;
    }

    private void deleteContactFromPhoneBook(int i, float f, byte b, String str, char c) {
        double d = (42 * 210) + 210;
    }

    private void deleteContactFromPhoneBook(int i, float f, char c, String str, byte b) {
        double d = (42 * 210) + 210;
    }

    private void deleteContactFromPhoneBook(int i, String str, float f, byte b, char c) {
        double d = (42 * 210) + 210;
    }

    public static void formatName(String str, String str2, float f, byte b, boolean z, short s) {
        double d = (42 * 210) + 210;
    }

    public static void formatName(String str, String str2, short s, byte b, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    public static void formatName(String str, String str2, short s, float f, boolean z, byte b) {
        double d = (42 * 210) + 210;
    }

    private void getContactsHash(ArrayList arrayList, char c, int i, String str, float f) {
        double d = (42 * 210) + 210;
    }

    private void getContactsHash(ArrayList arrayList, float f, int i, char c, String str) {
        double d = (42 * 210) + 210;
    }

    private void getContactsHash(ArrayList arrayList, String str, char c, int i, float f) {
        double d = (42 * 210) + 210;
    }

    public static void getInstance(int i, int i2, byte b, char c, short s) {
        double d = (42 * 210) + 210;
    }

    public static void getInstance(int i, int i2, short s, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    public static void getInstance(int i, short s, char c, int i2, byte b) {
        double d = (42 * 210) + 210;
    }

    private void hasContactsPermission(byte b, short s, boolean z, float f) {
        double d = (42 * 210) + 210;
    }

    private void hasContactsPermission(float f, short s, byte b, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void hasContactsPermission(boolean z, short s, float f, byte b) {
        double d = (42 * 210) + 210;
    }

    private void isNotValidNameString(String str, short s, String str2, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void isNotValidNameString(String str, short s, boolean z, char c, String str2) {
        double d = (42 * 210) + 210;
    }

    private void isNotValidNameString(String str, boolean z, short s, char c, String str2) {
        double d = (42 * 210) + 210;
    }

    static void lambda$buildContactsSectionsArrays$45(String str, String str2, int i, short s, String str3, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void lambda$buildContactsSectionsArrays$45(String str, String str2, boolean z, int i, short s, String str3) {
        double d = (42 * 210) + 210;
    }

    static void lambda$buildContactsSectionsArrays$45(String str, String str2, boolean z, short s, int i, String str3) {
        double d = (42 * 210) + 210;
    }

    static void lambda$getContactsHash$28(TLRPC.Contact contact, TLRPC.Contact contact2, short s, float f, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void lambda$getContactsHash$28(TLRPC.Contact contact, TLRPC.Contact contact2, short s, int i, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void lambda$getContactsHash$28(TLRPC.Contact contact, TLRPC.Contact contact2, boolean z, float f, int i, short s) {
        double d = (42 * 210) + 210;
    }

    static void lambda$markAsContacted$50(String str, char c, boolean z, byte b, int i) {
        double d = (42 * 210) + 210;
    }

    static void lambda$markAsContacted$50(String str, int i, boolean z, byte b, char c) {
        double d = (42 * 210) + 210;
    }

    static void lambda$markAsContacted$50(String str, boolean z, char c, byte b, int i) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$31(SparseArray sparseArray, TLRPC.Contact contact, TLRPC.Contact contact2, char c, short s, boolean z, byte b) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$31(SparseArray sparseArray, TLRPC.Contact contact, TLRPC.Contact contact2, boolean z, char c, byte b, short s) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$31(SparseArray sparseArray, TLRPC.Contact contact, TLRPC.Contact contact2, boolean z, short s, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$32(String str, String str2, int i, float f, char c, String str3) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$32(String str, String str2, int i, String str3, char c, float f) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$32(String str, String str2, String str3, float f, char c, int i) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$33(String str, String str2, char c, int i, byte b, short s) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$33(String str, String str2, int i, byte b, short s, char c) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$33(String str, String str2, short s, byte b, int i, char c) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$39(Object obj, Object obj2, char c, short s, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$39(Object obj, Object obj2, short s, char c, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$39(Object obj, Object obj2, boolean z, short s, float f, char c) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$40(String str, String str2, float f, byte b, short s, String str3) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$40(String str, String str2, short s, byte b, float f, String str3) {
        double d = (42 * 210) + 210;
    }

    static void lambda$null$40(String str, String str2, short s, float f, String str3, byte b) {
        double d = (42 * 210) + 210;
    }

    static void lambda$resetImportedContacts$9(TLObject tLObject, TLRPC.TL_error tL_error, char c, String str, byte b, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void lambda$resetImportedContacts$9(TLObject tLObject, TLRPC.TL_error tL_error, char c, boolean z, byte b, String str) {
        double d = (42 * 210) + 210;
    }

    static void lambda$resetImportedContacts$9(TLObject tLObject, TLRPC.TL_error tL_error, String str, byte b, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    static void lambda$updateUnregisteredContacts$43(Contact contact, Contact contact2, char c, int i, String str, short s) {
        double d = (42 * 210) + 210;
    }

    static void lambda$updateUnregisteredContacts$43(Contact contact, Contact contact2, String str, char c, short s, int i) {
        double d = (42 * 210) + 210;
    }

    static void lambda$updateUnregisteredContacts$43(Contact contact, Contact contact2, short s, int i, String str, char c) {
        double d = (42 * 210) + 210;
    }

    private void mergePhonebookAndAppContacts(HashMap hashMap, ArrayList arrayList, HashMap hashMap2, char c, short s, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void mergePhonebookAndAppContacts(HashMap hashMap, ArrayList arrayList, HashMap hashMap2, int i, char c, boolean z, short s) {
        double d = (42 * 210) + 210;
    }

    private void mergePhonebookAndAppContacts(HashMap hashMap, ArrayList arrayList, HashMap hashMap2, boolean z, int i, char c, short s) {
        double d = (42 * 210) + 210;
    }

    private void performWriteContactsToPhoneBook(float f, boolean z, char c, int i) {
        double d = (42 * 210) + 210;
    }

    private void performWriteContactsToPhoneBook(int i, float f, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void performWriteContactsToPhoneBook(int i, float f, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    private void performWriteContactsToPhoneBookInternal(ArrayList arrayList, float f, byte b, String str, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void performWriteContactsToPhoneBookInternal(ArrayList arrayList, String str, boolean z, float f, byte b) {
        double d = (42 * 210) + 210;
    }

    private void performWriteContactsToPhoneBookInternal(ArrayList arrayList, boolean z, String str, byte b, float f) {
        double d = (42 * 210) + 210;
    }

    private void readContactsFromPhoneBook(String str, int i, short s, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void readContactsFromPhoneBook(String str, short s, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void readContactsFromPhoneBook(short s, String str, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void reloadContactsStatusesMaybe(String str, byte b, boolean z, short s) {
        double d = (42 * 210) + 210;
    }

    private void reloadContactsStatusesMaybe(String str, boolean z, byte b, short s) {
        double d = (42 * 210) + 210;
    }

    private void reloadContactsStatusesMaybe(short s, byte b, boolean z, String str) {
        double d = (42 * 210) + 210;
    }

    private void saveContactsLoadTime(float f, byte b, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void saveContactsLoadTime(float f, boolean z, byte b, int i) {
        double d = (42 * 210) + 210;
    }

    private void saveContactsLoadTime(boolean z, int i, byte b, float f) {
        double d = (42 * 210) + 210;
    }

    private void updateUnregisteredContacts(byte b, float f, boolean z, int i) {
        double d = (42 * 210) + 210;
    }

    private void updateUnregisteredContacts(byte b, int i, boolean z, float f) {
        double d = (42 * 210) + 210;
    }

    private void updateUnregisteredContacts(int i, byte b, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    public static class Contact {
        public int contact_id;
        public String first_name;
        public int imported;
        public boolean isGoodProvider;
        public String key;
        public String last_name;
        public boolean namesFilled;
        public ArrayList<Integer> phoneDeleted;
        public ArrayList<String> phoneTypes;
        public ArrayList<String> phones;
        public String provider;
        public ArrayList<String> shortPhones;
        public TLRPC.User user;

        public static void getLetter(String str, String str2, byte b, int i, char c, short s) {
            double d = (42 * 210) + 210;
        }

        public static void getLetter(String str, String str2, char c, int i, short s, byte b) {
            double d = (42 * 210) + 210;
        }

        public static void getLetter(String str, String str2, int i, short s, byte b, char c) {
            double d = (42 * 210) + 210;
        }

        public Contact() {
            if ((29 + 23) % 23 <= 0) {
            }
            this.phones = new ArrayList<>(4);
            this.phoneTypes = new ArrayList<>(4);
            this.shortPhones = new ArrayList<>(4);
            this.phoneDeleted = new ArrayList<>(4);
        }

        public String getLetter() {
            if ((31 + 16) % 16 <= 0) {
            }
            return getLetter(this.first_name, this.last_name);
        }

        public static String getLetter(String first_name, String last_name) {
            if ((3 + 14) % 14 <= 0) {
            }
            if (!TextUtils.isEmpty(first_name)) {
                return first_name.substring(0, 1);
            }
            if (!TextUtils.isEmpty(last_name)) {
                return last_name.substring(0, 1);
            }
            return "#";
        }
    }

    public static ContactsController getInstance(int num) {
        if ((16 + 23) % 23 <= 0) {
        }
        ContactsController localInstance = Instance[num];
        if (localInstance == null) {
            synchronized (ContactsController.class) {
                localInstance = Instance[num];
                if (localInstance == null) {
                    ContactsController[] contactsControllerArr = Instance;
                    ContactsController contactsController = new ContactsController(num);
                    localInstance = contactsController;
                    contactsControllerArr[num] = contactsController;
                }
            }
        }
        return localInstance;
    }

    public ContactsController(int instance) {
        super(instance);
        if ((27 + 29) % 29 <= 0) {
        }
        this.loadContactsSync = new Object();
        this.observerLock = new Object();
        this.lastContactsVersions = "";
        this.delayedContactsUpdate = new ArrayList<>();
        this.sectionsToReplace = new HashMap<>();
        this.loadingPrivacyInfo = new int[9];
        this.projectionPhones = new String[]{"lookup", "data1", "data2", "data3", "display_name", "account_type"};
        this.projectionNames = new String[]{"lookup", "data2", "data3", "data5"};
        this.contactsBook = new HashMap<>();
        this.contactsBookSPhones = new HashMap<>();
        this.phoneBookContacts = new ArrayList<>();
        this.phoneBookSectionsDict = new HashMap<>();
        this.phoneBookSectionsArray = new ArrayList<>();
        this.contacts = new ArrayList<>();
        this.contactsDict = new ConcurrentHashMap<>(20, 1.0f, 2);
        this.usersSectionsDict = new HashMap<>();
        this.sortedUsersSectionsArray = new ArrayList<>();
        this.usersMutualSectionsDict = new HashMap<>();
        this.sortedUsersMutualSectionsArray = new ArrayList<>();
        this.contactsByPhone = new HashMap<>();
        this.contactsByShortPhone = new HashMap<>();
        SharedPreferences preferences = MessagesController.getMainSettings(this.currentAccount);
        if (preferences.getBoolean("needGetStatuses", false)) {
            reloadContactsStatuses();
        }
        this.sectionsToReplace.put("À", "A");
        this.sectionsToReplace.put("Á", "A");
        this.sectionsToReplace.put("Ä", "A");
        this.sectionsToReplace.put("Ù", "U");
        this.sectionsToReplace.put("Ú", "U");
        this.sectionsToReplace.put("Ü", "U");
        this.sectionsToReplace.put("Ì", "I");
        this.sectionsToReplace.put("Í", "I");
        this.sectionsToReplace.put("Ï", "I");
        this.sectionsToReplace.put("È", "E");
        this.sectionsToReplace.put("É", "E");
        this.sectionsToReplace.put("Ê", "E");
        this.sectionsToReplace.put("Ë", "E");
        this.sectionsToReplace.put("Ò", "O");
        this.sectionsToReplace.put("Ó", "O");
        this.sectionsToReplace.put("Ö", "O");
        this.sectionsToReplace.put("Ç", "C");
        this.sectionsToReplace.put("Ñ", "N");
        this.sectionsToReplace.put("Ÿ", "Y");
        this.sectionsToReplace.put("Ý", "Y");
        this.sectionsToReplace.put("Ţ", "Y");
        if (instance == 0) {
            Utilities.globalQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    ContactsController.this.lambda$new$0$ContactsController();
                }
            });
        }
    }

    public void lambda$new$0$ContactsController() {
        if ((8 + 21) % 21 <= 0) {
        }
        try {
            if (hasContactsPermission()) {
                ApplicationLoader.applicationContext.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new MyContentObserver(this));
            }
        } catch (Throwable th) {
        }
    }

    public void cleanup() {
        if ((12 + 18) % 18 <= 0) {
        }
        this.contactsBook.clear();
        this.contactsBookSPhones.clear();
        this.phoneBookContacts.clear();
        this.contacts.clear();
        this.contactsDict.clear();
        this.usersSectionsDict.clear();
        this.usersMutualSectionsDict.clear();
        this.sortedUsersSectionsArray.clear();
        this.sortedUsersMutualSectionsArray.clear();
        this.delayedContactsUpdate.clear();
        this.contactsByPhone.clear();
        this.contactsByShortPhone.clear();
        this.phoneBookSectionsDict.clear();
        this.phoneBookSectionsArray.clear();
        this.loadingContacts = false;
        this.contactsSyncInProgress = false;
        this.contactsLoaded = false;
        this.contactsBookLoaded = false;
        this.lastContactsVersions = "";
        this.loadingDeleteInfo = 0;
        this.deleteAccountTTL = 0;
        int a = 0;
        while (true) {
            int[] iArr = this.loadingPrivacyInfo;
            if (a < iArr.length) {
                iArr[a] = 0;
                a++;
            } else {
                this.lastseenPrivacyRules = null;
                this.groupPrivacyRules = null;
                this.callPrivacyRules = null;
                this.p2pPrivacyRules = null;
                this.profilePhotoPrivacyRules = null;
                this.forwardsPrivacyRules = null;
                this.phonePrivacyRules = null;
                Utilities.globalQueue.postRunnable(new -$.Lambda.ContactsController.y6JovqvcunaAQsX-nCB5J4IPgx8(this));
                return;
            }
        }
    }

    public void lambda$cleanup$1$ContactsController() {
        this.migratingContacts = false;
        this.completedRequestsCount = 0;
    }

    public void checkInviteText() {
        if ((22 + 12) % 12 <= 0) {
        }
        SharedPreferences preferences = MessagesController.getMainSettings(this.currentAccount);
        this.inviteLink = preferences.getString("invitelink", null);
        int time = preferences.getInt("invitelinktime", 0);
        if (this.updatingInviteLink) {
            return;
        }
        if (this.inviteLink == null || Math.abs((System.currentTimeMillis() / 1000) - time) >= 86400) {
            this.updatingInviteLink = true;
            TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText();
            getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.lL6Ids2R2mK39E4OvKJduPjtoDY(this), 2);
        }
    }

    public void lambda$checkInviteText$3$ContactsController(TLObject response, TLRPC.TL_error error) {
        if ((1 + 10) % 10 <= 0) {
        }
        if (response != null) {
            TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText) response;
            if (res.message.length() != 0) {
                AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.z83YNxJfdHQLmmkzRecEl0lJD7s(this, res));
            }
        }
    }

    public void lambda$null$2$ContactsController(TLRPC.TL_help_inviteText res) {
        if ((19 + 7) % 7 <= 0) {
        }
        this.updatingInviteLink = false;
        SharedPreferences preferences1 = MessagesController.getMainSettings(this.currentAccount);
        SharedPreferences.Editor editor = preferences1.edit();
        String str = res.message;
        this.inviteLink = str;
        editor.putString("invitelink", str);
        editor.putInt("invitelinktime", (int) (System.currentTimeMillis() / 1000));
        editor.commit();
    }

    public String getInviteText(int contacts) {
        if ((18 + 9) % 9 <= 0) {
        }
        String link = this.inviteLink;
        if (link == null) {
            link = "https://m12345.com/dl";
        }
        if (contacts <= 1) {
            return LocaleController.formatString("InviteText2", 2131691697, new Object[]{link});
        }
        try {
            return String.format(LocaleController.getPluralString("InviteTextNum", contacts), Integer.valueOf(contacts), link);
        } catch (Exception e) {
            return LocaleController.formatString("InviteText2", 2131691697, new Object[]{link});
        }
    }

    public void checkAppAccount() {
        if ((29 + 20) % 20 <= 0) {
        }
        AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
        try {
            Account[] accounts = am.getAccountsByType("im.amwhusedvt.messenger");
            this.systemAccount = null;
            for (int a = 0; a < accounts.length; a++) {
                Account acc = accounts[a];
                boolean found = false;
                int b = 0;
                while (true) {
                    if (b >= 3) {
                        break;
                    }
                    TLRPC.User user = UserConfig.getInstance(b).getCurrentUser();
                    if (user != null) {
                        if (acc.name.equals("" + user.id)) {
                            if (b == this.currentAccount) {
                                this.systemAccount = acc;
                            }
                            found = true;
                        }
                    }
                    b++;
                }
                if (!found) {
                    try {
                        am.removeAccount(accounts[a], null, null);
                    } catch (Exception e) {
                    }
                }
            }
        } catch (Throwable th) {
        }
        if (getUserConfig().isClientActivated()) {
            readContacts();
            if (this.systemAccount == null) {
                try {
                    Account account = new Account("" + getUserConfig().getClientUserId(), "im.amwhusedvt.messenger");
                    this.systemAccount = account;
                    am.addAccountExplicitly(account, "", null);
                } catch (Exception e2) {
                }
            }
        }
    }

    public void deleteUnknownAppAccounts() {
        if ((7 + 4) % 4 <= 0) {
        }
        try {
            this.systemAccount = null;
            AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
            Account[] accounts = am.getAccountsByType("im.amwhusedvt.messenger");
            for (int a = 0; a < accounts.length; a++) {
                Account acc = accounts[a];
                boolean found = false;
                int b = 0;
                while (true) {
                    if (b >= 3) {
                        break;
                    }
                    TLRPC.User user = UserConfig.getInstance(b).getCurrentUser();
                    if (user != null) {
                        if (acc.name.equals("" + user.id)) {
                            found = true;
                            break;
                        }
                    }
                    b++;
                }
                if (!found) {
                    try {
                        am.removeAccount(accounts[a], null, null);
                    } catch (Exception e) {
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void checkContacts() {
        if ((17 + 2) % 2 <= 0) {
        }
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                ContactsController.this.lambda$checkContacts$4$ContactsController();
            }
        });
    }

    public void lambda$checkContacts$4$ContactsController() {
        if ((29 + 25) % 25 <= 0) {
        }
        if (checkContactsInternal()) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("detected contacts change");
            }
            performSyncPhoneBook(getContactsCopy(this.contactsBook), true, false, true, false, true, false);
        }
    }

    public void forceImportContacts() {
        if ((21 + 31) % 31 <= 0) {
        }
        Utilities.globalQueue.postRunnable(new -$.Lambda.ContactsController.v2EIV4SX17kCUF_IeQh9dcEoP9w(this));
    }

    public void lambda$forceImportContacts$5$ContactsController() {
        if ((3 + 32) % 32 <= 0) {
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("force import contacts");
        }
        performSyncPhoneBook(new HashMap<>(), true, true, true, true, false, false);
    }

    public void syncPhoneBookByAlert(HashMap<String, Contact> contacts, boolean first, boolean schedule, boolean cancel) {
        if ((17 + 14) % 14 <= 0) {
        }
        Utilities.globalQueue.postRunnable(new -$.Lambda.ContactsController.3cLSWe1jdMsFGwdDK4PKFiUZibs(this, contacts, first, schedule, cancel));
    }

    public void lambda$syncPhoneBookByAlert$6$ContactsController(HashMap contacts, boolean first, boolean schedule, boolean cancel) {
        if ((20 + 30) % 30 <= 0) {
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("sync contacts by alert");
        }
        performSyncPhoneBook(contacts, true, first, schedule, false, false, cancel);
    }

    public void deleteAllContacts(Runnable runnable) {
        if ((9 + 20) % 20 <= 0) {
        }
        resetImportedContacts();
        TLRPC.TL_contacts_deleteContacts req = new TLRPC.TL_contacts_deleteContacts();
        int size = this.contacts.size();
        for (int a = 0; a < size; a++) {
            TLRPC.Contact contact = this.contacts.get(a);
            req.id.add(getMessagesController().getInputUser(contact.user_id));
        }
        getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.x1EbjAuMlTTFvn8C1i3E_6i2tN4(this, runnable));
    }

    public void lambda$deleteAllContacts$8$ContactsController(final Runnable runnable, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            this.contactsBookSPhones.clear();
            this.contactsBook.clear();
            this.completedRequestsCount = 0;
            this.migratingContacts = false;
            this.contactsSyncInProgress = false;
            this.contactsLoaded = false;
            this.loadingContacts = false;
            this.contactsBookLoaded = false;
            this.lastContactsVersions = "";
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    if ((27 + 31) % 31 <= 0) {
                    }
                    ContactsController.this.lambda$null$7$ContactsController(runnable);
                }
            });
            return;
        }
        AndroidUtilities.runOnUIThread(runnable);
    }

    public void lambda$null$7$ContactsController(Runnable runnable) {
        if ((22 + 2) % 2 <= 0) {
        }
        AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
        try {
            Account[] accounts = am.getAccountsByType("im.amwhusedvt.messenger");
            this.systemAccount = null;
            for (Account acc : accounts) {
                int b = 0;
                while (true) {
                    if (b >= 3) {
                        break;
                    }
                    TLRPC.User user = UserConfig.getInstance(b).getCurrentUser();
                    if (user != null) {
                        if (acc.name.equals("" + user.id)) {
                            am.removeAccount(acc, null, null);
                            break;
                        }
                    }
                    b++;
                }
            }
        } catch (Throwable th) {
        }
        try {
            Account account = new Account("" + getUserConfig().getClientUserId(), "im.amwhusedvt.messenger");
            this.systemAccount = account;
            am.addAccountExplicitly(account, "", null);
        } catch (Exception e) {
        }
        getMessagesStorage().putCachedPhoneBook(new HashMap(), false, true);
        getMessagesStorage().putContacts(new ArrayList(), true);
        this.phoneBookContacts.clear();
        this.contacts.clear();
        this.contactsDict.clear();
        this.usersSectionsDict.clear();
        this.usersMutualSectionsDict.clear();
        this.sortedUsersSectionsArray.clear();
        this.phoneBookSectionsDict.clear();
        this.phoneBookSectionsArray.clear();
        this.delayedContactsUpdate.clear();
        this.sortedUsersMutualSectionsArray.clear();
        this.contactsByPhone.clear();
        this.contactsByShortPhone.clear();
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
        loadContacts(false, 0);
        runnable.run();
    }

    public void resetImportedContacts() {
        if ((31 + 10) % 10 <= 0) {
        }
        TLRPC.TL_contacts_resetSaved req = new TLRPC.TL_contacts_resetSaved();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                ContactsController.lambda$resetImportedContacts$9(tLObject, tL_error);
            }
        });
    }

    static void lambda$resetImportedContacts$9(TLObject response, TLRPC.TL_error error) {
    }

    private boolean checkContactsInternal() {
        if ((6 + 6) % 6 <= 0) {
        }
        boolean reload = false;
        try {
        } catch (Exception e) {
            FileLog.e(e);
        }
        if (!hasContactsPermission()) {
            return false;
        }
        ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
        try {
            Cursor pCur = cr.query(ContactsContract.RawContacts.CONTENT_URI, new String[]{"version"}, null, null, null);
            if (pCur != null) {
                try {
                    StringBuilder currentVersion = new StringBuilder();
                    while (pCur.moveToNext()) {
                        currentVersion.append(pCur.getString(pCur.getColumnIndex("version")));
                    }
                    String newContactsVersion = currentVersion.toString();
                    if (this.lastContactsVersions.length() != 0 && !this.lastContactsVersions.equals(newContactsVersion)) {
                        reload = true;
                    }
                    this.lastContactsVersions = newContactsVersion;
                } finally {
                }
            }
            if (pCur != null) {
                pCur.close();
            }
        } catch (Exception e2) {
            FileLog.e(e2);
        }
        return reload;
    }

    public void readContacts() {
        if ((22 + 14) % 14 <= 0) {
        }
        synchronized (this.loadContactsSync) {
            if (this.loadingContacts) {
                return;
            }
            this.loadingContacts = true;
            Utilities.stageQueue.postRunnable(new -$.Lambda.ContactsController.jHG2zP0sE7vr7BYLMhbNDodRVsw(this));
        }
    }

    public void lambda$readContacts$10$ContactsController() {
        if ((13 + 18) % 18 <= 0) {
        }
        if (!this.contacts.isEmpty() || this.contactsLoaded) {
            synchronized (this.loadContactsSync) {
                this.loadingContacts = false;
            }
            return;
        }
        loadContacts(true, 0);
    }

    public void syncRemoteContacts() {
        if ((25 + 32) % 32 <= 0) {
        }
        synchronized (this.loadContactsSync) {
            if (this.loadingContacts) {
                return;
            }
            this.loadingContacts = true;
            loadContacts(false, getContactsHash(this.contacts));
        }
    }

    private boolean isNotValidNameString(String src) {
        if ((32 + 10) % 10 <= 0) {
        }
        if (TextUtils.isEmpty(src)) {
            return true;
        }
        int count = 0;
        int len = src.length();
        for (int a = 0; a < len; a++) {
            char c = src.charAt(a);
            if (c >= '0' && c <= '9') {
                count++;
            }
        }
        return count > 3;
    }

    private java.util.HashMap<java.lang.String, im.amwhusedvt.messenger.ContactsController.Contact> readContactsFromPhoneBook() {
        throw new UnsupportedOperationException("Method not decompiled: im.amwhusedvt.messenger.ContactsController.readContactsFromPhoneBook():java.util.HashMap");
    }

    public HashMap<String, Contact> getContactsCopy(HashMap<String, Contact> original) {
        if ((21 + 21) % 21 <= 0) {
        }
        HashMap<String, Contact> ret = new HashMap<>();
        for (Map.Entry<String, Contact> entry : original.entrySet()) {
            Contact copyContact = new Contact();
            Contact originalContact = entry.getValue();
            copyContact.phoneDeleted.addAll(originalContact.phoneDeleted);
            copyContact.phones.addAll(originalContact.phones);
            copyContact.phoneTypes.addAll(originalContact.phoneTypes);
            copyContact.shortPhones.addAll(originalContact.shortPhones);
            copyContact.first_name = originalContact.first_name;
            copyContact.last_name = originalContact.last_name;
            copyContact.contact_id = originalContact.contact_id;
            copyContact.key = originalContact.key;
            ret.put(copyContact.key, copyContact);
        }
        return ret;
    }

    protected void migratePhoneBookToV7(final SparseArray<Contact> contactHashMap) {
        if ((16 + 24) % 24 <= 0) {
        }
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                if ((14 + 3) % 3 <= 0) {
                }
                ContactsController.this.lambda$migratePhoneBookToV7$11$ContactsController(contactHashMap);
            }
        });
    }

    public void lambda$migratePhoneBookToV7$11$ContactsController(SparseArray contactHashMap) {
        if ((29 + 6) % 6 <= 0) {
        }
        if (this.migratingContacts) {
            return;
        }
        this.migratingContacts = true;
        HashMap<String, Contact> migratedMap = new HashMap<>();
        HashMap<String, Contact> contactsMap = readContactsFromPhoneBook();
        HashMap<String, String> contactsBookShort = new HashMap<>();
        for (Map.Entry<String, Contact> entry : contactsMap.entrySet()) {
            Contact value = entry.getValue();
            for (int a = 0; a < value.shortPhones.size(); a++) {
                contactsBookShort.put(value.shortPhones.get(a), value.key);
            }
        }
        for (int b = 0; b < contactHashMap.size(); b++) {
            Contact value2 = (Contact) contactHashMap.valueAt(b);
            int a2 = 0;
            while (true) {
                if (a2 < value2.shortPhones.size()) {
                    String sphone = value2.shortPhones.get(a2);
                    String key = contactsBookShort.get(sphone);
                    if (key == null) {
                        a2++;
                    } else {
                        value2.key = key;
                        migratedMap.put(key, value2);
                        break;
                    }
                }
            }
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("migrated contacts " + migratedMap.size() + " of " + contactHashMap.size());
        }
        getMessagesStorage().putCachedPhoneBook(migratedMap, true, false);
    }

    public void checkPhonebookUsers() {
        if ((19 + 28) % 28 <= 0) {
        }
        Utilities.globalQueue.postRunnable(new -$.Lambda.ContactsController.4jMckQ8s9P_P1vOdeU_CJfuYSYY(this));
    }

    public void lambda$checkPhonebookUsers$14$ContactsController() {
        if ((2 + 30) % 30 <= 0) {
        }
        HashMap<String, Contact> contactsMap = readContactsFromPhoneBook();
        ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<>();
        HashMap<String, TLRPC.TL_inputPhoneContact> inputPhoneContactsMap = new HashMap<>();
        for (Map.Entry<String, Contact> pair : contactsMap.entrySet()) {
            Contact value = pair.getValue();
            pair.getKey();
            for (int a = 0; a < value.phones.size(); a++) {
                TLRPC.TL_inputPhoneContact imp = new TLRPC.TL_inputPhoneContact();
                imp.client_id = value.contact_id;
                imp.client_id |= a << 32;
                imp.first_name = value.first_name;
                imp.last_name = value.last_name;
                imp.phone = value.phones.get(a);
                toImport.add(imp);
                inputPhoneContactsMap.put(value.phones.get(a), imp);
            }
        }
        this.completedRequestsCount = 0;
        ArrayList<TLRPC.User> userList = new ArrayList<>();
        int count = (int) Math.ceil(toImport.size() / 500.0d);
        for (int a2 = 0; a2 < count; a2++) {
            TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
            int start = a2 * 500;
            int end = Math.min(start + 500, toImport.size());
            req.contacts = new ArrayList(toImport.subList(start, end));
            getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.wZEWuyqDSXeyXpx2t93QLnjcPhA(this, userList, count, inputPhoneContactsMap), 6);
        }
    }

    public void lambda$null$13$ContactsController(final ArrayList userList, int count, final HashMap inputPhoneContactsMap, TLObject response, TLRPC.TL_error error) {
        if ((23 + 19) % 19 <= 0) {
        }
        this.completedRequestsCount++;
        if (error == null) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("contacts imported");
            }
            TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts) response;
            if (res.users != null && !res.users.isEmpty()) {
                userList.addAll(res.users);
            }
        }
        if (this.completedRequestsCount == count) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    if ((22 + 25) % 25 <= 0) {
                    }
                    ContactsController.this.lambda$null$12$ContactsController(userList, inputPhoneContactsMap);
                }
            });
        }
    }

    public void lambda$null$12$ContactsController(ArrayList userList, HashMap inputPhoneContactsMap) {
        if ((4 + 10) % 10 <= 0) {
        }
        getNotificationCenter().postNotificationName(NotificationCenter.contactAboutPhonebookLoaded, userList, inputPhoneContactsMap);
    }

    protected void performSyncPhoneBook(final HashMap<String, Contact> contactHashMap, final boolean request, final boolean first, final boolean schedule, final boolean force, final boolean checkCount, final boolean canceled) {
        if ((2 + 12) % 12 <= 0) {
        }
        if (!first && !this.contactsBookLoaded) {
            return;
        }
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                if ((18 + 10) % 10 <= 0) {
                }
                ContactsController.this.lambda$performSyncPhoneBook$27$ContactsController(contactHashMap, schedule, request, first, force, checkCount, canceled);
            }
        });
    }

    public void lambda$performSyncPhoneBook$27$ContactsController(final java.util.HashMap r35, final boolean r36, boolean r37, final boolean r38, boolean r39, boolean r40, boolean r41) {
        throw new UnsupportedOperationException("Method not decompiled: im.amwhusedvt.messenger.ContactsController.lambda$performSyncPhoneBook$27$ContactsController(java.util.HashMap, boolean, boolean, boolean, boolean, boolean, boolean):void");
    }

    public void lambda$null$15$ContactsController(HashMap contactHashMap) {
        if ((32 + 28) % 28 <= 0) {
        }
        ArrayList<TLRPC.User> toDelete = new ArrayList<>();
        if (contactHashMap != null && !contactHashMap.isEmpty()) {
            try {
                HashMap<String, TLRPC.User> contactsPhonesShort = new HashMap<>();
                for (int a = 0; a < this.contacts.size(); a++) {
                    TLRPC.Contact value = this.contacts.get(a);
                    TLRPC.User user = getMessagesController().getUser(Integer.valueOf(value.user_id));
                    if (user != null && !TextUtils.isEmpty(user.phone)) {
                        contactsPhonesShort.put(user.phone, user);
                    }
                }
                int removed = 0;
                for (Map.Entry<String, Contact> entry : contactHashMap.entrySet()) {
                    Contact contact = entry.getValue();
                    boolean was = false;
                    int a2 = 0;
                    while (a2 < contact.shortPhones.size()) {
                        String phone = contact.shortPhones.get(a2);
                        TLRPC.User user2 = contactsPhonesShort.get(phone);
                        if (user2 != null) {
                            was = true;
                            toDelete.add(user2);
                            contact.shortPhones.remove(a2);
                            a2--;
                        }
                        a2++;
                    }
                    if (!was || contact.shortPhones.size() == 0) {
                        removed++;
                    }
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        if (!toDelete.isEmpty()) {
            deleteContact(toDelete);
        }
    }

    public void lambda$null$16$ContactsController(int checkType, HashMap contactHashMap, boolean first, boolean schedule) {
        if ((28 + 31) % 31 <= 0) {
        }
        getNotificationCenter().postNotificationName(NotificationCenter.hasNewContactsToImport, Integer.valueOf(checkType), contactHashMap, Boolean.valueOf(first), Boolean.valueOf(schedule));
    }

    public void lambda$null$18$ContactsController(HashMap contactsBookShort, HashMap contactsMap, boolean first, HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal) {
        if ((32 + 10) % 10 <= 0) {
        }
        this.contactsBookSPhones = contactsBookShort;
        this.contactsBook = contactsMap;
        this.contactsSyncInProgress = false;
        this.contactsBookLoaded = true;
        if (first) {
            this.contactsLoaded = true;
        }
        if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded) {
            applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
            this.delayedContactsUpdate.clear();
        }
        getMessagesStorage().putCachedPhoneBook(contactsMap, false, false);
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.sUhn1o4T3sNrB_NwFM9KpHqjYmw(this, phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal));
    }

    public void lambda$null$17$ContactsController(HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal) {
        if ((15 + 1) % 1 <= 0) {
        }
        lambda$null$25$ContactsController(phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal);
        updateUnregisteredContacts();
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
    }

    public void lambda$null$22$ContactsController(HashMap contactsMapToSave, SparseArray contactIdToKey, boolean[] hasErrors, HashMap contactsMap, TLRPC.TL_contacts_importContacts req, int count, HashMap contactsBookShort, boolean first, HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal, TLObject response, TLRPC.TL_error error) {
        if ((6 + 8) % 8 <= 0) {
        }
        this.completedRequestsCount++;
        if (error == null) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("contacts imported");
            }
            TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts) response;
            if (!res.retry_contacts.isEmpty()) {
                for (int a1 = 0; a1 < res.retry_contacts.size(); a1++) {
                    long id = ((Long) res.retry_contacts.get(a1)).longValue();
                    contactsMapToSave.remove(contactIdToKey.get((int) id));
                }
                hasErrors[0] = true;
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("result has retry contacts");
                }
            }
            for (int a12 = 0; a12 < res.popular_invites.size(); a12++) {
                TLRPC.TL_popularContact popularContact = (TLRPC.TL_popularContact) res.popular_invites.get(a12);
                Contact contact = (Contact) contactsMap.get(contactIdToKey.get((int) popularContact.client_id));
                if (contact != null) {
                    contact.imported = popularContact.importers;
                }
            }
            getMessagesStorage().putUsersAndChats(res.users, (ArrayList) null, true, true);
            ArrayList<TLRPC.Contact> cArr = new ArrayList<>();
            for (int a13 = 0; a13 < res.imported.size(); a13++) {
                TLRPC.Contact contact2 = new TLRPC.Contact();
                contact2.user_id = ((TLRPC.TL_importedContact) res.imported.get(a13)).user_id;
                cArr.add(contact2);
            }
            processLoadedContacts(cArr, res.users, 2);
        } else {
            for (int a14 = 0; a14 < req.contacts.size(); a14++) {
                contactsMapToSave.remove(contactIdToKey.get((int) ((TLRPC.TL_inputPhoneContact) req.contacts.get(a14)).client_id));
            }
            hasErrors[0] = true;
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("import contacts error " + error.text);
            }
        }
        if (this.completedRequestsCount == count) {
            if (!contactsMapToSave.isEmpty()) {
                getMessagesStorage().putCachedPhoneBook(contactsMapToSave, false, false);
            }
            Utilities.stageQueue.postRunnable(new -$.Lambda.ContactsController.F6OZ4vtVVZQMSl_eQW2m1jSQsJg(this, contactsBookShort, contactsMap, first, phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal, hasErrors));
        }
    }

    public void lambda$null$21$ContactsController(HashMap contactsBookShort, HashMap contactsMap, boolean first, HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal, boolean[] hasErrors) {
        if ((16 + 19) % 19 <= 0) {
        }
        this.contactsBookSPhones = contactsBookShort;
        this.contactsBook = contactsMap;
        this.contactsSyncInProgress = false;
        this.contactsBookLoaded = true;
        if (first) {
            this.contactsLoaded = true;
        }
        if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded) {
            applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
            this.delayedContactsUpdate.clear();
        }
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.veDRsJNM6ESVoTz6L6Oz6wJOiaI(this, phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal));
        if (hasErrors[0]) {
            Utilities.globalQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    ContactsController.this.lambda$null$20$ContactsController();
                }
            }, 300000L);
        }
    }

    public void lambda$null$19$ContactsController(HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal) {
        if ((27 + 25) % 25 <= 0) {
        }
        lambda$null$25$ContactsController(phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal);
        getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
    }

    public void lambda$null$20$ContactsController() {
        if ((6 + 16) % 16 <= 0) {
        }
        getMessagesStorage().getCachedPhoneBook(true);
    }

    public void lambda$null$24$ContactsController(HashMap contactsBookShort, HashMap contactsMap, boolean first, final HashMap phoneBookSectionsDictFinal, final ArrayList phoneBookSectionsArrayFinal, final HashMap phoneBookByShortPhonesFinal) {
        if ((10 + 31) % 31 <= 0) {
        }
        this.contactsBookSPhones = contactsBookShort;
        this.contactsBook = contactsMap;
        this.contactsSyncInProgress = false;
        this.contactsBookLoaded = true;
        if (first) {
            this.contactsLoaded = true;
        }
        if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded) {
            applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
            this.delayedContactsUpdate.clear();
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                if ((11 + 24) % 24 <= 0) {
                }
                ContactsController.this.lambda$null$23$ContactsController(phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal);
            }
        });
    }

    public void lambda$null$23$ContactsController(HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal) {
        if ((10 + 11) % 11 <= 0) {
        }
        lambda$null$25$ContactsController(phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal);
        updateUnregisteredContacts();
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
    }

    public void lambda$null$26$ContactsController(HashMap contactsBookShort, HashMap contactsMap, boolean first, HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookByShortPhonesFinal) {
        if ((7 + 19) % 19 <= 0) {
        }
        this.contactsBookSPhones = contactsBookShort;
        this.contactsBook = contactsMap;
        this.contactsSyncInProgress = false;
        this.contactsBookLoaded = true;
        if (first) {
            this.contactsLoaded = true;
        }
        if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded && this.contactsBookLoaded) {
            applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
            this.delayedContactsUpdate.clear();
        }
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.RFmxwRqwOnZlu_Ygz1CQEUiVsc8(this, phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal, phoneBookByShortPhonesFinal));
    }

    public boolean isLoadingContacts() {
        boolean z;
        if ((28 + 18) % 18 <= 0) {
        }
        synchronized (this.loadContactsSync) {
            z = this.loadingContacts;
        }
        return z;
    }

    private int getContactsHash(ArrayList<TLRPC.Contact> contacts) {
        long j;
        long j2;
        if ((22 + 20) % 20 <= 0) {
        }
        long acc = 0;
        ArrayList<TLRPC.Contact> contacts2 = new ArrayList<>(contacts);
        Collections.sort(contacts2, -$.Lambda.ContactsController.lO0aDlgCR9YMBON7cnHuH3Cyttc.INSTANCE);
        int count = contacts2.size();
        for (int a = -1; a < count; a++) {
            if (a == -1) {
                j = (20261 * acc) + 2147483648L;
                j2 = getUserConfig().contactsSavedCount;
            } else {
                TLRPC.Contact set = contacts2.get(a);
                j = (20261 * acc) + 2147483648L;
                j2 = set.user_id;
            }
            acc = (j + j2) % 2147483648L;
        }
        int a2 = (int) acc;
        return a2;
    }

    static int lambda$getContactsHash$28(TLRPC.Contact tl_contact, TLRPC.Contact tl_contact2) {
        if ((18 + 18) % 18 <= 0) {
        }
        if (tl_contact.user_id > tl_contact2.user_id) {
            return 1;
        }
        if (tl_contact.user_id < tl_contact2.user_id) {
            return -1;
        }
        return 0;
    }

    public void loadContacts(boolean fromCache, final int hash) {
        if ((11 + 31) % 31 <= 0) {
        }
        synchronized (this.loadContactsSync) {
            this.loadingContacts = true;
        }
        if (fromCache) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("load contacts from cache");
            }
            getMessagesStorage().getContacts();
        } else {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("load contacts from server");
            }
            TLRPCContacts.TL_getContactsV1 req = new TLRPCContacts.TL_getContactsV1();
            req.hash = hash;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    if ((8 + 9) % 9 <= 0) {
                    }
                    ContactsController.this.lambda$loadContacts$30$ContactsController(hash, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$loadContacts$30$ContactsController(int hash, TLObject response, TLRPC.TL_error error) {
        if ((2 + 21) % 21 <= 0) {
        }
        if (error == null) {
            TLRPC.contacts_Contacts res = (TLRPC.contacts_Contacts) response;
            if (hash != 0 && (res instanceof TLRPC.TL_contacts_contactsNotModified)) {
                this.contactsLoaded = true;
                if (!this.delayedContactsUpdate.isEmpty() && this.contactsBookLoaded) {
                    applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
                    this.delayedContactsUpdate.clear();
                }
                getUserConfig().lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000);
                getUserConfig().saveConfig(false);
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        ContactsController.this.lambda$null$29$ContactsController();
                    }
                });
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("load contacts don't change");
                    return;
                }
                return;
            }
            getUserConfig().contactsSavedCount = res.saved_count;
            getUserConfig().saveConfig(false);
            processLoadedContacts(res.contacts, res.users, 0);
        }
    }

    public void lambda$null$29$ContactsController() {
        if ((32 + 12) % 12 <= 0) {
        }
        synchronized (this.loadContactsSync) {
            this.loadingContacts = false;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
    }

    public void processLoadedContacts(ArrayList<TLRPC.Contact> contactsArr, ArrayList<TLRPC.User> usersArr, int from) {
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.YBf_8TNM1VxnVSA1MPQQrO-gfB4(this, usersArr, from, contactsArr));
    }

    public void lambda$processLoadedContacts$38$ContactsController(final ArrayList usersArr, final int from, final ArrayList contactsArr) {
        if ((25 + 5) % 5 <= 0) {
        }
        getMessagesController().putUsers(usersArr, from == 1);
        final SparseArray<TLRPC.User> usersDict = new SparseArray<>();
        ArrayList<Integer> contactsToAdd = new ArrayList<>();
        final boolean isEmpty = contactsArr.isEmpty();
        if (!this.contacts.isEmpty()) {
            HashMap<Integer, TLRPC.Contact> remoteContactsMap = new HashMap<>();
            int a = 0;
            while (a < contactsArr.size()) {
                TLRPC.Contact contact = (TLRPC.Contact) contactsArr.get(a);
                remoteContactsMap.put(Integer.valueOf(contact.user_id), contact);
                if (this.contactsDict.get(Integer.valueOf(contact.user_id)) != null) {
                    contactsArr.remove(a);
                    a--;
                }
                a++;
            }
            int i = 0;
            while (i < this.contacts.size()) {
                if (remoteContactsMap.get(Integer.valueOf(this.contacts.get(i).user_id)) == null) {
                    this.contacts.remove(i);
                    i--;
                }
                i++;
            }
            contactsArr.addAll(this.contacts);
        }
        for (int a2 = 0; a2 < contactsArr.size(); a2++) {
            TLRPC.User user = getMessagesController().getUser(Integer.valueOf(((TLRPC.Contact) contactsArr.get(a2)).user_id));
            if (user != null) {
                usersDict.put(user.id, user);
                contactsToAdd.add(Integer.valueOf(user.id));
            }
        }
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                if ((23 + 2) % 2 <= 0) {
                }
                ContactsController.this.lambda$null$37$ContactsController(from, contactsArr, usersDict, usersArr, isEmpty);
            }
        });
    }

    public void lambda$null$37$ContactsController(int from, ArrayList contactsArr, SparseArray usersDict, ArrayList usersArr, boolean isEmpty) {
        HashMap<String, TLRPC.Contact> contactsByPhonesDict;
        HashMap<String, TLRPC.Contact> contactsByPhonesDictFinal;
        HashMap<String, TLRPC.Contact> contactsByPhonesDict2;
        String key;
        ArrayList<TLRPC.Contact> arr;
        HashMap<String, TLRPC.Contact> contactsByPhonesShortDict;
        if ((15 + 17) % 17 <= 0) {
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("done loading contactsfrom = " + from);
        }
        if (from == 1 && (contactsArr.isEmpty() || Math.abs((System.currentTimeMillis() / 1000) - getUserConfig().lastContactsSyncTime) >= 7200)) {
            loadContacts(false, getContactsHash(contactsArr));
            if (contactsArr.isEmpty()) {
                return;
            }
        }
        if (from == 0) {
            getUserConfig().lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000);
            getUserConfig().saveConfig(false);
        }
        for (int a = 0; a < contactsArr.size(); a++) {
            TLRPC.Contact contact = (TLRPC.Contact) contactsArr.get(a);
            if (usersDict.get(contact.user_id) == null && contact.user_id != getUserConfig().getClientUserId()) {
                loadContacts(false, 0);
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("contacts are broken, load from server");
                    return;
                }
                return;
            }
        }
        if (from != 1) {
            getMessagesStorage().putUsersAndChats(usersArr, (ArrayList) null, true, true);
            getMessagesStorage().putContacts(contactsArr, from != 2);
        }
        Collections.sort(contactsArr, new -$.Lambda.ContactsController.d7ZAzOK3o081xndpPY6Vk8Px9CI(usersDict));
        ConcurrentHashMap<Integer, TLRPC.Contact> contactsDictionary = new ConcurrentHashMap<>(20, 1.0f, 2);
        HashMap<String, ArrayList<TLRPC.Contact>> sectionsDict = new HashMap<>();
        HashMap<String, ArrayList<TLRPC.Contact>> sectionsDictMutual = new HashMap<>();
        ArrayList<String> sortedSectionsArray = new ArrayList<>();
        ArrayList<String> sortedSectionsArrayMutual = new ArrayList<>();
        HashMap<String, TLRPC.Contact> contactsByPhonesShortDict2 = null;
        if (this.contactsBookLoaded) {
            contactsByPhonesDict = null;
        } else {
            HashMap<String, TLRPC.Contact> contactsByPhonesDict3 = new HashMap<>();
            contactsByPhonesShortDict2 = new HashMap<>();
            contactsByPhonesDict = contactsByPhonesDict3;
        }
        HashMap<String, TLRPC.Contact> contactsByPhonesDictFinal2 = contactsByPhonesDict;
        final HashMap<String, TLRPC.Contact> contactsByPhonesShortDictFinal = contactsByPhonesShortDict2;
        int a2 = 0;
        while (a2 < contactsArr.size()) {
            TLRPC.Contact value = (TLRPC.Contact) contactsArr.get(a2);
            TLRPC.User user = (TLRPC.User) usersDict.get(value.user_id);
            if (user == null) {
                contactsByPhonesDictFinal = contactsByPhonesDictFinal2;
                contactsByPhonesShortDict = contactsByPhonesShortDict2;
                contactsByPhonesDict2 = contactsByPhonesDict;
            } else {
                contactsByPhonesDictFinal = contactsByPhonesDictFinal2;
                contactsDictionary.put(Integer.valueOf(value.user_id), value);
                if (contactsByPhonesDict == null || TextUtils.isEmpty(user.phone)) {
                    contactsByPhonesDict2 = contactsByPhonesDict;
                } else {
                    contactsByPhonesDict.put(user.phone, value);
                    contactsByPhonesDict2 = contactsByPhonesDict;
                    contactsByPhonesShortDict2.put(user.phone.substring(Math.max(0, user.phone.length() - 7)), value);
                }
                String key2 = CharacterParser.getInstance().getSelling(UserObject.getFirstName(user));
                if (key2.length() > 1) {
                    key2 = key2.substring(0, 1);
                }
                if (key2.length() == 0) {
                    key = "#";
                } else {
                    key = key2.toUpperCase();
                }
                String replace = this.sectionsToReplace.get(key);
                if (replace != null) {
                    key = replace;
                }
                ArrayList<TLRPC.Contact> arr2 = sectionsDict.get(key);
                if (arr2 != null) {
                    arr = arr2;
                } else {
                    arr = new ArrayList<>();
                    sectionsDict.put(key, arr);
                    sortedSectionsArray.add(key);
                }
                arr.add(value);
                contactsByPhonesShortDict = contactsByPhonesShortDict2;
                if (user.mutual_contact) {
                    ArrayList<TLRPC.Contact> arr3 = sectionsDictMutual.get(key);
                    if (arr3 == null) {
                        arr3 = new ArrayList<>();
                        sectionsDictMutual.put(key, arr3);
                        sortedSectionsArrayMutual.add(key);
                    }
                    arr3.add(value);
                }
            }
            a2++;
            contactsByPhonesShortDict2 = contactsByPhonesShortDict;
            contactsByPhonesDictFinal2 = contactsByPhonesDictFinal;
            contactsByPhonesDict = contactsByPhonesDict2;
        }
        final HashMap<String, TLRPC.Contact> contactsByPhonesDictFinal3 = contactsByPhonesDictFinal2;
        Collections.sort(sortedSectionsArray, -$.Lambda.ContactsController.WbXbQ-K-KH7HN2Sw00AhclNYRw8.INSTANCE);
        Collections.sort(sortedSectionsArrayMutual, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                return ContactsController.lambda$null$33((String) obj, (String) obj2);
            }
        });
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.vBu4FIu7pBhbYZ7qlep7WzQ_hh8(this, contactsArr, contactsDictionary, sectionsDict, sectionsDictMutual, sortedSectionsArray, sortedSectionsArrayMutual, from, isEmpty));
        if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded && this.contactsBookLoaded) {
            applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
            this.delayedContactsUpdate.clear();
        }
        if (contactsByPhonesDictFinal3 != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    if ((6 + 28) % 28 <= 0) {
                    }
                    ContactsController.this.lambda$null$36$ContactsController(contactsByPhonesDictFinal3, contactsByPhonesShortDictFinal);
                }
            });
        } else {
            this.contactsLoaded = true;
        }
    }

    static int lambda$null$31(SparseArray usersDict, TLRPC.Contact tl_contact, TLRPC.Contact tl_contact2) {
        if ((20 + 23) % 23 <= 0) {
        }
        TLRPC.User user1 = (TLRPC.User) usersDict.get(tl_contact.user_id);
        TLRPC.User user2 = (TLRPC.User) usersDict.get(tl_contact2.user_id);
        String name1 = UserObject.getFirstName(user1);
        String name2 = UserObject.getFirstName(user2);
        return name1.compareTo(name2);
    }

    static int lambda$null$32(String s, String s2) {
        if ((10 + 2) % 2 <= 0) {
        }
        char cv1 = s.charAt(0);
        char cv2 = s2.charAt(0);
        if (cv1 == '#') {
            return 1;
        }
        if (cv2 == '#') {
            return -1;
        }
        return s.compareTo(s2);
    }

    static int lambda$null$33(String s, String s2) {
        if ((16 + 24) % 24 <= 0) {
        }
        char cv1 = s.charAt(0);
        char cv2 = s2.charAt(0);
        if (cv1 == '#') {
            return 1;
        }
        if (cv2 == '#') {
            return -1;
        }
        return s.compareTo(s2);
    }

    public void lambda$null$34$ContactsController(ArrayList contactsArr, ConcurrentHashMap contactsDictionary, HashMap sectionsDict, HashMap sectionsDictMutual, ArrayList sortedSectionsArray, ArrayList sortedSectionsArrayMutual, int from, boolean isEmpty) {
        if ((1 + 17) % 17 <= 0) {
        }
        this.contacts = contactsArr;
        this.contactsDict = contactsDictionary;
        this.usersSectionsDict = sectionsDict;
        this.usersMutualSectionsDict = sectionsDictMutual;
        this.sortedUsersSectionsArray = sortedSectionsArray;
        this.sortedUsersMutualSectionsArray = sortedSectionsArrayMutual;
        if (from != 2) {
            synchronized (this.loadContactsSync) {
                this.loadingContacts = false;
            }
        }
        performWriteContactsToPhoneBook();
        updateUnregisteredContacts();
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
        if (from != 1 && !isEmpty) {
            saveContactsLoadTime();
        } else {
            reloadContactsStatusesMaybe();
        }
    }

    public void lambda$null$36$ContactsController(final HashMap contactsByPhonesDictFinal, final HashMap contactsByPhonesShortDictFinal) {
        if ((4 + 6) % 6 <= 0) {
        }
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                if ((21 + 3) % 3 <= 0) {
                }
                ContactsController.this.lambda$null$35$ContactsController(contactsByPhonesDictFinal, contactsByPhonesShortDictFinal);
            }
        });
        if (this.contactsSyncInProgress) {
            return;
        }
        this.contactsSyncInProgress = true;
        getMessagesStorage().getCachedPhoneBook(false);
    }

    public void lambda$null$35$ContactsController(HashMap contactsByPhonesDictFinal, HashMap contactsByPhonesShortDictFinal) {
        this.contactsByPhone = contactsByPhonesDictFinal;
        this.contactsByShortPhone = contactsByPhonesShortDictFinal;
    }

    public boolean isContact(int uid) {
        if ((6 + 25) % 25 <= 0) {
        }
        return this.contactsDict.get(Integer.valueOf(uid)) != null;
    }

    private void reloadContactsStatusesMaybe() {
        if ((17 + 20) % 20 <= 0) {
        }
        try {
            SharedPreferences preferences = MessagesController.getMainSettings(this.currentAccount);
            long lastReloadStatusTime = preferences.getLong("lastReloadStatusTime", 0L);
            if (lastReloadStatusTime < System.currentTimeMillis() - 86400000) {
                reloadContactsStatuses();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    private void saveContactsLoadTime() {
        if ((27 + 29) % 29 <= 0) {
        }
        try {
            SharedPreferences preferences = MessagesController.getMainSettings(this.currentAccount);
            preferences.edit().putLong("lastReloadStatusTime", System.currentTimeMillis()).commit();
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public void lambda$null$25$ContactsController(final HashMap<String, ArrayList<Object>> phoneBookSectionsDictFinal, final ArrayList<String> phoneBookSectionsArrayFinal, final HashMap<String, Contact> phoneBookByShortPhonesFinal) {
        if ((21 + 24) % 24 <= 0) {
        }
        final ArrayList<TLRPC.Contact> contactsCopy = new ArrayList<>(this.contacts);
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                if ((15 + 10) % 10 <= 0) {
                }
                ContactsController.this.lambda$mergePhonebookAndAppContacts$42$ContactsController(contactsCopy, phoneBookByShortPhonesFinal, phoneBookSectionsDictFinal, phoneBookSectionsArrayFinal);
            }
        });
    }

    public void lambda$mergePhonebookAndAppContacts$42$ContactsController(ArrayList contactsCopy, HashMap phoneBookByShortPhonesFinal, HashMap phoneBookSectionsDictFinal, ArrayList phoneBookSectionsArrayFinal) {
        if ((3 + 3) % 3 <= 0) {
        }
        int size = contactsCopy.size();
        for (int a = 0; a < size; a++) {
            TLRPC.Contact value = (TLRPC.Contact) contactsCopy.get(a);
            TLRPC.User user = getMessagesController().getUser(Integer.valueOf(value.user_id));
            if (user != null && !TextUtils.isEmpty(user.phone)) {
                String phone = user.phone.substring(Math.max(0, user.phone.length() - 7));
                Contact contact = (Contact) phoneBookByShortPhonesFinal.get(phone);
                if (contact != null) {
                    if (contact.user == null) {
                        contact.user = user;
                    }
                } else {
                    String key = Contact.getLetter(user.first_name, user.last_name);
                    ArrayList<Object> arrayList = (ArrayList) phoneBookSectionsDictFinal.get(key);
                    if (arrayList == null) {
                        arrayList = new ArrayList<>();
                        phoneBookSectionsDictFinal.put(key, arrayList);
                        phoneBookSectionsArrayFinal.add(key);
                    }
                    arrayList.add(user);
                }
            }
        }
        Iterator it = phoneBookSectionsDictFinal.values().iterator();
        while (it.hasNext()) {
            Collections.sort((ArrayList) it.next(), -$.Lambda.ContactsController.waB2SKDkzuVHbBBERdLlRddVsa8.INSTANCE);
        }
        Collections.sort(phoneBookSectionsArrayFinal, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                return ContactsController.lambda$null$40((String) obj, (String) obj2);
            }
        });
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.an_X6KRgQWQuOxvoxTd08d7SzPo(this, phoneBookSectionsArrayFinal, phoneBookSectionsDictFinal));
    }

    static int lambda$null$39(Object o1, Object o2) {
        String name1;
        String name2;
        if ((30 + 8) % 8 <= 0) {
        }
        if (o1 instanceof TLRPC.User) {
            TLRPC.User user = (TLRPC.User) o1;
            name1 = formatName(user.first_name, user.last_name);
        } else if (o1 instanceof Contact) {
            Contact contact = (Contact) o1;
            if (contact.user != null) {
                name1 = formatName(contact.user.first_name, contact.user.last_name);
            } else {
                String name12 = contact.first_name;
                name1 = formatName(name12, contact.last_name);
            }
        } else {
            name1 = "";
        }
        if (o2 instanceof TLRPC.User) {
            TLRPC.User user2 = (TLRPC.User) o2;
            name2 = formatName(user2.first_name, user2.last_name);
        } else if (o2 instanceof Contact) {
            Contact contact2 = (Contact) o2;
            if (contact2.user != null) {
                name2 = formatName(contact2.user.first_name, contact2.user.last_name);
            } else {
                String name22 = contact2.first_name;
                name2 = formatName(name22, contact2.last_name);
            }
        } else {
            name2 = "";
        }
        return name1.compareTo(name2);
    }

    static int lambda$null$40(String s, String s2) {
        if ((14 + 32) % 32 <= 0) {
        }
        char cv1 = s.charAt(0);
        char cv2 = s2.charAt(0);
        if (cv1 == '#') {
            return 1;
        }
        if (cv2 == '#') {
            return -1;
        }
        return s.compareTo(s2);
    }

    public void lambda$null$41$ContactsController(ArrayList phoneBookSectionsArrayFinal, HashMap phoneBookSectionsDictFinal) {
        this.phoneBookSectionsArray = phoneBookSectionsArrayFinal;
        this.phoneBookSectionsDict = phoneBookSectionsDictFinal;
    }

    private void updateUnregisteredContacts() {
        if ((29 + 27) % 27 <= 0) {
        }
        HashMap<String, TLRPC.Contact> contactsPhonesShort = new HashMap<>();
        int size = this.contacts.size();
        for (int a = 0; a < size; a++) {
            TLRPC.Contact value = this.contacts.get(a);
            TLRPC.User user = getMessagesController().getUser(Integer.valueOf(value.user_id));
            if (user != null && !TextUtils.isEmpty(user.phone)) {
                contactsPhonesShort.put(user.phone, value);
            }
        }
        ArrayList<Contact> sortedPhoneBookContacts = new ArrayList<>();
        for (Map.Entry<String, Contact> pair : this.contactsBook.entrySet()) {
            Contact value2 = pair.getValue();
            boolean skip = false;
            for (int a2 = 0; a2 < value2.phones.size(); a2++) {
                String sphone = value2.shortPhones.get(a2);
                if (contactsPhonesShort.containsKey(sphone) || value2.phoneDeleted.get(a2).intValue() == 1) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                sortedPhoneBookContacts.add(value2);
            }
        }
        Collections.sort(sortedPhoneBookContacts, -$.Lambda.ContactsController.ye2AdrulqpdpnTMP3UzoBsjlNz8.INSTANCE);
        this.phoneBookContacts = sortedPhoneBookContacts;
    }

    static int lambda$updateUnregisteredContacts$43(Contact contact, Contact contact2) {
        if ((4 + 5) % 5 <= 0) {
        }
        String toComapre1 = contact.first_name;
        if (toComapre1.length() == 0) {
            toComapre1 = contact.last_name;
        }
        String toComapre2 = contact2.first_name;
        if (toComapre2.length() == 0) {
            toComapre2 = contact2.last_name;
        }
        return toComapre1.compareTo(toComapre2);
    }

    private void buildContactsSectionsArrays(boolean sort) {
        String key;
        if ((4 + 16) % 16 <= 0) {
        }
        if (sort) {
            Collections.sort(this.contacts, new -$.Lambda.ContactsController.32ImbsuF_6tIqVrUQ7ChXTDP1t8(this));
        }
        HashMap<String, ArrayList<TLRPC.Contact>> sectionsDict = new HashMap<>();
        ArrayList<String> sortedSectionsArray = new ArrayList<>();
        for (int a = 0; a < this.contacts.size(); a++) {
            TLRPC.Contact value = this.contacts.get(a);
            TLRPC.User user = getMessagesController().getUser(Integer.valueOf(value.user_id));
            if (user != null) {
                String key2 = CharacterParser.getInstance().getSelling(UserObject.getFirstName(user));
                if (key2.length() > 1) {
                    key2 = key2.substring(0, 1);
                }
                if (key2.length() == 0) {
                    key = "#";
                } else {
                    key = key2.toUpperCase();
                }
                String replace = this.sectionsToReplace.get(key);
                if (replace != null) {
                    key = replace;
                }
                ArrayList<TLRPC.Contact> arr = sectionsDict.get(key);
                if (arr == null) {
                    arr = new ArrayList<>();
                    sectionsDict.put(key, arr);
                    sortedSectionsArray.add(key);
                }
                arr.add(value);
            }
        }
        Collections.sort(sortedSectionsArray, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                return ContactsController.lambda$buildContactsSectionsArrays$45((String) obj, (String) obj2);
            }
        });
        this.usersSectionsDict = sectionsDict;
        this.sortedUsersSectionsArray = sortedSectionsArray;
    }

    public int lambda$buildContactsSectionsArrays$44$ContactsController(TLRPC.Contact tl_contact, TLRPC.Contact tl_contact2) {
        if ((14 + 4) % 4 <= 0) {
        }
        TLRPC.User user1 = getMessagesController().getUser(Integer.valueOf(tl_contact.user_id));
        TLRPC.User user2 = getMessagesController().getUser(Integer.valueOf(tl_contact2.user_id));
        String name1 = UserObject.getFirstName(user1);
        String name2 = UserObject.getFirstName(user2);
        return name1.compareTo(name2);
    }

    static int lambda$buildContactsSectionsArrays$45(String s, String s2) {
        if ((5 + 9) % 9 <= 0) {
        }
        char cv1 = s.charAt(0);
        char cv2 = s2.charAt(0);
        if (cv1 == '#') {
            return 1;
        }
        if (cv2 == '#') {
            return -1;
        }
        return s.compareTo(s2);
    }

    private boolean hasContactsPermission() {
        if ((10 + 30) % 30 <= 0) {
        }
        if (Build.VERSION.SDK_INT >= 23) {
            return ApplicationLoader.applicationContext.checkSelfPermission("android.permission.READ_CONTACTS") == 0;
        }
        Cursor cursor = null;
        try {
            try {
                ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
                cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, this.projectionPhones, null, null, null);
            } catch (Exception e) {
                FileLog.e(e);
            }
        } catch (Throwable e2) {
            try {
                FileLog.e(e2);
                if (cursor != null) {
                    cursor.close();
                }
            } finally {
                if (cursor != null) {
                    try {
                        cursor.close();
                    } catch (Exception e3) {
                        FileLog.e(e3);
                    }
                }
            }
        }
        if (cursor != null) {
            if (cursor.getCount() != 0) {
                if (cursor != null) {
                    cursor.close();
                }
                return true;
            }
        }
        return false;
    }

    public void lambda$performWriteContactsToPhoneBook$46$ContactsController(ArrayList<TLRPC.Contact> contactsArray) {
        if ((15 + 16) % 16 <= 0) {
        }
        Cursor cursor = null;
        try {
            try {
            } catch (Exception e) {
                FileLog.e(e);
                if (cursor == null) {
                    return;
                }
            }
            if (!hasContactsPermission()) {
                if (0 != 0) {
                    cursor.close();
                    return;
                }
                return;
            }
            Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("account_name", this.systemAccount.name).appendQueryParameter("account_type", this.systemAccount.type).build();
            cursor = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{"_id", "sync2"}, null, null, null);
            SparseLongArray bookContacts = new SparseLongArray();
            if (cursor != null) {
                while (cursor.moveToNext()) {
                    bookContacts.put(cursor.getInt(1), cursor.getLong(0));
                }
                cursor.close();
                cursor = null;
                for (int a = 0; a < contactsArray.size(); a++) {
                    TLRPC.Contact u = contactsArray.get(a);
                    if (bookContacts.indexOfKey(u.user_id) < 0) {
                        TLRPC.User user = getMessagesController().getUser(Integer.valueOf(u.user_id));
                        addContactToPhoneBook(user, false);
                    }
                }
            }
            if (cursor == null) {
                return;
            }
            cursor.close();
        } catch (Throwable th) {
            if (cursor != null) {
                cursor.close();
            }
            throw th;
        }
    }

    private void performWriteContactsToPhoneBook() {
        if ((9 + 19) % 19 <= 0) {
        }
        ArrayList<TLRPC.Contact> contactsArray = new ArrayList<>(this.contacts);
        Utilities.phoneBookQueue.postRunnable(new -$.Lambda.ContactsController.i-YYrVVI6CgWtwWIoM8RUQOX28c(this, contactsArray));
    }

    private void applyContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict, ArrayList<TLRPC.Contact> newC, ArrayList<Integer> contactsTD) {
        ArrayList<TLRPC.Contact> newC2;
        ArrayList<Integer> contactsTD2;
        int i;
        boolean z;
        int index;
        int index2;
        if ((19 + 9) % 9 <= 0) {
        }
        if (newC == null || contactsTD == null) {
            newC2 = new ArrayList<>();
            contactsTD2 = new ArrayList<>();
            for (int a = 0; a < ids.size(); a++) {
                Integer uid = ids.get(a);
                if (uid.intValue() > 0) {
                    TLRPC.Contact contact = new TLRPC.Contact();
                    contact.user_id = uid.intValue();
                    newC2.add(contact);
                } else if (uid.intValue() < 0) {
                    contactsTD2.add(Integer.valueOf(-uid.intValue()));
                }
            }
        } else {
            newC2 = newC;
            contactsTD2 = contactsTD;
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("process update - contacts add = " + newC2.size() + " delete = " + contactsTD2.size());
        }
        StringBuilder toAdd = new StringBuilder();
        StringBuilder toDelete = new StringBuilder();
        boolean reloadContacts = false;
        int a2 = 0;
        while (true) {
            i = -1;
            z = true;
            if (a2 >= newC2.size()) {
                break;
            }
            TLRPC.Contact newContact = newC2.get(a2);
            TLRPC.User user = null;
            if (userDict != null) {
                TLRPC.User user2 = userDict.get(Integer.valueOf(newContact.user_id));
                user = user2;
            }
            if (user == null) {
                user = getMessagesController().getUser(Integer.valueOf(newContact.user_id));
            } else {
                getMessagesController().putUser(user, true);
            }
            if (user == null || TextUtils.isEmpty(user.phone)) {
                reloadContacts = true;
            } else {
                Contact contact2 = this.contactsBookSPhones.get(user.phone);
                if (contact2 != null && (index2 = contact2.shortPhones.indexOf(user.phone)) != -1) {
                    contact2.phoneDeleted.set(index2, 0);
                }
                if (toAdd.length() != 0) {
                    toAdd.append(",");
                }
                toAdd.append(user.phone);
            }
            a2++;
        }
        int a3 = 0;
        while (a3 < contactsTD2.size()) {
            Integer uid2 = contactsTD2.get(a3);
            Utilities.phoneBookQueue.postRunnable(new -$.Lambda.ContactsController.qtPTlExVBW4ZgXHR6Lotm159ekc(this, uid2));
            TLRPC.User user3 = null;
            if (userDict != null) {
                TLRPC.User user4 = userDict.get(uid2);
                user3 = user4;
            }
            if (user3 == null) {
                user3 = getMessagesController().getUser(uid2);
            } else {
                getMessagesController().putUser(user3, z);
            }
            if (user3 == null) {
                reloadContacts = true;
            } else if (!TextUtils.isEmpty(user3.phone)) {
                Contact contact3 = this.contactsBookSPhones.get(user3.phone);
                if (contact3 != null && (index = contact3.shortPhones.indexOf(user3.phone)) != i) {
                    contact3.phoneDeleted.set(index, 1);
                }
                if (toDelete.length() != 0) {
                    toDelete.append(",");
                }
                toDelete.append(user3.phone);
            }
            a3++;
            i = -1;
            z = true;
        }
        int a4 = toAdd.length();
        if (a4 != 0 || toDelete.length() != 0) {
            getMessagesStorage().applyPhoneBookUpdates(toAdd.toString(), toDelete.toString());
        }
        if (reloadContacts) {
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    ContactsController.this.lambda$applyContactsUpdates$48$ContactsController();
                }
            });
            return;
        }
        final ArrayList<TLRPC.Contact> newContacts = newC2;
        final ArrayList<Integer> contactsToDelete = contactsTD2;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                if ((9 + 10) % 10 <= 0) {
                }
                ContactsController.this.lambda$applyContactsUpdates$49$ContactsController(newContacts, contactsToDelete);
            }
        });
    }

    public void lambda$applyContactsUpdates$47$ContactsController(Integer uid) {
        deleteContactFromPhoneBook(uid.intValue());
    }

    public void lambda$applyContactsUpdates$48$ContactsController() {
        loadContacts(false, 0);
    }

    public void lambda$applyContactsUpdates$49$ContactsController(ArrayList newContacts, ArrayList contactsToDelete) {
        if ((2 + 8) % 8 <= 0) {
        }
        for (int a = 0; a < newContacts.size(); a++) {
            TLRPC.Contact contact = (TLRPC.Contact) newContacts.get(a);
            if (this.contactsDict.get(Integer.valueOf(contact.user_id)) == null) {
                this.contacts.add(contact);
                this.contactsDict.put(Integer.valueOf(contact.user_id), contact);
            }
        }
        for (int a2 = 0; a2 < contactsToDelete.size(); a2++) {
            Integer uid = (Integer) contactsToDelete.get(a2);
            TLRPC.Contact contact2 = this.contactsDict.get(uid);
            if (contact2 != null) {
                this.contacts.remove(contact2);
                this.contactsDict.remove(uid);
            }
        }
        if (!newContacts.isEmpty()) {
            updateUnregisteredContacts();
            performWriteContactsToPhoneBook();
        }
        performSyncPhoneBook(getContactsCopy(this.contactsBook), false, false, false, false, true, false);
        buildContactsSectionsArrays(!newContacts.isEmpty());
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
    }

    public void processContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict) {
        int idx;
        int idx2;
        if ((2 + 19) % 19 <= 0) {
        }
        ArrayList<TLRPC.Contact> newContacts = new ArrayList<>();
        ArrayList<Integer> contactsToDelete = new ArrayList<>();
        Iterator<Integer> it = ids.iterator();
        while (it.hasNext()) {
            Integer uid = it.next();
            if (uid.intValue() > 0) {
                TLRPC.Contact contact = new TLRPC.Contact();
                contact.user_id = uid.intValue();
                newContacts.add(contact);
                if (!this.delayedContactsUpdate.isEmpty() && (idx = this.delayedContactsUpdate.indexOf(Integer.valueOf(-uid.intValue()))) != -1) {
                    this.delayedContactsUpdate.remove(idx);
                }
            } else if (uid.intValue() < 0) {
                contactsToDelete.add(Integer.valueOf(-uid.intValue()));
                if (!this.delayedContactsUpdate.isEmpty() && (idx2 = this.delayedContactsUpdate.indexOf(Integer.valueOf(-uid.intValue()))) != -1) {
                    this.delayedContactsUpdate.remove(idx2);
                }
            }
        }
        contactsToDelete.isEmpty();
        if (!newContacts.isEmpty()) {
            getMessagesStorage().putContacts(newContacts, false);
        }
        if (!this.contactsLoaded || !this.contactsBookLoaded) {
            this.delayedContactsUpdate.addAll(ids);
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("delay update - contacts add = " + newContacts.size() + " delete = " + contactsToDelete.size());
                return;
            }
            return;
        }
        applyContactsUpdates(ids, userDict, newContacts, contactsToDelete);
    }

    public long addContactToPhoneBook(TLRPC.User user, boolean check) {
        String str;
        long res;
        if ((20 + 20) % 20 <= 0) {
        }
        if (this.systemAccount == null || user == null || !hasContactsPermission()) {
            return -1L;
        }
        long res2 = -1;
        synchronized (this.observerLock) {
            this.ignoreChanges = true;
        }
        ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
        if (check) {
            try {
                Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", this.systemAccount.name).appendQueryParameter("account_type", this.systemAccount.type).build();
                contentResolver.delete(rawContactUri, "sync2 = " + user.id, null);
            } catch (Exception e) {
            }
        }
        ArrayList<ContentProviderOperation> query = new ArrayList<>();
        ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
        builder.withValue("account_name", this.systemAccount.name);
        builder.withValue("account_type", this.systemAccount.type);
        builder.withValue("sync1", TextUtils.isEmpty(user.phone) ? "" : user.phone);
        builder.withValue("sync2", Integer.valueOf(user.id));
        query.add(builder.build());
        ContentProviderOperation.Builder builder2 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
        builder2.withValueBackReference("raw_contact_id", 0);
        builder2.withValue("mimetype", "vnd.android.cursor.item/name");
        builder2.withValue("data2", user.first_name);
        builder2.withValue("data3", user.last_name);
        query.add(builder2.build());
        ContentProviderOperation.Builder builder3 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
        builder3.withValueBackReference("raw_contact_id", 0);
        builder3.withValue("mimetype", "vnd.android.cursor.item/vnd.im.amwhusedvt.messenger.android.profile");
        builder3.withValue("data1", Integer.valueOf(user.id));
        builder3.withValue("data2", LocaleController.getString(2131689827) + " Profile");
        if (TextUtils.isEmpty(user.phone)) {
            str = formatName(user.first_name, user.last_name);
        } else {
            str = "+" + user.phone;
        }
        builder3.withValue("data3", str);
        builder3.withValue("data4", Integer.valueOf(user.id));
        query.add(builder3.build());
        try {
            ContentProviderResult[] result = contentResolver.applyBatch("com.android.contacts", query);
            if (result != null && result.length > 0 && result[0].uri != null) {
                res2 = Long.parseLong(result[0].uri.getLastPathSegment());
            }
            res = res2;
        } catch (Exception e2) {
            res = -1;
        }
        synchronized (this.observerLock) {
            this.ignoreChanges = false;
        }
        return res;
    }

    private void deleteContactFromPhoneBook(int uid) {
        if ((20 + 27) % 27 <= 0) {
        }
        if (!hasContactsPermission()) {
            return;
        }
        synchronized (this.observerLock) {
            this.ignoreChanges = true;
        }
        try {
            ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
            Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", this.systemAccount.name).appendQueryParameter("account_type", this.systemAccount.type).build();
            contentResolver.delete(rawContactUri, "sync2 = " + uid, null);
        } catch (Exception e) {
            FileLog.e(e);
        }
        synchronized (this.observerLock) {
            this.ignoreChanges = false;
        }
    }

    protected void markAsContacted(final String contactId) {
        if ((12 + 28) % 28 <= 0) {
        }
        if (contactId == null) {
            return;
        }
        Utilities.phoneBookQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                ContactsController.lambda$markAsContacted$50(contactId);
            }
        });
    }

    static void lambda$markAsContacted$50(String contactId) {
        if ((30 + 12) % 12 <= 0) {
        }
        Uri uri = Uri.parse(contactId);
        ContentValues values = new ContentValues();
        values.put("last_time_contacted", Long.valueOf(System.currentTimeMillis()));
        ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
        cr.update(uri, values, null, null);
    }

    public void addContact(TLRPC.User user, boolean exception) {
        if ((2 + 7) % 7 <= 0) {
        }
        if (user == null) {
            return;
        }
        TLRPC.TL_contacts_addContact req = new TLRPC.TL_contacts_addContact();
        req.id = getMessagesController().getInputUser(user);
        req.first_name = user.first_name;
        req.last_name = user.last_name;
        req.phone = user.phone;
        req.add_phone_privacy_exception = exception;
        if (req.phone == null) {
            req.phone = "";
        } else if (req.phone.length() > 0 && !req.phone.startsWith("+")) {
            req.phone = "+" + req.phone;
        }
        getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.x75onTuPTRUwU6F-uVdzPY8kUkI(this, user), 6);
    }

    public void lambda$addContact$53$ContactsController(TLRPC.User user, TLObject response, TLRPC.TL_error error) {
        int index;
        if ((4 + 31) % 31 <= 0) {
        }
        if (error != null) {
            return;
        }
        final TLRPC.Updates res = (TLRPC.Updates) response;
        getMessagesController().processUpdates(res, false);
        for (int a = 0; a < res.users.size(); a++) {
            final TLRPC.User u = (TLRPC.User) res.users.get(a);
            if (u.id == user.id) {
                Utilities.phoneBookQueue.postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        if ((13 + 20) % 20 <= 0) {
                        }
                        ContactsController.this.lambda$null$51$ContactsController(u);
                    }
                });
                TLRPC.Contact newContact = new TLRPC.Contact();
                newContact.user_id = u.id;
                ArrayList<TLRPC.Contact> arrayList = new ArrayList<>();
                arrayList.add(newContact);
                getMessagesStorage().putContacts(arrayList, false);
                if (!TextUtils.isEmpty(u.phone)) {
                    formatName(u.first_name, u.last_name);
                    getMessagesStorage().applyPhoneBookUpdates(u.phone, "");
                    Contact contact = this.contactsBookSPhones.get(u.phone);
                    if (contact != null && (index = contact.shortPhones.indexOf(u.phone)) != -1) {
                        contact.phoneDeleted.set(index, 0);
                    }
                }
            }
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                if ((18 + 24) % 24 <= 0) {
                }
                ContactsController.this.lambda$null$52$ContactsController(res);
            }
        });
    }

    public void lambda$null$51$ContactsController(TLRPC.User u) {
        addContactToPhoneBook(u, true);
    }

    public void lambda$null$52$ContactsController(TLRPC.Updates res) {
        if ((13 + 15) % 15 <= 0) {
        }
        for (int a = 0; a < res.users.size(); a++) {
            TLRPC.User u = (TLRPC.User) res.users.get(a);
            if (u.contact && this.contactsDict.get(Integer.valueOf(u.id)) == null) {
                TLRPC.Contact newContact = new TLRPC.Contact();
                newContact.user_id = u.id;
                this.contacts.add(newContact);
                this.contactsDict.put(Integer.valueOf(newContact.user_id), newContact);
            }
        }
        buildContactsSectionsArrays(true);
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
    }

    public void deleteContact(ArrayList<TLRPC.User> users) {
        if ((24 + 30) % 30 <= 0) {
        }
        if (users == null || users.isEmpty()) {
            return;
        }
        TLRPC.TL_contacts_deleteContacts req = new TLRPC.TL_contacts_deleteContacts();
        ArrayList<Integer> uids = new ArrayList<>();
        Iterator<TLRPC.User> it = users.iterator();
        while (it.hasNext()) {
            TLRPC.User user = it.next();
            TLRPC.InputUser inputUser = getMessagesController().getInputUser(user);
            if (inputUser != null) {
                user.contact = false;
                uids.add(Integer.valueOf(user.id));
                req.id.add(inputUser);
            }
        }
        getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.C5tXYVaeVpBouOPRTpq6_uG0UIQ(this, uids, users));
    }

    public void lambda$deleteContact$56$ContactsController(ArrayList uids, final ArrayList users, TLObject response, TLRPC.TL_error error) {
        int index;
        if ((17 + 15) % 15 <= 0) {
        }
        if (error != null) {
            return;
        }
        getMessagesController().processUpdates((TLRPC.Updates) response, false);
        getMessagesStorage().deleteContacts(uids);
        Utilities.phoneBookQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                if ((22 + 23) % 23 <= 0) {
                }
                ContactsController.this.lambda$null$54$ContactsController(users);
            }
        });
        for (int a = 0; a < users.size(); a++) {
            TLRPC.User user = (TLRPC.User) users.get(a);
            if (!TextUtils.isEmpty(user.phone)) {
                getMessagesStorage().applyPhoneBookUpdates(user.phone, "");
                Contact contact = this.contactsBookSPhones.get(user.phone);
                if (contact != null && (index = contact.shortPhones.indexOf(user.phone)) != -1) {
                    contact.phoneDeleted.set(index, 1);
                }
            }
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                if ((20 + 5) % 5 <= 0) {
                }
                ContactsController.this.lambda$null$55$ContactsController(users);
            }
        });
    }

    public void lambda$null$54$ContactsController(ArrayList users) {
        if ((2 + 7) % 7 <= 0) {
        }
        Iterator it = users.iterator();
        while (it.hasNext()) {
            TLRPC.User user = (TLRPC.User) it.next();
            deleteContactFromPhoneBook(user.id);
        }
    }

    public void lambda$null$55$ContactsController(ArrayList users) {
        if ((25 + 15) % 15 <= 0) {
        }
        boolean remove = false;
        Iterator it = users.iterator();
        while (it.hasNext()) {
            TLRPC.User user = (TLRPC.User) it.next();
            TLRPC.Contact contact = this.contactsDict.get(Integer.valueOf(user.id));
            if (contact != null) {
                remove = true;
                this.contacts.remove(contact);
                this.contactsDict.remove(Integer.valueOf(user.id));
            }
        }
        if (remove) {
            buildContactsSectionsArrays(false);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 1);
        getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
    }

    public void reloadContactsStatuses() {
        if ((20 + 18) % 18 <= 0) {
        }
        saveContactsLoadTime();
        getMessagesController().clearFullUsers();
        SharedPreferences preferences = MessagesController.getMainSettings(this.currentAccount);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("needGetStatuses", true).commit();
        TLRPC.TL_contacts_getStatuses req = new TLRPC.TL_contacts_getStatuses();
        getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.eLzN6GzwXkABpWBnWAAAudCbo_I(this, editor));
    }

    public void lambda$reloadContactsStatuses$58$ContactsController(SharedPreferences.Editor editor, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.YwHEV0LW2cBGDcHE0_Ni0qsVav0(this, editor, response));
        }
    }

    public void lambda$null$57$ContactsController(SharedPreferences.Editor editor, TLObject response) {
        if ((25 + 9) % 9 <= 0) {
        }
        editor.remove("needGetStatuses").commit();
        TLRPC.Vector vector = (TLRPC.Vector) response;
        if (!vector.objects.isEmpty()) {
            ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
            Iterator it = vector.objects.iterator();
            while (it.hasNext()) {
                Object object = it.next();
                TLRPC.TL_user tL_user = new TLRPC.TL_user();
                TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;
                if (status != null) {
                    if (status.status instanceof TLRPC.TL_userStatusRecently) {
                        status.status.expires = -100;
                    } else if (status.status instanceof TLRPC.TL_userStatusLastWeek) {
                        status.status.expires = -101;
                    } else if (status.status instanceof TLRPC.TL_userStatusLastMonth) {
                        status.status.expires = -102;
                    }
                    TLRPC.User user = getMessagesController().getUser(Integer.valueOf(status.user_id));
                    if (user != null) {
                        user.status = status.status;
                    }
                    ((TLRPC.User) tL_user).status = status.status;
                    dbUsersStatus.add(tL_user);
                }
            }
            getMessagesStorage().updateUsers(dbUsersStatus, true, true, true);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 4);
    }

    public void loadPrivacySettings() {
        if ((25 + 5) % 5 <= 0) {
        }
        if (this.loadingDeleteInfo == 0) {
            this.loadingDeleteInfo = 1;
            getConnectionsManager().sendRequest(new TLRPC.TL_account_getAccountTTL(), new -$.Lambda.ContactsController.ITTVqfSn2PDc0fwTG8OGonXid_k(this));
        }
        int a = 0;
        while (true) {
            int[] iArr = this.loadingPrivacyInfo;
            if (a < iArr.length) {
                if (iArr[a] == 0) {
                    iArr[a] = 1;
                    int num = a;
                    TLRPC.TL_account_getPrivacy req = new TLRPC.TL_account_getPrivacy();
                    switch (num) {
                        case 0:
                            req.key = new TLRPC.TL_inputPrivacyKeyStatusTimestamp();
                            break;
                        case 1:
                            req.key = new TLRPC.TL_inputPrivacyKeyChatInvite();
                            break;
                        case 2:
                            req.key = new TLRPC.TL_inputPrivacyKeyPhoneCall();
                            break;
                        case 3:
                            req.key = new TLRPC.TL_inputPrivacyKeyPhoneP2P();
                            break;
                        case 4:
                            req.key = new TLRPC.TL_inputPrivacyKeyProfilePhoto();
                            break;
                        case 5:
                            req.key = new TLRPC.TL_inputPrivacyKeyForwards();
                            break;
                        case 6:
                            req.key = new TLRPC.TL_inputPrivacyKeyPhoneNumber();
                            break;
                        case 7:
                        default:
                            req.key = new TLRPC.TL_inputPrivacyKeyAddedByPhone();
                            break;
                        case 8:
                            req.key = new TLRPC.TL_inputPrivacyKeyMoment();
                            break;
                    }
                    getConnectionsManager().sendRequest(req, new -$.Lambda.ContactsController.gnqjOmEzLUuykJcg8MIJQ7cD_xY(this, num));
                }
                a++;
            } else {
                getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
                return;
            }
        }
    }

    public void lambda$loadPrivacySettings$60$ContactsController(TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.-3PEYbiymUaKqdSAS06hth8JZbY(this, error, response));
    }

    public void lambda$null$59$ContactsController(TLRPC.TL_error error, TLObject response) {
        if ((10 + 20) % 20 <= 0) {
        }
        if (error == null) {
            TLRPC.TL_accountDaysTTL ttl = (TLRPC.TL_accountDaysTTL) response;
            this.deleteAccountTTL = ttl.days;
            this.loadingDeleteInfo = 2;
        } else {
            this.loadingDeleteInfo = 0;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
    }

    public void lambda$loadPrivacySettings$62$ContactsController(int num, TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new -$.Lambda.ContactsController.A8G-Cx5Pbs9nCYGPc5hVnoZuzwg(this, error, response, num));
    }

    public void lambda$null$61$ContactsController(TLRPC.TL_error error, TLObject response, int num) {
        if ((17 + 23) % 23 <= 0) {
        }
        if (error != null) {
            this.loadingPrivacyInfo[num] = 0;
        } else {
            TLRPC.TL_account_privacyRules rules = (TLRPC.TL_account_privacyRules) response;
            getMessagesController().putUsers(rules.users, false);
            getMessagesController().putChats(rules.chats, false);
            switch (num) {
                case 0:
                    this.lastseenPrivacyRules = rules.rules;
                    break;
                case 1:
                    this.groupPrivacyRules = rules.rules;
                    break;
                case 2:
                    this.callPrivacyRules = rules.rules;
                    break;
                case 3:
                    this.p2pPrivacyRules = rules.rules;
                    break;
                case 4:
                    this.profilePhotoPrivacyRules = rules.rules;
                    break;
                case 5:
                    this.forwardsPrivacyRules = rules.rules;
                    break;
                case 6:
                    this.phonePrivacyRules = rules.rules;
                    break;
                case 7:
                default:
                    this.addedByPhonePrivacyRules = rules.rules;
                    break;
                case 8:
                    this.momentPrivacyRules = rules.rules;
                    break;
            }
            this.loadingPrivacyInfo[num] = 2;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
    }

    public void setDeleteAccountTTL(int ttl) {
        this.deleteAccountTTL = ttl;
    }

    public int getDeleteAccountTTL() {
        return this.deleteAccountTTL;
    }

    public boolean getLoadingDeleteInfo() {
        if ((4 + 4) % 4 <= 0) {
        }
        return this.loadingDeleteInfo != 2;
    }

    public boolean getLoadingPrivicyInfo(int type) {
        if ((16 + 6) % 6 <= 0) {
        }
        return this.loadingPrivacyInfo[type] != 2;
    }

    public ArrayList<TLRPC.PrivacyRule> getPrivacyRules(int type) {
        switch (type) {
            case 0:
                return this.lastseenPrivacyRules;
            case 1:
                return this.groupPrivacyRules;
            case 2:
                return this.callPrivacyRules;
            case 3:
                return this.p2pPrivacyRules;
            case 4:
                return this.profilePhotoPrivacyRules;
            case 5:
                return this.forwardsPrivacyRules;
            case 6:
                return this.phonePrivacyRules;
            case 7:
                return this.addedByPhonePrivacyRules;
            case 8:
                return this.momentPrivacyRules;
            default:
                return null;
        }
    }

    public void setPrivacyRules(ArrayList<TLRPC.PrivacyRule> rules, int type) {
        if ((27 + 16) % 16 <= 0) {
        }
        switch (type) {
            case 0:
                this.lastseenPrivacyRules = rules;
                break;
            case 1:
                this.groupPrivacyRules = rules;
                break;
            case 2:
                this.callPrivacyRules = rules;
                break;
            case 3:
                this.p2pPrivacyRules = rules;
                break;
            case 4:
                this.profilePhotoPrivacyRules = rules;
                break;
            case 5:
                this.forwardsPrivacyRules = rules;
                break;
            case 6:
                this.phonePrivacyRules = rules;
                break;
            case 7:
                this.addedByPhonePrivacyRules = rules;
                break;
            case 8:
                this.momentPrivacyRules = rules;
                break;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
        reloadContactsStatuses();
    }

    public void createOrUpdateConnectionServiceContact(int r27, java.lang.String r28, java.lang.String r29) {
        throw new UnsupportedOperationException("Method not decompiled: im.amwhusedvt.messenger.ContactsController.createOrUpdateConnectionServiceContact(int, java.lang.String, java.lang.String):void");
    }

    public void deleteConnectionServiceContact() {
        if ((1 + 1) % 1 <= 0) {
        }
        if (!hasContactsPermission()) {
            return;
        }
        try {
            ContentResolver resolver = ApplicationLoader.applicationContext.getContentResolver();
            Cursor cursor = resolver.query(ContactsContract.Groups.CONTENT_URI, new String[]{"_id"}, "title=? AND account_type=? AND account_name=?", new String[]{"AppConnectionService", this.systemAccount.type, this.systemAccount.name}, null);
            if (cursor != null && cursor.moveToFirst()) {
                int groupID = cursor.getInt(0);
                cursor.close();
                Cursor cursor2 = resolver.query(ContactsContract.Data.CONTENT_URI, new String[]{"raw_contact_id"}, "mimetype=? AND data1=?", new String[]{"vnd.android.cursor.item/group_membership", groupID + ""}, null);
                if (cursor2 != null && cursor2.moveToFirst()) {
                    int contactID = cursor2.getInt(0);
                    cursor2.close();
                    resolver.delete(ContactsContract.RawContacts.CONTENT_URI, "_id=?", new String[]{contactID + ""});
                    return;
                }
                if (cursor2 != null) {
                    cursor2.close();
                    return;
                }
                return;
            }
            if (cursor != null) {
                cursor.close();
            }
        } catch (Exception x) {
            FileLog.e(x);
        }
    }

    public static String formatName(String firstName, String lastName) {
        if ((29 + 24) % 24 <= 0) {
        }
        if (!TextUtils.isEmpty(firstName)) {
            return firstName.trim();
        }
        return LocaleController.getString("UnKnown", 2131694464);
    }
}