正在查看: Telegram v11.13.0 应用的 ContactsController.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Telegram v11.13.0 应用的 ContactsController.java JAVA 源代码文件
本页面展示 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.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.SparseArray;
import androidx.collection.LongSparseArray;
import j$.util.concurrent.ConcurrentHashMap;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.telegram.messenger.ContactsController$;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.tgnet.TLRPC$User;
import org.telegram.tgnet.Vector;
import org.telegram.tgnet.tl.TL_account;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.Bulletin;
public class ContactsController extends BaseController {
private static volatile ContactsController[] Instance = new ContactsController[4];
public static final int PRIVACY_RULES_TYPE_ADDED_BY_PHONE = 7;
public static final int PRIVACY_RULES_TYPE_BIO = 9;
public static final int PRIVACY_RULES_TYPE_BIRTHDAY = 11;
public static final int PRIVACY_RULES_TYPE_CALLS = 2;
public static final int PRIVACY_RULES_TYPE_COUNT = 14;
public static final int PRIVACY_RULES_TYPE_FORWARDS = 5;
public static final int PRIVACY_RULES_TYPE_GIFTS = 12;
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_MESSAGES = 10;
public static final int PRIVACY_RULES_TYPE_NO_PAID_MESSAGES = 13;
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;
public static final int PRIVACY_RULES_TYPE_VOICE_MESSAGES = 8;
private static Collator cachedCollator;
private static Locale cachedCollatorLocale;
private ArrayList<TLRPC.PrivacyRule> addedByPhonePrivacyRules;
private ArrayList<TLRPC.PrivacyRule> bioPrivacyRules;
private ArrayList<TLRPC.PrivacyRule> birthdayPrivacyRules;
private ArrayList<TLRPC.PrivacyRule> callPrivacyRules;
private int completedRequestsCount;
public ArrayList<TLRPC.TL_contact> contacts;
public HashMap<String, Contact> contactsBook;
private boolean contactsBookLoaded;
public HashMap<String, Contact> contactsBookSPhones;
public HashMap<String, TLRPC.TL_contact> contactsByPhone;
public HashMap<String, TLRPC.TL_contact> contactsByShortPhone;
public ConcurrentHashMap<Long, TLRPC.TL_contact> contactsDict;
public boolean contactsLoaded;
private boolean contactsSyncInProgress;
private ArrayList<Long> delayedContactsUpdate;
private int deleteAccountTTL;
public boolean doneLoadingContacts;
private ArrayList<TLRPC.PrivacyRule> forwardsPrivacyRules;
private ArrayList<TLRPC.PrivacyRule> giftsPrivacyRules;
private TLRPC.GlobalPrivacySettings globalPrivacySettings;
private ArrayList<TLRPC.PrivacyRule> groupPrivacyRules;
private boolean ignoreChanges;
private String inviteLink;
private String lastContactsVersions;
private ArrayList<TLRPC.PrivacyRule> lastseenPrivacyRules;
private final Object loadContactsSync;
private boolean loadingContacts;
private int loadingDeleteInfo;
private int loadingGlobalSettings;
private int[] loadingPrivacyInfo;
private boolean migratingContacts;
private ArrayList<TLRPC.PrivacyRule> noPaidMessagesPrivacyRules;
private final Object observerLock;
private ArrayList<TLRPC.PrivacyRule> p2pPrivacyRules;
public HashMap<String, Contact> phoneBookByShortPhones;
public ArrayList<Contact> phoneBookContacts;
public ArrayList<String> phoneBookSectionsArray;
public HashMap<String, ArrayList<Object>> phoneBookSectionsDict;
private ArrayList<TLRPC.PrivacyRule> phonePrivacyRules;
private ArrayList<TLRPC.PrivacyRule> profilePhotoPrivacyRules;
private String[] projectionNames;
private String[] projectionPhones;
private HashMap<String, String> sectionsToReplace;
public ArrayList<String> sortedUsersMutualSectionsArray;
public ArrayList<String> sortedUsersSectionsArray;
private Account systemAccount;
private boolean updatingInviteLink;
public HashMap<String, ArrayList<TLRPC.TL_contact>> usersMutualSectionsDict;
public HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict;
private ArrayList<TLRPC.PrivacyRule> voiceMessagesRules;
public ContactsController(int i) {
super(i);
this.loadContactsSync = new Object();
this.observerLock = new Object();
this.lastContactsVersions = "";
this.delayedContactsUpdate = new ArrayList<>();
this.sectionsToReplace = new HashMap<>();
this.loadingPrivacyInfo = new int[14];
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.phoneBookByShortPhones = new HashMap<>();
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 ContactsController$.ExternalSyntheticLambda54(this));
}
}
private void applyContactToPhoneBook(ArrayList<ContentProviderOperation> arrayList, TLRPC$User tLRPC$User) {
String str;
if (tLRPC$User == null) {
return;
}
int size = arrayList.size();
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(tLRPC$User.phone) ? "" : tLRPC$User.phone);
newInsert.withValue("sync2", Long.valueOf(tLRPC$User.id));
arrayList.add(newInsert.build());
Uri uri = ContactsContract.Data.CONTENT_URI;
ContentProviderOperation.Builder newInsert2 = ContentProviderOperation.newInsert(uri);
newInsert2.withValueBackReference("raw_contact_id", size);
newInsert2.withValue("mimetype", "vnd.android.cursor.item/name");
newInsert2.withValue("data2", tLRPC$User.first_name);
newInsert2.withValue("data3", tLRPC$User.last_name);
arrayList.add(newInsert2.build());
if (TextUtils.isEmpty(tLRPC$User.phone)) {
str = formatName(tLRPC$User.first_name, tLRPC$User.last_name);
} else {
str = "+" + tLRPC$User.phone;
}
ContentProviderOperation.Builder newInsert3 = ContentProviderOperation.newInsert(uri);
newInsert3.withValueBackReference("raw_contact_id", size);
newInsert3.withValue("mimetype", "vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile");
newInsert3.withValue("data1", Long.valueOf(tLRPC$User.id));
newInsert3.withValue("data2", "Telegram Profile");
newInsert3.withValue("data3", LocaleController.formatString("ContactShortcutMessage", R.string.ContactShortcutMessage, str));
newInsert3.withValue("data4", Long.valueOf(tLRPC$User.id));
arrayList.add(newInsert3.build());
ContentProviderOperation.Builder newInsert4 = ContentProviderOperation.newInsert(uri);
newInsert4.withValueBackReference("raw_contact_id", size);
newInsert4.withValue("mimetype", "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call");
newInsert4.withValue("data1", Long.valueOf(tLRPC$User.id));
newInsert4.withValue("data2", "Telegram Voice Call");
newInsert4.withValue("data3", LocaleController.formatString("ContactShortcutVoiceCall", R.string.ContactShortcutVoiceCall, str));
newInsert4.withValue("data4", Long.valueOf(tLRPC$User.id));
arrayList.add(newInsert4.build());
ContentProviderOperation.Builder newInsert5 = ContentProviderOperation.newInsert(uri);
newInsert5.withValueBackReference("raw_contact_id", size);
newInsert5.withValue("mimetype", "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call.video");
newInsert5.withValue("data1", Long.valueOf(tLRPC$User.id));
newInsert5.withValue("data2", "Telegram Video Call");
newInsert5.withValue("data3", LocaleController.formatString("ContactShortcutVideoCall", R.string.ContactShortcutVideoCall, str));
newInsert5.withValue("data4", Long.valueOf(tLRPC$User.id));
arrayList.add(newInsert5.build());
}
private void applyContactsUpdates(ArrayList<Long> arrayList, ConcurrentHashMap<Long, TLRPC$User> concurrentHashMap, ArrayList<TLRPC.TL_contact> arrayList2, 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) {
TLRPC.TL_contact tL_contact = new TLRPC.TL_contact();
tL_contact.user_id = l.longValue();
arrayList2.add(tL_contact);
} 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;
}
TLRPC.TL_contact tL_contact2 = arrayList2.get(i2);
TLRPC$User tLRPC$User = concurrentHashMap != null ? (TLRPC$User) concurrentHashMap.get(Long.valueOf(tL_contact2.user_id)) : null;
if (tLRPC$User == null) {
tLRPC$User = getMessagesController().getUser(Long.valueOf(tL_contact2.user_id));
} else {
getMessagesController().putUser(tLRPC$User, true);
}
if (tLRPC$User == null || TextUtils.isEmpty(tLRPC$User.phone)) {
z = true;
} else {
Contact contact = this.contactsBookSPhones.get(tLRPC$User.phone);
if (contact != null && (indexOf2 = contact.shortPhones.indexOf(tLRPC$User.phone)) != -1) {
contact.phoneDeleted.set(indexOf2, 0);
}
if (sb.length() != 0) {
sb.append(",");
}
sb.append(tLRPC$User.phone);
}
i2++;
}
for (int i3 = 0; i3 < arrayList3.size(); i3++) {
Long l2 = arrayList3.get(i3);
Utilities.phoneBookQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda2(this, l2));
TLRPC$User tLRPC$User2 = concurrentHashMap != null ? (TLRPC$User) concurrentHashMap.get(l2) : null;
if (tLRPC$User2 == null) {
tLRPC$User2 = getMessagesController().getUser(l2);
} else {
getMessagesController().putUser(tLRPC$User2, true);
}
if (tLRPC$User2 == null) {
z = true;
} else if (!TextUtils.isEmpty(tLRPC$User2.phone)) {
Contact contact2 = this.contactsBookSPhones.get(tLRPC$User2.phone);
if (contact2 != null && (indexOf = contact2.shortPhones.indexOf(tLRPC$User2.phone)) != -1) {
contact2.phoneDeleted.set(indexOf, 1);
}
if (sb2.length() != 0) {
sb2.append(",");
}
sb2.append(tLRPC$User2.phone);
}
}
if (sb.length() != 0 || sb2.length() != 0) {
getMessagesStorage().applyPhoneBookUpdates(sb.toString(), sb2.toString());
}
if (z) {
Utilities.stageQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda3(this));
} else {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda4(this, arrayList2, arrayList3));
}
}
private void buildContactsSectionsArrays(boolean z) {
Collator localeCollator = getLocaleCollator();
if (z) {
Collections.sort(this.contacts, new ContactsController$.ExternalSyntheticLambda16(this, localeCollator));
}
HashMap<String, ArrayList<TLRPC.TL_contact>> hashMap = new HashMap<>();
ArrayList<String> arrayList = new ArrayList<>();
for (int i = 0; i < this.contacts.size(); i++) {
TLRPC.TL_contact tL_contact = this.contacts.get(i);
TLRPC$User user = getMessagesController().getUser(Long.valueOf(tL_contact.user_id));
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<TLRPC.TL_contact> arrayList2 = hashMap.get(upperCase);
if (arrayList2 == null) {
arrayList2 = new ArrayList<>();
hashMap.put(upperCase, arrayList2);
arrayList.add(upperCase);
}
arrayList2.add(tL_contact);
}
}
Collections.sort(arrayList, new ContactsController$.ExternalSyntheticLambda17(localeCollator));
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 {
}
}
if (query != null) {
query.close();
}
} 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((Throwable) e, false);
}
synchronized (this.observerLock) {
this.ignoreChanges = false;
}
}
}
public static <T extends TLRPC.PrivacyRule> T findRule(ArrayList<TLRPC.PrivacyRule> arrayList, Class<T> cls) {
if (arrayList == null) {
return null;
}
Iterator<TLRPC.PrivacyRule> it = arrayList.iterator();
while (it.hasNext()) {
TLRPC.PrivacyRule next = it.next();
if (cls.isInstance(next)) {
return cls.cast(next);
}
}
return null;
}
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 (str != null && str2 == null && i > 0 && str.contains(" ")) {
int indexOf = str.indexOf(" ");
String substring = str.substring(indexOf + 1);
str = str.substring(0, indexOf);
str2 = substring;
}
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();
}
public static String formatName(TLObject tLObject) {
return tLObject instanceof TLRPC$User ? formatName((TLRPC$User) tLObject) : tLObject instanceof TLRPC.Chat ? ((TLRPC.Chat) tLObject).title : LocaleController.getString(R.string.HiddenName);
}
public static String formatName(TLRPC$User tLRPC$User) {
return tLRPC$User == null ? "" : formatName(tLRPC$User.first_name, tLRPC$User.last_name, 0);
}
private long getContactsHash(ArrayList<TLRPC.TL_contact> arrayList) {
ArrayList arrayList2 = new ArrayList(arrayList);
Collections.sort(arrayList2, new ContactsController$.ExternalSyntheticLambda49());
int size = arrayList2.size();
long j = 0;
int i = -1;
while (i < size) {
j = MediaDataController.calcHash(j, i == -1 ? getUserConfig().contactsSavedCount : ((TLRPC.TL_contact) arrayList2.get(i)).user_id);
i++;
}
return j;
}
public static ContactsController getInstance(int i) {
ContactsController contactsController = Instance[i];
if (contactsController == null) {
synchronized (ContactsController.class) {
try {
contactsController = Instance[i];
if (contactsController == null) {
ContactsController[] contactsControllerArr = Instance;
ContactsController contactsController2 = new ContactsController(i);
contactsControllerArr[i] = contactsController2;
contactsController = contactsController2;
}
} finally {
}
}
}
return contactsController;
}
public static Collator getLocaleCollator() {
if (cachedCollator == null || cachedCollatorLocale != Locale.getDefault()) {
try {
Locale locale = Locale.getDefault();
cachedCollatorLocale = locale;
Collator collator = Collator.getInstance(locale);
cachedCollator = collator;
collator.setStrength(1);
} catch (Exception e) {
FileLog.e((Throwable) e, true);
}
}
if (cachedCollator == null) {
try {
Collator collator2 = Collator.getInstance();
cachedCollator = collator2;
collator2.setStrength(1);
} catch (Exception e2) {
FileLog.e((Throwable) e2, true);
}
}
if (cachedCollator == null) {
cachedCollator = new 1();
}
return cachedCollator;
}
private boolean hasContactsPermission() {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.hasContactsPermission():boolean");
}
private boolean hasContactsWritePermission() {
int checkSelfPermission;
if (Build.VERSION.SDK_INT < 23) {
return true;
}
checkSelfPermission = ApplicationLoader.applicationContext.checkSelfPermission("android.permission.WRITE_CONTACTS");
return checkSelfPermission == 0;
}
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(TLRPC$User tLRPC$User) {
addContactToPhoneBook(tLRPC$User, true);
}
public void lambda$addContact$51(TLRPC.Updates updates, TLRPC$User tLRPC$User) {
Contact contact;
boolean z = false;
for (int i = 0; i < updates.users.size(); i++) {
TLRPC$User tLRPC$User2 = (TLRPC$User) updates.users.get(i);
if (tLRPC$User2.contact && (contact = this.contactsBookSPhones.get(tLRPC$User2.phone)) != null) {
String letter = contact.getLetter();
String letter2 = Contact.getLetter(tLRPC$User.first_name, tLRPC$User.last_name);
if (contact.user == null) {
contact.user = tLRPC$User;
if (!letter.equals(letter2)) {
ArrayList<Object> arrayList = this.phoneBookSectionsDict.get(letter2);
if (arrayList == null) {
arrayList = new ArrayList<>();
this.phoneBookSectionsDict.put(letter2, arrayList);
this.phoneBookSectionsArray.add(letter2);
}
arrayList.add(contact);
ArrayList<Object> arrayList2 = this.phoneBookSectionsDict.get(letter);
if (arrayList2 != null) {
Iterator<Object> it = arrayList2.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
Object next = it.next();
if (next instanceof Contact) {
Contact contact2 = (Contact) next;
if (contact2.contact_id == contact.contact_id) {
if (arrayList2.remove(contact2) && arrayList2.isEmpty()) {
this.phoneBookSectionsDict.remove(letter);
this.phoneBookSectionsArray.remove(letter);
}
}
}
}
}
}
z = true;
}
}
if (tLRPC$User2.contact && this.contactsDict.get(Long.valueOf(tLRPC$User2.id)) == null) {
TLRPC.TL_contact tL_contact = new TLRPC.TL_contact();
tL_contact.user_id = tLRPC$User2.id;
this.contacts.add(tL_contact);
this.contactsDict.put(Long.valueOf(tL_contact.user_id), tL_contact);
}
}
buildContactsSectionsArrays(true);
if (z) {
mergePhonebookAndTelegramContacts(this.phoneBookSectionsDict, this.phoneBookSectionsArray, this.phoneBookByShortPhones, false);
}
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void lambda$addContact$52(TLRPC$User tLRPC$User, TLObject tLObject, TLRPC.TL_error tL_error) {
int indexOf;
if (tL_error != null) {
return;
}
TLRPC.Updates updates = (TLRPC.Updates) tLObject;
TLRPC.UserProfilePhoto userProfilePhoto = tLRPC$User.photo;
if (userProfilePhoto != null && userProfilePhoto.personal) {
for (int i = 0; i < updates.users.size(); i++) {
if (((TLRPC$User) updates.users.get(i)).id == tLRPC$User.id) {
((TLRPC$User) updates.users.get(i)).photo = tLRPC$User.photo;
}
}
}
getMessagesController().processUpdates(updates, false);
for (int i2 = 0; i2 < updates.users.size(); i2++) {
TLRPC$User tLRPC$User2 = (TLRPC$User) updates.users.get(i2);
if (tLRPC$User2.id == tLRPC$User.id) {
Utilities.phoneBookQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda18(this, tLRPC$User2));
TLRPC.TL_contact tL_contact = new TLRPC.TL_contact();
tL_contact.user_id = tLRPC$User2.id;
ArrayList arrayList = new ArrayList();
arrayList.add(tL_contact);
getMessagesStorage().putContacts(arrayList, false);
if (!TextUtils.isEmpty(tLRPC$User2.phone)) {
formatName(tLRPC$User2.first_name, tLRPC$User2.last_name);
getMessagesStorage().applyPhoneBookUpdates(tLRPC$User2.phone, "");
Contact contact = this.contactsBookSPhones.get(tLRPC$User2.phone);
if (contact != null && (indexOf = contact.shortPhones.indexOf(tLRPC$User2.phone)) != -1) {
contact.phoneDeleted.set(indexOf, 0);
}
}
}
}
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda19(this, updates, tLRPC$User));
}
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++) {
TLRPC.TL_contact tL_contact = (TLRPC.TL_contact) arrayList.get(i);
if (this.contactsDict.get(Long.valueOf(tL_contact.user_id)) == null) {
this.contacts.add(tL_contact);
this.contactsDict.put(Long.valueOf(tL_contact.user_id), tL_contact);
}
}
for (int i2 = 0; i2 < arrayList2.size(); i2++) {
Long l = (Long) arrayList2.get(i2);
TLRPC.TL_contact tL_contact2 = (TLRPC.TL_contact) this.contactsDict.get(l);
if (tL_contact2 != null) {
this.contacts.remove(tL_contact2);
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(Collator collator, TLRPC.TL_contact tL_contact, TLRPC.TL_contact tL_contact2) {
return collator.compare(UserObject.getFirstName(getMessagesController().getUser(Long.valueOf(tL_contact.user_id))), UserObject.getFirstName(getMessagesController().getUser(Long.valueOf(tL_contact2.user_id))));
}
public static int lambda$buildContactsSectionsArrays$44(Collator collator, String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return collator.compare(str, str2);
}
public void lambda$checkAppAccount$4() {
AccountManager accountManager = AccountManager.get(ApplicationLoader.applicationContext);
try {
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 < 4) {
TLRPC$User currentUser = UserConfig.getInstance(i2).getCurrentUser();
if (currentUser != null) {
if (account.name.equals("" + currentUser.id)) {
if (i2 == this.currentAccount) {
this.systemAccount = account;
}
}
}
i2++;
} else {
try {
accountManager.removeAccount(accountsByType[i], null, null);
break;
} catch (Exception unused) {
}
}
}
}
} catch (Throwable unused2) {
}
if (getUserConfig().isClientActivated()) {
readContacts();
if (this.systemAccount == null) {
try {
Account account2 = new Account("" + getUserConfig().getClientUserId(), "org.telegram.messenger");
this.systemAccount = account2;
accountManager.addAccountExplicitly(account2, "", null);
} catch (Exception unused3) {
}
}
}
}
public void lambda$checkContacts$5() {
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(TLRPC.TL_help_inviteText tL_help_inviteText) {
this.updatingInviteLink = false;
SharedPreferences.Editor edit = MessagesController.getMainSettings(this.currentAccount).edit();
String str = tL_help_inviteText.message;
this.inviteLink = str;
edit.putString("invitelink", str);
edit.putInt("invitelinktime", (int) (System.currentTimeMillis() / 1000));
edit.commit();
}
public void lambda$checkInviteText$3(TLObject tLObject, TLRPC.TL_error tL_error) {
if (tLObject != null) {
TLRPC.TL_help_inviteText tL_help_inviteText = (TLRPC.TL_help_inviteText) tLObject;
if (tL_help_inviteText.message.length() != 0) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda23(this, tL_help_inviteText));
}
}
}
public void lambda$cleanup$1() {
this.migratingContacts = false;
this.completedRequestsCount = 0;
}
public void lambda$deleteAllContacts$8(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 >= 4) {
break;
}
TLRPC$User currentUser = UserConfig.getInstance(i).getCurrentUser();
if (currentUser != null) {
if (account.name.equals("" + currentUser.id)) {
accountManager.removeAccount(account, null, null);
break;
}
}
i++;
}
}
} catch (Throwable unused) {
}
try {
Account account2 = new Account("" + getUserConfig().getClientUserId(), "org.telegram.messenger");
this.systemAccount = account2;
accountManager.addAccountExplicitly(account2, "", null);
} catch (Exception unused2) {
}
getMessagesStorage().putCachedPhoneBook(new HashMap(), false, true);
getMessagesStorage().putContacts(new ArrayList(), true);
this.phoneBookContacts.clear();
this.contacts.clear();
this.contactsDict.clear();
this.usersSectionsDict.clear();
this.usersMutualSectionsDict.clear();
this.sortedUsersSectionsArray.clear();
this.phoneBookSectionsDict.clear();
this.phoneBookSectionsArray.clear();
this.phoneBookByShortPhones.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$9(Runnable runnable, TLObject tLObject, TLRPC.TL_error tL_error) {
if (tL_error != 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 = "";
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda1(this, runnable));
}
public void lambda$deleteContact$55(ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
deleteContactFromPhoneBook(((TLRPC$User) it.next()).id);
}
}
public void lambda$deleteContact$56(ArrayList arrayList, boolean z, String str) {
Iterator it = arrayList.iterator();
boolean z2 = false;
while (it.hasNext()) {
TLRPC$User tLRPC$User = (TLRPC$User) it.next();
TLRPC.TL_contact tL_contact = (TLRPC.TL_contact) this.contactsDict.get(Long.valueOf(tLRPC$User.id));
if (tL_contact != null) {
this.contacts.remove(tL_contact);
this.contactsDict.remove(Long.valueOf(tLRPC$User.id));
z2 = true;
}
}
if (z2) {
buildContactsSectionsArrays(false);
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, new Object[]{Integer.valueOf(MessagesController.UPDATE_MASK_NAME)});
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
if (z) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.showBulletin, new Object[]{1, LocaleController.formatString("DeletedFromYourContacts", R.string.DeletedFromYourContacts, str)});
}
}
public void lambda$deleteContact$57(ArrayList arrayList, ArrayList arrayList2, boolean z, String str, TLObject tLObject, TLRPC.TL_error tL_error) {
int indexOf;
if (tL_error != null) {
return;
}
getMessagesController().processUpdates((TLRPC.Updates) tLObject, false);
getMessagesStorage().deleteContacts(arrayList);
Utilities.phoneBookQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda35(this, arrayList2));
for (int i = 0; i < arrayList2.size(); i++) {
TLRPC$User tLRPC$User = (TLRPC$User) arrayList2.get(i);
if (!TextUtils.isEmpty(tLRPC$User.phone)) {
getMessagesStorage().applyPhoneBookUpdates(tLRPC$User.phone, "");
Contact contact = this.contactsBookSPhones.get(tLRPC$User.phone);
if (contact != null && (indexOf = contact.shortPhones.indexOf(tLRPC$User.phone)) != -1) {
contact.phoneDeleted.set(indexOf, 1);
}
}
}
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda36(this, arrayList2, z, str));
}
public void lambda$deleteContactsUndoable$53(HashMap hashMap) {
for (Map.Entry entry : hashMap.entrySet()) {
TLRPC$User tLRPC$User = (TLRPC$User) entry.getKey();
TLRPC.TL_contact tL_contact = (TLRPC.TL_contact) entry.getValue();
tLRPC$User.contact = true;
this.contacts.add(tL_contact);
this.contactsDict.put(Long.valueOf(tLRPC$User.id), tL_contact);
}
buildContactsSectionsArrays(true);
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, new Object[]{Integer.valueOf(MessagesController.UPDATE_MASK_NAME)});
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void lambda$deleteContactsUndoable$54(ArrayList arrayList) {
deleteContact(arrayList, false);
}
public void lambda$forceImportContacts$6() {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("force import contacts");
}
performSyncPhoneBook(new HashMap<>(), true, true, true, true, false, false);
}
public static int lambda$getContactsHash$26(TLRPC.TL_contact tL_contact, TLRPC.TL_contact tL_contact2) {
long j = tL_contact.user_id;
long j2 = tL_contact2.user_id;
if (j > j2) {
return 1;
}
return j < j2 ? -1 : 0;
}
public void lambda$loadContacts$27() {
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public void lambda$loadContacts$28(long j, TLObject tLObject, TLRPC.TL_error tL_error) {
if (tL_error == null) {
TLRPC.contacts_Contacts contacts_contacts = (TLRPC.contacts_Contacts) tLObject;
if (j == 0 || !(contacts_contacts instanceof TLRPC.TL_contacts_contactsNotModified)) {
getUserConfig().contactsSavedCount = contacts_contacts.saved_count;
getUserConfig().saveConfig(false);
processLoadedContacts(contacts_contacts.contacts, contacts_contacts.users, 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 ContactsController$.ExternalSyntheticLambda0(this));
if (BuildVars.LOGS_ENABLED) {
FileLog.d("load contacts don't change");
}
}
}
public void lambda$loadGlobalPrivacySetting$60(TLRPC.TL_error tL_error, TLObject tLObject) {
if (tL_error == null) {
this.globalPrivacySettings = (TLRPC.GlobalPrivacySettings) tLObject;
this.loadingGlobalSettings = 2;
} else {
this.loadingGlobalSettings = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadGlobalPrivacySetting$61(TLObject tLObject, TLRPC.TL_error tL_error) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda29(this, tL_error, tLObject));
}
public void lambda$loadPrivacySettings$62(TLRPC.TL_error tL_error, TLObject tLObject) {
if (tL_error == null) {
this.deleteAccountTTL = ((TLRPC.TL_accountDaysTTL) tLObject).days;
this.loadingDeleteInfo = 2;
} else {
this.loadingDeleteInfo = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadPrivacySettings$63(TLObject tLObject, TLRPC.TL_error tL_error) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda62(this, tL_error, tLObject));
}
public void lambda$loadPrivacySettings$64(TLRPC.TL_error tL_error, TLObject tLObject, int i) {
if (tL_error == null) {
TL_account.privacyRules privacyrules = (TL_account.privacyRules) tLObject;
getMessagesController().putUsers(privacyrules.users, false);
getMessagesController().putChats(privacyrules.chats, false);
ArrayList<TLRPC.PrivacyRule> arrayList = privacyrules.rules;
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:
case 10:
default:
this.addedByPhonePrivacyRules = arrayList;
break;
case 8:
this.voiceMessagesRules = arrayList;
break;
case 9:
this.bioPrivacyRules = arrayList;
break;
case 11:
this.birthdayPrivacyRules = arrayList;
break;
case 12:
this.giftsPrivacyRules = arrayList;
break;
case 13:
this.noPaidMessagesPrivacyRules = arrayList;
break;
}
this.loadingPrivacyInfo[i] = 2;
} else {
this.loadingPrivacyInfo[i] = 0;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
}
public void lambda$loadPrivacySettings$65(int i, TLObject tLObject, TLRPC.TL_error tL_error) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda13(this, tL_error, tLObject, 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(java.text.Collator r2, java.lang.Object r3, java.lang.Object r4) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.lambda$mergePhonebookAndTelegramContacts$38(java.text.Collator, java.lang.Object, java.lang.Object):int");
}
public static int lambda$mergePhonebookAndTelegramContacts$39(Collator collator, String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return collator.compare(str, str2);
}
public void lambda$mergePhonebookAndTelegramContacts$40(ArrayList arrayList, HashMap hashMap, HashMap hashMap2) {
this.phoneBookSectionsArray = arrayList;
this.phoneBookByShortPhones = hashMap;
this.phoneBookSectionsDict = hashMap2;
}
public void lambda$mergePhonebookAndTelegramContacts$41(boolean z, ArrayList arrayList, HashMap hashMap, HashMap hashMap2, ArrayList arrayList2) {
if (z) {
int size = arrayList.size();
for (int i = 0; i < size; i++) {
TLRPC$User user = getMessagesController().getUser(Long.valueOf(((TLRPC.TL_contact) arrayList.get(i)).user_id));
if (user != null && !TextUtils.isEmpty(user.phone)) {
Contact contact = (Contact) hashMap.get(user.phone.substring(Math.max(0, r3.length() - 7)));
if (contact == null) {
String letter = Contact.getLetter(user.first_name, user.last_name);
ArrayList arrayList3 = (ArrayList) hashMap2.get(letter);
if (arrayList3 == null) {
arrayList3 = new ArrayList();
hashMap2.put(letter, arrayList3);
arrayList2.add(letter);
}
arrayList3.add(user);
} else if (contact.user == null) {
contact.user = user;
}
}
}
}
Collator localeCollator = getLocaleCollator();
Iterator it = hashMap2.values().iterator();
while (it.hasNext()) {
Collections.sort((ArrayList) it.next(), new ContactsController$.ExternalSyntheticLambda24(localeCollator));
}
Collections.sort(arrayList2, new ContactsController$.ExternalSyntheticLambda25(localeCollator));
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda26(this, arrayList2, hashMap, hashMap2));
}
public void lambda$migratePhoneBookToV7$12(SparseArray sparseArray) {
if (this.migratingContacts) {
return;
}
this.migratingContacts = true;
HashMap 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((String) 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((String) 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(this));
}
} catch (Throwable unused) {
}
}
private void lambda$performSyncPhoneBook$13(HashMap hashMap) {
ArrayList<TLRPC$User> arrayList = new ArrayList<>();
if (hashMap != null && !hashMap.isEmpty()) {
try {
HashMap hashMap2 = new HashMap();
for (int i = 0; i < this.contacts.size(); i++) {
TLRPC$User user = getMessagesController().getUser(Long.valueOf(this.contacts.get(i).user_id));
if (user != null && !TextUtils.isEmpty(user.phone)) {
hashMap2.put(user.phone, user);
}
}
Iterator it = hashMap.entrySet().iterator();
while (it.hasNext()) {
Contact contact = (Contact) ((Map.Entry) it.next()).getValue();
int i2 = 0;
boolean z = false;
while (i2 < contact.shortPhones.size()) {
TLRPC$User tLRPC$User = (TLRPC$User) hashMap2.get((String) contact.shortPhones.get(i2));
if (tLRPC$User != null) {
arrayList.add(tLRPC$User);
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$14(int i, HashMap hashMap, boolean z, boolean z2) {
getNotificationCenter().postNotificationName(NotificationCenter.hasNewContactsToImport, new Object[]{Integer.valueOf(i), hashMap, Boolean.valueOf(z), Boolean.valueOf(z2)});
}
public void lambda$performSyncPhoneBook$15(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$performSyncPhoneBook$23(hashMap, arrayList, hashMap2);
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$performSyncPhoneBook$16(HashMap hashMap, HashMap hashMap2, boolean z, HashMap hashMap3, ArrayList arrayList, 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 ContactsController$.ExternalSyntheticLambda20(this, hashMap3, arrayList, hashMap4));
}
public void lambda$performSyncPhoneBook$17(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$performSyncPhoneBook$23(hashMap, arrayList, hashMap2);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$performSyncPhoneBook$18() {
getMessagesStorage().getCachedPhoneBook(true);
}
public void lambda$performSyncPhoneBook$19(HashMap hashMap, HashMap hashMap2, boolean z, HashMap hashMap3, ArrayList arrayList, 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 ContactsController$.ExternalSyntheticLambda31(this, hashMap3, arrayList, hashMap4));
if (zArr[0]) {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda32(this), 300000L);
}
}
public void lambda$performSyncPhoneBook$20(HashMap hashMap, SparseArray sparseArray, boolean[] zArr, HashMap hashMap2, TLRPC.TL_contacts_importContacts tL_contacts_importContacts, int i, HashMap hashMap3, boolean z, HashMap hashMap4, ArrayList arrayList, HashMap hashMap5, TLObject tLObject, TLRPC.TL_error tL_error) {
this.completedRequestsCount++;
if (tL_error == null) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("contacts imported");
}
TLRPC.TL_contacts_importedContacts tL_contacts_importedContacts = (TLRPC.TL_contacts_importedContacts) tLObject;
if (!tL_contacts_importedContacts.retry_contacts.isEmpty()) {
for (int i2 = 0; i2 < tL_contacts_importedContacts.retry_contacts.size(); i2++) {
hashMap.remove(sparseArray.get((int) ((Long) tL_contacts_importedContacts.retry_contacts.get(i2)).longValue()));
}
zArr[0] = true;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("result has retry contacts");
}
}
for (int i3 = 0; i3 < tL_contacts_importedContacts.popular_invites.size(); i3++) {
TLRPC.TL_popularContact tL_popularContact = (TLRPC.TL_popularContact) tL_contacts_importedContacts.popular_invites.get(i3);
Contact contact = (Contact) hashMap2.get(sparseArray.get((int) tL_popularContact.client_id));
if (contact != null) {
contact.imported = tL_popularContact.importers;
}
}
getMessagesStorage().putUsersAndChats(tL_contacts_importedContacts.users, (List) null, true, true);
ArrayList<TLRPC.TL_contact> arrayList2 = new ArrayList<>();
for (int i4 = 0; i4 < tL_contacts_importedContacts.imported.size(); i4++) {
TLRPC.TL_contact tL_contact = new TLRPC.TL_contact();
tL_contact.user_id = ((TLRPC.TL_importedContact) tL_contacts_importedContacts.imported.get(i4)).user_id;
arrayList2.add(tL_contact);
}
processLoadedContacts(arrayList2, tL_contacts_importedContacts.users, 2);
} else {
for (int i5 = 0; i5 < tL_contacts_importContacts.contacts.size(); i5++) {
hashMap.remove(sparseArray.get((int) ((TLRPC.TL_inputPhoneContact) tL_contacts_importContacts.contacts.get(i5)).client_id));
}
zArr[0] = true;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("import contacts error " + tL_error.text);
}
}
if (this.completedRequestsCount == i) {
if (!hashMap.isEmpty()) {
getMessagesStorage().putCachedPhoneBook(hashMap, false, false);
}
Utilities.stageQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda55(this, hashMap3, hashMap2, z, hashMap4, arrayList, hashMap5, zArr));
}
}
public void lambda$performSyncPhoneBook$21(HashMap hashMap, ArrayList arrayList, HashMap hashMap2) {
lambda$performSyncPhoneBook$23(hashMap, arrayList, hashMap2);
updateUnregisteredContacts();
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
getNotificationCenter().postNotificationName(NotificationCenter.contactsImported, new Object[0]);
}
public void lambda$performSyncPhoneBook$22(HashMap hashMap, HashMap hashMap2, boolean z, HashMap hashMap3, ArrayList arrayList, 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 ContactsController$.ExternalSyntheticLambda30(this, hashMap3, arrayList, hashMap4));
}
public void lambda$performSyncPhoneBook$24(HashMap hashMap, HashMap hashMap2, boolean z, HashMap hashMap3, ArrayList arrayList, 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 ContactsController$.ExternalSyntheticLambda33(this, hashMap3, arrayList, hashMap4));
}
public void lambda$performSyncPhoneBook$25(java.util.HashMap r27, boolean r28, boolean r29, boolean r30, boolean r31, boolean r32, boolean r33) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.lambda$performSyncPhoneBook$25(java.util.HashMap, boolean, boolean, boolean, boolean, boolean, boolean):void");
}
public void lambda$processLoadedContacts$29() {
this.doneLoadingContacts = true;
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
}
public static int lambda$processLoadedContacts$30(LongSparseArray longSparseArray, Collator collator, TLRPC.TL_contact tL_contact, TLRPC.TL_contact tL_contact2) {
return collator.compare(UserObject.getFirstName((TLRPC$User) longSparseArray.get(tL_contact.user_id)), UserObject.getFirstName((TLRPC$User) longSparseArray.get(tL_contact2.user_id)));
}
public static int lambda$processLoadedContacts$31(Collator collator, String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return collator.compare(str, str2);
}
public static int lambda$processLoadedContacts$32(Collator collator, String str, String str2) {
char charAt = str.charAt(0);
char charAt2 = str2.charAt(0);
if (charAt == '#') {
return 1;
}
if (charAt2 == '#') {
return -1;
}
return collator.compare(str, str2);
}
public void lambda$processLoadedContacts$33(ArrayList arrayList, ConcurrentHashMap concurrentHashMap, HashMap hashMap, HashMap hashMap2, ArrayList arrayList2, ArrayList arrayList3, int i, boolean z, boolean z2) {
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(false);
} else {
saveContactsLoadTime();
}
if (z2) {
loadContacts(false, 0L);
}
}
public void lambda$processLoadedContacts$34(HashMap hashMap, HashMap hashMap2) {
this.contactsByPhone = hashMap;
this.contactsByShortPhone = hashMap2;
}
public void lambda$processLoadedContacts$35(HashMap hashMap, HashMap hashMap2) {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda56(this, hashMap, hashMap2));
if (this.contactsSyncInProgress) {
return;
}
this.contactsSyncInProgress = true;
getMessagesStorage().getCachedPhoneBook(false);
}
public void lambda$processLoadedContacts$36(int i, ArrayList arrayList, ArrayList arrayList2, LongSparseArray longSparseArray, boolean z) {
HashMap hashMap;
HashMap hashMap2;
int i2;
int i3;
HashMap hashMap3;
ArrayList arrayList3;
ArrayList arrayList4 = arrayList;
LongSparseArray longSparseArray2 = longSparseArray;
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(arrayList4));
if (arrayList.isEmpty()) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda38(this));
return;
}
}
if (i == 0) {
getUserConfig().lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000);
getUserConfig().saveConfig(false);
}
int i4 = 0;
boolean z2 = false;
while (i4 < arrayList.size()) {
TLRPC.TL_contact tL_contact = arrayList4.get(i4);
if (MessagesController.getInstance(this.currentAccount).getUser(Long.valueOf(tL_contact.user_id)) == null && tL_contact.user_id != getUserConfig().getClientUserId()) {
arrayList4.remove(i4);
i4--;
z2 = true;
}
i4++;
}
if (i != 1) {
getMessagesStorage().putUsersAndChats(arrayList2, (List) null, true, true);
getMessagesStorage().putContacts(arrayList4, i != 2);
}
Collator localeCollator = getLocaleCollator();
Collections.sort(arrayList4, new ContactsController$.ExternalSyntheticLambda39(longSparseArray2, localeCollator));
ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap(20, 1.0f, 2);
HashMap hashMap4 = new HashMap();
HashMap hashMap5 = new HashMap();
ArrayList arrayList5 = new ArrayList();
ArrayList arrayList6 = new ArrayList();
if (this.contactsBookLoaded) {
hashMap = null;
hashMap2 = null;
} else {
hashMap2 = new HashMap();
hashMap = new HashMap();
}
int i5 = 0;
while (i5 < arrayList.size()) {
TLRPC.TL_contact tL_contact2 = arrayList4.get(i5);
TLRPC$User tLRPC$User = (TLRPC$User) longSparseArray2.get(tL_contact2.user_id);
if (tLRPC$User == null) {
hashMap3 = hashMap;
i2 = i5;
arrayList3 = arrayList6;
} else {
i2 = i5;
ArrayList arrayList7 = arrayList6;
concurrentHashMap.put(Long.valueOf(tL_contact2.user_id), tL_contact2);
if (hashMap2 == null || TextUtils.isEmpty(tLRPC$User.phone)) {
i3 = 0;
} else {
hashMap2.put(tLRPC$User.phone, tL_contact2);
i3 = 0;
hashMap.put(tLRPC$User.phone.substring(Math.max(0, r13.length() - 7)), tL_contact2);
}
String firstName = UserObject.getFirstName(tLRPC$User);
hashMap3 = hashMap;
if (firstName.length() > 1) {
firstName = firstName.substring(i3, 1);
}
String upperCase = firstName.length() == 0 ? "#" : firstName.toUpperCase();
String str = this.sectionsToReplace.get(upperCase);
if (str != null) {
upperCase = str;
}
ArrayList arrayList8 = (ArrayList) hashMap4.get(upperCase);
if (arrayList8 == null) {
arrayList8 = new ArrayList();
hashMap4.put(upperCase, arrayList8);
arrayList5.add(upperCase);
}
arrayList8.add(tL_contact2);
if (tLRPC$User.mutual_contact) {
ArrayList arrayList9 = (ArrayList) hashMap5.get(upperCase);
if (arrayList9 == null) {
arrayList9 = new ArrayList();
hashMap5.put(upperCase, arrayList9);
arrayList3 = arrayList7;
arrayList3.add(upperCase);
} else {
arrayList3 = arrayList7;
}
arrayList9.add(tL_contact2);
} else {
arrayList3 = arrayList7;
}
}
int i6 = i2 + 1;
arrayList4 = arrayList;
longSparseArray2 = longSparseArray;
arrayList6 = arrayList3;
hashMap = hashMap3;
i5 = i6;
}
HashMap hashMap6 = hashMap;
ArrayList arrayList10 = arrayList6;
Collections.sort(arrayList5, new ContactsController$.ExternalSyntheticLambda40(localeCollator));
Collections.sort(arrayList10, new ContactsController$.ExternalSyntheticLambda41(localeCollator));
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda42(this, arrayList, concurrentHashMap, hashMap4, hashMap5, arrayList5, arrayList10, i, z, z2));
if (!this.delayedContactsUpdate.isEmpty() && this.contactsLoaded && this.contactsBookLoaded) {
applyContactsUpdates(this.delayedContactsUpdate, null, null, null);
this.delayedContactsUpdate.clear();
}
if (hashMap2 != null) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda43(this, hashMap2, hashMap6));
} else {
this.contactsLoaded = true;
}
}
public void lambda$processLoadedContacts$37(ArrayList arrayList, int i, ArrayList arrayList2) {
getMessagesController().putUsers(arrayList, i == 1);
LongSparseArray longSparseArray = new LongSparseArray();
boolean isEmpty = arrayList2.isEmpty();
if (i == 2 && !this.contacts.isEmpty()) {
int i2 = 0;
while (i2 < arrayList2.size()) {
if (this.contactsDict.get(Long.valueOf(((TLRPC.TL_contact) arrayList2.get(i2)).user_id)) != null) {
arrayList2.remove(i2);
i2--;
}
i2++;
}
arrayList2.addAll(this.contacts);
}
for (int i3 = 0; i3 < arrayList2.size(); i3++) {
TLRPC$User user = getMessagesController().getUser(Long.valueOf(((TLRPC.TL_contact) arrayList2.get(i3)).user_id));
if (user != null) {
longSparseArray.put(user.id, user);
}
}
Utilities.stageQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda52(this, i, arrayList2, arrayList, longSparseArray, isEmpty));
}
public void lambda$readContacts$11() {
if (this.contacts.isEmpty() && !this.contactsLoaded) {
loadContacts(true, 0L);
return;
}
synchronized (this.loadContactsSync) {
this.loadingContacts = false;
}
}
public void lambda$reloadContactsStatuses$58(android.content.SharedPreferences.Editor r7, org.telegram.tgnet.TLObject r8) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.lambda$reloadContactsStatuses$58(android.content.SharedPreferences$Editor, org.telegram.tgnet.TLObject):void");
}
public void lambda$reloadContactsStatuses$59(SharedPreferences.Editor editor, TLObject tLObject, TLRPC.TL_error tL_error) {
if (tLObject instanceof Vector) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda22(this, editor, tLObject));
}
}
public static void lambda$resetImportedContacts$10(TLObject tLObject, TLRPC.TL_error tL_error) {
}
public void lambda$syncPhoneBookByAlert$7(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(Collator collator, 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 collator.compare(str, str2);
}
public void lambda$performSyncPhoneBook$23(HashMap<String, ArrayList<Object>> hashMap, ArrayList<String> arrayList, HashMap<String, Contact> hashMap2) {
mergePhonebookAndTelegramContacts(hashMap, arrayList, hashMap2, true);
}
private void mergePhonebookAndTelegramContacts(HashMap<String, ArrayList<Object>> hashMap, ArrayList<String> arrayList, HashMap<String, Contact> hashMap2, boolean z) {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda46(this, z, new ArrayList(this.contacts), hashMap2, hashMap, arrayList));
}
private void performWriteContactsToPhoneBook() {
Utilities.phoneBookQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda37(this, new ArrayList(this.contacts)));
}
public void lambda$performWriteContactsToPhoneBook$45(java.util.ArrayList<org.telegram.tgnet.TLRPC.TL_contact> r15) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.lambda$performWriteContactsToPhoneBook$45(java.util.ArrayList):void");
}
private void reloadContactsStatuses() {
saveContactsLoadTime();
getMessagesController().clearFullUsers();
SharedPreferences.Editor edit = MessagesController.getMainSettings(this.currentAccount).edit();
edit.putBoolean("needGetStatuses", true).commit();
getConnectionsManager().sendRequest(new TLRPC.TL_contacts_getStatuses(), new ContactsController$.ExternalSyntheticLambda57(this, edit));
}
private void saveContactsLoadTime() {
try {
MessagesController.getMainSettings(this.currentAccount).edit().putLong("lastReloadStatusTime", System.currentTimeMillis()).commit();
} catch (Exception e) {
FileLog.e(e);
}
}
private void updateUnregisteredContacts() {
HashMap hashMap = new HashMap();
int size = this.contacts.size();
for (int i = 0; i < size; i++) {
TLRPC.TL_contact tL_contact = this.contacts.get(i);
TLRPC$User user = getMessagesController().getUser(Long.valueOf(tL_contact.user_id));
if (user != null && !TextUtils.isEmpty(user.phone)) {
hashMap.put(user.phone, tL_contact);
}
}
ArrayList<Contact> arrayList = new ArrayList<>();
Iterator<Map.Entry<String, Contact>> it = this.contactsBook.entrySet().iterator();
while (it.hasNext()) {
Contact value = it.next().getValue();
int i2 = 0;
while (true) {
if (i2 >= value.phones.size()) {
arrayList.add(value);
break;
} else if (!hashMap.containsKey((String) value.shortPhones.get(i2)) && ((Integer) value.phoneDeleted.get(i2)).intValue() != 1) {
i2++;
}
}
}
Collections.sort(arrayList, new ContactsController$.ExternalSyntheticLambda50(getLocaleCollator()));
this.phoneBookContacts = arrayList;
}
public void addContact(TLRPC$User tLRPC$User, boolean z) {
String str;
if (tLRPC$User == null) {
return;
}
TLRPC.TL_contacts_addContact tL_contacts_addContact = new TLRPC.TL_contacts_addContact();
tL_contacts_addContact.id = getMessagesController().getInputUser(tLRPC$User);
tL_contacts_addContact.first_name = tLRPC$User.first_name;
tL_contacts_addContact.last_name = tLRPC$User.last_name;
String str2 = tLRPC$User.phone;
tL_contacts_addContact.phone = str2;
tL_contacts_addContact.add_phone_privacy_exception = z;
if (str2 != null) {
if (str2.length() > 0 && !tL_contacts_addContact.phone.startsWith("+")) {
str = "+" + tL_contacts_addContact.phone;
}
getConnectionsManager().sendRequest(tL_contacts_addContact, new ContactsController$.ExternalSyntheticLambda51(this, tLRPC$User), 6);
}
str = "";
tL_contacts_addContact.phone = str;
getConnectionsManager().sendRequest(tL_contacts_addContact, new ContactsController$.ExternalSyntheticLambda51(this, tLRPC$User), 6);
}
public long addContactToPhoneBook(TLRPC$User tLRPC$User, boolean z) {
Uri uri;
long j = -1;
if (this.systemAccount == null || tLRPC$User == null || !hasContactsWritePermission()) {
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 = " + tLRPC$User.id, null);
} catch (Exception unused) {
}
}
ArrayList<ContentProviderOperation> arrayList = new ArrayList<>();
applyContactToPhoneBook(arrayList, tLRPC$User);
try {
ContentProviderResult[] applyBatch = contentResolver.applyBatch("com.android.contacts", arrayList);
if (applyBatch != null && applyBatch.length > 0 && (uri = applyBatch[0].uri) != null) {
j = Long.parseLong(uri.getLastPathSegment());
}
} catch (Exception e) {
FileLog.e(e);
}
synchronized (this.observerLock) {
this.ignoreChanges = false;
}
return j;
}
public void checkAppAccount() {
this.systemAccount = null;
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda48(this));
}
public void checkContacts() {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda7(this));
}
public void checkInviteText() {
SharedPreferences mainSettings = MessagesController.getMainSettings(this.currentAccount);
this.inviteLink = mainSettings.getString("invitelink", null);
int i = mainSettings.getInt("invitelinktime", 0);
if (this.updatingInviteLink) {
return;
}
if (this.inviteLink == null || Math.abs((System.currentTimeMillis() / 1000) - i) >= 86400) {
this.updatingInviteLink = true;
getConnectionsManager().sendRequest(new TLRPC.TL_help_getInviteText(), new ContactsController$.ExternalSyntheticLambda15(this), 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.phoneBookByShortPhones.clear();
this.loadingContacts = false;
this.contactsSyncInProgress = false;
this.doneLoadingContacts = false;
this.contactsLoaded = false;
this.contactsBookLoaded = false;
this.lastContactsVersions = "";
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.bioPrivacyRules = null;
this.birthdayPrivacyRules = null;
this.giftsPrivacyRules = null;
this.forwardsPrivacyRules = null;
this.phonePrivacyRules = null;
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda53(this));
}
public void createOrUpdateConnectionServiceContact(long j, String str, String str2) {
String str3;
int parseInt;
Cursor cursor;
ArrayList<ContentProviderOperation> arrayList;
ContentProviderOperation.Builder withValue;
if (hasContactsPermission()) {
try {
ContentResolver contentResolver = ApplicationLoader.applicationContext.getContentResolver();
ArrayList<ContentProviderOperation> arrayList2 = new ArrayList<>();
Uri build = ContactsContract.Groups.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").build();
Uri build2 = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").build();
Account account = this.systemAccount;
Cursor query = contentResolver.query(build, 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);
contentValues.put("group_is_read_only", (Integer) 1);
contentValues.put("title", "TelegramConnectionService");
parseInt = Integer.parseInt(contentResolver.insert(build, contentValues).getLastPathSegment());
} else {
parseInt = query.getInt(0);
str3 = "account_type";
}
if (query != null) {
query.close();
}
Uri uri = ContactsContract.Data.CONTENT_URI;
String str4 = str3;
Cursor query2 = contentResolver.query(uri, new String[]{"raw_contact_id"}, "mimetype=? AND data1=?", new String[]{"vnd.android.cursor.item/group_membership", parseInt + ""}, null);
int size = arrayList2.size();
int i = parseInt;
if (query2 == null || !query2.moveToFirst()) {
cursor = query2;
arrayList = arrayList2;
arrayList.add(ContentProviderOperation.newInsert(build2).withValue(str4, this.systemAccount.type).withValue("account_name", this.systemAccount.name).withValue("raw_contact_is_read_only", 1).withValue("aggregation_mode", 3).build());
arrayList.add(ContentProviderOperation.newInsert(uri).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/name").withValue("data2", str).withValue("data3", str2).build());
arrayList.add(ContentProviderOperation.newInsert(uri).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/phone_v2").withValue("data1", "+99084" + j).build());
withValue = ContentProviderOperation.newInsert(uri).withValueBackReference("raw_contact_id", size).withValue("mimetype", "vnd.android.cursor.item/group_membership").withValue("data1", Integer.valueOf(i));
} else {
int i2 = query2.getInt(0);
cursor = query2;
arrayList = arrayList2;
arrayList.add(ContentProviderOperation.newUpdate(build2).withSelection("_id=?", new String[]{i2 + ""}).withValue("deleted", 0).build());
arrayList.add(ContentProviderOperation.newUpdate(uri).withSelection("raw_contact_id=? AND mimetype=?", new String[]{i2 + "", "vnd.android.cursor.item/phone_v2"}).withValue("data1", "+99084" + j).build());
withValue = ContentProviderOperation.newUpdate(uri).withSelection("raw_contact_id=? AND mimetype=?", new String[]{i2 + "", "vnd.android.cursor.item/name"}).withValue("data2", str).withValue("data3", str2);
}
arrayList.add(withValue.build());
if (cursor != null) {
cursor.close();
}
contentResolver.applyBatch("com.android.contacts", arrayList);
} catch (Exception e) {
FileLog.e(e);
}
}
}
public void deleteAllContacts(Runnable runnable) {
resetImportedContacts();
TLRPC.TL_contacts_deleteContacts tL_contacts_deleteContacts = new TLRPC.TL_contacts_deleteContacts();
int size = this.contacts.size();
for (int i = 0; i < size; i++) {
tL_contacts_deleteContacts.id.add(getMessagesController().getInputUser(this.contacts.get(i).user_id));
}
getConnectionsManager().sendRequest(tL_contacts_deleteContacts, new ContactsController$.ExternalSyntheticLambda6(this, runnable));
}
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 + ""}, null);
if (query2 == null || !query2.moveToFirst()) {
if (query2 != null) {
query2.close();
return;
}
return;
}
int i2 = query2.getInt(0);
query2.close();
contentResolver.delete(ContactsContract.RawContacts.CONTENT_URI, "_id=?", new String[]{i2 + ""});
} catch (Exception e) {
FileLog.e(e);
}
}
}
public void deleteContact(ArrayList<TLRPC$User> arrayList, boolean z) {
if (arrayList == null || arrayList.isEmpty()) {
return;
}
TLRPC.TL_contacts_deleteContacts tL_contacts_deleteContacts = new TLRPC.TL_contacts_deleteContacts();
ArrayList arrayList2 = new ArrayList();
int size = arrayList.size();
for (int i = 0; i < size; i++) {
TLRPC$User tLRPC$User = arrayList.get(i);
getMessagesController().getStoriesController().removeContact(tLRPC$User.id);
TLRPC.InputUser inputUser = getMessagesController().getInputUser(tLRPC$User);
if (inputUser != null) {
tLRPC$User.contact = false;
arrayList2.add(Long.valueOf(tLRPC$User.id));
tL_contacts_deleteContacts.id.add(inputUser);
}
}
getConnectionsManager().sendRequest(tL_contacts_deleteContacts, new ContactsController$.ExternalSyntheticLambda34(this, arrayList2, arrayList, z, arrayList.get(0).first_name));
}
public void deleteContactsUndoable(Context context, BaseFragment baseFragment, ArrayList<TLRPC$User> arrayList) {
if (arrayList == null || arrayList.isEmpty()) {
return;
}
HashMap hashMap = new HashMap();
int size = arrayList.size();
for (int i = 0; i < size; i++) {
TLRPC$User tLRPC$User = arrayList.get(i);
TLRPC.TL_contact tL_contact = (TLRPC.TL_contact) this.contactsDict.get(Long.valueOf(tLRPC$User.id));
tLRPC$User.contact = false;
this.contacts.remove(tL_contact);
this.contactsDict.remove(Long.valueOf(tLRPC$User.id));
hashMap.put(tLRPC$User, tL_contact);
}
buildContactsSectionsArrays(false);
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, new Object[]{Integer.valueOf(MessagesController.UPDATE_MASK_NAME)});
getNotificationCenter().postNotificationName(NotificationCenter.contactsDidLoad, new Object[0]);
Bulletin.SimpleLayout simpleLayout = new Bulletin.SimpleLayout(context, baseFragment.getResourceProvider());
simpleLayout.setTimer();
simpleLayout.textView.setText(LocaleController.formatPluralString("ContactsDeletedUndo", hashMap.size(), new Object[0]));
Bulletin.UndoButton undoButton = new Bulletin.UndoButton(context, true, true, baseFragment.getResourceProvider());
undoButton.setUndoAction(new ContactsController$.ExternalSyntheticLambda63(this, hashMap));
undoButton.setDelayedAction(new ContactsController$.ExternalSyntheticLambda64(this, arrayList));
simpleLayout.setButton(undoButton);
Bulletin.make(baseFragment, simpleLayout, 5000).show();
}
public void deleteUnknownAppAccounts() {
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 < 4) {
TLRPC$User currentUser = UserConfig.getInstance(i2).getCurrentUser();
if (currentUser != null) {
if (account.name.equals("" + currentUser.id)) {
break;
}
}
i2++;
} else {
try {
accountManager.removeAccount(accountsByType[i], null, null);
break;
} catch (Exception unused) {
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void forceImportContacts() {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda5(this));
}
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 TLRPC.GlobalPrivacySettings getGlobalPrivacySettings() {
return this.globalPrivacySettings;
}
public String getInviteText(int i) {
String str = this.inviteLink;
if (str == null) {
str = "https://telegram.org/dl";
}
if (i <= 1) {
return LocaleController.formatString("InviteText2", R.string.InviteText2, str);
}
try {
return String.format(LocaleController.getPluralString("InviteTextNum", i), Integer.valueOf(i), str);
} catch (Exception unused) {
return LocaleController.formatString("InviteText2", R.string.InviteText2, str);
}
}
public boolean getLoadingDeleteInfo() {
return this.loadingDeleteInfo != 2;
}
public boolean getLoadingGlobalSettings() {
return this.loadingGlobalSettings != 2;
}
public boolean getLoadingPrivacyInfo(int i) {
return this.loadingPrivacyInfo[i] != 2;
}
public ArrayList<TLRPC.PrivacyRule> getPrivacyRules(int i) {
switch (i) {
case 0:
return this.lastseenPrivacyRules;
case 1:
return this.groupPrivacyRules;
case 2:
return this.callPrivacyRules;
case 3:
return this.p2pPrivacyRules;
case 4:
return this.profilePhotoPrivacyRules;
case 5:
return this.forwardsPrivacyRules;
case 6:
return this.phonePrivacyRules;
case 7:
return this.addedByPhonePrivacyRules;
case 8:
return this.voiceMessagesRules;
case 9:
return this.bioPrivacyRules;
case 10:
default:
return null;
case 11:
return this.birthdayPrivacyRules;
case 12:
return this.giftsPrivacyRules;
case 13:
return this.noPaidMessagesPrivacyRules;
}
}
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, 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");
}
TLRPC.TL_contacts_getContacts tL_contacts_getContacts = new TLRPC.TL_contacts_getContacts();
tL_contacts_getContacts.hash = j;
getConnectionsManager().sendRequest(tL_contacts_getContacts, new ContactsController$.ExternalSyntheticLambda21(this, j));
}
}
public void loadGlobalPrivacySetting() {
if (this.loadingGlobalSettings == 0) {
this.loadingGlobalSettings = 1;
getConnectionsManager().sendRequest(new TL_account.getGlobalPrivacySettings(), new ContactsController$.ExternalSyntheticLambda27(this));
}
}
public void loadPrivacySettings() {
loadPrivacySettings(false);
}
public void loadPrivacySettings(boolean r7) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.loadPrivacySettings(boolean):void");
}
protected void markAsContacted(String str) {
if (str == null) {
return;
}
Utilities.phoneBookQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda60(str));
}
protected void migratePhoneBookToV7(SparseArray<Contact> sparseArray) {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda47(this, sparseArray));
}
protected void performSyncPhoneBook(HashMap<String, Contact> hashMap, boolean z, boolean z2, boolean z3, boolean z4, boolean z5, boolean z6) {
if (z2 || this.contactsBookLoaded) {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda14(this, hashMap, z3, z, z2, z4, z5, z6));
}
}
public void processContactsUpdates(ArrayList<Long> arrayList, ConcurrentHashMap<Long, TLRPC$User> concurrentHashMap) {
int indexOf;
ArrayList<TLRPC.TL_contact> arrayList2 = new ArrayList<>();
ArrayList<Long> arrayList3 = new ArrayList<>();
Iterator<Long> it = arrayList.iterator();
while (it.hasNext()) {
Long next = it.next();
if (next.longValue() > 0) {
TLRPC.TL_contact tL_contact = new TLRPC.TL_contact();
tL_contact.user_id = next.longValue();
arrayList2.add(tL_contact);
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(ArrayList<TLRPC.TL_contact> arrayList, ArrayList<TLRPC$User> arrayList2, int i) {
AndroidUtilities.runOnUIThread(new ContactsController$.ExternalSyntheticLambda44(this, arrayList2, i, arrayList));
}
public void readContacts() {
synchronized (this.loadContactsSync) {
try {
if (this.loadingContacts) {
return;
}
this.loadingContacts = true;
Utilities.stageQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda61(this));
} catch (Throwable th) {
throw th;
}
}
}
public java.util.HashMap<java.lang.String, org.telegram.messenger.ContactsController.Contact> readContactsFromPhoneBook() {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.ContactsController.readContactsFromPhoneBook():java.util.HashMap");
}
public void reloadContactsStatusesMaybe(boolean z) {
try {
if (MessagesController.getMainSettings(this.currentAccount).getLong("lastReloadStatusTime", 0L) < System.currentTimeMillis() - 10800000 || z) {
reloadContactsStatuses();
}
} catch (Exception e) {
FileLog.e(e);
}
}
public void resetImportedContacts() {
getConnectionsManager().sendRequest(new TLRPC.TL_contacts_resetSaved(), new ContactsController$.ExternalSyntheticLambda45());
}
public void setDeleteAccountTTL(int i) {
this.deleteAccountTTL = i;
}
public void setPrivacyRules(ArrayList<TLRPC.PrivacyRule> arrayList, int i) {
switch (i) {
case 0:
this.lastseenPrivacyRules = arrayList;
break;
case 1:
this.groupPrivacyRules = arrayList;
break;
case 2:
this.callPrivacyRules = arrayList;
break;
case 3:
this.p2pPrivacyRules = arrayList;
break;
case 4:
this.profilePhotoPrivacyRules = arrayList;
break;
case 5:
this.forwardsPrivacyRules = arrayList;
break;
case 6:
this.phonePrivacyRules = arrayList;
break;
case 7:
this.addedByPhonePrivacyRules = arrayList;
break;
case 8:
this.voiceMessagesRules = arrayList;
break;
case 9:
this.bioPrivacyRules = arrayList;
break;
case 11:
this.birthdayPrivacyRules = arrayList;
break;
case 12:
this.giftsPrivacyRules = arrayList;
break;
case 13:
this.noPaidMessagesPrivacyRules = arrayList;
break;
}
getNotificationCenter().postNotificationName(NotificationCenter.privacyRulesUpdated, new Object[0]);
reloadContactsStatuses();
}
public void syncPhoneBookByAlert(HashMap<String, Contact> hashMap, boolean z, boolean z2, boolean z3) {
Utilities.globalQueue.postRunnable(new ContactsController$.ExternalSyntheticLambda28(this, hashMap, z, z2, z3));
}
}