TRsnnPP♥️️ v2.7.0版本的 MD5 值为:b2c0ede0dab6219a3c74c99b83ed6b25
以下内容为反编译后的 ContactsController.java 源代码,内容仅作参考
package im.uslhaplvsp.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.ContentObserver;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.SparseArray;
import androidx.exifinterface.media.ExifInterface;
import com.bjz.comm.net.premission.PermissionUtils;
import im.uslhaplvsp.messenger.ContactsController;
import im.uslhaplvsp.messenger.support.SparseLongArray;
import im.uslhaplvsp.phoneformat.PhoneFormat;
import im.uslhaplvsp.tgnet.ConnectionsManager;
import im.uslhaplvsp.tgnet.RequestDelegate;
import im.uslhaplvsp.tgnet.TLObject;
import im.uslhaplvsp.tgnet.TLRPC;
import im.uslhaplvsp.tgnet.TLRPCContacts;
import im.uslhaplvsp.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;
import org.slf4j.Marker;
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;
public static void lambda$resetImportedContacts$9(TLObject tLObject, TLRPC.TL_error tL_error) {
}
private class MyContentObserver extends ContentObserver {
private Runnable checkRunnable;
@Override
public boolean deliverSelfNotifications() {
return false;
}
public static void lambda$new$0() {
for (int i = 0; i < 3; i++) {
if (UserConfig.getInstance(i).isClientActivated()) {
ConnectionsManager.getInstance(i).resumeNetworkMaybe();
}
}
}
public MyContentObserver() {
super(null);
this.checkRunnable = new Runnable() {
@Override
public final void run() {
ContactsController.MyContentObserver.lambda$new$0();
}
};
}
@Override
public void onChange(boolean z) {
super.onChange(z);
synchronized (ContactsController.this.observerLock) {
if (ContactsController.this.ignoreChanges) {
return;
}
Utilities.globalQueue.cancelRunnable(this.checkRunnable);
Utilities.globalQueue.postRunnable(this.checkRunnable, 500L);
}
}
}
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 String provider;
public TLRPC.User user;
public ArrayList<String> phones = new ArrayList<>(4);
public ArrayList<String> phoneTypes = new ArrayList<>(4);
public ArrayList<String> shortPhones = new ArrayList<>(4);
public ArrayList<Integer> phoneDeleted = new ArrayList<>(4);
public String getLetter() {
return getLetter(this.first_name, this.last_name);
}
public static String getLetter(String str, String str2) {
if (TextUtils.isEmpty(str)) {
return !TextUtils.isEmpty(str2) ? str2.substring(0, 1) : "#";
}
return str.substring(0, 1);
}
}
public static ContactsController getInstance(int i) {
ContactsController contactsController = Instance[i];
if (contactsController == null) {
synchronized (ContactsController.class) {
contactsController = Instance[i];
if (contactsController == null) {
ContactsController[] contactsControllerArr = Instance;
ContactsController contactsController2 = new ContactsController(i);
contactsControllerArr[i] = contactsController2;
contactsController = contactsController2;
}
}
}
return contactsController;
}
public ContactsController(int i) {
super(i);
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<>();
if (MessagesController.getMainSettings(this.currentAccount).getBoolean("needGetStatuses", false)) {
reloadContactsStatuses();
}
this.sectionsToReplace.put("À", ExifInterface.GPS_MEASUREMENT_IN_PROGRESS);
this.sectionsToReplace.put("Á", ExifInterface.GPS_MEASUREMENT_IN_PROGRESS);
this.sectionsToReplace.put("Ä", ExifInterface.GPS_MEASUREMENT_IN_PROGRESS);
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("È", ExifInterface.LONGITUDE_EAST);
this.sectionsToReplace.put("É", ExifInterface.LONGITUDE_EAST);
this.sectionsToReplace.put("Ê", ExifInterface.LONGITUDE_EAST);
this.sectionsToReplace.put("Ë", ExifInterface.LONGITUDE_EAST);
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 (i == 0) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$new$0$ContactsController();
}
});
}
}
public void lambda$new$0$ContactsController() {
try {
if (hasContactsPermission()) {
ApplicationLoader.applicationContext.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new MyContentObserver());
}
} catch (Throwable unused) {
}
}
public void cleanup() {
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 i = 0;
while (true) {
int[] iArr = this.loadingPrivacyInfo;
if (i < iArr.length) {
iArr[i] = 0;
i++;
} 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 Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$cleanup$1$ContactsController();
}
});
return;
}
}
}
public void lambda$cleanup$1$ContactsController() {
this.migratingContacts = false;
this.completedRequestsCount = 0;
}
public void checkInviteText() {
SharedPreferences mainSettings = MessagesController.getMainSettings(this.currentAccount);
this.inviteLink = mainSettings.getString("invitelink", null);
int i = mainSettings.getInt("invitelinktime", 0);
if (this.updatingInviteLink) {
return;
}
if (this.inviteLink == null || Math.abs((System.currentTimeMillis() / 1000) - i) >= 86400) {
this.updatingInviteLink = true;
getConnectionsManager().sendRequest(new TLRPC.TL_help_getInviteText(), new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$checkInviteText$3$ContactsController(tLObject, tL_error);
}
}, 2);
}
}
public void lambda$checkInviteText$3$ContactsController(TLObject tLObject, TLRPC.TL_error tL_error) {
if (tLObject != null) {
final TLRPC.TL_help_inviteText tL_help_inviteText = (TLRPC.TL_help_inviteText) tLObject;
if (tL_help_inviteText.message.length() != 0) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$2$ContactsController(tL_help_inviteText);
}
});
}
}
}
public void lambda$null$2$ContactsController(TLRPC.TL_help_inviteText tL_help_inviteText) {
this.updatingInviteLink = false;
SharedPreferences.Editor edit = MessagesController.getMainSettings(this.currentAccount).edit();
String str = tL_help_inviteText.message;
this.inviteLink = str;
edit.putString("invitelink", str);
edit.putInt("invitelinktime", (int) (System.currentTimeMillis() / 1000));
edit.commit();
}
public String getInviteText(int i) {
String str = this.inviteLink;
if (str == null) {
str = "https://m12345.cc/dl";
}
if (i <= 1) {
return LocaleController.formatString("InviteText2", R.string.InviteText2, str);
}
try {
return String.format(LocaleController.getPluralString("InviteTextNum", i), Integer.valueOf(i), str);
} catch (Exception unused) {
return LocaleController.formatString("InviteText2", R.string.InviteText2, str);
}
}
public void checkAppAccount() {
boolean z;
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
try {
Account[] accountsByType = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
this.systemAccount = null;
for (int i = 0; i < accountsByType.length; i++) {
Account account = accountsByType[i];
int i2 = 0;
while (true) {
if (i2 >= 3) {
z = false;
break;
}
TLRPC.User currentUser = UserConfig.getInstance(i2).getCurrentUser();
if (currentUser != null) {
if (account.name.equals("" + currentUser.id)) {
if (i2 == this.currentAccount) {
this.systemAccount = account;
}
z = true;
}
}
i2++;
}
if (!z) {
try {
accountManager.removeAccount(accountsByType[i], null, null);
} catch (Exception unused) {
}
}
}
} catch (Throwable unused2) {
}
if (getUserConfig().isClientActivated()) {
readContacts();
if (this.systemAccount == null) {
try {
Account account2 = new Account("" + getUserConfig().getClientUserId(), BuildConfig.APPLICATION_ID);
this.systemAccount = account2;
accountManager.addAccountExplicitly(account2, "", null);
} catch (Exception unused3) {
}
}
}
}
public void deleteUnknownAppAccounts() {
boolean z;
try {
this.systemAccount = null;
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
Account[] accountsByType = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
for (int i = 0; i < accountsByType.length; i++) {
Account account = accountsByType[i];
int i2 = 0;
while (true) {
if (i2 >= 3) {
z = false;
break;
}
TLRPC.User currentUser = UserConfig.getInstance(i2).getCurrentUser();
if (currentUser != null) {
if (account.name.equals("" + currentUser.id)) {
z = true;
break;
}
}
i2++;
}
if (!z) {
try {
accountManager.removeAccount(accountsByType[i], null, null);
} catch (Exception unused) {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void checkContacts() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$checkContacts$4$ContactsController();
}
});
}
public void lambda$checkContacts$4$ContactsController() {
if (checkContactsInternal()) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("detected contacts change");
}
performSyncPhoneBook(getContactsCopy(this.contactsBook), true, false, true, false, true, false);
}
}
public void forceImportContacts() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$forceImportContacts$5$ContactsController();
}
});
}
public void lambda$forceImportContacts$5$ContactsController() {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("force import contacts");
}
performSyncPhoneBook(new HashMap<>(), true, true, true, true, false, false);
}
public void syncPhoneBookByAlert(final HashMap<String, Contact> hashMap, final boolean z, final boolean z2, final boolean z3) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$syncPhoneBookByAlert$6$ContactsController(hashMap, z, z2, z3);
}
});
}
public void lambda$syncPhoneBookByAlert$6$ContactsController(HashMap hashMap, boolean z, boolean z2, boolean z3) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("sync contacts by alert");
}
performSyncPhoneBook(hashMap, true, z, z2, false, false, z3);
}
public void deleteAllContacts(final Runnable runnable) {
resetImportedContacts();
TLRPC.TL_contacts_deleteContacts tL_contacts_deleteContacts = new TLRPC.TL_contacts_deleteContacts();
int size = this.contacts.size();
for (int i = 0; i < size; i++) {
tL_contacts_deleteContacts.id.add(getMessagesController().getInputUser(this.contacts.get(i).user_id));
}
getConnectionsManager().sendRequest(tL_contacts_deleteContacts, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$deleteAllContacts$8$ContactsController(runnable, tLObject, tL_error);
}
});
}
public void lambda$deleteAllContacts$8$ContactsController(final Runnable runnable, TLObject tLObject, TLRPC.TL_error tL_error) {
if (tL_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() {
ContactsController.this.lambda$null$7$ContactsController(runnable);
}
});
return;
}
AndroidUtilities.runOnUIThread(runnable);
}
public void lambda$null$7$ContactsController(Runnable runnable) {
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
try {
Account[] accountsByType = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
this.systemAccount = null;
for (Account account : accountsByType) {
int i = 0;
while (true) {
if (i >= 3) {
break;
}
TLRPC.User currentUser = UserConfig.getInstance(i).getCurrentUser();
if (currentUser != null) {
if (account.name.equals("" + currentUser.id)) {
accountManager.removeAccount(account, null, null);
break;
}
}
i++;
}
}
} catch (Throwable unused) {
}
try {
Account account2 = new Account("" + getUserConfig().getClientUserId(), BuildConfig.APPLICATION_ID);
this.systemAccount = account2;
accountManager.addAccountExplicitly(account2, "", null);
} catch (Exception unused2) {
}
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() {
getConnectionsManager().sendRequest(new TLRPC.TL_contacts_resetSaved(), new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.lambda$resetImportedContacts$9(tLObject, tL_error);
}
});
}
private boolean checkContactsInternal() {
boolean z = false;
try {
} catch (Exception e) {
FileLog.e(e);
}
if (!hasContactsPermission()) {
return false;
}
try {
Cursor query = ApplicationLoader.applicationContext.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, new String[]{"version"}, null, null, null);
if (query != null) {
try {
StringBuilder sb = new StringBuilder();
while (query.moveToNext()) {
sb.append(query.getString(query.getColumnIndex("version")));
}
String sb2 = sb.toString();
if (this.lastContactsVersions.length() != 0 && !this.lastContactsVersions.equals(sb2)) {
z = true;
}
this.lastContactsVersions = sb2;
} finally {
}
}
if (query != null) {
query.close();
}
} catch (Exception e2) {
FileLog.e(e2);
}
return z;
}
public void readContacts() {
synchronized (this.loadContactsSync) {
if (this.loadingContacts) {
return;
}
this.loadingContacts = true;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$readContacts$10$ContactsController();
}
});
}
}
public void lambda$readContacts$10$ContactsController() {
if (!this.contacts.isEmpty() || this.contactsLoaded) {
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
return;
}
loadContacts(true, 0);
}
public void syncRemoteContacts() {
synchronized (this.loadContactsSync) {
if (this.loadingContacts) {
return;
}
this.loadingContacts = true;
loadContacts(false, getContactsHash(this.contacts));
}
}
private boolean isNotValidNameString(String str) {
if (TextUtils.isEmpty(str)) {
return true;
}
int length = str.length();
int i = 0;
for (int i2 = 0; i2 < length; i2++) {
char charAt = str.charAt(i2);
if (charAt >= '0' && charAt <= '9') {
i++;
}
}
return i > 3;
}
private HashMap<String, Contact> readContactsFromPhoneBook() {
HashMap<String, Contact> hashMap;
Cursor cursor;
HashMap<String, Contact> hashMap2;
ContentResolver contentResolver;
HashMap<String, Contact> hashMap3;
Cursor cursor2;
String substring;
StringBuilder sb;
ContentResolver contentResolver2;
Cursor cursor3;
ContactsController contactsController = this;
if (!getUserConfig().syncContacts) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts sync disabled");
}
return new HashMap<>();
}
if (!hasContactsPermission()) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("app has no contacts permissions");
}
return new HashMap<>();
}
try {
StringBuilder sb2 = new StringBuilder();
ContentResolver contentResolver3 = ApplicationLoader.applicationContext.getContentResolver();
HashMap hashMap4 = new HashMap();
ArrayList arrayList = new ArrayList();
?? query = contentResolver3.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, contactsController.projectionPhones, null, null, null);
int i = 0;
?? r9 = 1;
if (query != 0) {
try {
int count = query.getCount();
if (count > 0) {
hashMap3 = new HashMap<>(count);
int i2 = 1;
while (query.moveToNext()) {
try {
String string = query.getString(r9);
String string2 = query.getString(5);
if (string2 == null) {
string2 = "";
}
boolean z = string2.indexOf(".sim") != 0;
if (!TextUtils.isEmpty(string)) {
?? stripExceptNumbers = PhoneFormat.stripExceptNumbers(string, r9);
if (!TextUtils.isEmpty(stripExceptNumbers)) {
if (stripExceptNumbers.startsWith(Marker.ANY_NON_NULL_MARKER)) {
try {
substring = stripExceptNumbers.substring(r9);
} catch (Throwable th) {
th = th;
hashMap = hashMap3;
cursor = query;
try {
FileLog.e(th);
if (hashMap != null) {
}
if (cursor != null) {
}
hashMap2 = hashMap;
if (hashMap2 != null) {
}
} finally {
}
}
} else {
substring = stripExceptNumbers;
}
String string3 = query.getString(i);
sb2.setLength(i);
DatabaseUtils.appendEscapedSQLString(sb2, string3);
String sb3 = sb2.toString();
Contact contact = (Contact) hashMap4.get(substring);
if (contact != null) {
if (!contact.isGoodProvider && !string2.equals(contact.provider)) {
sb2.setLength(0);
DatabaseUtils.appendEscapedSQLString(sb2, contact.key);
arrayList.remove(sb2.toString());
arrayList.add(sb3);
contact.key = string3;
contact.isGoodProvider = z;
contact.provider = string2;
}
} else {
if (!arrayList.contains(sb3)) {
arrayList.add(sb3);
}
int i3 = query.getInt(2);
Contact contact2 = hashMap3.get(string3);
if (contact2 == null) {
contact2 = new Contact();
sb = sb2;
String string4 = query.getString(4);
String trim = string4 == null ? "" : string4.trim();
if (contactsController.isNotValidNameString(trim)) {
contact2.first_name = trim;
contact2.last_name = "";
contentResolver2 = contentResolver3;
} else {
contentResolver2 = contentResolver3;
int lastIndexOf = trim.lastIndexOf(32);
if (lastIndexOf != -1) {
contact2.first_name = trim.substring(0, lastIndexOf).trim();
contact2.last_name = trim.substring(lastIndexOf + 1).trim();
} else {
contact2.first_name = trim;
contact2.last_name = "";
}
}
contact2.provider = string2;
contact2.isGoodProvider = z;
contact2.key = string3;
contact2.contact_id = i2;
hashMap3.put(string3, contact2);
i2++;
} else {
sb = sb2;
contentResolver2 = contentResolver3;
}
contact2.shortPhones.add(substring);
contact2.phones.add(stripExceptNumbers);
contact2.phoneDeleted.add(0);
if (i3 == 0) {
String string5 = query.getString(3);
ArrayList<String> arrayList2 = contact2.phoneTypes;
if (string5 == null) {
string5 = LocaleController.getString("PhoneMobile", R.string.PhoneMobile);
}
arrayList2.add(string5);
} else if (i3 == 1) {
contact2.phoneTypes.add(LocaleController.getString("PhoneHome", R.string.PhoneHome));
} else if (i3 == 2) {
contact2.phoneTypes.add(LocaleController.getString("PhoneMobile", R.string.PhoneMobile));
} else if (i3 == 3) {
contact2.phoneTypes.add(LocaleController.getString("PhoneWork", R.string.PhoneWork));
} else if (i3 == 12) {
contact2.phoneTypes.add(LocaleController.getString("PhoneMain", R.string.PhoneMain));
} else {
contact2.phoneTypes.add(LocaleController.getString("PhoneOther", R.string.PhoneOther));
}
hashMap4.put(substring, contact2);
sb2 = sb;
contentResolver3 = contentResolver2;
r9 = 1;
i = 0;
contactsController = this;
}
}
}
r9 = 1;
i = 0;
} catch (Throwable th2) {
th = th2;
}
}
contentResolver = contentResolver3;
} else {
contentResolver = contentResolver3;
hashMap3 = null;
}
try {
query.close();
} catch (Exception unused) {
hashMap2 = hashMap3;
cursor2 = null;
}
} catch (Throwable th3) {
th = th3;
hashMap = null;
cursor = query;
}
} else {
contentResolver = contentResolver3;
cursor2 = query;
hashMap2 = null;
}
try {
String join = TextUtils.join(",", arrayList);
Uri uri = ContactsContract.Data.CONTENT_URI;
try {
cursor2 = contentResolver.query(uri, this.projectionNames, "lookup IN (" + join + ") AND mimetype = 'vnd.android.cursor.item/name'", null, null);
if (cursor2 != null) {
while (cursor2.moveToNext()) {
String string6 = cursor2.getString(0);
String string7 = cursor2.getString(1);
String string8 = cursor2.getString(2);
String string9 = cursor2.getString(3);
Contact contact3 = hashMap2.get(string6);
if (contact3 != null && !contact3.namesFilled) {
if (contact3.isGoodProvider) {
if (string7 != null) {
contact3.first_name = string7;
} else {
contact3.first_name = "";
}
if (string8 != null) {
contact3.last_name = string8;
} else {
contact3.last_name = "";
}
if (!TextUtils.isEmpty(string9)) {
if (!TextUtils.isEmpty(contact3.first_name)) {
contact3.first_name += " " + string9;
} else {
contact3.first_name = string9;
}
}
} else if ((!isNotValidNameString(string7) && (contact3.first_name.contains(string7) || string7.contains(contact3.first_name))) || (!isNotValidNameString(string8) && (contact3.last_name.contains(string8) || string7.contains(contact3.last_name)))) {
if (string7 != null) {
contact3.first_name = string7;
} else {
contact3.first_name = "";
}
if (!TextUtils.isEmpty(string9)) {
if (!TextUtils.isEmpty(contact3.first_name)) {
contact3.first_name += " " + string9;
} else {
contact3.first_name = string9;
}
}
if (string8 != null) {
contact3.last_name = string8;
} else {
contact3.last_name = "";
}
}
contact3.namesFilled = true;
}
}
try {
cursor2.close();
} catch (Exception unused2) {
}
cursor3 = null;
} else {
cursor3 = cursor2;
}
if (cursor3 != null) {
try {
cursor3.close();
} catch (Exception e) {
FileLog.e(e);
}
}
} catch (Throwable th4) {
th = th4;
cursor = cursor2;
hashMap = hashMap2;
FileLog.e(th);
if (hashMap != null) {
hashMap.clear();
}
if (cursor != null) {
try {
cursor.close();
} catch (Exception e2) {
FileLog.e(e2);
}
}
hashMap2 = hashMap;
if (hashMap2 != null) {
}
}
} catch (Throwable th5) {
th = th5;
}
} catch (Throwable th6) {
th = th6;
hashMap = null;
cursor = null;
}
return hashMap2 != null ? hashMap2 : new HashMap<>();
}
public HashMap<String, Contact> getContactsCopy(HashMap<String, Contact> hashMap) {
HashMap<String, Contact> hashMap2 = new HashMap<>();
for (Map.Entry<String, Contact> entry : hashMap.entrySet()) {
Contact contact = new Contact();
Contact value = entry.getValue();
contact.phoneDeleted.addAll(value.phoneDeleted);
contact.phones.addAll(value.phones);
contact.phoneTypes.addAll(value.phoneTypes);
contact.shortPhones.addAll(value.shortPhones);
contact.first_name = value.first_name;
contact.last_name = value.last_name;
contact.contact_id = value.contact_id;
contact.key = value.key;
hashMap2.put(contact.key, contact);
}
return hashMap2;
}
public void migratePhoneBookToV7(final SparseArray<Contact> sparseArray) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$migratePhoneBookToV7$11$ContactsController(sparseArray);
}
});
}
public void lambda$migratePhoneBookToV7$11$ContactsController(SparseArray sparseArray) {
if (this.migratingContacts) {
return;
}
this.migratingContacts = true;
HashMap<String, Contact> hashMap = new HashMap<>();
HashMap<String, Contact> readContactsFromPhoneBook = readContactsFromPhoneBook();
HashMap hashMap2 = new HashMap();
Iterator<Map.Entry<String, Contact>> it = readContactsFromPhoneBook.entrySet().iterator();
while (true) {
if (!it.hasNext()) {
break;
}
Contact value = it.next().getValue();
for (int i = 0; i < value.shortPhones.size(); i++) {
hashMap2.put(value.shortPhones.get(i), value.key);
}
}
for (int i2 = 0; i2 < sparseArray.size(); i2++) {
Contact contact = (Contact) sparseArray.valueAt(i2);
int i3 = 0;
while (true) {
if (i3 >= contact.shortPhones.size()) {
break;
}
String str = (String) hashMap2.get(contact.shortPhones.get(i3));
if (str != null) {
contact.key = str;
hashMap.put(str, contact);
break;
}
i3++;
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("migrated contacts " + hashMap.size() + " of " + sparseArray.size());
}
getMessagesStorage().putCachedPhoneBook(hashMap, true, false);
}
public void checkPhonebookUsers() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$checkPhonebookUsers$14$ContactsController();
}
});
}
public void lambda$checkPhonebookUsers$14$ContactsController() {
int i;
HashMap<String, Contact> readContactsFromPhoneBook = readContactsFromPhoneBook();
ArrayList arrayList = new ArrayList();
final HashMap hashMap = new HashMap();
Iterator<Map.Entry<String, Contact>> it = readContactsFromPhoneBook.entrySet().iterator();
while (true) {
i = 0;
if (!it.hasNext()) {
break;
}
Map.Entry<String, Contact> next = it.next();
Contact value = next.getValue();
next.getKey();
while (i < value.phones.size()) {
TLRPC.TL_inputPhoneContact tL_inputPhoneContact = new TLRPC.TL_inputPhoneContact();
tL_inputPhoneContact.client_id = value.contact_id;
tL_inputPhoneContact.client_id |= i << 32;
tL_inputPhoneContact.first_name = value.first_name;
tL_inputPhoneContact.last_name = value.last_name;
tL_inputPhoneContact.phone = value.phones.get(i);
arrayList.add(tL_inputPhoneContact);
hashMap.put(value.phones.get(i), tL_inputPhoneContact);
i++;
}
}
this.completedRequestsCount = 0;
final ArrayList arrayList2 = new ArrayList();
double size = arrayList.size();
Double.isNaN(size);
final int ceil = (int) Math.ceil(size / 500.0d);
while (i < ceil) {
TLRPC.TL_contacts_importContacts tL_contacts_importContacts = new TLRPC.TL_contacts_importContacts();
int i2 = i * 500;
tL_contacts_importContacts.contacts = new ArrayList<>(arrayList.subList(i2, Math.min(i2 + 500, arrayList.size())));
getConnectionsManager().sendRequest(tL_contacts_importContacts, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$null$13$ContactsController(arrayList2, ceil, hashMap, tLObject, tL_error);
}
}, 6);
i++;
}
}
public void lambda$null$13$ContactsController(final ArrayList arrayList, int i, final HashMap hashMap, TLObject tLObject, TLRPC.TL_error tL_error) {
this.completedRequestsCount++;
if (tL_error == null) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts imported");
}
TLRPC.TL_contacts_importedContacts tL_contacts_importedContacts = (TLRPC.TL_contacts_importedContacts) tLObject;
if (tL_contacts_importedContacts.users != null && !tL_contacts_importedContacts.users.isEmpty()) {
arrayList.addAll(tL_contacts_importedContacts.users);
}
}
if (this.completedRequestsCount == i) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$12$ContactsController(arrayList, hashMap);
}
});
}
}
public void lambda$null$12$ContactsController(ArrayList arrayList, HashMap hashMap) {
getNotificationCenter().postNotificationName(NotificationCenter.contactAboutPhonebookLoaded, arrayList, hashMap);
}
public void performSyncPhoneBook(final HashMap<String, Contact> hashMap, final boolean z, final boolean z2, final boolean z3, final boolean z4, final boolean z5, final boolean z6) {
if (z2 || this.contactsBookLoaded) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performSyncPhoneBook$27$ContactsController(hashMap, z3, z, z2, z4, z5, z6);
}
});
}
}
public void lambda$performSyncPhoneBook$27$ContactsController(final HashMap hashMap, final boolean z, boolean z2, final boolean z3, boolean z4, boolean z5, boolean z6) {
int i;
ArrayList arrayList;
HashMap hashMap2;
HashMap hashMap3;
ContactsController contactsController;
int i2;
int i3;
int i4;
Contact contact;
HashMap hashMap4;
String str;
ArrayList arrayList2;
HashMap hashMap5;
HashMap hashMap6;
int i5;
int indexOf;
ArrayList arrayList3;
int i6;
int i7;
boolean z7;
ContactsController contactsController2 = this;
HashMap hashMap7 = new HashMap();
Iterator it = hashMap.entrySet().iterator();
while (true) {
i = 0;
if (!it.hasNext()) {
break;
}
Contact contact2 = (Contact) ((Map.Entry) it.next()).getValue();
while (i < contact2.shortPhones.size()) {
hashMap7.put(contact2.shortPhones.get(i), contact2);
i++;
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("start read contacts from phone");
}
if (!z) {
checkContactsInternal();
}
final HashMap<String, Contact> readContactsFromPhoneBook = readContactsFromPhoneBook();
HashMap hashMap8 = new HashMap();
HashMap hashMap9 = new HashMap();
ArrayList arrayList4 = new ArrayList();
Iterator<Map.Entry<String, Contact>> it2 = readContactsFromPhoneBook.entrySet().iterator();
while (it2.hasNext()) {
Contact value = it2.next().getValue();
int size = value.shortPhones.size();
for (int i8 = 0; i8 < size; i8++) {
hashMap9.put(value.shortPhones.get(i8).substring(Math.max(0, r6.length() - 7)), value);
}
String letter = value.getLetter();
ArrayList arrayList5 = (ArrayList) hashMap8.get(letter);
if (arrayList5 == null) {
arrayList5 = new ArrayList();
hashMap8.put(letter, arrayList5);
arrayList4.add(letter);
}
arrayList5.add(value);
}
final HashMap hashMap10 = new HashMap();
int size2 = hashMap.size();
ArrayList arrayList6 = new ArrayList();
String str2 = "";
if (hashMap.isEmpty()) {
arrayList = arrayList4;
hashMap2 = hashMap9;
hashMap3 = hashMap8;
if (z2) {
int i9 = 0;
for (Map.Entry<String, Contact> entry : readContactsFromPhoneBook.entrySet()) {
Contact value2 = entry.getValue();
entry.getKey();
while (i4 < value2.phones.size()) {
if (!z4) {
String str3 = value2.shortPhones.get(i4);
String substring = str3.substring(Math.max(0, str3.length() - 7));
TLRPC.Contact contact3 = this.contactsByPhone.get(str3);
if (contact3 != null) {
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(contact3.user_id));
if (user != null) {
i9++;
i4 = (((user.first_name != null ? user.first_name : "").equals(value2.first_name) && (user.last_name != null ? user.last_name : "").equals(value2.last_name)) || (TextUtils.isEmpty(value2.first_name) && TextUtils.isEmpty(value2.last_name))) ? i4 + 1 : 0;
}
} else if (this.contactsByShortPhone.containsKey(substring)) {
i9++;
}
}
TLRPC.TL_inputPhoneContact tL_inputPhoneContact = new TLRPC.TL_inputPhoneContact();
tL_inputPhoneContact.client_id = value2.contact_id;
tL_inputPhoneContact.client_id |= i4 << 32;
tL_inputPhoneContact.first_name = value2.first_name;
tL_inputPhoneContact.last_name = value2.last_name;
tL_inputPhoneContact.phone = value2.phones.get(i4);
arrayList6.add(tL_inputPhoneContact);
}
}
contactsController = this;
i2 = i9;
} else {
contactsController = this;
i2 = 0;
}
i3 = 0;
} else {
Iterator<Map.Entry<String, Contact>> it3 = readContactsFromPhoneBook.entrySet().iterator();
i3 = 0;
int i10 = 0;
while (it3.hasNext()) {
Map.Entry<String, Contact> next = it3.next();
String key = next.getKey();
Contact value3 = next.getValue();
Contact contact4 = (Contact) hashMap.get(key);
Iterator<Map.Entry<String, Contact>> it4 = it3;
if (contact4 == null) {
while (i < value3.shortPhones.size()) {
contact = (Contact) hashMap7.get(value3.shortPhones.get(i));
if (contact != null) {
key = contact.key;
break;
}
i++;
}
}
contact = contact4;
if (contact != null) {
value3.imported = contact.imported;
}
if (contact != null) {
if (TextUtils.isEmpty(value3.first_name)) {
hashMap4 = hashMap7;
} else {
hashMap4 = hashMap7;
}
if (!TextUtils.isEmpty(value3.last_name)) {
}
} else {
hashMap4 = hashMap7;
}
boolean z8 = false;
if (contact == null || z8) {
str = str2;
arrayList2 = arrayList4;
hashMap5 = hashMap9;
hashMap6 = hashMap8;
int i11 = 0;
while (i11 < value3.phones.size()) {
String str4 = value3.shortPhones.get(i11);
str4.substring(Math.max(0, str4.length() - 7));
hashMap10.put(str4, value3);
if (contact != null && (indexOf = contact.shortPhones.indexOf(str4)) != -1) {
Integer num = contact.phoneDeleted.get(indexOf);
value3.phoneDeleted.set(i11, num);
}
boolean z9 = z8;
int i12 = size2;
i11++;
size2 = i12;
z8 = z9;
contactsController2 = this;
}
i5 = size2;
if (contact != null) {
hashMap.remove(key);
}
} else {
int i13 = 0;
while (i13 < value3.phones.size()) {
String str5 = value3.shortPhones.get(i13);
String str6 = str2;
HashMap hashMap11 = hashMap9;
String substring2 = str5.substring(Math.max(0, str5.length() - 7));
hashMap10.put(str5, value3);
int indexOf2 = contact.shortPhones.indexOf(str5);
if (z2) {
i6 = indexOf2;
TLRPC.Contact contact5 = contactsController2.contactsByPhone.get(str5);
if (contact5 != null) {
arrayList3 = arrayList4;
TLRPC.User user2 = getMessagesController().getUser(Integer.valueOf(contact5.user_id));
if (user2 != null) {
i10++;
if (TextUtils.isEmpty(user2.first_name) && TextUtils.isEmpty(user2.last_name) && (!TextUtils.isEmpty(value3.first_name) || !TextUtils.isEmpty(value3.last_name))) {
z7 = true;
i6 = -1;
i7 = i6;
HashMap hashMap12 = hashMap8;
if (i7 != -1) {
value3.phoneDeleted.set(i13, contact.phoneDeleted.get(i7));
contact.phones.remove(i7);
contact.shortPhones.remove(i7);
contact.phoneDeleted.remove(i7);
contact.phoneTypes.remove(i7);
} else if (z2) {
if (!z7) {
TLRPC.Contact contact6 = contactsController2.contactsByPhone.get(str5);
if (contact6 != null) {
TLRPC.User user3 = getMessagesController().getUser(Integer.valueOf(contact6.user_id));
if (user3 != null) {
i10++;
String str7 = user3.first_name != null ? user3.first_name : str6;
String str8 = user3.last_name != null ? user3.last_name : str6;
if (str7.equals(value3.first_name)) {
if (str8.equals(value3.last_name)) {
}
}
if (TextUtils.isEmpty(value3.first_name) && TextUtils.isEmpty(value3.last_name)) {
}
} else {
i3++;
}
} else if (contactsController2.contactsByShortPhone.containsKey(substring2)) {
i10++;
}
}
TLRPC.TL_inputPhoneContact tL_inputPhoneContact2 = new TLRPC.TL_inputPhoneContact();
tL_inputPhoneContact2.client_id = value3.contact_id;
tL_inputPhoneContact2.client_id = (i13 << 32) | tL_inputPhoneContact2.client_id;
tL_inputPhoneContact2.first_name = value3.first_name;
tL_inputPhoneContact2.last_name = value3.last_name;
tL_inputPhoneContact2.phone = value3.phones.get(i13);
arrayList6.add(tL_inputPhoneContact2);
i3 = i3;
}
i13++;
hashMap9 = hashMap11;
str2 = str6;
hashMap8 = hashMap12;
arrayList4 = arrayList3;
}
}
z7 = false;
i7 = i6;
HashMap hashMap122 = hashMap8;
if (i7 != -1) {
}
i13++;
hashMap9 = hashMap11;
str2 = str6;
hashMap8 = hashMap122;
arrayList4 = arrayList3;
} else {
arrayList3 = arrayList4;
if (contactsController2.contactsByShortPhone.containsKey(substring2)) {
i10++;
}
}
} else {
arrayList3 = arrayList4;
i6 = indexOf2;
}
i7 = i6;
z7 = false;
HashMap hashMap1222 = hashMap8;
if (i7 != -1) {
}
i13++;
hashMap9 = hashMap11;
str2 = str6;
hashMap8 = hashMap1222;
arrayList4 = arrayList3;
}
str = str2;
arrayList2 = arrayList4;
hashMap5 = hashMap9;
hashMap6 = hashMap8;
if (contact.phones.isEmpty()) {
hashMap.remove(key);
}
i5 = size2;
}
it3 = it4;
size2 = i5;
hashMap7 = hashMap4;
hashMap9 = hashMap5;
str2 = str;
hashMap8 = hashMap6;
arrayList4 = arrayList2;
i = 0;
contactsController2 = this;
}
int i14 = size2;
arrayList = arrayList4;
hashMap2 = hashMap9;
hashMap3 = hashMap8;
if (!z3 && hashMap.isEmpty() && arrayList6.isEmpty()) {
size2 = i14;
if (size2 == readContactsFromPhoneBook.size()) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts not changed!");
return;
}
return;
}
} else {
size2 = i14;
}
if (z2 && !hashMap.isEmpty() && !readContactsFromPhoneBook.isEmpty() && arrayList6.isEmpty()) {
getMessagesStorage().putCachedPhoneBook(readContactsFromPhoneBook, false, false);
}
contactsController = this;
i2 = i10;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("done processing contacts");
}
if (z2) {
if (!arrayList6.isEmpty()) {
if (BuildVars.LOGS_ENABLED) {
FileLog.e("start import contacts");
}
final int i15 = 2;
if (z5 && i3 != 0) {
if (i3 >= 30) {
i15 = 1;
} else if (z3) {
if (size2 == 0) {
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("new phone book contacts " + i3 + " serverContactsInPhonebook " + i2 + " totalContacts " + contactsController.contactsByPhone.size());
}
if (i15 == 0) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$16$ContactsController(i15, hashMap, z3, z);
}
});
return;
}
if (z6) {
final HashMap hashMap13 = hashMap3;
final ArrayList arrayList7 = arrayList;
final HashMap hashMap14 = hashMap2;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$18$ContactsController(hashMap10, readContactsFromPhoneBook, z3, hashMap13, arrayList7, hashMap14);
}
});
return;
}
boolean[] zArr = {false};
HashMap hashMap15 = new HashMap(readContactsFromPhoneBook);
SparseArray sparseArray = new SparseArray();
Iterator it5 = hashMap15.entrySet().iterator();
while (it5.hasNext()) {
Contact contact7 = (Contact) ((Map.Entry) it5.next()).getValue();
sparseArray.put(contact7.contact_id, contact7.key);
}
contactsController.completedRequestsCount = 0;
double size3 = arrayList6.size();
Double.isNaN(size3);
int ceil = (int) Math.ceil(size3 / 500.0d);
int i16 = 0;
while (i16 < ceil) {
final TLRPC.TL_contacts_importContacts tL_contacts_importContacts = new TLRPC.TL_contacts_importContacts();
int i17 = i16 * 500;
tL_contacts_importContacts.contacts = new ArrayList<>(arrayList6.subList(i17, Math.min(i17 + 500, arrayList6.size())));
final HashMap hashMap16 = hashMap15;
final SparseArray sparseArray2 = sparseArray;
final boolean[] zArr2 = zArr;
int i18 = i16;
final int i19 = ceil;
int i20 = ceil;
final HashMap hashMap17 = hashMap10;
HashMap hashMap18 = hashMap10;
final HashMap hashMap19 = hashMap3;
final ArrayList arrayList8 = arrayList;
HashMap hashMap20 = hashMap15;
final HashMap hashMap21 = hashMap2;
getConnectionsManager().sendRequest(tL_contacts_importContacts, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$null$22$ContactsController(hashMap16, sparseArray2, zArr2, readContactsFromPhoneBook, tL_contacts_importContacts, i19, hashMap17, z3, hashMap19, arrayList8, hashMap21, tLObject, tL_error);
}
}, 6);
i16 = i18 + 1;
zArr = zArr;
ceil = i20;
arrayList6 = arrayList6;
hashMap10 = hashMap18;
sparseArray = sparseArray;
hashMap15 = hashMap20;
arrayList = arrayList8;
}
return;
}
i15 = 0;
if (BuildVars.LOGS_ENABLED) {
}
if (i15 == 0) {
}
} else {
final ArrayList arrayList9 = arrayList;
final HashMap hashMap22 = hashMap3;
final HashMap hashMap23 = hashMap2;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$24$ContactsController(hashMap10, readContactsFromPhoneBook, z3, hashMap22, arrayList9, hashMap23);
}
});
}
} else {
final ArrayList arrayList10 = arrayList;
final HashMap hashMap24 = hashMap3;
final HashMap hashMap25 = hashMap2;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$26$ContactsController(hashMap10, readContactsFromPhoneBook, z3, hashMap24, arrayList10, hashMap25);
}
});
if (readContactsFromPhoneBook.isEmpty()) {
return;
}
getMessagesStorage().putCachedPhoneBook(readContactsFromPhoneBook, false, false);
}
}
private void lambda$null$15(HashMap hashMap) {
ArrayList<TLRPC.User> arrayList = new ArrayList<>();
if (hashMap != null && !hashMap.isEmpty()) {
try {
HashMap hashMap2 = new HashMap();
for (int i = 0; i < this.contacts.size(); i++) {
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(this.contacts.get(i).user_id));
if (user != null && !TextUtils.isEmpty(user.phone)) {
hashMap2.put(user.phone, user);
}
}
Iterator it = hashMap.entrySet().iterator();
while (it.hasNext()) {
Contact contact = (Contact) ((Map.Entry) it.next()).getValue();
int i2 = 0;
boolean z = false;
while (i2 < contact.shortPhones.size()) {
TLRPC.User user2 = (TLRPC.User) hashMap2.get(contact.shortPhones.get(i2));
if (user2 != null) {
arrayList.add(user2);
contact.shortPhones.remove(i2);
i2--;
z = true;
}
i2++;
}
if (z) {
contact.shortPhones.size();
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
if (arrayList.isEmpty()) {
return;
}
deleteContact(arrayList);
}
public void lambda$null$16$ContactsController(int i, HashMap hashMap, boolean z, boolean z2) {
getNotificationCenter().postNotificationName(NotificationCenter.hasNewContactsToImport, Integer.valueOf(i), hashMap, Boolean.valueOf(z), Boolean.valueOf(z2));
}
public void lambda$null$18$ContactsController(HashMap hashMap, HashMap hashMap2, boolean z, final HashMap hashMap3, final ArrayList arrayList, final HashMap hashMap4) {
this.contactsBookSPhones = hashMap;
this.contactsBook = hashMap2;
this.contactsSyncInProgress = false;
this.contactsBookLoaded = true;
if (z) {
this.contactsLoaded = true;
}
if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded) {
applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
this.delayedContactsUpdate.clear();
}
getMessagesStorage().putCachedPhoneBook(hashMap2, false, false);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$17$ContactsController(hashMap3, arrayList, hashMap4);
}
});
}
public void lambda$null$17$ContactsController(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$null$25$ContactsController(hashMap, arrayList, hashMap2);
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$null$22$ContactsController(HashMap hashMap, SparseArray sparseArray, final boolean[] zArr, final HashMap hashMap2, TLRPC.TL_contacts_importContacts tL_contacts_importContacts, int i, final HashMap hashMap3, final boolean z, final HashMap hashMap4, final ArrayList arrayList, final HashMap hashMap5, TLObject tLObject, TLRPC.TL_error tL_error) {
this.completedRequestsCount++;
if (tL_error == null) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts imported");
}
TLRPC.TL_contacts_importedContacts tL_contacts_importedContacts = (TLRPC.TL_contacts_importedContacts) tLObject;
if (!tL_contacts_importedContacts.retry_contacts.isEmpty()) {
for (int i2 = 0; i2 < tL_contacts_importedContacts.retry_contacts.size(); i2++) {
hashMap.remove(sparseArray.get((int) tL_contacts_importedContacts.retry_contacts.get(i2).longValue()));
}
zArr[0] = true;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("result has retry contacts");
}
}
for (int i3 = 0; i3 < tL_contacts_importedContacts.popular_invites.size(); i3++) {
TLRPC.TL_popularContact tL_popularContact = tL_contacts_importedContacts.popular_invites.get(i3);
Contact contact = (Contact) hashMap2.get(sparseArray.get((int) tL_popularContact.client_id));
if (contact != null) {
contact.imported = tL_popularContact.importers;
}
}
getMessagesStorage().putUsersAndChats(tL_contacts_importedContacts.users, null, true, true);
ArrayList<TLRPC.Contact> arrayList2 = new ArrayList<>();
for (int i4 = 0; i4 < tL_contacts_importedContacts.imported.size(); i4++) {
TLRPC.Contact contact2 = new TLRPC.Contact();
contact2.user_id = tL_contacts_importedContacts.imported.get(i4).user_id;
arrayList2.add(contact2);
}
processLoadedContacts(arrayList2, tL_contacts_importedContacts.users, 2);
} else {
for (int i5 = 0; i5 < tL_contacts_importContacts.contacts.size(); i5++) {
hashMap.remove(sparseArray.get((int) tL_contacts_importContacts.contacts.get(i5).client_id));
}
zArr[0] = true;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("import contacts error " + tL_error.text);
}
}
if (this.completedRequestsCount == i) {
if (!hashMap.isEmpty()) {
getMessagesStorage().putCachedPhoneBook(hashMap, false, false);
}
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$21$ContactsController(hashMap3, hashMap2, z, hashMap4, arrayList, hashMap5, zArr);
}
});
}
}
public void lambda$null$21$ContactsController(HashMap hashMap, HashMap hashMap2, boolean z, final HashMap hashMap3, final ArrayList arrayList, final HashMap hashMap4, boolean[] zArr) {
this.contactsBookSPhones = hashMap;
this.contactsBook = hashMap2;
this.contactsSyncInProgress = false;
this.contactsBookLoaded = true;
if (z) {
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() {
ContactsController.this.lambda$null$19$ContactsController(hashMap3, arrayList, hashMap4);
}
});
if (zArr[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 hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$null$25$ContactsController(hashMap, arrayList, hashMap2);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$null$20$ContactsController() {
getMessagesStorage().getCachedPhoneBook(true);
}
public void lambda$null$24$ContactsController(HashMap hashMap, HashMap hashMap2, boolean z, final HashMap hashMap3, final ArrayList arrayList, final HashMap hashMap4) {
this.contactsBookSPhones = hashMap;
this.contactsBook = hashMap2;
this.contactsSyncInProgress = false;
this.contactsBookLoaded = true;
if (z) {
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() {
ContactsController.this.lambda$null$23$ContactsController(hashMap3, arrayList, hashMap4);
}
});
}
public void lambda$null$23$ContactsController(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$null$25$ContactsController(hashMap, arrayList, hashMap2);
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$null$26$ContactsController(HashMap hashMap, HashMap hashMap2, boolean z, final HashMap hashMap3, final ArrayList arrayList, final HashMap hashMap4) {
this.contactsBookSPhones = hashMap;
this.contactsBook = hashMap2;
this.contactsSyncInProgress = false;
this.contactsBookLoaded = true;
if (z) {
this.contactsLoaded = true;
}
if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded && this.contactsBookLoaded) {
applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
this.delayedContactsUpdate.clear();
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$25$ContactsController(hashMap3, arrayList, hashMap4);
}
});
}
public boolean isLoadingContacts() {
boolean z;
synchronized (this.loadContactsSync) {
z = this.loadingContacts;
}
return z;
}
private int getContactsHash(ArrayList<TLRPC.Contact> arrayList) {
long j;
int i;
ArrayList arrayList2 = new ArrayList(arrayList);
Collections.sort(arrayList2, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$getContactsHash$28((TLRPC.Contact) obj, (TLRPC.Contact) obj2);
}
});
int size = arrayList2.size();
long j2 = 0;
for (int i2 = -1; i2 < size; i2++) {
if (i2 == -1) {
j = (j2 * 20261) + 2147483648L;
i = getUserConfig().contactsSavedCount;
} else {
j = (j2 * 20261) + 2147483648L;
i = ((TLRPC.Contact) arrayList2.get(i2)).user_id;
}
j2 = (j + i) % 2147483648L;
}
return (int) j2;
}
public static int lambda$getContactsHash$28(TLRPC.Contact contact, TLRPC.Contact contact2) {
if (contact.user_id > contact2.user_id) {
return 1;
}
return contact.user_id < contact2.user_id ? -1 : 0;
}
public void loadContacts(boolean z, final int i) {
synchronized (this.loadContactsSync) {
this.loadingContacts = true;
}
if (z) {
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 tL_getContactsV1 = new TLRPCContacts.TL_getContactsV1();
tL_getContactsV1.hash = i;
getConnectionsManager().sendRequest(tL_getContactsV1, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$loadContacts$30$ContactsController(i, tLObject, tL_error);
}
});
}
}
public void lambda$loadContacts$30$ContactsController(int i, TLObject tLObject, TLRPC.TL_error tL_error) {
if (tL_error == null) {
TLRPC.contacts_Contacts contacts_contacts = (TLRPC.contacts_Contacts) tLObject;
if (i != 0 && (contacts_contacts 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 = contacts_contacts.saved_count;
getUserConfig().saveConfig(false);
processLoadedContacts(contacts_contacts.contacts, contacts_contacts.users, 0);
}
}
public void lambda$null$29$ContactsController() {
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void processLoadedContacts(final ArrayList<TLRPC.Contact> arrayList, final ArrayList<TLRPC.User> arrayList2, final int i) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$38$ContactsController(arrayList2, i, arrayList);
}
});
}
public void lambda$processLoadedContacts$38$ContactsController(final ArrayList arrayList, final int i, final ArrayList arrayList2) {
getMessagesController().putUsers(arrayList, i == 1);
final SparseArray sparseArray = new SparseArray();
ArrayList arrayList3 = new ArrayList();
final boolean isEmpty = arrayList2.isEmpty();
if (!this.contacts.isEmpty()) {
HashMap hashMap = new HashMap();
int i2 = 0;
while (i2 < arrayList2.size()) {
TLRPC.Contact contact = (TLRPC.Contact) arrayList2.get(i2);
hashMap.put(Integer.valueOf(contact.user_id), contact);
if (this.contactsDict.get(Integer.valueOf(contact.user_id)) != null) {
arrayList2.remove(i2);
i2--;
}
i2++;
}
int i3 = 0;
while (i3 < this.contacts.size()) {
if (hashMap.get(Integer.valueOf(this.contacts.get(i3).user_id)) == null) {
this.contacts.remove(i3);
i3--;
}
i3++;
}
arrayList2.addAll(this.contacts);
}
for (int i4 = 0; i4 < arrayList2.size(); i4++) {
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(((TLRPC.Contact) arrayList2.get(i4)).user_id));
if (user != null) {
sparseArray.put(user.id, user);
arrayList3.add(Integer.valueOf(user.id));
}
}
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$37$ContactsController(i, arrayList2, sparseArray, arrayList, isEmpty);
}
});
}
public void lambda$null$37$ContactsController(final int i, final ArrayList arrayList, SparseArray sparseArray, ArrayList arrayList2, final boolean z) {
final HashMap hashMap;
final HashMap hashMap2;
int i2;
ArrayList arrayList3 = arrayList;
final SparseArray sparseArray2 = sparseArray;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("done loading contactsfrom = " + i);
}
if (i == 1 && (arrayList.isEmpty() || Math.abs((System.currentTimeMillis() / 1000) - getUserConfig().lastContactsSyncTime) >= 7200)) {
loadContacts(false, getContactsHash(arrayList3));
if (arrayList.isEmpty()) {
return;
}
}
if (i == 0) {
getUserConfig().lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000);
getUserConfig().saveConfig(false);
}
for (int i3 = 0; i3 < arrayList.size(); i3++) {
TLRPC.Contact contact = arrayList3.get(i3);
if (sparseArray2.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 (i != 1) {
getMessagesStorage().putUsersAndChats(arrayList2, null, true, true);
getMessagesStorage().putContacts(arrayList3, i != 2);
}
Collections.sort(arrayList3, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int compareTo;
compareTo = UserObject.getFirstName((TLRPC.User) r0.get(((TLRPC.Contact) obj).user_id)).compareTo(UserObject.getFirstName((TLRPC.User) sparseArray2.get(((TLRPC.Contact) obj2).user_id)));
return compareTo;
}
});
final ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap(20, 1.0f, 2);
final HashMap hashMap3 = new HashMap();
final HashMap hashMap4 = new HashMap();
final ArrayList arrayList4 = new ArrayList();
final ArrayList arrayList5 = new ArrayList();
if (this.contactsBookLoaded) {
hashMap = null;
hashMap2 = null;
} else {
HashMap hashMap5 = new HashMap();
hashMap2 = new HashMap();
hashMap = hashMap5;
}
int i4 = 0;
while (i4 < arrayList.size()) {
TLRPC.Contact contact2 = arrayList3.get(i4);
TLRPC.User user = (TLRPC.User) sparseArray2.get(contact2.user_id);
if (user != null) {
concurrentHashMap.put(Integer.valueOf(contact2.user_id), contact2);
if (hashMap == null || TextUtils.isEmpty(user.phone)) {
i2 = 0;
} else {
hashMap.put(user.phone, contact2);
i2 = 0;
hashMap2.put(user.phone.substring(Math.max(0, user.phone.length() - 7)), contact2);
}
String selling = CharacterParser.getInstance().getSelling(UserObject.getFirstName(user));
if (selling.length() > 1) {
selling = selling.substring(i2, 1);
}
String upperCase = selling.length() == 0 ? "#" : selling.toUpperCase();
String str = this.sectionsToReplace.get(upperCase);
if (str != null) {
upperCase = str;
}
ArrayList arrayList6 = (ArrayList) hashMap3.get(upperCase);
if (arrayList6 == null) {
arrayList6 = new ArrayList();
hashMap3.put(upperCase, arrayList6);
arrayList4.add(upperCase);
}
arrayList6.add(contact2);
if (user.mutual_contact) {
ArrayList arrayList7 = (ArrayList) hashMap4.get(upperCase);
if (arrayList7 == null) {
arrayList7 = new ArrayList();
hashMap4.put(upperCase, arrayList7);
arrayList5.add(upperCase);
}
arrayList7.add(contact2);
}
}
i4++;
arrayList3 = arrayList;
sparseArray2 = sparseArray;
}
Collections.sort(arrayList4, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$null$32((String) obj, (String) obj2);
}
});
Collections.sort(arrayList5, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$null$33((String) obj, (String) obj2);
}
});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$34$ContactsController(arrayList, concurrentHashMap, hashMap3, hashMap4, arrayList4, arrayList5, i, z);
}
});
if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded && this.contactsBookLoaded) {
applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
this.delayedContactsUpdate.clear();
}
if (hashMap != null) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$36$ContactsController(hashMap, hashMap2);
}
});
} else {
this.contactsLoaded = true;
}
}
public static int lambda$null$32(String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return str.compareTo(str2);
}
public static int lambda$null$33(String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return str.compareTo(str2);
}
public void lambda$null$34$ContactsController(ArrayList arrayList, ConcurrentHashMap concurrentHashMap, HashMap hashMap, HashMap hashMap2, ArrayList arrayList2, ArrayList arrayList3, int i, boolean z) {
this.contacts = arrayList;
this.contactsDict = concurrentHashMap;
this.usersSectionsDict = hashMap;
this.usersMutualSectionsDict = hashMap2;
this.sortedUsersSectionsArray = arrayList2;
this.sortedUsersMutualSectionsArray = arrayList3;
if (i != 2) {
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
}
performWriteContactsToPhoneBook();
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
if (i != 1 && !z) {
saveContactsLoadTime();
} else {
reloadContactsStatusesMaybe();
}
}
public void lambda$null$36$ContactsController(final HashMap hashMap, final HashMap hashMap2) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$35$ContactsController(hashMap, hashMap2);
}
});
if (this.contactsSyncInProgress) {
return;
}
this.contactsSyncInProgress = true;
getMessagesStorage().getCachedPhoneBook(false);
}
public void lambda$null$35$ContactsController(HashMap hashMap, HashMap hashMap2) {
this.contactsByPhone = hashMap;
this.contactsByShortPhone = hashMap2;
}
public boolean isContact(int i) {
return this.contactsDict.get(Integer.valueOf(i)) != null;
}
private void reloadContactsStatusesMaybe() {
try {
if (MessagesController.getMainSettings(this.currentAccount).getLong("lastReloadStatusTime", 0L) < System.currentTimeMillis() - 86400000) {
reloadContactsStatuses();
}
} catch (Exception e) {
FileLog.e(e);
}
}
private void saveContactsLoadTime() {
try {
MessagesController.getMainSettings(this.currentAccount).edit().putLong("lastReloadStatusTime", System.currentTimeMillis()).commit();
} catch (Exception e) {
FileLog.e(e);
}
}
public void lambda$null$25$ContactsController(final HashMap<String, ArrayList<Object>> hashMap, final ArrayList<String> arrayList, final HashMap<String, Contact> hashMap2) {
final ArrayList arrayList2 = new ArrayList(this.contacts);
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$mergePhonebookAndAppContacts$42$ContactsController(arrayList2, hashMap2, hashMap, arrayList);
}
});
}
public void lambda$mergePhonebookAndAppContacts$42$ContactsController(ArrayList arrayList, HashMap hashMap, final HashMap hashMap2, final ArrayList arrayList2) {
int size = arrayList.size();
for (int i = 0; i < size; i++) {
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(((TLRPC.Contact) arrayList.get(i)).user_id));
if (user != null && !TextUtils.isEmpty(user.phone)) {
Contact contact = (Contact) hashMap.get(user.phone.substring(Math.max(0, user.phone.length() - 7)));
if (contact != null) {
if (contact.user == null) {
contact.user = user;
}
} else {
String letter = Contact.getLetter(user.first_name, user.last_name);
ArrayList arrayList3 = (ArrayList) hashMap2.get(letter);
if (arrayList3 == null) {
arrayList3 = new ArrayList();
hashMap2.put(letter, arrayList3);
arrayList2.add(letter);
}
arrayList3.add(user);
}
}
}
Iterator it = hashMap2.values().iterator();
while (it.hasNext()) {
Collections.sort((ArrayList) it.next(), new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$null$39(obj, obj2);
}
});
}
Collections.sort(arrayList2, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$null$40((String) obj, (String) obj2);
}
});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$41$ContactsController(arrayList2, hashMap2);
}
});
}
public static int lambda$null$39(Object obj, Object obj2) {
String str;
String formatName;
String str2 = "";
if (obj instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) obj;
str = formatName(user.first_name, user.last_name);
} else if (obj instanceof Contact) {
Contact contact = (Contact) obj;
if (contact.user != null) {
str = formatName(contact.user.first_name, contact.user.last_name);
} else {
str = formatName(contact.first_name, contact.last_name);
}
} else {
str = "";
}
if (obj2 instanceof TLRPC.User) {
TLRPC.User user2 = (TLRPC.User) obj2;
str2 = formatName(user2.first_name, user2.last_name);
} else if (obj2 instanceof Contact) {
Contact contact2 = (Contact) obj2;
if (contact2.user != null) {
formatName = formatName(contact2.user.first_name, contact2.user.last_name);
} else {
formatName = formatName(contact2.first_name, contact2.last_name);
}
str2 = formatName;
}
return str.compareTo(str2);
}
public static int lambda$null$40(String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return str.compareTo(str2);
}
public void lambda$null$41$ContactsController(ArrayList arrayList, HashMap hashMap) {
this.phoneBookSectionsArray = arrayList;
this.phoneBookSectionsDict = hashMap;
}
private void updateUnregisteredContacts() {
boolean z;
HashMap hashMap = new HashMap();
int size = this.contacts.size();
for (int i = 0; i < size; i++) {
TLRPC.Contact contact = this.contacts.get(i);
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(contact.user_id));
if (user != null && !TextUtils.isEmpty(user.phone)) {
hashMap.put(user.phone, contact);
}
}
ArrayList<Contact> arrayList = new ArrayList<>();
Iterator<Map.Entry<String, Contact>> it = this.contactsBook.entrySet().iterator();
while (it.hasNext()) {
Contact value = it.next().getValue();
int i2 = 0;
while (true) {
z = true;
if (i2 >= value.phones.size()) {
z = false;
break;
} else if (hashMap.containsKey(value.shortPhones.get(i2)) || value.phoneDeleted.get(i2).intValue() == 1) {
break;
} else {
i2++;
}
}
if (!z) {
arrayList.add(value);
}
}
Collections.sort(arrayList, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$updateUnregisteredContacts$43((ContactsController.Contact) obj, (ContactsController.Contact) obj2);
}
});
this.phoneBookContacts = arrayList;
}
public static int lambda$updateUnregisteredContacts$43(Contact contact, Contact contact2) {
String str = contact.first_name;
if (str.length() == 0) {
str = contact.last_name;
}
String str2 = contact2.first_name;
if (str2.length() == 0) {
str2 = contact2.last_name;
}
return str.compareTo(str2);
}
private void buildContactsSectionsArrays(boolean z) {
if (z) {
Collections.sort(this.contacts, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.this.lambda$buildContactsSectionsArrays$44$ContactsController((TLRPC.Contact) obj, (TLRPC.Contact) obj2);
}
});
}
HashMap<String, ArrayList<TLRPC.Contact>> hashMap = new HashMap<>();
ArrayList<String> arrayList = new ArrayList<>();
for (int i = 0; i < this.contacts.size(); i++) {
TLRPC.Contact contact = this.contacts.get(i);
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(contact.user_id));
if (user != null) {
String selling = CharacterParser.getInstance().getSelling(UserObject.getFirstName(user));
if (selling.length() > 1) {
selling = selling.substring(0, 1);
}
String upperCase = selling.length() == 0 ? "#" : selling.toUpperCase();
String str = this.sectionsToReplace.get(upperCase);
if (str != null) {
upperCase = str;
}
ArrayList<TLRPC.Contact> arrayList2 = hashMap.get(upperCase);
if (arrayList2 == null) {
arrayList2 = new ArrayList<>();
hashMap.put(upperCase, arrayList2);
arrayList.add(upperCase);
}
arrayList2.add(contact);
}
}
Collections.sort(arrayList, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
return ContactsController.lambda$buildContactsSectionsArrays$45((String) obj, (String) obj2);
}
});
this.usersSectionsDict = hashMap;
this.sortedUsersSectionsArray = arrayList;
}
public int lambda$buildContactsSectionsArrays$44$ContactsController(TLRPC.Contact contact, TLRPC.Contact contact2) {
return UserObject.getFirstName(getMessagesController().getUser(Integer.valueOf(contact.user_id))).compareTo(UserObject.getFirstName(getMessagesController().getUser(Integer.valueOf(contact2.user_id))));
}
public static int lambda$buildContactsSectionsArrays$45(String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return str.compareTo(str2);
}
private boolean hasContactsPermission() {
if (Build.VERSION.SDK_INT >= 23) {
return ApplicationLoader.applicationContext.checkSelfPermission(PermissionUtils.LINKMAIN) == 0;
}
Cursor cursor = null;
try {
try {
cursor = ApplicationLoader.applicationContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, this.projectionPhones, null, null, null);
} catch (Throwable th) {
try {
FileLog.e(th);
if (cursor != null) {
cursor.close();
}
} finally {
if (cursor != null) {
try {
cursor.close();
} catch (Exception e) {
FileLog.e(e);
}
}
}
}
} catch (Exception e2) {
FileLog.e(e2);
}
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> arrayList) {
Cursor cursor = null;
try {
try {
} catch (Exception e) {
e = e;
}
if (hasContactsPermission()) {
Cursor query = ApplicationLoader.applicationContext.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("account_name", this.systemAccount.name).appendQueryParameter("account_type", this.systemAccount.type).build(), new String[]{"_id", "sync2"}, null, null, null);
try {
SparseLongArray sparseLongArray = new SparseLongArray();
if (query != null) {
while (query.moveToNext()) {
sparseLongArray.put(query.getInt(1), query.getLong(0));
}
query.close();
for (int i = 0; i < arrayList.size(); i++) {
TLRPC.Contact contact = arrayList.get(i);
if (sparseLongArray.indexOfKey(contact.user_id) < 0) {
addContactToPhoneBook(getMessagesController().getUser(Integer.valueOf(contact.user_id)), false);
}
}
} else {
cursor = query;
}
if (cursor == null) {
return;
}
} catch (Exception e2) {
e = e2;
cursor = query;
FileLog.e(e);
if (cursor == null) {
return;
}
cursor.close();
} catch (Throwable th) {
th = th;
cursor = query;
if (cursor != null) {
cursor.close();
}
throw th;
}
cursor.close();
}
} catch (Throwable th2) {
th = th2;
}
}
private void performWriteContactsToPhoneBook() {
final ArrayList arrayList = new ArrayList(this.contacts);
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performWriteContactsToPhoneBook$46$ContactsController(arrayList);
}
});
}
private void applyContactsUpdates(ArrayList<Integer> arrayList, ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap, final ArrayList<TLRPC.Contact> arrayList2, final ArrayList<Integer> arrayList3) {
int indexOf;
int indexOf2;
if (arrayList2 == null || arrayList3 == null) {
arrayList2 = new ArrayList<>();
arrayList3 = new ArrayList<>();
for (int i = 0; i < arrayList.size(); i++) {
Integer num = arrayList.get(i);
if (num.intValue() > 0) {
TLRPC.Contact contact = new TLRPC.Contact();
contact.user_id = num.intValue();
arrayList2.add(contact);
} else if (num.intValue() < 0) {
arrayList3.add(Integer.valueOf(-num.intValue()));
}
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("process update - contacts add = " + arrayList2.size() + " delete = " + arrayList3.size());
}
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
int i2 = 0;
boolean z = false;
while (true) {
if (i2 >= arrayList2.size()) {
break;
}
TLRPC.Contact contact2 = arrayList2.get(i2);
TLRPC.User user = concurrentHashMap != null ? concurrentHashMap.get(Integer.valueOf(contact2.user_id)) : null;
if (user == null) {
user = getMessagesController().getUser(Integer.valueOf(contact2.user_id));
} else {
getMessagesController().putUser(user, true);
}
if (user == null || TextUtils.isEmpty(user.phone)) {
z = true;
} else {
Contact contact3 = this.contactsBookSPhones.get(user.phone);
if (contact3 != null && (indexOf2 = contact3.shortPhones.indexOf(user.phone)) != -1) {
contact3.phoneDeleted.set(indexOf2, 0);
}
if (sb.length() != 0) {
sb.append(",");
}
sb.append(user.phone);
}
i2++;
}
for (int i3 = 0; i3 < arrayList3.size(); i3++) {
final Integer num2 = arrayList3.get(i3);
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$applyContactsUpdates$47$ContactsController(num2);
}
});
TLRPC.User user2 = concurrentHashMap != null ? concurrentHashMap.get(num2) : null;
if (user2 == null) {
user2 = getMessagesController().getUser(num2);
} else {
getMessagesController().putUser(user2, true);
}
if (user2 == null) {
z = true;
} else if (!TextUtils.isEmpty(user2.phone)) {
Contact contact4 = this.contactsBookSPhones.get(user2.phone);
if (contact4 != null && (indexOf = contact4.shortPhones.indexOf(user2.phone)) != -1) {
contact4.phoneDeleted.set(indexOf, 1);
}
if (sb2.length() != 0) {
sb2.append(",");
}
sb2.append(user2.phone);
}
}
if (sb.length() != 0 || sb2.length() != 0) {
getMessagesStorage().applyPhoneBookUpdates(sb.toString(), sb2.toString());
}
if (z) {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$applyContactsUpdates$48$ContactsController();
}
});
} else {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$applyContactsUpdates$49$ContactsController(arrayList2, arrayList3);
}
});
}
}
public void lambda$applyContactsUpdates$47$ContactsController(Integer num) {
deleteContactFromPhoneBook(num.intValue());
}
public void lambda$applyContactsUpdates$48$ContactsController() {
loadContacts(false, 0);
}
public void lambda$applyContactsUpdates$49$ContactsController(ArrayList arrayList, ArrayList arrayList2) {
for (int i = 0; i < arrayList.size(); i++) {
TLRPC.Contact contact = (TLRPC.Contact) arrayList.get(i);
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 i2 = 0; i2 < arrayList2.size(); i2++) {
Integer num = (Integer) arrayList2.get(i2);
TLRPC.Contact contact2 = this.contactsDict.get(num);
if (contact2 != null) {
this.contacts.remove(contact2);
this.contactsDict.remove(num);
}
}
if (!arrayList.isEmpty()) {
updateUnregisteredContacts();
performWriteContactsToPhoneBook();
}
performSyncPhoneBook(getContactsCopy(this.contactsBook), false, false, false, false, true, false);
buildContactsSectionsArrays(!arrayList.isEmpty());
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void processContactsUpdates(ArrayList<Integer> arrayList, ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap) {
int indexOf;
int indexOf2;
ArrayList<TLRPC.Contact> arrayList2 = new ArrayList<>();
ArrayList<Integer> arrayList3 = new ArrayList<>();
Iterator<Integer> it = arrayList.iterator();
while (it.hasNext()) {
Integer next = it.next();
if (next.intValue() > 0) {
TLRPC.Contact contact = new TLRPC.Contact();
contact.user_id = next.intValue();
arrayList2.add(contact);
if (!this.delayedContactsUpdate.isEmpty() && (indexOf = this.delayedContactsUpdate.indexOf(Integer.valueOf(-next.intValue()))) != -1) {
this.delayedContactsUpdate.remove(indexOf);
}
} else if (next.intValue() < 0) {
arrayList3.add(Integer.valueOf(-next.intValue()));
if (!this.delayedContactsUpdate.isEmpty() && (indexOf2 = this.delayedContactsUpdate.indexOf(Integer.valueOf(-next.intValue()))) != -1) {
this.delayedContactsUpdate.remove(indexOf2);
}
}
}
arrayList3.isEmpty();
if (!arrayList2.isEmpty()) {
getMessagesStorage().putContacts(arrayList2, false);
}
if (!this.contactsLoaded || !this.contactsBookLoaded) {
this.delayedContactsUpdate.addAll(arrayList);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("delay update - contacts add = " + arrayList2.size() + " delete = " + arrayList3.size());
return;
}
return;
}
applyContactsUpdates(arrayList, concurrentHashMap, arrayList2, arrayList3);
}
public long addContactToPhoneBook(TLRPC.User user, boolean z) {
String str;
long j = -1;
if (this.systemAccount == null || user == null || !hasContactsPermission()) {
return -1L;
}
synchronized (this.observerLock) {
this.ignoreChanges = true;
}
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
if (z) {
try {
contentResolver.delete(ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", this.systemAccount.name).appendQueryParameter("account_type", this.systemAccount.type).build(), "sync2 = " + user.id, null);
} catch (Exception unused) {
}
}
ArrayList<ContentProviderOperation> arrayList = new ArrayList<>();
ContentProviderOperation.Builder newInsert = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
newInsert.withValue("account_name", this.systemAccount.name);
newInsert.withValue("account_type", this.systemAccount.type);
newInsert.withValue("sync1", TextUtils.isEmpty(user.phone) ? "" : user.phone);
newInsert.withValue("sync2", Integer.valueOf(user.id));
arrayList.add(newInsert.build());
ContentProviderOperation.Builder newInsert2 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
newInsert2.withValueBackReference("raw_contact_id", 0);
newInsert2.withValue("mimetype", "vnd.android.cursor.item/name");
newInsert2.withValue("data2", user.first_name);
newInsert2.withValue("data3", user.last_name);
arrayList.add(newInsert2.build());
ContentProviderOperation.Builder newInsert3 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
newInsert3.withValueBackReference("raw_contact_id", 0);
newInsert3.withValue("mimetype", "vnd.android.cursor.item/vnd.im.uslhaplvsp.messenger.android.profile");
newInsert3.withValue("data1", Integer.valueOf(user.id));
newInsert3.withValue("data2", LocaleController.getString(R.string.AppName) + " Profile");
if (TextUtils.isEmpty(user.phone)) {
str = formatName(user.first_name, user.last_name);
} else {
str = Marker.ANY_NON_NULL_MARKER + user.phone;
}
newInsert3.withValue("data3", str);
newInsert3.withValue("data4", Integer.valueOf(user.id));
arrayList.add(newInsert3.build());
try {
ContentProviderResult[] applyBatch = contentResolver.applyBatch("com.android.contacts", arrayList);
if (applyBatch != null && applyBatch.length > 0 && applyBatch[0].uri != null) {
j = Long.parseLong(applyBatch[0].uri.getLastPathSegment());
}
} catch (Exception unused2) {
}
synchronized (this.observerLock) {
this.ignoreChanges = false;
}
return j;
}
private void deleteContactFromPhoneBook(int i) {
if (hasContactsPermission()) {
synchronized (this.observerLock) {
this.ignoreChanges = true;
}
try {
ApplicationLoader.applicationContext.getContentResolver().delete(ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", this.systemAccount.name).appendQueryParameter("account_type", this.systemAccount.type).build(), "sync2 = " + i, null);
} catch (Exception e) {
FileLog.e(e);
}
synchronized (this.observerLock) {
this.ignoreChanges = false;
}
}
}
protected void markAsContacted(final String str) {
if (str == null) {
return;
}
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.lambda$markAsContacted$50(str);
}
});
}
public static void lambda$markAsContacted$50(String str) {
Uri parse = Uri.parse(str);
ContentValues contentValues = new ContentValues();
contentValues.put("last_time_contacted", Long.valueOf(System.currentTimeMillis()));
ApplicationLoader.applicationContext.getContentResolver().update(parse, contentValues, null, null);
}
public void addContact(final TLRPC.User user, boolean z) {
if (user == null) {
return;
}
TLRPC.TL_contacts_addContact tL_contacts_addContact = new TLRPC.TL_contacts_addContact();
tL_contacts_addContact.id = getMessagesController().getInputUser(user);
tL_contacts_addContact.first_name = user.first_name;
tL_contacts_addContact.last_name = user.last_name;
tL_contacts_addContact.phone = user.phone;
tL_contacts_addContact.add_phone_privacy_exception = z;
if (tL_contacts_addContact.phone == null) {
tL_contacts_addContact.phone = "";
} else if (tL_contacts_addContact.phone.length() > 0 && !tL_contacts_addContact.phone.startsWith(Marker.ANY_NON_NULL_MARKER)) {
tL_contacts_addContact.phone = Marker.ANY_NON_NULL_MARKER + tL_contacts_addContact.phone;
}
getConnectionsManager().sendRequest(tL_contacts_addContact, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$addContact$53$ContactsController(user, tLObject, tL_error);
}
}, 6);
}
public void lambda$addContact$53$ContactsController(TLRPC.User user, TLObject tLObject, TLRPC.TL_error tL_error) {
int indexOf;
if (tL_error != null) {
return;
}
final TLRPC.Updates updates = (TLRPC.Updates) tLObject;
getMessagesController().processUpdates(updates, false);
for (int i = 0; i < updates.users.size(); i++) {
final TLRPC.User user2 = updates.users.get(i);
if (user2.id == user.id) {
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$51$ContactsController(user2);
}
});
TLRPC.Contact contact = new TLRPC.Contact();
contact.user_id = user2.id;
ArrayList<TLRPC.Contact> arrayList = new ArrayList<>();
arrayList.add(contact);
getMessagesStorage().putContacts(arrayList, false);
if (!TextUtils.isEmpty(user2.phone)) {
formatName(user2.first_name, user2.last_name);
getMessagesStorage().applyPhoneBookUpdates(user2.phone, "");
Contact contact2 = this.contactsBookSPhones.get(user2.phone);
if (contact2 != null && (indexOf = contact2.shortPhones.indexOf(user2.phone)) != -1) {
contact2.phoneDeleted.set(indexOf, 0);
}
}
}
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$52$ContactsController(updates);
}
});
}
public void lambda$null$51$ContactsController(TLRPC.User user) {
addContactToPhoneBook(user, true);
}
public void lambda$null$52$ContactsController(TLRPC.Updates updates) {
for (int i = 0; i < updates.users.size(); i++) {
TLRPC.User user = updates.users.get(i);
if (user.contact && this.contactsDict.get(Integer.valueOf(user.id)) == null) {
TLRPC.Contact contact = new TLRPC.Contact();
contact.user_id = user.id;
this.contacts.add(contact);
this.contactsDict.put(Integer.valueOf(contact.user_id), contact);
}
}
buildContactsSectionsArrays(true);
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void deleteContact(final ArrayList<TLRPC.User> arrayList) {
if (arrayList == null || arrayList.isEmpty()) {
return;
}
TLRPC.TL_contacts_deleteContacts tL_contacts_deleteContacts = new TLRPC.TL_contacts_deleteContacts();
final ArrayList arrayList2 = new ArrayList();
Iterator<TLRPC.User> it = arrayList.iterator();
while (it.hasNext()) {
TLRPC.User next = it.next();
TLRPC.InputUser inputUser = getMessagesController().getInputUser(next);
if (inputUser != null) {
next.contact = false;
arrayList2.add(Integer.valueOf(next.id));
tL_contacts_deleteContacts.id.add(inputUser);
}
}
getConnectionsManager().sendRequest(tL_contacts_deleteContacts, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$deleteContact$56$ContactsController(arrayList2, arrayList, tLObject, tL_error);
}
});
}
public void lambda$deleteContact$56$ContactsController(ArrayList arrayList, final ArrayList arrayList2, TLObject tLObject, TLRPC.TL_error tL_error) {
int indexOf;
if (tL_error != null) {
return;
}
getMessagesController().processUpdates((TLRPC.Updates) tLObject, false);
getMessagesStorage().deleteContacts(arrayList);
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$54$ContactsController(arrayList2);
}
});
for (int i = 0; i < arrayList2.size(); i++) {
TLRPC.User user = (TLRPC.User) arrayList2.get(i);
if (!TextUtils.isEmpty(user.phone)) {
getMessagesStorage().applyPhoneBookUpdates(user.phone, "");
Contact contact = this.contactsBookSPhones.get(user.phone);
if (contact != null && (indexOf = contact.shortPhones.indexOf(user.phone)) != -1) {
contact.phoneDeleted.set(indexOf, 1);
}
}
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$55$ContactsController(arrayList2);
}
});
}
public void lambda$null$54$ContactsController(ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
deleteContactFromPhoneBook(((TLRPC.User) it.next()).id);
}
}
public void lambda$null$55$ContactsController(ArrayList arrayList) {
Iterator it = arrayList.iterator();
boolean z = false;
while (it.hasNext()) {
TLRPC.User user = (TLRPC.User) it.next();
TLRPC.Contact contact = this.contactsDict.get(Integer.valueOf(user.id));
if (contact != null) {
this.contacts.remove(contact);
this.contactsDict.remove(Integer.valueOf(user.id));
z = true;
}
}
if (z) {
buildContactsSectionsArrays(false);
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 1);
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void reloadContactsStatuses() {
saveContactsLoadTime();
getMessagesController().clearFullUsers();
final SharedPreferences.Editor edit = MessagesController.getMainSettings(this.currentAccount).edit();
edit.putBoolean("needGetStatuses", true).commit();
getConnectionsManager().sendRequest(new TLRPC.TL_contacts_getStatuses(), new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$reloadContactsStatuses$58$ContactsController(edit, tLObject, tL_error);
}
});
}
public void lambda$reloadContactsStatuses$58$ContactsController(final SharedPreferences.Editor editor, final TLObject tLObject, TLRPC.TL_error tL_error) {
if (tL_error == null) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$57$ContactsController(editor, tLObject);
}
});
}
}
public void lambda$null$57$ContactsController(SharedPreferences.Editor editor, TLObject tLObject) {
editor.remove("needGetStatuses").commit();
TLRPC.Vector vector = (TLRPC.Vector) tLObject;
if (!vector.objects.isEmpty()) {
ArrayList<TLRPC.User> arrayList = new ArrayList<>();
Iterator<Object> it = vector.objects.iterator();
while (it.hasNext()) {
Object next = it.next();
TLRPC.TL_user tL_user = new TLRPC.TL_user();
TLRPC.TL_contactStatus tL_contactStatus = (TLRPC.TL_contactStatus) next;
if (tL_contactStatus != null) {
if (tL_contactStatus.status instanceof TLRPC.TL_userStatusRecently) {
tL_contactStatus.status.expires = -100;
} else if (tL_contactStatus.status instanceof TLRPC.TL_userStatusLastWeek) {
tL_contactStatus.status.expires = -101;
} else if (tL_contactStatus.status instanceof TLRPC.TL_userStatusLastMonth) {
tL_contactStatus.status.expires = -102;
}
TLRPC.User user = getMessagesController().getUser(Integer.valueOf(tL_contactStatus.user_id));
if (user != null) {
user.status = tL_contactStatus.status;
}
tL_user.status = tL_contactStatus.status;
arrayList.add(tL_user);
}
}
getMessagesStorage().updateUsers(arrayList, true, true, true);
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 4);
}
public void loadPrivacySettings() {
if (this.loadingDeleteInfo == 0) {
this.loadingDeleteInfo = 1;
getConnectionsManager().sendRequest(new TLRPC.TL_account_getAccountTTL(), new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$loadPrivacySettings$60$ContactsController(tLObject, tL_error);
}
});
}
final int i = 0;
while (true) {
int[] iArr = this.loadingPrivacyInfo;
if (i < iArr.length) {
if (iArr[i] == 0) {
iArr[i] = 1;
TLRPC.TL_account_getPrivacy tL_account_getPrivacy = new TLRPC.TL_account_getPrivacy();
switch (i) {
case 0:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyStatusTimestamp();
break;
case 1:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyChatInvite();
break;
case 2:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyPhoneCall();
break;
case 3:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyPhoneP2P();
break;
case 4:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyProfilePhoto();
break;
case 5:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyForwards();
break;
case 6:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyPhoneNumber();
break;
case 7:
default:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyAddedByPhone();
break;
case 8:
tL_account_getPrivacy.key = new TLRPC.TL_inputPrivacyKeyMoment();
break;
}
getConnectionsManager().sendRequest(tL_account_getPrivacy, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
ContactsController.this.lambda$loadPrivacySettings$62$ContactsController(i, tLObject, tL_error);
}
});
}
i++;
} else {
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
return;
}
}
}
public void lambda$loadPrivacySettings$60$ContactsController(final TLObject tLObject, final TLRPC.TL_error tL_error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$59$ContactsController(tL_error, tLObject);
}
});
}
public void lambda$null$59$ContactsController(TLRPC.TL_error tL_error, TLObject tLObject) {
if (tL_error == null) {
this.deleteAccountTTL = ((TLRPC.TL_accountDaysTTL) tLObject).days;
this.loadingDeleteInfo = 2;
} else {
this.loadingDeleteInfo = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadPrivacySettings$62$ContactsController(final int i, final TLObject tLObject, final TLRPC.TL_error tL_error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$null$61$ContactsController(tL_error, tLObject, i);
}
});
}
public void lambda$null$61$ContactsController(TLRPC.TL_error tL_error, TLObject tLObject, int i) {
if (tL_error == null) {
TLRPC.TL_account_privacyRules tL_account_privacyRules = (TLRPC.TL_account_privacyRules) tLObject;
getMessagesController().putUsers(tL_account_privacyRules.users, false);
getMessagesController().putChats(tL_account_privacyRules.chats, false);
switch (i) {
case 0:
this.lastseenPrivacyRules = tL_account_privacyRules.rules;
break;
case 1:
this.groupPrivacyRules = tL_account_privacyRules.rules;
break;
case 2:
this.callPrivacyRules = tL_account_privacyRules.rules;
break;
case 3:
this.p2pPrivacyRules = tL_account_privacyRules.rules;
break;
case 4:
this.profilePhotoPrivacyRules = tL_account_privacyRules.rules;
break;
case 5:
this.forwardsPrivacyRules = tL_account_privacyRules.rules;
break;
case 6:
this.phonePrivacyRules = tL_account_privacyRules.rules;
break;
case 7:
default:
this.addedByPhonePrivacyRules = tL_account_privacyRules.rules;
break;
case 8:
this.momentPrivacyRules = tL_account_privacyRules.rules;
break;
}
this.loadingPrivacyInfo[i] = 2;
} else {
this.loadingPrivacyInfo[i] = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void setDeleteAccountTTL(int i) {
this.deleteAccountTTL = i;
}
public int getDeleteAccountTTL() {
return this.deleteAccountTTL;
}
public boolean getLoadingDeleteInfo() {
return this.loadingDeleteInfo != 2;
}
public boolean getLoadingPrivicyInfo(int i) {
return this.loadingPrivacyInfo[i] != 2;
}
public ArrayList<TLRPC.PrivacyRule> getPrivacyRules(int i) {
switch (i) {
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> arrayList, int i) {
switch (i) {
case 0:
this.lastseenPrivacyRules = arrayList;
break;
case 1:
this.groupPrivacyRules = arrayList;
break;
case 2:
this.callPrivacyRules = arrayList;
break;
case 3:
this.p2pPrivacyRules = arrayList;
break;
case 4:
this.profilePhotoPrivacyRules = arrayList;
break;
case 5:
this.forwardsPrivacyRules = arrayList;
break;
case 6:
this.phonePrivacyRules = arrayList;
break;
case 7:
this.addedByPhonePrivacyRules = arrayList;
break;
case 8:
this.momentPrivacyRules = arrayList;
break;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
reloadContactsStatuses();
}
public void createOrUpdateConnectionServiceContact(int i, String str, String str2) {
String str3;
int parseInt;
Cursor cursor;
ArrayList<ContentProviderOperation> arrayList;
if (hasContactsPermission()) {
try {
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
ArrayList<ContentProviderOperation> arrayList2 = new ArrayList<>();
Uri build = ContactsContract.Groups.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").build();
Uri build2 = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").build();
Cursor query = contentResolver.query(build, new String[]{"_id"}, "title=? AND account_type=? AND account_name=?", new String[]{"AppConnectionService", this.systemAccount.type, this.systemAccount.name}, null);
if (query != null && query.moveToFirst()) {
parseInt = query.getInt(0);
str3 = "account_type";
} else {
ContentValues contentValues = new ContentValues();
contentValues.put("account_type", this.systemAccount.type);
contentValues.put("account_name", this.systemAccount.name);
contentValues.put("group_visible", (Integer) 0);
str3 = "account_type";
contentValues.put("group_is_read_only", (Integer) 1);
contentValues.put("title", "AppConnectionService");
parseInt = Integer.parseInt(contentResolver.insert(build, contentValues).getLastPathSegment());
}
if (query != null) {
query.close();
}
String str4 = str3;
Cursor query2 = contentResolver.query(ContactsContract.Data.CONTENT_URI, new String[]{"raw_contact_id"}, "mimetype=? AND data1=?", new String[]{"vnd.android.cursor.item/group_membership", parseInt + ""}, null);
int size = arrayList2.size();
int i2 = parseInt;
if (query2 != null && query2.moveToFirst()) {
int i3 = query2.getInt(0);
cursor = query2;
arrayList = arrayList2;
arrayList.add(ContentProviderOperation.newUpdate(build2).withSelection("_id=?", new String[]{i3 + ""}).withValue("deleted", 0).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{i3 + "", "vnd.android.cursor.item/phone_v2"}).withValue("data1", "+99084" + i).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{i3 + "", "vnd.android.cursor.item/name"}).withValue("data2", str).withValue("data3", str2).build());
} else {
cursor = query2;
arrayList = arrayList2;
arrayList.add(ContentProviderOperation.newInsert(build2).withValue(str4, this.systemAccount.type).withValue("account_name", this.systemAccount.name).withValue("raw_contact_is_read_only", 1).withValue("aggregation_mode", 3).build());
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/name").withValue("data2", str).withValue("data3", str2).build());
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/phone_v2").withValue("data1", "+99084" + i).build());
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/group_membership").withValue("data1", Integer.valueOf(i2)).build());
}
if (cursor != null) {
cursor.close();
}
contentResolver.applyBatch("com.android.contacts", arrayList);
} catch (Exception e) {
FileLog.e(e);
}
}
}
public void deleteConnectionServiceContact() {
if (hasContactsPermission()) {
try {
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
Cursor query = contentResolver.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 (query == null || !query.moveToFirst()) {
if (query != null) {
query.close();
return;
}
return;
}
int i = query.getInt(0);
query.close();
Cursor query2 = contentResolver.query(ContactsContract.Data.CONTENT_URI, new String[]{"raw_contact_id"}, "mimetype=? AND data1=?", new String[]{"vnd.android.cursor.item/group_membership", i + ""}, null);
if (query2 == null || !query2.moveToFirst()) {
if (query2 != null) {
query2.close();
return;
}
return;
}
int i2 = query2.getInt(0);
query2.close();
contentResolver.delete(ContactsContract.RawContacts.CONTENT_URI, "_id=?", new String[]{i2 + ""});
} catch (Exception e) {
FileLog.e(e);
}
}
}
public static String formatName(String str, String str2) {
if (!TextUtils.isEmpty(str)) {
return str.trim();
}
return LocaleController.getString("UnKnown", R.string.UnKnown);
}
}