From 2136c934b006e8f6c8144f9f9dd91f0e9475b4a8 Mon Sep 17 00:00:00 2001 From: qwq233 Date: Sun, 10 Nov 2024 00:56:02 +0800 Subject: [PATCH] feat: optimise hide proxy ad Signed-off-by: qwq233 --- .../messenger/MessagesController.java | 516 +++++++++--------- 1 file changed, 263 insertions(+), 253 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 5d08a6564..6f042fd7b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -171,9 +171,9 @@ public class MessagesController extends BaseController implements NotificationCe public LongSparseArray> printingStringsTypes = new LongSparseArray<>(); public LongSparseArray>[] sendingTypings = new LongSparseArray[12]; public ConcurrentHashMap onlinePrivacy = new ConcurrentHashMap<>(20, 1.0f, 2); - private final LongSparseIntArray pendingUnreadCounter = new LongSparseIntArray(); + private LongSparseIntArray pendingUnreadCounter = new LongSparseIntArray(); private int lastPrintingStringCount; - private final SparseArray chatlistFoldersUpdates = new SparseArray<>(); + private SparseArray chatlistFoldersUpdates = new SparseArray<>(); public int largeQueueMaxActiveOperations = 2; public int smallQueueMaxActiveOperations = 5; public int stealthModeFuture; @@ -236,29 +236,29 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { private boolean dialogsInTransaction; - private final LongSparseArray loadingPeerSettings = new LongSparseArray<>(); + private LongSparseArray loadingPeerSettings = new LongSparseArray<>(); - private final ArrayList createdDialogIds = new ArrayList<>(); - private final ArrayList createdScheduledDialogIds = new ArrayList<>(); - private final ArrayList createdDialogMainThreadIds = new ArrayList<>(); - private final ArrayList visibleDialogMainThreadIds = new ArrayList<>(); - private final ArrayList visibleScheduledDialogMainThreadIds = new ArrayList<>(); + private ArrayList createdDialogIds = new ArrayList<>(); + private ArrayList createdScheduledDialogIds = new ArrayList<>(); + private ArrayList createdDialogMainThreadIds = new ArrayList<>(); + private ArrayList visibleDialogMainThreadIds = new ArrayList<>(); + private ArrayList visibleScheduledDialogMainThreadIds = new ArrayList<>(); - private final LongSparseIntArray shortPollChannels = new LongSparseIntArray(); - private final LongSparseArray> needShortPollChannels = new LongSparseArray<>(); - private final LongSparseIntArray shortPollOnlines = new LongSparseIntArray(); - private final LongSparseArray> needShortPollOnlines = new LongSparseArray<>(); + private LongSparseIntArray shortPollChannels = new LongSparseIntArray(); + private LongSparseArray> needShortPollChannels = new LongSparseArray<>(); + private LongSparseIntArray shortPollOnlines = new LongSparseIntArray(); + private LongSparseArray> needShortPollOnlines = new LongSparseArray<>(); - private final LongSparseArray deletingDialogs = new LongSparseArray<>(); - private final LongSparseArray clearingHistoryDialogs = new LongSparseArray<>(); + private LongSparseArray deletingDialogs = new LongSparseArray<>(); + private LongSparseArray clearingHistoryDialogs = new LongSparseArray<>(); public boolean loadingBlockedPeers = false; public LongSparseIntArray blockePeers = new LongSparseIntArray(); public int totalBlockedCount = -1; public boolean blockedEndReached; - private final LongSparseArray> channelViewsToSend = new LongSparseArray<>(); - private final LongSparseArray> pollsToCheck = new LongSparseArray<>(); + private LongSparseArray> channelViewsToSend = new LongSparseArray<>(); + private LongSparseArray> pollsToCheck = new LongSparseArray<>(); private int pollsToCheckSize; private long lastViewsCheckTime; public SparseIntArray premiumFeaturesTypesToPosition = new SparseIntArray(); @@ -279,34 +279,34 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { private LongSparseArray gettingDifferenceChannels = new LongSparseArray<>(); private LongSparseArray gettingChatInviters = new LongSparseArray<>(); - private final LongSparseArray gettingUnknownChannels = new LongSparseArray<>(); - private final LongSparseArray gettingUnknownDialogs = new LongSparseArray<>(); - private final LongSparseArray checkingLastMessagesDialogs = new LongSparseArray<>(); + private LongSparseArray gettingUnknownChannels = new LongSparseArray<>(); + private LongSparseArray gettingUnknownDialogs = new LongSparseArray<>(); + private LongSparseArray checkingLastMessagesDialogs = new LongSparseArray<>(); - private final ArrayList updatesQueueSeq = new ArrayList<>(); - private final ArrayList updatesQueuePts = new ArrayList<>(); - private final ArrayList updatesQueueQts = new ArrayList<>(); + private ArrayList updatesQueueSeq = new ArrayList<>(); + private ArrayList updatesQueuePts = new ArrayList<>(); + private ArrayList updatesQueueQts = new ArrayList<>(); private long updatesStartWaitTimeSeq; private long updatesStartWaitTimePts; private long updatesStartWaitTimeQts; - private final LongSparseArray fullUsers = new LongSparseArray<>(); - private final LongSparseArray fullChats = new LongSparseArray<>(); - private final LongSparseArray groupCalls = new LongSparseArray<>(); - private final LongSparseArray groupCallsByChatId = new LongSparseArray<>(); - private final HashSet loadingFullUsers = new HashSet<>(); - private final LongSparseLongArray loadedFullUsers = new LongSparseLongArray(); - private final HashSet loadingFullChats = new HashSet<>(); - private final HashSet loadingGroupCalls = new HashSet<>(); - private final HashSet loadingFullParticipants = new HashSet<>(); - private final HashSet loadedFullParticipants = new HashSet<>(); + private LongSparseArray fullUsers = new LongSparseArray<>(); + private LongSparseArray fullChats = new LongSparseArray<>(); + private LongSparseArray groupCalls = new LongSparseArray<>(); + private LongSparseArray groupCallsByChatId = new LongSparseArray<>(); + private HashSet loadingFullUsers = new HashSet<>(); + private LongSparseLongArray loadedFullUsers = new LongSparseLongArray(); + private HashSet loadingFullChats = new HashSet<>(); + private HashSet loadingGroupCalls = new HashSet<>(); + private HashSet loadingFullParticipants = new HashSet<>(); + private HashSet loadedFullParticipants = new HashSet<>(); public LongSparseLongArray loadedFullChats = new LongSparseLongArray(); - private final LongSparseArray> channelAdmins = new LongSparseArray<>(); - private final LongSparseIntArray loadingChannelAdmins = new LongSparseIntArray(); + private LongSparseArray> channelAdmins = new LongSparseArray<>(); + private LongSparseIntArray loadingChannelAdmins = new LongSparseIntArray(); - private final SparseIntArray migratedChats = new SparseIntArray(); + private SparseIntArray migratedChats = new SparseIntArray(); - private final LongSparseArray sponsoredMessages = new LongSparseArray<>(); - private final LongSparseArray sendAsPeers = new LongSparseArray<>(); + private LongSparseArray sponsoredMessages = new LongSparseArray<>(); + private LongSparseArray sendAsPeers = new LongSparseArray<>(); private HashMap> reloadingWebpages = new HashMap<>(); private LongSparseArray> reloadingWebpagesPending = new LongSparseArray<>(); @@ -320,12 +320,12 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { private LongSparseArray lastSavedServerQueryTime = new LongSparseArray<>(); private LongSparseArray lastServerQueryTime = new LongSparseArray<>(); - private final LongSparseArray> reloadingMessages = new LongSparseArray<>(); + private LongSparseArray> reloadingMessages = new LongSparseArray<>(); - private final ArrayList readTasks = new ArrayList<>(); - private final LongSparseArray readTasksMap = new LongSparseArray<>(); - private final ArrayList repliesReadTasks = new ArrayList<>(); - private final HashMap threadsReadTasksMap = new HashMap<>(); + private ArrayList readTasks = new ArrayList<>(); + private LongSparseArray readTasksMap = new LongSparseArray<>(); + private ArrayList repliesReadTasks = new ArrayList<>(); + private HashMap threadsReadTasksMap = new HashMap<>(); private boolean gettingNewDeleteTask; private int currentDeletingTaskTime; @@ -334,10 +334,10 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { private Runnable currentDeleteTaskRunnable; public boolean dialogsLoaded; - private final SparseIntArray nextDialogsCacheOffset = new SparseIntArray(); - private final SparseBooleanArray loadingDialogs = new SparseBooleanArray(); - private final SparseBooleanArray dialogsEndReached = new SparseBooleanArray(); - private final SparseBooleanArray serverDialogsEndReached = new SparseBooleanArray(); + private SparseIntArray nextDialogsCacheOffset = new SparseIntArray(); + private SparseBooleanArray loadingDialogs = new SparseBooleanArray(); + private SparseBooleanArray dialogsEndReached = new SparseBooleanArray(); + private SparseBooleanArray serverDialogsEndReached = new SparseBooleanArray(); private boolean loadingUnreadDialogs; private boolean migratingDialogs; @@ -350,7 +350,7 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { private boolean resetingDialogs; private TLRPC.TL_messages_peerDialogs resetDialogsPinned; private TLRPC.messages_Dialogs resetDialogsAll; - private final SparseIntArray loadingPinnedDialogs = new SparseIntArray(); + private SparseIntArray loadingPinnedDialogs = new SparseIntArray(); public ArrayList faqSearchArray = new ArrayList<>(); public TLRPC.WebPage faqWebPage; @@ -377,10 +377,10 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { public boolean suggestContacts = true; private volatile static long lastThemeCheckTime; - private final Runnable themeCheckRunnable = Theme::checkAutoNightThemeConditions; + private Runnable themeCheckRunnable = Theme::checkAutoNightThemeConditions; private volatile static long lastPasswordCheckTime; - private final Runnable passwordCheckRunnable = () -> getUserConfig().checkSavedPassword(); + private Runnable passwordCheckRunnable = () -> getUserConfig().checkSavedPassword(); private long lastStatusUpdateTime; private int statusRequest; @@ -388,7 +388,7 @@ public ChatlistUpdatesStat(TL_chatlists.TL_chatlists_chatlistUpdates value) { private boolean offlineSent; private String uploadingAvatar; - private final HashMap uploadingThemes = new HashMap<>(); + private HashMap uploadingThemes = new HashMap<>(); public String uploadingWallpaper; public Theme.OverrideWallpaperInfo uploadingWallpaperInfo; @@ -694,10 +694,10 @@ public boolean premiumPurchaseBlocked() { private long recentEmojiStatusUpdateRunnableTimeout, recentEmojiStatusUpdateRunnableTime; private Runnable recentEmojiStatusUpdateRunnable; - private final LongSparseArray emojiStatusUntilValues = new LongSparseArray<>(); - private final TopicsController topicsController; - private final CacheByChatsController cacheByChatsController; - private final TranslateController translateController; + private LongSparseArray emojiStatusUntilValues = new LongSparseArray<>(); + private TopicsController topicsController; + private CacheByChatsController cacheByChatsController; + private TranslateController translateController; public boolean uploadMarkupVideo; public boolean giftAttachMenuIcon; public boolean giftTextFieldIcon; @@ -1197,21 +1197,31 @@ public boolean includesDialog(AccountInstance accountInstance, long dialogId, TL if (user != null) { if (!user.bot) { if (user.self || user.contact || contactsController.isContact(dialogId)) { - return (flags & DIALOG_FILTER_FLAG_CONTACTS) != 0; + if ((flags & DIALOG_FILTER_FLAG_CONTACTS) != 0) { + return true; + } } else { - return (flags & DIALOG_FILTER_FLAG_NON_CONTACTS) != 0; + if ((flags & DIALOG_FILTER_FLAG_NON_CONTACTS) != 0) { + return true; + } } } else { - return (flags & DIALOG_FILTER_FLAG_BOTS) != 0; + if ((flags & DIALOG_FILTER_FLAG_BOTS) != 0) { + return true; + } } } } else if (dialogId < 0) { TLRPC.Chat chat = messagesController.getChat(-dialogId); if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { - return (flags & DIALOG_FILTER_FLAG_CHANNELS) != 0; + if ((flags & DIALOG_FILTER_FLAG_CHANNELS) != 0) { + return true; + } } else { - return (flags & DIALOG_FILTER_FLAG_GROUPS) != 0; + if ((flags & DIALOG_FILTER_FLAG_GROUPS) != 0) { + return true; + } } } } @@ -1287,7 +1297,7 @@ public void sortDialogsList(ArrayList dialogs) { Collections.sort(dialogs, dialogComparator); } - private final Comparator dialogComparator = (dialog1, dialog2) -> { + private Comparator dialogComparator = (dialog1, dialog2) -> { if (dialog1 instanceof TLRPC.TL_dialogFolder && !(dialog2 instanceof TLRPC.TL_dialogFolder)) { return -1; } else if (!(dialog1 instanceof TLRPC.TL_dialogFolder) && dialog2 instanceof TLRPC.TL_dialogFolder) { @@ -1316,7 +1326,7 @@ public void sortDialogsList(ArrayList dialogs) { return 0; }; - private final Comparator updatesComparator = (lhs, rhs) -> { + private Comparator updatesComparator = (lhs, rhs) -> { int ltype = getUpdateType(lhs); int rtype = getUpdateType(rhs); if (ltype != rtype) { @@ -1337,7 +1347,7 @@ public void sortDialogsList(ArrayList dialogs) { return 0; }; - private static final MessagesController[] Instance = new MessagesController[UserConfig.MAX_ACCOUNT_COUNT]; + private static volatile MessagesController[] Instance = new MessagesController[UserConfig.MAX_ACCOUNT_COUNT]; private static final Object[] lockObjects = new Object[UserConfig.MAX_ACCOUNT_COUNT]; static { for (int i = 0; i < UserConfig.MAX_ACCOUNT_COUNT; i++) { @@ -6149,7 +6159,9 @@ public boolean putUser(TLRPC.User user, boolean fromCache, boolean force) { getUserConfig().saveConfig(true); } getUserNameResolver().update(oldUser, user); - return oldUser != null && user.status != null && oldUser.status != null && user.status.expires != oldUser.status.expires; + if (oldUser != null && user.status != null && oldUser.status != null && user.status.expires != oldUser.status.expires) { + return true; + } } else if (oldUser == null) { users.put(user.id, user); } else if (oldUser.min) { @@ -9428,7 +9440,7 @@ public void updateTimerProc() { } } if (minExpireTime < 5) { - lastViewsCheckTime = Math.min(lastViewsCheckTime, System.currentTimeMillis() - (5 - minExpireTime) * 1000L); + lastViewsCheckTime = Math.min(lastViewsCheckTime, System.currentTimeMillis() - (5 - minExpireTime) * 1000); } if (array.size() == 0) { pollsToCheck.remove(pollsToCheck.keyAt(a)); @@ -9612,220 +9624,217 @@ private void checkPromoInfoInternal(boolean reset) { return; } boolean noDialog = false; - if (response instanceof TLRPC.TL_help_promoDataEmpty) { + if (Config.hideProxySponsorChannel) { + nextPromoInfoCheckTime = getConnectionsManager().getCurrentTime() + 60 * 60; + noDialog = true; + } else if (response instanceof TLRPC.TL_help_promoDataEmpty) { TLRPC.TL_help_promoDataEmpty res = (TLRPC.TL_help_promoDataEmpty) response; nextPromoInfoCheckTime = res.expires; noDialog = true; } else if (response instanceof TLRPC.TL_help_promoData) { TLRPC.TL_help_promoData res = (TLRPC.TL_help_promoData) response; - SharedConfig.ProxyInfo proxy = SharedConfig.currentProxy; - if (res.proxy && (Config.hideProxySponsorChannel || (proxy != null && proxy.subId == 1L))) { - nextPromoInfoCheckTime = getConnectionsManager().getCurrentTime() + 60 * 60; - noDialog = true; - } else { - long did; - if (res.peer.user_id != 0) { - did = res.peer.user_id; - } else if (res.peer.chat_id != 0) { - did = -res.peer.chat_id; - for (int a = 0; a < res.chats.size(); a++) { - TLRPC.Chat chat = res.chats.get(a); - if (chat.id == res.peer.chat_id) { - if (chat.kicked || chat.restricted) { - noDialog = true; - } - break; + long did; + if (res.peer.user_id != 0) { + did = res.peer.user_id; + } else if (res.peer.chat_id != 0) { + did = -res.peer.chat_id; + for (int a = 0; a < res.chats.size(); a++) { + TLRPC.Chat chat = res.chats.get(a); + if (chat.id == res.peer.chat_id) { + if (chat.kicked || chat.restricted) { + noDialog = true; } + break; } - } else { - did = -res.peer.channel_id; - for (int a = 0; a < res.chats.size(); a++) { - TLRPC.Chat chat = res.chats.get(a); - if (chat.id == res.peer.channel_id) { - if (chat.kicked || chat.restricted) { - noDialog = true; - } - break; + } + } else { + did = -res.peer.channel_id; + for (int a = 0; a < res.chats.size(); a++) { + TLRPC.Chat chat = res.chats.get(a); + if (chat.id == res.peer.channel_id) { + if (chat.kicked || chat.restricted) { + noDialog = true; } + break; } } - promoDialogId = did; - if (res.proxy) { - promoDialogType = PROMO_TYPE_PROXY; - } else if (!TextUtils.isEmpty(res.psa_type)) { - promoDialogType = PROMO_TYPE_PSA; - promoPsaType = res.psa_type; - } else { - promoDialogType = PROMO_TYPE_OTHER; - } - proxyDialogAddress = proxyAddress + proxySecret; - promoPsaMessage = res.psa_message; - nextPromoInfoCheckTime = res.expires; - SharedPreferences.Editor editor = getGlobalMainSettings().edit(); - editor.putLong("proxy_dialog", promoDialogId); - editor.putString("proxyDialogAddress", proxyDialogAddress); - editor.putInt("promo_dialog_type", promoDialogType); - if (promoPsaMessage != null) { - editor.putString("promo_psa_message", promoPsaMessage); - } else { - editor.remove("promo_psa_message"); - } - if (promoPsaType != null) { - editor.putString("promo_psa_type", promoPsaType); - } else { - editor.remove("promo_psa_type"); - } - editor.putInt("nextPromoInfoCheckTime", nextPromoInfoCheckTime); - editor.commit(); + } + promoDialogId = did; + if (res.proxy) { + promoDialogType = PROMO_TYPE_PROXY; + } else if (!TextUtils.isEmpty(res.psa_type)) { + promoDialogType = PROMO_TYPE_PSA; + promoPsaType = res.psa_type; + } else { + promoDialogType = PROMO_TYPE_OTHER; + } + proxyDialogAddress = proxyAddress + proxySecret; + promoPsaMessage = res.psa_message; + nextPromoInfoCheckTime = res.expires; + SharedPreferences.Editor editor = getGlobalMainSettings().edit(); + editor.putLong("proxy_dialog", promoDialogId); + editor.putString("proxyDialogAddress", proxyDialogAddress); + editor.putInt("promo_dialog_type", promoDialogType); + if (promoPsaMessage != null) { + editor.putString("promo_psa_message", promoPsaMessage); + } else { + editor.remove("promo_psa_message"); + } + if (promoPsaType != null) { + editor.putString("promo_psa_type", promoPsaType); + } else { + editor.remove("promo_psa_type"); + } + editor.putInt("nextPromoInfoCheckTime", nextPromoInfoCheckTime); + editor.commit(); - if (!noDialog) { - AndroidUtilities.runOnUIThread(() -> { - if (promoDialog != null && did != promoDialog.id) { - removePromoDialog(); + if (!noDialog) { + AndroidUtilities.runOnUIThread(() -> { + if (promoDialog != null && did != promoDialog.id) { + removePromoDialog(); + } + promoDialog = dialogs_dict.get(did); + + if (promoDialog != null) { + checkingPromoInfo = false; + sortDialogs(null); + getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true); + } else { + LongSparseArray usersDict = new LongSparseArray<>(); + LongSparseArray chatsDict = new LongSparseArray<>(); + for (int a = 0; a < res.users.size(); a++) { + TLRPC.User u = res.users.get(a); + usersDict.put(u.id, u); + } + for (int a = 0; a < res.chats.size(); a++) { + TLRPC.Chat c = res.chats.get(a); + chatsDict.put(c.id, c); } - promoDialog = dialogs_dict.get(did); - if (promoDialog != null) { - checkingPromoInfo = false; - sortDialogs(null); - getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true); - } else { - LongSparseArray usersDict = new LongSparseArray<>(); - LongSparseArray chatsDict = new LongSparseArray<>(); - for (int a = 0; a < res.users.size(); a++) { - TLRPC.User u = res.users.get(a); - usersDict.put(u.id, u); + TLRPC.TL_messages_getPeerDialogs req1 = new TLRPC.TL_messages_getPeerDialogs(); + TLRPC.TL_inputDialogPeer peer = new TLRPC.TL_inputDialogPeer(); + if (res.peer.user_id != 0) { + peer.peer = new TLRPC.TL_inputPeerUser(); + peer.peer.user_id = res.peer.user_id; + TLRPC.User user = usersDict.get(res.peer.user_id); + if (user != null) { + peer.peer.access_hash = user.access_hash; } - for (int a = 0; a < res.chats.size(); a++) { - TLRPC.Chat c = res.chats.get(a); - chatsDict.put(c.id, c); + } else if (res.peer.chat_id != 0) { + peer.peer = new TLRPC.TL_inputPeerChat(); + peer.peer.chat_id = res.peer.chat_id; + TLRPC.Chat chat = chatsDict.get(res.peer.chat_id); + if (chat != null) { + peer.peer.access_hash = chat.access_hash; } - - TLRPC.TL_messages_getPeerDialogs req1 = new TLRPC.TL_messages_getPeerDialogs(); - TLRPC.TL_inputDialogPeer peer = new TLRPC.TL_inputDialogPeer(); - if (res.peer.user_id != 0) { - peer.peer = new TLRPC.TL_inputPeerUser(); - peer.peer.user_id = res.peer.user_id; - TLRPC.User user = usersDict.get(res.peer.user_id); - if (user != null) { - peer.peer.access_hash = user.access_hash; - } - } else if (res.peer.chat_id != 0) { - peer.peer = new TLRPC.TL_inputPeerChat(); - peer.peer.chat_id = res.peer.chat_id; - TLRPC.Chat chat = chatsDict.get(res.peer.chat_id); - if (chat != null) { - peer.peer.access_hash = chat.access_hash; - } - } else { - peer.peer = new TLRPC.TL_inputPeerChannel(); - peer.peer.channel_id = res.peer.channel_id; - TLRPC.Chat chat = chatsDict.get(res.peer.channel_id); - if (chat != null) { - peer.peer.access_hash = chat.access_hash; - } + } else { + peer.peer = new TLRPC.TL_inputPeerChannel(); + peer.peer.channel_id = res.peer.channel_id; + TLRPC.Chat chat = chatsDict.get(res.peer.channel_id); + if (chat != null) { + peer.peer.access_hash = chat.access_hash; } + } - req1.peers.add(peer); - checkingPromoInfoRequestId = getConnectionsManager().sendRequest(req1, (response1, error1) -> { - if (checkPromoId != lastCheckPromoId) { - return; - } - checkingPromoInfoRequestId = 0; - TLRPC.TL_messages_peerDialogs res2 = (TLRPC.TL_messages_peerDialogs) response1; - if (res2 != null && !res2.dialogs.isEmpty()) { - getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true); - TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs(); - dialogs.chats = res2.chats; - dialogs.users = res2.users; - dialogs.dialogs = res2.dialogs; - dialogs.messages = res2.messages; - getMessagesStorage().putDialogs(dialogs, 2); - AndroidUtilities.runOnUIThread(() -> { - putUsers(res.users, false); - putChats(res.chats, false); - putUsers(res2.users, false); - putChats(res2.chats, false); - - if (promoDialog != null) { - if (promoDialog.id < 0) { - TLRPC.Chat chat = getChat(-promoDialog.id); - if (ChatObject.isNotInChat(chat) || chat.restricted) { - removeDialog(promoDialog); - } - } else { + req1.peers.add(peer); + checkingPromoInfoRequestId = getConnectionsManager().sendRequest(req1, (response1, error1) -> { + if (checkPromoId != lastCheckPromoId) { + return; + } + checkingPromoInfoRequestId = 0; + TLRPC.TL_messages_peerDialogs res2 = (TLRPC.TL_messages_peerDialogs) response1; + if (res2 != null && !res2.dialogs.isEmpty()) { + getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true); + TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs(); + dialogs.chats = res2.chats; + dialogs.users = res2.users; + dialogs.dialogs = res2.dialogs; + dialogs.messages = res2.messages; + getMessagesStorage().putDialogs(dialogs, 2); + AndroidUtilities.runOnUIThread(() -> { + putUsers(res.users, false); + putChats(res.chats, false); + putUsers(res2.users, false); + putChats(res2.chats, false); + + if (promoDialog != null) { + if (promoDialog.id < 0) { + TLRPC.Chat chat = getChat(-promoDialog.id); + if (ChatObject.isNotInChat(chat) || chat.restricted) { removeDialog(promoDialog); } + } else { + removeDialog(promoDialog); } + } - promoDialog = res2.dialogs.get(0); - promoDialog.id = did; - promoDialog.folder_id = 0; - if (DialogObject.isChannel(promoDialog)) { - channelsPts.put(-promoDialog.id, promoDialog.pts); + promoDialog = res2.dialogs.get(0); + promoDialog.id = did; + promoDialog.folder_id = 0; + if (DialogObject.isChannel(promoDialog)) { + channelsPts.put(-promoDialog.id, promoDialog.pts); + } + Integer value = dialogs_read_inbox_max.get(promoDialog.id); + if (value == null) { + value = 0; + } + dialogs_read_inbox_max.put(promoDialog.id, Math.max(value, promoDialog.read_inbox_max_id)); + value = dialogs_read_outbox_max.get(promoDialog.id); + if (value == null) { + value = 0; + } + dialogs_read_outbox_max.put(promoDialog.id, Math.max(value, promoDialog.read_outbox_max_id)); + dialogs_dict.put(did, promoDialog); + if (!res2.messages.isEmpty()) { + LongSparseArray usersDict1 = new LongSparseArray<>(); + LongSparseArray chatsDict1 = new LongSparseArray<>(); + for (int a = 0; a < res2.users.size(); a++) { + TLRPC.User u = res2.users.get(a); + usersDict1.put(u.id, u); } - Integer value = dialogs_read_inbox_max.get(promoDialog.id); - if (value == null) { - value = 0; + for (int a = 0; a < res2.chats.size(); a++) { + TLRPC.Chat c = res2.chats.get(a); + chatsDict1.put(c.id, c); } - dialogs_read_inbox_max.put(promoDialog.id, Math.max(value, promoDialog.read_inbox_max_id)); - value = dialogs_read_outbox_max.get(promoDialog.id); - if (value == null) { - value = 0; + MessageObject messageObject = new MessageObject(currentAccount, res2.messages.get(0), usersDict1, chatsDict1, false, true); + ArrayList objects = dialogMessage.get(did); + if (objects == null) { + objects = new ArrayList<>(1); } - dialogs_read_outbox_max.put(promoDialog.id, Math.max(value, promoDialog.read_outbox_max_id)); - dialogs_dict.put(did, promoDialog); - if (!res2.messages.isEmpty()) { - LongSparseArray usersDict1 = new LongSparseArray<>(); - LongSparseArray chatsDict1 = new LongSparseArray<>(); - for (int a = 0; a < res2.users.size(); a++) { - TLRPC.User u = res2.users.get(a); - usersDict1.put(u.id, u); - } - for (int a = 0; a < res2.chats.size(); a++) { - TLRPC.Chat c = res2.chats.get(a); - chatsDict1.put(c.id, c); - } - MessageObject messageObject = new MessageObject(currentAccount, res2.messages.get(0), usersDict1, chatsDict1, false, true); - ArrayList objects = dialogMessage.get(did); - if (objects == null) { - objects = new ArrayList<>(1); - } - if (objects.size() > 0 && objects.get(0) != null && objects.get(0).hasValidGroupId() && objects.get(0).getGroupIdForUse() != messageObject.getGroupIdForUse()) { - objects.clear(); - } - objects.add(messageObject); - dialogMessage.put(did, objects); - if (promoDialog.last_message_date == 0) { - promoDialog.last_message_date = messageObject.messageOwner.date; - } + if (objects.size() > 0 && objects.get(0) != null && objects.get(0).hasValidGroupId() && objects.get(0).getGroupIdForUse() != messageObject.getGroupIdForUse()) { + objects.clear(); } - sortDialogs(null); - getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true); - }); - } else { - AndroidUtilities.runOnUIThread(() -> { - if (promoDialog != null) { - if (promoDialog.id < 0) { - TLRPC.Chat chat = getChat(-promoDialog.id); - if (ChatObject.isNotInChat(chat) || chat.restricted) { - removeDialog(promoDialog); - } - } else { + objects.add(messageObject); + dialogMessage.put(did, objects); + if (promoDialog.last_message_date == 0) { + promoDialog.last_message_date = messageObject.messageOwner.date; + } + } + sortDialogs(null); + getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true); + }); + } else { + AndroidUtilities.runOnUIThread(() -> { + if (promoDialog != null) { + if (promoDialog.id < 0) { + TLRPC.Chat chat = getChat(-promoDialog.id); + if (ChatObject.isNotInChat(chat) || chat.restricted) { removeDialog(promoDialog); } - promoDialog = null; - sortDialogs(null); - getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload); + } else { + removeDialog(promoDialog); } - }); - } - checkingPromoInfo = false; - }); - } - }); - } + promoDialog = null; + sortDialogs(null); + getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload); + } + }); + } + checkingPromoInfo = false; + }); + } + }); } } else { nextPromoInfoCheckTime = getConnectionsManager().getCurrentTime() + 60 * 60; @@ -9846,7 +9855,6 @@ private void checkPromoInfoInternal(boolean reset) { getGlobalMainSettings().edit().putLong("proxy_dialog", promoDialogId).remove("proxyDialogAddress").putInt("nextPromoInfoCheckTime", nextPromoInfoCheckTime).commit(); AndroidUtilities.runOnUIThread(this::removePromoDialog); } - } private void removePromoDialog() { @@ -12977,7 +12985,7 @@ public void addToPollsQueue(long dialogId, ArrayList visibleObjec if (hasExpiredPolls) { lastViewsCheckTime = 0; } else if (minExpireTime < 5) { - lastViewsCheckTime = Math.min(lastViewsCheckTime, System.currentTimeMillis() - (5 - minExpireTime) * 1000L); + lastViewsCheckTime = Math.min(lastViewsCheckTime, System.currentTimeMillis() - (5 - minExpireTime) * 1000); } } @@ -13856,7 +13864,7 @@ public void addUserToChat(long chatId, TLRPC.User user, int forwardCount, String public interface ErrorDelegate { // if returns true, a delegate allows to show default alert - boolean run(TLRPC.TL_error error); + public boolean run(TLRPC.TL_error error); } public void loadUsersPremiumLocked( @@ -19599,7 +19607,9 @@ private boolean updatePrintingUsersWithNewMessages(long uid, ArrayList