CheetahGram v8.5.4版本的 MD5 值为:3d14e79cc242c314d3933620ff3ab030
以下内容为反编译后的 ContactsController.java 源代码,内容仅作参考
package org.telegram.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 com.batch.android.Batch;
import j$.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.p110.as0;
import org.telegram.messenger.p110.br5;
import org.telegram.messenger.p110.d27;
import org.telegram.messenger.p110.dr5;
import org.telegram.messenger.p110.e16;
import org.telegram.messenger.p110.ew5;
import org.telegram.messenger.p110.f27;
import org.telegram.messenger.p110.fe5;
import org.telegram.messenger.p110.gb5;
import org.telegram.messenger.p110.gx5;
import org.telegram.messenger.p110.gz6;
import org.telegram.messenger.p110.ho6;
import org.telegram.messenger.p110.i07;
import org.telegram.messenger.p110.i16;
import org.telegram.messenger.p110.i27;
import org.telegram.messenger.p110.i95;
import org.telegram.messenger.p110.j07;
import org.telegram.messenger.p110.j16;
import org.telegram.messenger.p110.j27;
import org.telegram.messenger.p110.jd5;
import org.telegram.messenger.p110.jr5;
import org.telegram.messenger.p110.k16;
import org.telegram.messenger.p110.ke5;
import org.telegram.messenger.p110.kr5;
import org.telegram.messenger.p110.l16;
import org.telegram.messenger.p110.lz6;
import org.telegram.messenger.p110.m07;
import org.telegram.messenger.p110.m16;
import org.telegram.messenger.p110.mb5;
import org.telegram.messenger.p110.n16;
import org.telegram.messenger.p110.nr5;
import org.telegram.messenger.p110.o16;
import org.telegram.messenger.p110.ov5;
import org.telegram.messenger.p110.p16;
import org.telegram.messenger.p110.pr5;
import org.telegram.messenger.p110.rr5;
import org.telegram.messenger.p110.s52;
import org.telegram.messenger.p110.sr5;
import org.telegram.messenger.p110.uc5;
import org.telegram.messenger.p110.ur5;
import org.telegram.messenger.p110.uw3;
import org.telegram.messenger.p110.we5;
import org.telegram.messenger.p110.xq5;
import org.telegram.messenger.p110.y27;
import org.telegram.messenger.p110.yd5;
import org.telegram.messenger.p110.yw5;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
public class ContactsController extends BaseController {
public static final int FILTER_TYPE_ALL = 0;
public static final int FILTER_TYPE_BLOCKED = 4;
public static final int FILTER_TYPE_BLOCKED_ME = 5;
public static final int FILTER_TYPE_MUTUAL = 1;
public static final int FILTER_TYPE_NOT_MUTUAL = 2;
public static final int FILTER_TYPE_ONLINE = 3;
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 = 8;
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_P2P = 3;
public static final int PRIVACY_RULES_TYPE_PHONE = 6;
public static final int PRIVACY_RULES_TYPE_PHOTO = 4;
private ArrayList<uc5> addedByPhonePrivacyRules;
private ArrayList<uc5> callPrivacyRules;
private int completedRequestsCount;
public ArrayList<xq5> contacts;
public HashMap<String, Contact> contactsBook;
private boolean contactsBookLoaded;
public HashMap<String, Contact> contactsBookSPhones;
public HashMap<String, xq5> contactsByPhone;
public HashMap<String, xq5> contactsByShortPhone;
public ConcurrentHashMap<Long, xq5> contactsDict;
public boolean contactsLoaded;
private boolean contactsSyncInProgress;
private ArrayList<Long> delayedContactsUpdate;
private int deleteAccountTTL;
public boolean doneLoadingContacts;
private ArrayList<uc5> forwardsPrivacyRules;
private ew5 globalPrivacySettings;
private ArrayList<uc5> groupPrivacyRules;
private boolean ignoreChanges;
private String inviteLink;
private String lastContactsVersions;
private ArrayList<uc5> lastseenPrivacyRules;
private final Object loadContactsSync;
private boolean loadingContacts;
private int loadingDeleteInfo;
private int loadingGlobalSettings;
private int[] loadingPrivacyInfo;
private boolean migratingContacts;
private final Object observerLock;
public ArrayList<String> onlineSortedUsersSectionsArray;
public HashMap<String, ArrayList<xq5>> onlineUsersSectionsDict;
private ArrayList<uc5> p2pPrivacyRules;
public ArrayList<Contact> phoneBookContacts;
public ArrayList<String> phoneBookSectionsArray;
public HashMap<String, ArrayList<Object>> phoneBookSectionsDict;
private ArrayList<uc5> phonePrivacyRules;
private ArrayList<uc5> 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<xq5>> usersMutualSectionsDict;
public HashMap<String, ArrayList<xq5>> usersSectionsDict;
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 f27 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 static String getLetter(String str, String str2) {
return !TextUtils.isEmpty(str) ? str.substring(0, 1) : !TextUtils.isEmpty(str2) ? str2.substring(0, 1) : "#";
}
public String getLetter() {
return getLetter(this.first_name, this.last_name);
}
}
public class MyContentObserver extends ContentObserver {
private Runnable checkRunnable;
public MyContentObserver() {
super(null);
this.checkRunnable = new Runnable() {
@Override
public final void run() {
ContactsController.MyContentObserver.lambda$new$0();
}
};
}
public static void lambda$new$0() {
for (int i = 0; i < 3; i++) {
if (UserConfig.getInstance(i).isClientActivated()) {
ConnectionsManager.getInstance(i).resumeNetworkMaybe();
ContactsController.getInstance(i).checkContacts();
}
}
}
@Override
public boolean deliverSelfNotifications() {
return false;
}
@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 ContactsController(int i) {
super(i);
this.loadContactsSync = new Object();
this.observerLock = new Object();
this.lastContactsVersions = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
this.delayedContactsUpdate = new ArrayList<>();
this.sectionsToReplace = new HashMap<>();
this.loadingPrivacyInfo = new int[8];
this.onlineSortedUsersSectionsArray = new ArrayList<>();
this.onlineUsersSectionsDict = new HashMap<>();
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("À", "A");
this.sectionsToReplace.put("Á", "A");
this.sectionsToReplace.put("Ä", "A");
this.sectionsToReplace.put("Ù", "U");
this.sectionsToReplace.put("Ú", "U");
this.sectionsToReplace.put("Ü", "U");
this.sectionsToReplace.put("Ì", "I");
this.sectionsToReplace.put("Í", "I");
this.sectionsToReplace.put("Ï", "I");
this.sectionsToReplace.put("È", "E");
this.sectionsToReplace.put("É", "E");
this.sectionsToReplace.put("Ê", "E");
this.sectionsToReplace.put("Ë", "E");
this.sectionsToReplace.put("Ò", "O");
this.sectionsToReplace.put("Ó", "O");
this.sectionsToReplace.put("Ö", "O");
this.sectionsToReplace.put("Ç", "C");
this.sectionsToReplace.put("Ñ", "N");
this.sectionsToReplace.put("Ÿ", "Y");
this.sectionsToReplace.put("Ý", "Y");
this.sectionsToReplace.put("Ţ", "Y");
if (i == 0) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$new$0();
}
});
}
}
private void applyContactsUpdates(ArrayList<Long> arrayList, ConcurrentHashMap<Long, f27> concurrentHashMap, final ArrayList<xq5> arrayList2, final ArrayList<Long> arrayList3) {
int indexOf;
int indexOf2;
if (arrayList2 == null || arrayList3 == null) {
arrayList2 = new ArrayList<>();
arrayList3 = new ArrayList<>();
for (int i = 0; i < arrayList.size(); i++) {
Long l = arrayList.get(i);
if (l.longValue() > 0) {
xq5 xq5Var = new xq5();
xq5Var.a = l.longValue();
arrayList2.add(xq5Var);
} else if (l.longValue() < 0) {
arrayList3.add(Long.valueOf(-l.longValue()));
}
}
}
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;
}
xq5 xq5Var2 = arrayList2.get(i2);
f27 f27Var = concurrentHashMap != null ? concurrentHashMap.get(Long.valueOf(xq5Var2.a)) : null;
if (f27Var == null) {
f27Var = getMessagesController().getUser(Long.valueOf(xq5Var2.a));
} else {
getMessagesController().putUser(f27Var, true);
}
if (f27Var == null || TextUtils.isEmpty(f27Var.f)) {
z = true;
} else {
Contact contact = this.contactsBookSPhones.get(f27Var.f);
if (contact != null && (indexOf2 = contact.shortPhones.indexOf(f27Var.f)) != -1) {
contact.phoneDeleted.set(indexOf2, 0);
}
if (sb.length() != 0) {
sb.append(",");
}
sb.append(f27Var.f);
}
i2++;
}
for (int i3 = 0; i3 < arrayList3.size(); i3++) {
final Long l2 = arrayList3.get(i3);
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$applyContactsUpdates$46(l2);
}
});
f27 f27Var2 = concurrentHashMap != null ? concurrentHashMap.get(l2) : null;
if (f27Var2 == null) {
f27Var2 = getMessagesController().getUser(l2);
} else {
getMessagesController().putUser(f27Var2, true);
}
if (f27Var2 == null) {
z = true;
} else if (!TextUtils.isEmpty(f27Var2.f)) {
Contact contact2 = this.contactsBookSPhones.get(f27Var2.f);
if (contact2 != null && (indexOf = contact2.shortPhones.indexOf(f27Var2.f)) != -1) {
contact2.phoneDeleted.set(indexOf, 1);
}
if (sb2.length() != 0) {
sb2.append(",");
}
sb2.append(f27Var2.f);
}
}
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$47();
}
});
} else {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$applyContactsUpdates$48(arrayList2, arrayList3);
}
});
}
}
private void buildContactsSectionsArrays(boolean z) {
if (z) {
Collections.sort(this.contacts, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$buildContactsSectionsArrays$43;
lambda$buildContactsSectionsArrays$43 = ContactsController.this.lambda$buildContactsSectionsArrays$43((xq5) obj, (xq5) obj2);
return lambda$buildContactsSectionsArrays$43;
}
});
}
HashMap<String, ArrayList<xq5>> hashMap = new HashMap<>();
ArrayList<String> arrayList = new ArrayList<>();
for (int i = 0; i < this.contacts.size(); i++) {
xq5 xq5Var = this.contacts.get(i);
f27 user = getMessagesController().getUser(Long.valueOf(xq5Var.a));
if (user != null) {
String firstName = UserObject.getFirstName(user);
if (firstName.length() > 1) {
firstName = firstName.substring(0, 1);
}
String upperCase = firstName.length() == 0 ? "#" : firstName.toUpperCase();
String str = this.sectionsToReplace.get(upperCase);
if (str != null) {
upperCase = str;
}
ArrayList<xq5> arrayList2 = hashMap.get(upperCase);
if (arrayList2 == null) {
arrayList2 = new ArrayList<>();
hashMap.put(upperCase, arrayList2);
arrayList.add(upperCase);
}
arrayList2.add(xq5Var);
}
}
Collections.sort(arrayList, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$buildContactsSectionsArrays$44;
lambda$buildContactsSectionsArrays$44 = ContactsController.lambda$buildContactsSectionsArrays$44((String) obj, (String) obj2);
return lambda$buildContactsSectionsArrays$44;
}
});
this.usersSectionsDict = hashMap;
this.sortedUsersSectionsArray = arrayList;
}
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 {
try {
query.close();
} catch (Throwable unused) {
}
}
}
if (query != null) {
}
} catch (Exception e2) {
FileLog.e(e2);
}
return z;
}
private void deleteContactFromPhoneBook(long j) {
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 = " + j, null);
} catch (Exception e) {
FileLog.e(e);
}
synchronized (this.observerLock) {
this.ignoreChanges = false;
}
}
}
public static String formatName(String str, String str2) {
return formatName(str, str2, 0);
}
public static String formatName(String str, String str2, int i) {
char charAt;
if (str != null) {
str = str.trim();
}
if (str2 != null) {
str2 = str2.trim();
}
StringBuilder sb = new StringBuilder((str != null ? str.length() : 0) + (str2 != null ? str2.length() : 0) + 1);
if (LocaleController.nameDisplayOrder != 1) {
if (str2 == null || str2.length() <= 0) {
if (str != null && str.length() > 0) {
if (i > 0 && str.length() > i + 2) {
return str.substring(0, i);
}
sb.append(str);
}
} else {
if (i > 0 && str2.length() > i + 2) {
return str2.substring(0, i);
}
sb.append(str2);
if (str != null && str.length() > 0) {
sb.append(" ");
if (i > 0 && sb.length() + str.length() > i) {
charAt = str.charAt(0);
sb.append(charAt);
}
sb.append(str);
}
}
return sb.toString();
}
if (str == null || str.length() <= 0) {
if (str2 != null && str2.length() > 0) {
if (i > 0 && str2.length() > i + 2) {
return str2.substring(0, i);
}
sb.append(str2);
}
return sb.toString();
}
if (i > 0 && str.length() > i + 2) {
return str.substring(0, i);
}
sb.append(str);
if (str2 != null && str2.length() > 0) {
sb.append(" ");
if (i > 0 && sb.length() + str2.length() > i) {
charAt = str2.charAt(0);
sb.append(charAt);
}
sb.append(str2);
}
return sb.toString();
}
private long getContactsHash(ArrayList<xq5> arrayList) {
ArrayList arrayList2 = new ArrayList(arrayList);
Collections.sort(arrayList2, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$getContactsHash$25;
lambda$getContactsHash$25 = ContactsController.lambda$getContactsHash$25((xq5) obj, (xq5) obj2);
return lambda$getContactsHash$25;
}
});
int size = arrayList2.size();
long j = 0;
int i = -1;
while (i < size) {
j = MediaDataController.calcHash(j, i == -1 ? getUserConfig().contactsSavedCount : ((xq5) arrayList2.get(i)).a);
i++;
}
return j;
}
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;
}
private boolean hasContactsPermission() {
if (Build.VERSION.SDK_INT >= 23) {
return ApplicationLoader.applicationContext.checkSelfPermission("android.permission.READ_CONTACTS") == 0;
}
Cursor cursor = null;
try {
try {
cursor = ApplicationLoader.applicationContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, this.projectionPhones, null, null, null);
} catch (Exception e) {
FileLog.e(e);
}
} catch (Throwable th) {
try {
FileLog.e(th);
if (cursor != null) {
cursor.close();
}
} finally {
if (cursor != null) {
try {
cursor.close();
} catch (Exception e2) {
FileLog.e(e2);
}
}
}
}
if (cursor != null) {
if (cursor.getCount() != 0) {
cursor.close();
return true;
}
}
return false;
}
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;
}
public void lambda$addContact$50(f27 f27Var) {
addContactToPhoneBook(f27Var, true);
}
public void lambda$addContact$51(d27 d27Var) {
for (int i = 0; i < d27Var.users.size(); i++) {
f27 f27Var = d27Var.users.get(i);
if (f27Var.k && this.contactsDict.get(Long.valueOf(f27Var.a)) == null) {
xq5 xq5Var = new xq5();
xq5Var.a = f27Var.a;
this.contacts.add(xq5Var);
this.contactsDict.put(Long.valueOf(xq5Var.a), xq5Var);
}
}
buildContactsSectionsArrays(true);
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void lambda$addContact$52(f27 f27Var, i95 i95Var, ov5 ov5Var) {
int indexOf;
if (ov5Var != null) {
return;
}
final d27 d27Var = (d27) i95Var;
getMessagesController().processUpdates(d27Var, false);
for (int i = 0; i < d27Var.users.size(); i++) {
final f27 f27Var2 = d27Var.users.get(i);
if (f27Var2.a == f27Var.a) {
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$addContact$50(f27Var2);
}
});
xq5 xq5Var = new xq5();
xq5Var.a = f27Var2.a;
ArrayList<xq5> arrayList = new ArrayList<>();
arrayList.add(xq5Var);
getMessagesStorage().putContacts(arrayList, false);
if (!TextUtils.isEmpty(f27Var2.f)) {
formatName(f27Var2.b, f27Var2.c);
getMessagesStorage().applyPhoneBookUpdates(f27Var2.f, uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR);
Contact contact = this.contactsBookSPhones.get(f27Var2.f);
if (contact != null && (indexOf = contact.shortPhones.indexOf(f27Var2.f)) != -1) {
contact.phoneDeleted.set(indexOf, 0);
}
}
}
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$addContact$51(d27Var);
}
});
}
public void lambda$applyContactsUpdates$46(Long l) {
deleteContactFromPhoneBook(l.longValue());
}
public void lambda$applyContactsUpdates$47() {
loadContacts(false, 0L);
}
public void lambda$applyContactsUpdates$48(ArrayList arrayList, ArrayList arrayList2) {
for (int i = 0; i < arrayList.size(); i++) {
xq5 xq5Var = (xq5) arrayList.get(i);
if (this.contactsDict.get(Long.valueOf(xq5Var.a)) == null) {
this.contacts.add(xq5Var);
this.contactsDict.put(Long.valueOf(xq5Var.a), xq5Var);
}
}
for (int i2 = 0; i2 < arrayList2.size(); i2++) {
Long l = (Long) arrayList2.get(i2);
xq5 xq5Var2 = this.contactsDict.get(l);
if (xq5Var2 != null) {
this.contacts.remove(xq5Var2);
this.contactsDict.remove(l);
}
}
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 int lambda$buildContactsSectionsArrays$43(xq5 xq5Var, xq5 xq5Var2) {
return UserObject.getFirstName(getMessagesController().getUser(Long.valueOf(xq5Var.a))).compareTo(UserObject.getFirstName(getMessagesController().getUser(Long.valueOf(xq5Var2.a))));
}
public static int lambda$buildContactsSectionsArrays$44(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$checkContacts$4() {
if (checkContactsInternal()) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("detected contacts change");
}
performSyncPhoneBook(getContactsCopy(this.contactsBook), true, false, true, false, true, false);
}
}
public void lambda$checkInviteText$2(gx5 gx5Var) {
this.updatingInviteLink = false;
SharedPreferences.Editor edit = MessagesController.getMainSettings(this.currentAccount).edit();
String str = gx5Var.a;
this.inviteLink = str;
edit.putString("invitelink", str);
edit.putInt("invitelinktime", (int) (System.currentTimeMillis() / 1000));
edit.commit();
}
public void lambda$checkInviteText$3(i95 i95Var, ov5 ov5Var) {
if (i95Var != null) {
final gx5 gx5Var = (gx5) i95Var;
if (gx5Var.a.length() != 0) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$checkInviteText$2(gx5Var);
}
});
}
}
}
public void lambda$cleanup$1() {
this.migratingContacts = false;
this.completedRequestsCount = 0;
}
public void lambda$deleteAllContacts$7(Runnable runnable) {
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
try {
Account[] accountsByType = accountManager.getAccountsByType("org.telegram.messenger");
this.systemAccount = null;
for (Account account : accountsByType) {
int i = 0;
while (true) {
if (i >= 3) {
break;
}
f27 currentUser = UserConfig.getInstance(i).getCurrentUser();
if (currentUser != null) {
if (account.name.equals(uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR + currentUser.a)) {
accountManager.removeAccount(account, null, null);
break;
}
}
i++;
}
}
} catch (Throwable unused) {
}
try {
Account account2 = new Account(uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR + getUserConfig().getClientUserId(), "org.telegram.messenger");
this.systemAccount = account2;
accountManager.addAccountExplicitly(account2, uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR, 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, 0L);
runnable.run();
}
public void lambda$deleteAllContacts$8(final Runnable runnable, i95 i95Var, ov5 ov5Var) {
if (ov5Var != null) {
AndroidUtilities.runOnUIThread(runnable);
return;
}
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 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$deleteAllContacts$7(runnable);
}
});
}
public void lambda$deleteContact$53(ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
deleteContactFromPhoneBook(((f27) it.next()).a);
}
}
public void lambda$deleteContact$54(ArrayList arrayList, boolean z, String str) {
Iterator it = arrayList.iterator();
boolean z2 = false;
while (it.hasNext()) {
f27 f27Var = (f27) it.next();
xq5 xq5Var = this.contactsDict.get(Long.valueOf(f27Var.a));
if (xq5Var != null) {
this.contacts.remove(xq5Var);
this.contactsDict.remove(Long.valueOf(f27Var.a));
z2 = true;
}
}
if (z2) {
buildContactsSectionsArrays(false);
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, Integer.valueOf(MessagesController.UPDATE_MASK_NAME));
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
if (z) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.showBulletin, 1, LocaleController.formatString("DeletedFromYourContacts", co.cheetah.gram.R.string.DeletedFromYourContacts, str));
}
}
public void lambda$deleteContact$55(ArrayList arrayList, final ArrayList arrayList2, final boolean z, final String str, i95 i95Var, ov5 ov5Var) {
int indexOf;
if (ov5Var != null) {
return;
}
getMessagesController().processUpdates((d27) i95Var, false);
getMessagesStorage().deleteContacts(arrayList);
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$deleteContact$53(arrayList2);
}
});
for (int i = 0; i < arrayList2.size(); i++) {
f27 f27Var = (f27) arrayList2.get(i);
if (!TextUtils.isEmpty(f27Var.f)) {
getMessagesStorage().applyPhoneBookUpdates(f27Var.f, uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR);
Contact contact = this.contactsBookSPhones.get(f27Var.f);
if (contact != null && (indexOf = contact.shortPhones.indexOf(f27Var.f)) != -1) {
contact.phoneDeleted.set(indexOf, 1);
}
}
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$deleteContact$54(arrayList2, z, str);
}
});
}
public void lambda$forceImportContacts$5() {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("force import contacts");
}
performSyncPhoneBook(new HashMap<>(), true, true, true, true, false, false);
}
public static int lambda$getContactsHash$25(xq5 xq5Var, xq5 xq5Var2) {
long j = xq5Var.a;
long j2 = xq5Var2.a;
if (j > j2) {
return 1;
}
return j < j2 ? -1 : 0;
}
public static int lambda$initOnlineUsersSectionsDict$64(String str, String str2) {
if (str.charAt(0) == '#') {
return 1;
}
if (str2.charAt(0) == '#') {
return -1;
}
return str.compareTo(str2);
}
public void lambda$loadContacts$26() {
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void lambda$loadContacts$27(long j, i95 i95Var, ov5 ov5Var) {
if (ov5Var == null) {
y27 y27Var = (y27) i95Var;
if (j == 0 || !(y27Var instanceof jr5)) {
getUserConfig().contactsSavedCount = y27Var.b;
getUserConfig().saveConfig(false);
processLoadedContacts(y27Var.a, y27Var.c, 0);
return;
}
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$loadContacts$26();
}
});
if (BuildVars.LOGS_ENABLED) {
FileLog.d("load contacts don't change");
}
}
}
public void lambda$loadPrivacySettings$58(ov5 ov5Var, i95 i95Var) {
if (ov5Var == null) {
this.deleteAccountTTL = ((jd5) i95Var).a;
this.loadingDeleteInfo = 2;
} else {
this.loadingDeleteInfo = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadPrivacySettings$59(final i95 i95Var, final ov5 ov5Var) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$loadPrivacySettings$58(ov5Var, i95Var);
}
});
}
public void lambda$loadPrivacySettings$60(ov5 ov5Var, i95 i95Var) {
if (ov5Var == null) {
this.globalPrivacySettings = (ew5) i95Var;
this.loadingGlobalSettings = 2;
} else {
this.loadingGlobalSettings = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadPrivacySettings$61(final i95 i95Var, final ov5 ov5Var) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$loadPrivacySettings$60(ov5Var, i95Var);
}
});
}
public void lambda$loadPrivacySettings$62(ov5 ov5Var, i95 i95Var, int i) {
if (ov5Var == null) {
we5 we5Var = (we5) i95Var;
getMessagesController().putUsers(we5Var.c, false);
getMessagesController().putChats(we5Var.b, false);
ArrayList<uc5> arrayList = we5Var.a;
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;
default:
this.addedByPhonePrivacyRules = arrayList;
break;
}
this.loadingPrivacyInfo[i] = 2;
} else {
this.loadingPrivacyInfo[i] = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadPrivacySettings$63(final int i, final i95 i95Var, final ov5 ov5Var) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$loadPrivacySettings$62(ov5Var, i95Var, i);
}
});
}
public static void lambda$markAsContacted$49(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 static int lambda$mergePhonebookAndTelegramContacts$38(Object obj, Object obj2) {
String str;
String str2;
String str3;
boolean z = obj instanceof f27;
String str4 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
if (!z) {
if (obj instanceof Contact) {
Contact contact = (Contact) obj;
f27 f27Var = contact.user;
if (f27Var != null) {
str = formatName(f27Var.b, f27Var.c);
} else {
str2 = contact.first_name;
str3 = contact.last_name;
}
} else {
str = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
if (!(obj2 instanceof f27)) {
f27 f27Var2 = (f27) obj2;
str4 = formatName(f27Var2.b, f27Var2.c);
} else if (obj2 instanceof Contact) {
Contact contact2 = (Contact) obj2;
f27 f27Var3 = contact2.user;
str4 = f27Var3 != null ? formatName(f27Var3.b, f27Var3.c) : formatName(contact2.first_name, contact2.last_name);
}
return str.compareTo(str4);
}
f27 f27Var4 = (f27) obj;
str2 = f27Var4.b;
str3 = f27Var4.c;
str = formatName(str2, str3);
if (!(obj2 instanceof f27)) {
}
return str.compareTo(str4);
}
public static int lambda$mergePhonebookAndTelegramContacts$39(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$mergePhonebookAndTelegramContacts$40(ArrayList arrayList, HashMap hashMap) {
this.phoneBookSectionsArray = arrayList;
this.phoneBookSectionsDict = hashMap;
}
public void lambda$mergePhonebookAndTelegramContacts$41(ArrayList arrayList, HashMap hashMap, final HashMap hashMap2, final ArrayList arrayList2) {
int size = arrayList.size();
for (int i = 0; i < size; i++) {
f27 user = getMessagesController().getUser(Long.valueOf(((xq5) arrayList.get(i)).a));
if (user != null && !TextUtils.isEmpty(user.f)) {
Contact contact = (Contact) hashMap.get(user.f.substring(Math.max(0, r4.length() - 7)));
if (contact == null) {
String letter = Contact.getLetter(user.b, user.c);
ArrayList arrayList3 = (ArrayList) hashMap2.get(letter);
if (arrayList3 == null) {
arrayList3 = new ArrayList();
hashMap2.put(letter, arrayList3);
arrayList2.add(letter);
}
arrayList3.add(user);
} else if (contact.user == null) {
contact.user = 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) {
int lambda$mergePhonebookAndTelegramContacts$38;
lambda$mergePhonebookAndTelegramContacts$38 = ContactsController.lambda$mergePhonebookAndTelegramContacts$38(obj, obj2);
return lambda$mergePhonebookAndTelegramContacts$38;
}
});
}
Collections.sort(arrayList2, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$mergePhonebookAndTelegramContacts$39;
lambda$mergePhonebookAndTelegramContacts$39 = ContactsController.lambda$mergePhonebookAndTelegramContacts$39((String) obj, (String) obj2);
return lambda$mergePhonebookAndTelegramContacts$39;
}
});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$mergePhonebookAndTelegramContacts$40(arrayList2, hashMap2);
}
});
}
public void lambda$migratePhoneBookToV7$11(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 lambda$new$0() {
try {
if (hasContactsPermission()) {
ApplicationLoader.applicationContext.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new MyContentObserver());
}
} catch (Throwable unused) {
}
}
private void lambda$performSyncPhoneBook$12(HashMap hashMap) {
ArrayList<f27> arrayList = new ArrayList<>();
if (hashMap != null && !hashMap.isEmpty()) {
try {
HashMap hashMap2 = new HashMap();
for (int i = 0; i < this.contacts.size(); i++) {
f27 user = getMessagesController().getUser(Long.valueOf(this.contacts.get(i).a));
if (user != null && !TextUtils.isEmpty(user.f)) {
hashMap2.put(user.f, 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()) {
f27 f27Var = (f27) hashMap2.get(contact.shortPhones.get(i2));
if (f27Var != null) {
arrayList.add(f27Var);
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, false);
}
public void lambda$performSyncPhoneBook$13(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$performSyncPhoneBook$14(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$performSyncPhoneBook$22(hashMap, arrayList, hashMap2);
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$performSyncPhoneBook$15(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$performSyncPhoneBook$14(hashMap3, arrayList, hashMap4);
}
});
}
public void lambda$performSyncPhoneBook$16(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$performSyncPhoneBook$22(hashMap, arrayList, hashMap2);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$performSyncPhoneBook$17() {
getMessagesStorage().getCachedPhoneBook(true);
}
public void lambda$performSyncPhoneBook$18(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$performSyncPhoneBook$16(hashMap3, arrayList, hashMap4);
}
});
if (zArr[0]) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performSyncPhoneBook$17();
}
}, 300000L);
}
}
public void lambda$performSyncPhoneBook$19(HashMap hashMap, SparseArray sparseArray, final boolean[] zArr, final HashMap hashMap2, rr5 rr5Var, int i, final HashMap hashMap3, final boolean z, final HashMap hashMap4, final ArrayList arrayList, final HashMap hashMap5, i95 i95Var, ov5 ov5Var) {
this.completedRequestsCount++;
if (ov5Var == null) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts imported");
}
sr5 sr5Var = (sr5) i95Var;
if (!sr5Var.c.isEmpty()) {
for (int i2 = 0; i2 < sr5Var.c.size(); i2++) {
hashMap.remove(sparseArray.get((int) sr5Var.c.get(i2).longValue()));
}
zArr[0] = true;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("result has retry contacts");
}
}
for (int i3 = 0; i3 < sr5Var.b.size(); i3++) {
ho6 ho6Var = sr5Var.b.get(i3);
Contact contact = (Contact) hashMap2.get(sparseArray.get((int) ho6Var.a));
if (contact != null) {
contact.imported = ho6Var.b;
}
}
getMessagesStorage().putUsersAndChats(sr5Var.d, null, true, true);
ArrayList<xq5> arrayList2 = new ArrayList<>();
for (int i4 = 0; i4 < sr5Var.a.size(); i4++) {
xq5 xq5Var = new xq5();
xq5Var.a = sr5Var.a.get(i4).a;
arrayList2.add(xq5Var);
}
processLoadedContacts(arrayList2, sr5Var.d, 2);
} else {
for (int i5 = 0; i5 < rr5Var.a.size(); i5++) {
hashMap.remove(sparseArray.get((int) rr5Var.a.get(i5).a));
}
zArr[0] = true;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("import contacts error " + ov5Var.b);
}
}
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$performSyncPhoneBook$18(hashMap3, hashMap2, z, hashMap4, arrayList, hashMap5, zArr);
}
});
}
}
public void lambda$performSyncPhoneBook$20(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$performSyncPhoneBook$22(hashMap, arrayList, hashMap2);
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$performSyncPhoneBook$21(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$performSyncPhoneBook$20(hashMap3, arrayList, hashMap4);
}
});
}
public void lambda$performSyncPhoneBook$23(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$performSyncPhoneBook$22(hashMap3, arrayList, hashMap4);
}
});
}
public void lambda$performSyncPhoneBook$24(final HashMap hashMap, final boolean z, boolean z2, final boolean z3, boolean z4, boolean z5, boolean z6) {
int i;
ArrayList arrayList;
HashMap hashMap2;
HashMap<String, Contact> hashMap3;
HashMap hashMap4;
ContactsController contactsController;
int i2;
int i3;
int i4;
Contact contact;
HashMap hashMap5;
String str;
ArrayList arrayList2;
HashMap hashMap6;
HashMap<String, Contact> hashMap7;
HashMap hashMap8;
int indexOf;
ArrayList arrayList3;
int i5;
HashMap<String, Contact> hashMap9;
HashMap hashMap10;
int i6;
boolean z7;
ContactsController contactsController2 = this;
HashMap hashMap11 = 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()) {
hashMap11.put(contact2.shortPhones.get(i), contact2);
i++;
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("start read contacts from phone");
}
if (!z) {
checkContactsInternal();
}
HashMap<String, Contact> readContactsFromPhoneBook = readContactsFromPhoneBook();
HashMap hashMap12 = new HashMap();
HashMap hashMap13 = 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 i7 = 0; i7 < size; i7++) {
hashMap13.put(value.shortPhones.get(i7).substring(Math.max(0, r6.length() - 7)), value);
}
String letter = value.getLetter();
ArrayList arrayList5 = (ArrayList) hashMap12.get(letter);
if (arrayList5 == null) {
arrayList5 = new ArrayList();
hashMap12.put(letter, arrayList5);
arrayList4.add(letter);
}
arrayList5.add(value);
}
final HashMap hashMap14 = new HashMap();
int size2 = hashMap.size();
ArrayList arrayList6 = new ArrayList();
boolean isEmpty = hashMap.isEmpty();
String str2 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
if (isEmpty) {
arrayList = arrayList4;
hashMap2 = hashMap13;
hashMap3 = readContactsFromPhoneBook;
hashMap4 = hashMap12;
if (z2) {
int i8 = 0;
for (Map.Entry<String, Contact> entry : hashMap3.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));
xq5 xq5Var = this.contactsByPhone.get(str3);
if (xq5Var != null) {
f27 user = getMessagesController().getUser(Long.valueOf(xq5Var.a));
if (user != null) {
i8++;
String str4 = user.b;
if (str4 == null) {
str4 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
String str5 = user.c;
if (str5 == null) {
str5 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
i4 = ((str4.equals(value2.first_name) && str5.equals(value2.last_name)) || (TextUtils.isEmpty(value2.first_name) && TextUtils.isEmpty(value2.last_name))) ? i4 + 1 : 0;
}
} else if (this.contactsByShortPhone.containsKey(substring)) {
i8++;
}
}
e16 e16Var = new e16();
long j = value2.contact_id;
e16Var.a = j;
e16Var.a = j | (i4 << 32);
e16Var.c = value2.first_name;
e16Var.d = value2.last_name;
e16Var.b = value2.phones.get(i4);
arrayList6.add(e16Var);
}
}
contactsController = this;
i2 = i8;
} else {
contactsController = this;
i2 = 0;
}
i3 = 0;
} else {
Iterator<Map.Entry<String, Contact>> it3 = readContactsFromPhoneBook.entrySet().iterator();
i3 = 0;
int i9 = 0;
while (it3.hasNext()) {
Map.Entry<String, Contact> next = it3.next();
String key = next.getKey();
Contact value3 = next.getValue();
Contact contact3 = (Contact) hashMap.get(key);
Iterator<Map.Entry<String, Contact>> it4 = it3;
if (contact3 == null) {
while (i < value3.shortPhones.size()) {
contact = (Contact) hashMap11.get(value3.shortPhones.get(i));
if (contact != null) {
key = contact.key;
break;
}
i++;
}
}
contact = contact3;
if (contact != null) {
value3.imported = contact.imported;
}
if (contact != null) {
if (TextUtils.isEmpty(value3.first_name)) {
hashMap5 = hashMap11;
} else {
hashMap5 = hashMap11;
}
if (!TextUtils.isEmpty(value3.last_name)) {
}
} else {
hashMap5 = hashMap11;
}
boolean z8 = false;
if (contact == null || z8) {
str = str2;
arrayList2 = arrayList4;
hashMap6 = hashMap13;
hashMap7 = readContactsFromPhoneBook;
hashMap8 = hashMap12;
int i10 = 0;
while (i10 < value3.phones.size()) {
String str6 = value3.shortPhones.get(i10);
str6.substring(Math.max(0, str6.length() - 7));
hashMap14.put(str6, value3);
if (contact != null && (indexOf = contact.shortPhones.indexOf(str6)) != -1) {
Integer num = contact.phoneDeleted.get(indexOf);
value3.phoneDeleted.set(i10, num);
if (num.intValue() == 1) {
i10++;
contactsController2 = this;
}
}
i10++;
contactsController2 = this;
}
if (contact == null) {
contactsController2 = this;
it3 = it4;
hashMap11 = hashMap5;
hashMap13 = hashMap6;
str2 = str;
arrayList4 = arrayList2;
readContactsFromPhoneBook = hashMap7;
hashMap12 = hashMap8;
i = 0;
}
hashMap.remove(key);
contactsController2 = this;
it3 = it4;
hashMap11 = hashMap5;
hashMap13 = hashMap6;
str2 = str;
arrayList4 = arrayList2;
readContactsFromPhoneBook = hashMap7;
hashMap12 = hashMap8;
i = 0;
} else {
int i11 = 0;
while (i11 < value3.phones.size()) {
String str7 = value3.shortPhones.get(i11);
String str8 = str2;
HashMap hashMap15 = hashMap13;
String substring2 = str7.substring(Math.max(0, str7.length() - 7));
hashMap14.put(str7, value3);
int indexOf2 = contact.shortPhones.indexOf(str7);
if (z2) {
i5 = indexOf2;
xq5 xq5Var2 = contactsController2.contactsByPhone.get(str7);
arrayList3 = arrayList4;
if (xq5Var2 != null) {
hashMap9 = readContactsFromPhoneBook;
hashMap10 = hashMap12;
f27 user2 = getMessagesController().getUser(Long.valueOf(xq5Var2.a));
if (user2 != null) {
i9++;
if (TextUtils.isEmpty(user2.b) && TextUtils.isEmpty(user2.c) && (!TextUtils.isEmpty(value3.first_name) || !TextUtils.isEmpty(value3.last_name))) {
z7 = true;
i5 = -1;
i6 = i5;
if (i6 != -1) {
value3.phoneDeleted.set(i11, contact.phoneDeleted.get(i6));
contact.phones.remove(i6);
contact.shortPhones.remove(i6);
contact.phoneDeleted.remove(i6);
contact.phoneTypes.remove(i6);
} else if (z2) {
if (!z7) {
xq5 xq5Var3 = contactsController2.contactsByPhone.get(str7);
if (xq5Var3 != null) {
f27 user3 = getMessagesController().getUser(Long.valueOf(xq5Var3.a));
if (user3 != null) {
i9++;
String str9 = user3.b;
if (str9 == null) {
str9 = str8;
}
String str10 = user3.c;
if (str10 == null) {
str10 = str8;
}
if (str9.equals(value3.first_name)) {
if (str10.equals(value3.last_name)) {
}
}
if (TextUtils.isEmpty(value3.first_name) && TextUtils.isEmpty(value3.last_name)) {
}
} else {
i3++;
}
} else if (contactsController2.contactsByShortPhone.containsKey(substring2)) {
i9++;
}
}
e16 e16Var2 = new e16();
long j2 = value3.contact_id;
e16Var2.a = j2;
e16Var2.a = j2 | (i11 << 32);
e16Var2.c = value3.first_name;
e16Var2.d = value3.last_name;
e16Var2.b = value3.phones.get(i11);
arrayList6.add(e16Var2);
}
i11++;
hashMap13 = hashMap15;
str2 = str8;
arrayList4 = arrayList3;
readContactsFromPhoneBook = hashMap9;
hashMap12 = hashMap10;
}
}
z7 = false;
i6 = i5;
if (i6 != -1) {
}
i11++;
hashMap13 = hashMap15;
str2 = str8;
arrayList4 = arrayList3;
readContactsFromPhoneBook = hashMap9;
hashMap12 = hashMap10;
} else {
hashMap9 = readContactsFromPhoneBook;
hashMap10 = hashMap12;
if (contactsController2.contactsByShortPhone.containsKey(substring2)) {
i9++;
}
}
} else {
arrayList3 = arrayList4;
i5 = indexOf2;
hashMap9 = readContactsFromPhoneBook;
hashMap10 = hashMap12;
}
i6 = i5;
z7 = false;
if (i6 != -1) {
}
i11++;
hashMap13 = hashMap15;
str2 = str8;
arrayList4 = arrayList3;
readContactsFromPhoneBook = hashMap9;
hashMap12 = hashMap10;
}
str = str2;
arrayList2 = arrayList4;
hashMap6 = hashMap13;
hashMap7 = readContactsFromPhoneBook;
hashMap8 = hashMap12;
if (!contact.phones.isEmpty()) {
contactsController2 = this;
it3 = it4;
hashMap11 = hashMap5;
hashMap13 = hashMap6;
str2 = str;
arrayList4 = arrayList2;
readContactsFromPhoneBook = hashMap7;
hashMap12 = hashMap8;
i = 0;
}
hashMap.remove(key);
contactsController2 = this;
it3 = it4;
hashMap11 = hashMap5;
hashMap13 = hashMap6;
str2 = str;
arrayList4 = arrayList2;
readContactsFromPhoneBook = hashMap7;
hashMap12 = hashMap8;
i = 0;
}
}
arrayList = arrayList4;
hashMap2 = hashMap13;
HashMap<String, Contact> hashMap16 = readContactsFromPhoneBook;
hashMap4 = hashMap12;
if (!z3 && hashMap.isEmpty() && arrayList6.isEmpty() && size2 == hashMap16.size()) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts not changed!");
return;
}
return;
}
if (!z2 || hashMap.isEmpty() || hashMap16.isEmpty() || !arrayList6.isEmpty()) {
hashMap3 = hashMap16;
} else {
hashMap3 = hashMap16;
getMessagesStorage().putCachedPhoneBook(hashMap3, false, false);
}
contactsController = this;
i2 = i9;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("done processing contacts");
}
if (!z2) {
final ArrayList arrayList7 = arrayList;
final HashMap<String, Contact> hashMap17 = hashMap3;
final HashMap hashMap18 = hashMap4;
final HashMap hashMap19 = hashMap2;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performSyncPhoneBook$23(hashMap14, hashMap17, z3, hashMap18, arrayList7, hashMap19);
}
});
if (hashMap3.isEmpty()) {
return;
}
getMessagesStorage().putCachedPhoneBook(hashMap3, false, false);
return;
}
if (arrayList6.isEmpty()) {
final ArrayList arrayList8 = arrayList;
final HashMap<String, Contact> hashMap20 = hashMap3;
final HashMap hashMap21 = hashMap4;
final HashMap hashMap22 = hashMap2;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performSyncPhoneBook$21(hashMap14, hashMap20, z3, hashMap21, arrayList8, hashMap22);
}
});
return;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.e("start import contacts");
}
final int i12 = 2;
if (z5 && i3 != 0) {
if (i3 >= 30) {
i12 = 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 (i12 == 0) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performSyncPhoneBook$13(i12, hashMap, z3, z);
}
});
return;
}
if (z6) {
final HashMap<String, Contact> hashMap23 = hashMap3;
final HashMap hashMap24 = hashMap4;
final ArrayList arrayList9 = arrayList;
final HashMap hashMap25 = hashMap2;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performSyncPhoneBook$15(hashMap14, hashMap23, z3, hashMap24, arrayList9, hashMap25);
}
});
return;
}
boolean[] zArr = {false};
HashMap hashMap26 = new HashMap(hashMap3);
SparseArray sparseArray = new SparseArray();
Iterator it5 = hashMap26.entrySet().iterator();
while (it5.hasNext()) {
Contact contact4 = (Contact) ((Map.Entry) it5.next()).getValue();
sparseArray.put(contact4.contact_id, contact4.key);
}
contactsController.completedRequestsCount = 0;
double size3 = arrayList6.size();
Double.isNaN(size3);
int ceil = (int) Math.ceil(size3 / 500.0d);
int i13 = 0;
while (i13 < ceil) {
final rr5 rr5Var = new rr5();
int i14 = i13 * 500;
rr5Var.a = new ArrayList<>(arrayList6.subList(i14, Math.min(i14 + 500, arrayList6.size())));
final HashMap hashMap27 = hashMap26;
final SparseArray sparseArray2 = sparseArray;
final boolean[] zArr2 = zArr;
final HashMap<String, Contact> hashMap28 = hashMap3;
int i15 = i13;
final int i16 = ceil;
int i17 = ceil;
final HashMap hashMap29 = hashMap14;
HashMap hashMap30 = hashMap14;
final HashMap hashMap31 = hashMap4;
final ArrayList arrayList10 = arrayList;
HashMap hashMap32 = hashMap26;
final HashMap hashMap33 = hashMap2;
getConnectionsManager().sendRequest(rr5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$performSyncPhoneBook$19(hashMap27, sparseArray2, zArr2, hashMap28, rr5Var, i16, hashMap29, z3, hashMap31, arrayList10, hashMap33, i95Var, ov5Var);
}
}, 6);
i13 = i15 + 1;
zArr = zArr;
ceil = i17;
arrayList6 = arrayList6;
hashMap14 = hashMap30;
sparseArray = sparseArray;
hashMap26 = hashMap32;
}
return;
}
i12 = 0;
if (BuildVars.LOGS_ENABLED) {
}
if (i12 == 0) {
}
}
public void lambda$processLoadedContacts$28() {
this.doneLoadingContacts = true;
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void lambda$processLoadedContacts$29() {
this.doneLoadingContacts = true;
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public static int lambda$processLoadedContacts$30(androidx.collection.d dVar, xq5 xq5Var, xq5 xq5Var2) {
return UserObject.getFirstName((f27) dVar.get(xq5Var.a)).compareTo(UserObject.getFirstName((f27) dVar.get(xq5Var2.a)));
}
public static int lambda$processLoadedContacts$31(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$processLoadedContacts$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 void lambda$processLoadedContacts$33(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;
this.doneLoadingContacts = true;
if (i != 2) {
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
}
performWriteContactsToPhoneBook();
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
if (i == 1 || z) {
reloadContactsStatusesMaybe();
} else {
saveContactsLoadTime();
}
}
public void lambda$processLoadedContacts$34(HashMap hashMap, HashMap hashMap2) {
this.contactsByPhone = hashMap;
this.contactsByShortPhone = hashMap2;
}
public void lambda$processLoadedContacts$35(final HashMap hashMap, final HashMap hashMap2) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$34(hashMap, hashMap2);
}
});
if (this.contactsSyncInProgress) {
return;
}
this.contactsSyncInProgress = true;
getMessagesStorage().getCachedPhoneBook(false);
}
public void lambda$processLoadedContacts$36(final int i, final ArrayList arrayList, androidx.collection.d dVar, ArrayList arrayList2, final boolean z) {
final HashMap hashMap;
final HashMap hashMap2;
int i2;
Runnable runnable;
ArrayList arrayList3 = arrayList;
final androidx.collection.d dVar2 = dVar;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("done loading contacts");
}
if (i == 1 && (arrayList.isEmpty() || Math.abs((System.currentTimeMillis() / 1000) - getUserConfig().lastContactsSyncTime) >= 86400)) {
loadContacts(false, getContactsHash(arrayList3));
if (arrayList.isEmpty()) {
runnable = new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$28();
}
};
AndroidUtilities.runOnUIThread(runnable);
return;
}
}
if (i == 0) {
getUserConfig().lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000);
getUserConfig().saveConfig(false);
}
for (int i3 = 0; i3 < arrayList.size(); i3++) {
xq5 xq5Var = arrayList3.get(i3);
if (dVar2.get(xq5Var.a) == null && xq5Var.a != getUserConfig().getClientUserId()) {
loadContacts(false, 0L);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts are broken, load from server");
}
runnable = new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$29();
}
};
AndroidUtilities.runOnUIThread(runnable);
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 lambda$processLoadedContacts$30;
lambda$processLoadedContacts$30 = ContactsController.lambda$processLoadedContacts$30(androidx.collection.d.this, (xq5) obj, (xq5) obj2);
return lambda$processLoadedContacts$30;
}
});
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()) {
xq5 xq5Var2 = arrayList3.get(i4);
f27 f27Var = (f27) dVar2.get(xq5Var2.a);
if (f27Var != null) {
concurrentHashMap.put(Long.valueOf(xq5Var2.a), xq5Var2);
if (hashMap == null || TextUtils.isEmpty(f27Var.f)) {
i2 = 0;
} else {
hashMap.put(f27Var.f, xq5Var2);
i2 = 0;
hashMap2.put(f27Var.f.substring(Math.max(0, r1.length() - 7)), xq5Var2);
}
String firstName = UserObject.getFirstName(f27Var);
if (firstName.length() > 1) {
firstName = firstName.substring(i2, 1);
}
String upperCase = firstName.length() == 0 ? "#" : firstName.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(xq5Var2);
if (f27Var.l) {
ArrayList arrayList7 = (ArrayList) hashMap4.get(upperCase);
if (arrayList7 == null) {
arrayList7 = new ArrayList();
hashMap4.put(upperCase, arrayList7);
arrayList5.add(upperCase);
}
arrayList7.add(xq5Var2);
}
}
i4++;
arrayList3 = arrayList;
dVar2 = dVar;
}
Collections.sort(arrayList4, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$processLoadedContacts$31;
lambda$processLoadedContacts$31 = ContactsController.lambda$processLoadedContacts$31((String) obj, (String) obj2);
return lambda$processLoadedContacts$31;
}
});
Collections.sort(arrayList5, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$processLoadedContacts$32;
lambda$processLoadedContacts$32 = ContactsController.lambda$processLoadedContacts$32((String) obj, (String) obj2);
return lambda$processLoadedContacts$32;
}
});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$33(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$processLoadedContacts$35(hashMap, hashMap2);
}
});
} else {
this.contactsLoaded = true;
}
}
public void lambda$processLoadedContacts$37(final ArrayList arrayList, final int i, final ArrayList arrayList2) {
getMessagesController().putUsers(arrayList, i == 1);
final androidx.collection.d dVar = new androidx.collection.d();
final boolean isEmpty = arrayList2.isEmpty();
if (i == 2 && !this.contacts.isEmpty()) {
int i2 = 0;
while (i2 < arrayList2.size()) {
if (this.contactsDict.get(Long.valueOf(((xq5) arrayList2.get(i2)).a)) != null) {
arrayList2.remove(i2);
i2--;
}
i2++;
}
arrayList2.addAll(this.contacts);
}
for (int i3 = 0; i3 < arrayList2.size(); i3++) {
f27 user = getMessagesController().getUser(Long.valueOf(((xq5) arrayList2.get(i3)).a));
if (user != null) {
dVar.put(user.a, user);
}
}
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$36(i, arrayList2, dVar, arrayList, isEmpty);
}
});
}
public void lambda$readContacts$10() {
if (this.contacts.isEmpty() && !this.contactsLoaded) {
loadContacts(true, 0L);
return;
}
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
}
public void lambda$reloadContactsStatuses$56(SharedPreferences.Editor editor, i95 i95Var) {
int i;
f27 user;
editor.remove("needGetStatuses").commit();
j27 j27Var = (j27) i95Var;
if (!j27Var.a.isEmpty()) {
ArrayList<f27> arrayList = new ArrayList<>();
Iterator<Object> it = j27Var.a.iterator();
while (it.hasNext()) {
Object next = it.next();
gz6 gz6Var = new gz6();
br5 br5Var = (br5) next;
if (br5Var != null) {
i27 i27Var = br5Var.b;
if (i27Var instanceof m07) {
i = -100;
} else if (i27Var instanceof j07) {
i = -101;
} else {
if (i27Var instanceof i07) {
i = -102;
}
user = getMessagesController().getUser(Long.valueOf(br5Var.a));
if (user != null) {
user.h = br5Var.b;
}
gz6Var.h = br5Var.b;
arrayList.add(gz6Var);
}
i27Var.a = i;
user = getMessagesController().getUser(Long.valueOf(br5Var.a));
if (user != null) {
}
gz6Var.h = br5Var.b;
arrayList.add(gz6Var);
}
}
getMessagesStorage().updateUsers(arrayList, true, true, true);
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, Integer.valueOf(MessagesController.UPDATE_MASK_STATUS));
}
public void lambda$reloadContactsStatuses$57(final SharedPreferences.Editor editor, final i95 i95Var, ov5 ov5Var) {
if (ov5Var == null) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$reloadContactsStatuses$56(editor, i95Var);
}
});
}
}
public static void lambda$resetImportedContacts$9(i95 i95Var, ov5 ov5Var) {
}
public void lambda$syncPhoneBookByAlert$6(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 static int lambda$updateUnregisteredContacts$42(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);
}
public void lambda$performSyncPhoneBook$22(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$mergePhonebookAndTelegramContacts$41(arrayList2, hashMap2, hashMap, arrayList);
}
});
}
private void performWriteContactsToPhoneBook() {
final ArrayList arrayList = new ArrayList(this.contacts);
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$performWriteContactsToPhoneBook$45(arrayList);
}
});
}
public void lambda$performWriteContactsToPhoneBook$45(ArrayList<xq5> arrayList) {
Cursor cursor = null;
try {
try {
} catch (Exception e) {
e = e;
}
if (hasContactsPermission()) {
SharedPreferences mainSettings = MessagesController.getMainSettings(this.currentAccount);
boolean z = !mainSettings.getBoolean("contacts_updated_v7", false);
if (z) {
mainSettings.edit().putBoolean("contacts_updated_v7", true).commit();
}
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 {
androidx.collection.d dVar = new androidx.collection.d();
if (query != null) {
while (query.moveToNext()) {
dVar.put(query.getLong(1), Long.valueOf(query.getLong(0)));
}
query.close();
for (int i = 0; i < arrayList.size(); i++) {
xq5 xq5Var = arrayList.get(i);
if (z || dVar.indexOfKey(xq5Var.a) < 0) {
addContactToPhoneBook(getMessagesController().getUser(Long.valueOf(xq5Var.a)), z);
}
}
} 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 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;
ArrayList<String> arrayList;
String string;
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 arrayList2 = new ArrayList();
Cursor 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 string2 = query.getString(r9);
String string3 = query.getString(5);
if (string3 == null) {
string3 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
boolean z = string3.indexOf(".sim") != 0;
if (!TextUtils.isEmpty(string2)) {
String i3 = uw3.i(string2, r9);
if (!TextUtils.isEmpty(i3)) {
if (i3.startsWith("+")) {
try {
substring = i3.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 = i3;
}
String string4 = query.getString(i);
sb2.setLength(i);
DatabaseUtils.appendEscapedSQLString(sb2, string4);
String sb3 = sb2.toString();
Contact contact = (Contact) hashMap4.get(substring);
if (contact == null) {
if (!arrayList2.contains(sb3)) {
arrayList2.add(sb3);
}
int i4 = query.getInt(2);
Contact contact2 = hashMap3.get(string4);
if (contact2 == null) {
contact2 = new Contact();
sb = sb2;
String string5 = query.getString(4);
String trim = string5 == null ? uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR : string5.trim();
if (contactsController.isNotValidNameString(trim)) {
contact2.first_name = trim;
contact2.last_name = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
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 = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
}
contact2.provider = string3;
contact2.isGoodProvider = z;
contact2.key = string4;
contact2.contact_id = i2;
hashMap3.put(string4, contact2);
i2++;
} else {
sb = sb2;
contentResolver2 = contentResolver3;
}
contact2.shortPhones.add(substring);
contact2.phones.add(i3);
contact2.phoneDeleted.add(0);
if (i4 == 0) {
String string6 = query.getString(3);
ArrayList<String> arrayList3 = contact2.phoneTypes;
if (string6 == null) {
string6 = LocaleController.getString("PhoneMobile", co.cheetah.gram.R.string.PhoneMobile);
}
arrayList3.add(string6);
} else {
if (i4 == 1) {
arrayList = contact2.phoneTypes;
string = LocaleController.getString("PhoneHome", co.cheetah.gram.R.string.PhoneHome);
} else if (i4 == 2) {
contact2.phoneTypes.add(LocaleController.getString("PhoneMobile", co.cheetah.gram.R.string.PhoneMobile));
} else if (i4 == 3) {
arrayList = contact2.phoneTypes;
string = LocaleController.getString("PhoneWork", co.cheetah.gram.R.string.PhoneWork);
} else if (i4 == 12) {
arrayList = contact2.phoneTypes;
string = LocaleController.getString("PhoneMain", co.cheetah.gram.R.string.PhoneMain);
} else {
arrayList = contact2.phoneTypes;
string = LocaleController.getString("PhoneOther", co.cheetah.gram.R.string.PhoneOther);
}
arrayList.add(string);
}
hashMap4.put(substring, contact2);
contactsController = this;
sb2 = sb;
contentResolver3 = contentResolver2;
} else if (!contact.isGoodProvider && !string3.equals(contact.provider)) {
sb2.setLength(0);
DatabaseUtils.appendEscapedSQLString(sb2, contact.key);
arrayList2.remove(sb2.toString());
arrayList2.add(sb3);
contact.key = string4;
contact.isGoodProvider = z;
contact.provider = string3;
}
}
}
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(",", arrayList2);
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 string7 = cursor2.getString(0);
String string8 = cursor2.getString(1);
String string9 = cursor2.getString(2);
String string10 = cursor2.getString(3);
Contact contact3 = hashMap2 != null ? hashMap2.get(string7) : null;
if (contact3 != null && !contact3.namesFilled) {
if (contact3.isGoodProvider) {
if (string8 != null) {
contact3.first_name = string8;
} else {
contact3.first_name = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
if (string9 != null) {
contact3.last_name = string9;
} else {
contact3.last_name = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
if (!TextUtils.isEmpty(string10)) {
if (TextUtils.isEmpty(contact3.first_name)) {
contact3.first_name = string10;
} else {
contact3.first_name += " " + string10;
}
}
} else if ((!isNotValidNameString(string8) && (contact3.first_name.contains(string8) || string8.contains(contact3.first_name))) || (!isNotValidNameString(string9) && (contact3.last_name.contains(string9) || string8.contains(contact3.last_name)))) {
if (string8 != null) {
contact3.first_name = string8;
} else {
contact3.first_name = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
if (!TextUtils.isEmpty(string10)) {
if (TextUtils.isEmpty(contact3.first_name)) {
contact3.first_name = string10;
} else {
contact3.first_name += " " + string10;
}
}
if (string9 != null) {
contact3.last_name = string9;
} else {
contact3.last_name = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
}
}
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<>();
}
private void reloadContactsStatuses() {
saveContactsLoadTime();
getMessagesController().clearFullUsers();
final SharedPreferences.Editor edit = MessagesController.getMainSettings(this.currentAccount).edit();
edit.putBoolean("needGetStatuses", true).commit();
getConnectionsManager().sendRequest(new pr5(), new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$reloadContactsStatuses$57(edit, i95Var, ov5Var);
}
});
}
private void saveContactsLoadTime() {
try {
MessagesController.getMainSettings(this.currentAccount).edit().putLong("lastReloadStatusTime", System.currentTimeMillis()).commit();
} catch (Exception e) {
FileLog.e(e);
}
}
private void updateUnregisteredContacts() {
boolean z;
HashMap hashMap = new HashMap();
int size = this.contacts.size();
for (int i = 0; i < size; i++) {
xq5 xq5Var = this.contacts.get(i);
f27 user = getMessagesController().getUser(Long.valueOf(xq5Var.a));
if (user != null && !TextUtils.isEmpty(user.f)) {
hashMap.put(user.f, xq5Var);
}
}
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) {
int lambda$updateUnregisteredContacts$42;
lambda$updateUnregisteredContacts$42 = ContactsController.lambda$updateUnregisteredContacts$42((ContactsController.Contact) obj, (ContactsController.Contact) obj2);
return lambda$updateUnregisteredContacts$42;
}
});
this.phoneBookContacts = arrayList;
}
public void addContact(final f27 f27Var, boolean z) {
String str;
if (f27Var == null) {
return;
}
dr5 dr5Var = new dr5();
dr5Var.c = getMessagesController().getInputUser(f27Var);
dr5Var.d = f27Var.b;
dr5Var.e = f27Var.c;
String str2 = f27Var.f;
dr5Var.f = str2;
dr5Var.b = z;
if (str2 != null) {
if (str2.length() > 0 && !dr5Var.f.startsWith("+")) {
str = "+" + dr5Var.f;
}
getConnectionsManager().sendRequest(dr5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$addContact$52(f27Var, i95Var, ov5Var);
}
}, 6);
}
str = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
dr5Var.f = str;
getConnectionsManager().sendRequest(dr5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$addContact$52(f27Var, i95Var, ov5Var);
}
}, 6);
}
public long addContactToPhoneBook(f27 f27Var, boolean z) {
String str;
long j = -1;
if (this.systemAccount == null || f27Var == 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 = " + f27Var.a, 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(f27Var.f) ? uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR : f27Var.f);
newInsert.withValue("sync2", Long.valueOf(f27Var.a));
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", f27Var.b);
newInsert2.withValue("data3", f27Var.c);
arrayList.add(newInsert2.build());
if (TextUtils.isEmpty(f27Var.f)) {
str = formatName(f27Var.b, f27Var.c);
} else {
str = "+" + f27Var.f;
}
ContentProviderOperation.Builder newInsert3 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
newInsert3.withValueBackReference("raw_contact_id", 0);
newInsert3.withValue("mimetype", "vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile");
newInsert3.withValue("data1", Long.valueOf(f27Var.a));
newInsert3.withValue("data2", "Telegram Profile");
newInsert3.withValue("data3", LocaleController.formatString("ContactShortcutMessage", co.cheetah.gram.R.string.ContactShortcutMessage, str));
newInsert3.withValue("data4", Long.valueOf(f27Var.a));
arrayList.add(newInsert3.build());
ContentProviderOperation.Builder newInsert4 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
newInsert4.withValueBackReference("raw_contact_id", 0);
newInsert4.withValue("mimetype", "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call");
newInsert4.withValue("data1", Long.valueOf(f27Var.a));
newInsert4.withValue("data2", "Telegram Voice Call");
newInsert4.withValue("data3", LocaleController.formatString("ContactShortcutVoiceCall", co.cheetah.gram.R.string.ContactShortcutVoiceCall, str));
newInsert4.withValue("data4", Long.valueOf(f27Var.a));
arrayList.add(newInsert4.build());
ContentProviderOperation.Builder newInsert5 = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
newInsert5.withValueBackReference("raw_contact_id", 0);
newInsert5.withValue("mimetype", "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call.video");
newInsert5.withValue("data1", Long.valueOf(f27Var.a));
newInsert5.withValue("data2", "Telegram Video Call");
newInsert5.withValue("data3", LocaleController.formatString("ContactShortcutVideoCall", co.cheetah.gram.R.string.ContactShortcutVideoCall, str));
newInsert5.withValue("data4", Long.valueOf(f27Var.a));
arrayList.add(newInsert5.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;
}
public void checkAppAccount() {
boolean z;
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
try {
Account[] accountsByType = accountManager.getAccountsByType("org.telegram.messenger");
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;
}
f27 currentUser = UserConfig.getInstance(i2).getCurrentUser();
if (currentUser != null) {
if (account.name.equals(uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR + currentUser.a)) {
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(uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR + getUserConfig().getClientUserId(), "org.telegram.messenger");
this.systemAccount = account2;
accountManager.addAccountExplicitly(account2, uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR, null);
} catch (Exception unused3) {
}
}
}
}
public void checkContacts() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$checkContacts$4();
}
});
}
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 yw5(), new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$checkInviteText$3(i95Var, ov5Var);
}
}, 2);
}
}
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.doneLoadingContacts = false;
this.contactsLoaded = false;
this.contactsBookLoaded = false;
this.lastContactsVersions = uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR;
this.loadingGlobalSettings = 0;
this.loadingDeleteInfo = 0;
this.deleteAccountTTL = 0;
Arrays.fill(this.loadingPrivacyInfo, 0);
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();
}
});
}
public void createOrUpdateConnectionServiceContact(long j, String str, String str2) {
String str3;
String str4;
int parseInt;
Cursor cursor;
ArrayList<ContentProviderOperation> arrayList;
ContentProviderOperation build;
if (hasContactsPermission()) {
try {
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
ArrayList<ContentProviderOperation> arrayList2 = new ArrayList<>();
Uri build2 = ContactsContract.Groups.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").build();
Uri build3 = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").build();
Account account = this.systemAccount;
Cursor query = contentResolver.query(build2, new String[]{"_id"}, "title=? AND account_type=? AND account_name=?", new String[]{"TelegramConnectionService", account.type, account.name}, null);
if (query == null || !query.moveToFirst()) {
ContentValues contentValues = new ContentValues();
contentValues.put("account_type", this.systemAccount.type);
contentValues.put("account_name", this.systemAccount.name);
str3 = "account_type";
contentValues.put("group_visible", (Integer) 0);
str4 = "account_name";
contentValues.put("group_is_read_only", (Integer) 1);
contentValues.put(Batch.Push.TITLE_KEY, "TelegramConnectionService");
parseInt = Integer.parseInt(contentResolver.insert(build2, contentValues).getLastPathSegment());
} else {
parseInt = query.getInt(0);
str3 = "account_type";
str4 = "account_name";
}
if (query != null) {
query.close();
}
String str5 = str3;
String str6 = str4;
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 + uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR}, null);
int size = arrayList2.size();
int i = parseInt;
if (query2 == null || !query2.moveToFirst()) {
cursor = query2;
arrayList = arrayList2;
arrayList.add(ContentProviderOperation.newInsert(build3).withValue(str5, this.systemAccount.type).withValue(str6, 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" + j).build());
build = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/group_membership").withValue("data1", Integer.valueOf(i)).build();
} else {
int i2 = query2.getInt(0);
cursor = query2;
arrayList = arrayList2;
arrayList.add(ContentProviderOperation.newUpdate(build3).withSelection("_id=?", new String[]{i2 + uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR}).withValue("deleted", 0).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{i2 + uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR, "vnd.android.cursor.item/phone_v2"}).withValue("data1", "+99084" + j).build());
build = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{i2 + uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR, "vnd.android.cursor.item/name"}).withValue("data2", str).withValue("data3", str2).build();
}
arrayList.add(build);
if (cursor != null) {
cursor.close();
}
contentResolver.applyBatch("com.android.contacts", arrayList);
} catch (Exception e) {
FileLog.e(e);
}
}
}
public void deleteAllContacts(final Runnable runnable) {
resetImportedContacts();
kr5 kr5Var = new kr5();
int size = this.contacts.size();
for (int i = 0; i < size; i++) {
kr5Var.a.add(getMessagesController().getInputUser(this.contacts.get(i).a));
}
getConnectionsManager().sendRequest(kr5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$deleteAllContacts$8(runnable, i95Var, ov5Var);
}
});
}
public void deleteConnectionServiceContact() {
if (hasContactsPermission()) {
try {
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
Account account = this.systemAccount;
Cursor query = contentResolver.query(ContactsContract.Groups.CONTENT_URI, new String[]{"_id"}, "title=? AND account_type=? AND account_name=?", new String[]{"TelegramConnectionService", account.type, account.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 + uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR}, 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 + uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR});
} catch (Exception e) {
FileLog.e(e);
}
}
}
public void deleteContact(final ArrayList<f27> arrayList, final boolean z) {
if (arrayList == null || arrayList.isEmpty()) {
return;
}
kr5 kr5Var = new kr5();
final ArrayList arrayList2 = new ArrayList();
int size = arrayList.size();
for (int i = 0; i < size; i++) {
f27 f27Var = arrayList.get(i);
mb5 inputUser = getMessagesController().getInputUser(f27Var);
if (inputUser != null) {
f27Var.k = false;
arrayList2.add(Long.valueOf(f27Var.a));
kr5Var.a.add(inputUser);
}
}
final String str = arrayList.get(0).b;
getConnectionsManager().sendRequest(kr5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$deleteContact$55(arrayList2, arrayList, z, str, i95Var, ov5Var);
}
});
}
public void deleteUnknownAppAccounts() {
boolean z;
try {
this.systemAccount = null;
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
Account[] accountsByType = accountManager.getAccountsByType("org.telegram.messenger");
for (int i = 0; i < accountsByType.length; i++) {
Account account = accountsByType[i];
int i2 = 0;
while (true) {
if (i2 >= 3) {
z = false;
break;
}
f27 currentUser = UserConfig.getInstance(i2).getCurrentUser();
if (currentUser != null) {
if (account.name.equals(uk.co.chrisjenx.calligraphy.BuildConfig.FLAVOR + currentUser.a)) {
z = true;
break;
}
}
i2++;
}
if (!z) {
try {
accountManager.removeAccount(accountsByType[i], null, null);
} catch (Exception unused) {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public ArrayList<xq5> filterHiddenContacts(ArrayList<xq5> arrayList, int i) {
i27 i27Var;
i27 i27Var2;
ArrayList<xq5> arrayList2 = new ArrayList<>();
if (arrayList != null) {
Iterator<xq5> it = arrayList.iterator();
while (it.hasNext()) {
xq5 next = it.next();
if (!s52.e.n(Long.valueOf(next.a), as0.a.USERHIDDEN)) {
if (i != 0 && ((i != 1 || !next.b) && (i != 2 || next.b))) {
f27 user = MessagesController.getInstance(this.currentAccount).getUser(Long.valueOf(next.a));
if (user != null && i == 1 && user.l) {
arrayList2.add(next);
}
if (user != null && i == 4 && getMessagesController().blockePeers.indexOfKey(user.a) >= 0) {
arrayList2.add(next);
}
if (user == null || i != 3 || (user.a != UserConfig.getInstance(this.currentAccount).getClientUserId() && ((i27Var2 = user.h) == null || i27Var2.a <= ConnectionsManager.getInstance(this.currentAccount).getCurrentTime()))) {
if (user != null && i == 5 && ((i27Var = user.h) == null || i27Var.a == 0 || (user instanceof lz6))) {
if (!UserObject.isDeleted(user) && user.g == null) {
}
}
}
}
arrayList2.add(next);
}
}
}
return arrayList2;
}
public HashMap<String, ArrayList<xq5>> filterHiddenContacts(HashMap<String, ArrayList<xq5>> hashMap, int i) {
HashMap<String, ArrayList<xq5>> hashMap2 = new HashMap<>();
for (String str : hashMap.keySet()) {
hashMap2.put(str, filterHiddenContacts(hashMap.get(str), i));
}
return hashMap2;
}
public ArrayList<String> filterHiddenSectionsArray(ArrayList<String> arrayList, HashMap<String, ArrayList<xq5>> hashMap) {
ArrayList<String> arrayList2 = new ArrayList<>();
Iterator<String> it = arrayList.iterator();
while (it.hasNext()) {
String next = it.next();
ArrayList<xq5> arrayList3 = hashMap.get(next);
if (arrayList3 != null && arrayList3.size() > 0) {
arrayList2.add(next);
}
}
return arrayList2;
}
public void forceImportContacts() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$forceImportContacts$5();
}
});
}
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;
String str = value.key;
contact.key = str;
hashMap2.put(str, contact);
}
return hashMap2;
}
public int getDeleteAccountTTL() {
return this.deleteAccountTTL;
}
public ew5 getGlobalPrivacySettings() {
return this.globalPrivacySettings;
}
public String getInviteText(int i) {
String str = "https://play.google.com/store/apps/details?id=" + s52.f().getPackageName();
if (i <= 1) {
return LocaleController.formatString("InviteText2", co.cheetah.gram.R.string.InviteText2, str);
}
try {
return String.format(LocaleController.getPluralString("InviteTextNum", i), Integer.valueOf(i), str);
} catch (Exception unused) {
return LocaleController.formatString("InviteText2", co.cheetah.gram.R.string.InviteText2, str);
}
}
public boolean getLoadingDeleteInfo() {
return this.loadingDeleteInfo != 2;
}
public boolean getLoadingGlobalSettings() {
return this.loadingGlobalSettings != 2;
}
public boolean getLoadingPrivicyInfo(int i) {
return this.loadingPrivacyInfo[i] != 2;
}
public ArrayList<uc5> 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;
default:
return null;
}
}
public ArrayList<String> getSortedUsersMutualSectionsArray(int i) {
return filterHiddenSectionsArray(this.sortedUsersMutualSectionsArray, getUsersMutualSectionsDict(i));
}
public ArrayList<String> getSortedUsersSectionsArray(int i) {
return filterHiddenSectionsArray(this.sortedUsersSectionsArray, getUsersSectionsDict(i));
}
public HashMap<String, ArrayList<xq5>> getUsersMutualSectionsDict(int i) {
return filterHiddenContacts(this.usersMutualSectionsDict, i);
}
public HashMap<String, ArrayList<xq5>> getUsersSectionsDict(int i) {
return filterHiddenContacts(this.usersSectionsDict, i);
}
public void initOnlineUsersSectionsDict() {
reloadContactsStatuses();
this.onlineUsersSectionsDict = new HashMap<>();
this.onlineSortedUsersSectionsArray = new ArrayList<>();
for (String str : this.usersSectionsDict.keySet()) {
ArrayList<xq5> arrayList = new ArrayList<>();
ArrayList<xq5> arrayList2 = this.usersSectionsDict.get(str);
if (arrayList2 != null) {
Iterator<xq5> it = arrayList2.iterator();
while (it.hasNext()) {
xq5 next = it.next();
f27 user = MessagesController.getInstance(this.currentAccount).getUser(Long.valueOf(next.a));
String formatUserStatus = LocaleController.formatUserStatus(this.currentAccount, user);
if (user != null && (user.a == UserConfig.getInstance(this.currentAccount).getClientUserId() || formatUserStatus.contains(LocaleController.getString("Online", co.cheetah.gram.R.string.Online)))) {
arrayList.add(next);
}
}
}
if (arrayList.size() > 0) {
this.onlineUsersSectionsDict.put(str, arrayList);
if (!this.onlineSortedUsersSectionsArray.contains(str)) {
this.onlineSortedUsersSectionsArray.add(str);
}
}
}
Collections.sort(this.onlineSortedUsersSectionsArray, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int lambda$initOnlineUsersSectionsDict$64;
lambda$initOnlineUsersSectionsDict$64 = ContactsController.lambda$initOnlineUsersSectionsDict$64((String) obj, (String) obj2);
return lambda$initOnlineUsersSectionsDict$64;
}
});
}
public boolean isContact(long j) {
return this.contactsDict.get(Long.valueOf(j)) != null;
}
public boolean isLoadingContacts() {
boolean z;
synchronized (this.loadContactsSync) {
z = this.loadingContacts;
}
return z;
}
public void loadContacts(boolean z, final long j) {
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");
}
nr5 nr5Var = new nr5();
nr5Var.a = j;
getConnectionsManager().sendRequest(nr5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$loadContacts$27(j, i95Var, ov5Var);
}
});
}
}
public void loadPrivacySettings() {
gb5 p16Var;
if (this.loadingDeleteInfo == 0) {
this.loadingDeleteInfo = 1;
getConnectionsManager().sendRequest(new yd5(), new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$loadPrivacySettings$59(i95Var, ov5Var);
}
});
}
if (this.loadingGlobalSettings == 0) {
this.loadingGlobalSettings = 1;
getConnectionsManager().sendRequest(new fe5(), new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$loadPrivacySettings$61(i95Var, ov5Var);
}
});
}
final int i = 0;
while (true) {
int[] iArr = this.loadingPrivacyInfo;
if (i >= iArr.length) {
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
return;
}
if (iArr[i] == 0) {
iArr[i] = 1;
ke5 ke5Var = new ke5();
switch (i) {
case 0:
p16Var = new p16();
break;
case 1:
p16Var = new j16();
break;
case 2:
p16Var = new l16();
break;
case 3:
p16Var = new n16();
break;
case 4:
p16Var = new o16();
break;
case 5:
p16Var = new k16();
break;
case 6:
p16Var = new m16();
break;
default:
p16Var = new i16();
break;
}
ke5Var.a = p16Var;
getConnectionsManager().sendRequest(ke5Var, new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.this.lambda$loadPrivacySettings$63(i, i95Var, ov5Var);
}
});
}
i++;
}
}
public void markAsContacted(final String str) {
if (str == null) {
return;
}
Utilities.phoneBookQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.lambda$markAsContacted$49(str);
}
});
}
public void migratePhoneBookToV7(final SparseArray<Contact> sparseArray) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$migratePhoneBookToV7$11(sparseArray);
}
});
}
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$24(hashMap, z3, z, z2, z4, z5, z6);
}
});
}
}
public void processContactsUpdates(ArrayList<Long> arrayList, ConcurrentHashMap<Long, f27> concurrentHashMap) {
int indexOf;
ArrayList<xq5> arrayList2 = new ArrayList<>();
ArrayList<Long> arrayList3 = new ArrayList<>();
Iterator<Long> it = arrayList.iterator();
while (it.hasNext()) {
Long next = it.next();
if (next.longValue() > 0) {
xq5 xq5Var = new xq5();
xq5Var.a = next.longValue();
arrayList2.add(xq5Var);
if (!this.delayedContactsUpdate.isEmpty() && (indexOf = this.delayedContactsUpdate.indexOf(Long.valueOf(-next.longValue()))) != -1) {
this.delayedContactsUpdate.remove(indexOf);
}
} else if (next.longValue() < 0) {
arrayList3.add(Long.valueOf(-next.longValue()));
if (!this.delayedContactsUpdate.isEmpty() && (indexOf = this.delayedContactsUpdate.indexOf(Long.valueOf(-next.longValue()))) != -1) {
this.delayedContactsUpdate.remove(indexOf);
}
}
}
if (!arrayList3.isEmpty()) {
getMessagesStorage().deleteContacts(arrayList3);
}
if (!arrayList2.isEmpty()) {
getMessagesStorage().putContacts(arrayList2, false);
}
if (this.contactsLoaded && this.contactsBookLoaded) {
applyContactsUpdates(arrayList, concurrentHashMap, arrayList2, arrayList3);
return;
}
this.delayedContactsUpdate.addAll(arrayList);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("delay update - contacts add = " + arrayList2.size() + " delete = " + arrayList3.size());
}
}
public void processLoadedContacts(final ArrayList<xq5> arrayList, final ArrayList<f27> arrayList2, final int i) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
ContactsController.this.lambda$processLoadedContacts$37(arrayList2, i, arrayList);
}
});
}
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();
}
});
}
}
public void reloadContactsStatusesMaybe() {
try {
if (MessagesController.getMainSettings(this.currentAccount).getLong("lastReloadStatusTime", 0L) < System.currentTimeMillis() - 10800000) {
reloadContactsStatuses();
}
} catch (Exception e) {
FileLog.e(e);
}
}
public void resetImportedContacts() {
getConnectionsManager().sendRequest(new ur5(), new RequestDelegate() {
@Override
public final void run(i95 i95Var, ov5 ov5Var) {
ContactsController.lambda$resetImportedContacts$9(i95Var, ov5Var);
}
});
}
public void setDeleteAccountTTL(int i) {
this.deleteAccountTTL = i;
}
public void setPrivacyRules(ArrayList<uc5> 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;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
reloadContactsStatuses();
}
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(hashMap, z, z2, z3);
}
});
}
}