青竹传媒 v1.0.0版本的 MD5 值为:d5ec664fe20c17fd4f187bc728262336

以下内容为反编译后的 MessagesController.java 源代码,内容仅作参考


package im.jpeoubogmn.messenger;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.LongSparseArray;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import androidx.core.app.NotificationManagerCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import com.baidu.location.BDLocation;
import com.baidu.mapapi.UIMsg;
import com.bjz.comm.net.utils.AppPreferenceUtil;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.text.ttml.TtmlNode;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.util.MimeTypes;
import com.king.zxing.util.CodeUtils;
import com.king.zxing.util.LogUtils;
import im.jpeoubogmn.javaBean.fc.FollowedFcListBean;
import im.jpeoubogmn.javaBean.fc.HomeFcListBean;
import im.jpeoubogmn.javaBean.fc.RecommendFcListBean;
import im.jpeoubogmn.messenger.MessagesStorage;
import im.jpeoubogmn.messenger.NotificationCenter;
import im.jpeoubogmn.messenger.support.SparseLongArray;
import im.jpeoubogmn.messenger.voip.VoIPService;
import im.jpeoubogmn.sqlite.SQLiteCursor;
import im.jpeoubogmn.tgnet.ConnectionsManager;
import im.jpeoubogmn.tgnet.NativeByteBuffer;
import im.jpeoubogmn.tgnet.RequestDelegate;
import im.jpeoubogmn.tgnet.TLObject;
import im.jpeoubogmn.tgnet.TLRPC;
import im.jpeoubogmn.tgnet.TLRPCCall;
import im.jpeoubogmn.tgnet.TLRPCChats;
import im.jpeoubogmn.tgnet.TLRPCContacts;
import im.jpeoubogmn.ui.ChatActivity;
import im.jpeoubogmn.ui.DialogsActivity;
import im.jpeoubogmn.ui.ProfileActivity;
import im.jpeoubogmn.ui.actionbar.AlertDialog;
import im.jpeoubogmn.ui.actionbar.BaseFragment;
import im.jpeoubogmn.ui.actionbar.Theme;
import im.jpeoubogmn.ui.components.AlertsCreator;
import im.jpeoubogmn.ui.components.toast.ToastUtils;
import im.jpeoubogmn.ui.hui.chats.NewProfileActivity;
import im.jpeoubogmn.ui.hui.contacts.AddContactsInfoActivity;
import im.jpeoubogmn.ui.hui.friendscircle_v1.helper.FcDBHelper;
import im.jpeoubogmn.ui.hui.visualcall.VisualCallReceiveService;
import im.jpeoubogmn.ui.hviews.helper.MryDeviceHelper;
import java.io.File;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
public class MessagesController extends BaseController implements NotificationCenter.NotificationCenterDelegate {
    private static volatile MessagesController[] Instance = new MessagesController[3];
    public static final int UPDATE_MASK_ALL = 1535;
    public static final int UPDATE_MASK_AVATAR = 2;
    public static final int UPDATE_MASK_CHAT = 8192;
    public static final int UPDATE_MASK_CHAT_AVATAR = 8;
    public static final int UPDATE_MASK_CHAT_MEMBERS = 32;
    public static final int UPDATE_MASK_CHAT_NAME = 16;
    public static final int UPDATE_MASK_CHECK = 65536;
    public static final int UPDATE_MASK_MESSAGE_TEXT = 32768;
    public static final int UPDATE_MASK_NAME = 1;
    public static final int UPDATE_MASK_NEW_MESSAGE = 2048;
    public static final int UPDATE_MASK_PHONE = 1024;
    public static final int UPDATE_MASK_READ_DIALOG_MESSAGE = 256;
    public static final int UPDATE_MASK_REORDER = 131072;
    public static final int UPDATE_MASK_SELECT_DIALOG = 512;
    public static final int UPDATE_MASK_SEND_STATE = 4096;
    public static final int UPDATE_MASK_STATUS = 4;
    public static final int UPDATE_MASK_USER_PHONE = 128;
    public static final int UPDATE_MASK_USER_PRINT = 64;
    private static volatile long lastPasswordCheckTime;
    private static volatile long lastThemeCheckTime;
    private int DIALOGS_LOAD_TYPE_CACHE;
    private int DIALOGS_LOAD_TYPE_CHANNEL;
    private int DIALOGS_LOAD_TYPE_UNKNOWN;
    protected ArrayList<TLRPC.Dialog> allDialogs;
    public float animatedEmojisZoom;
    public int availableMapProviders;
    public boolean blockedCountry;
    public boolean blockedEndReached;
    public SparseIntArray blockedUsers;
    public int callConnectTimeout;
    public int callPacketTimeout;
    public int callReceiveTimeout;
    public int callRingTimeout;
    public boolean canRevokePmInbox;
    private SparseArray<SparseArray<String>> channelAdmins;
    private SparseArray<ArrayList<Integer>> channelViewsToSend;
    private SparseIntArray channelsPts;
    private ConcurrentHashMap<Integer, TLRPC.Chat> chats;
    private SparseBooleanArray checkingLastMessagesDialogs;
    private boolean checkingProxyInfo;
    private int checkingProxyInfoRequestId;
    private boolean checkingTosUpdate;
    private LongSparseArray<TLRPC.Dialog> clearingHistoryDialogs;
    private boolean contactsGetDiff;
    private ArrayList<Long> createdDialogIds;
    private ArrayList<Long> createdDialogMainThreadIds;
    private ArrayList<Long> createdScheduledDialogIds;
    private Runnable currentDeleteTaskRunnable;
    private int currentDeletingTaskChannelId;
    private ArrayList<Integer> currentDeletingTaskMids;
    private int currentDeletingTaskTime;
    public String dcDomainName;
    public boolean defaultP2pContacts;
    public LongSparseArray<Integer> deletedHistory;
    private LongSparseArray<TLRPC.Dialog> deletingDialogs;
    private final Comparator<TLRPC.Dialog> dialogComparator;
    public LongSparseArray<MessageObject> dialogMessage;
    public SparseArray<MessageObject> dialogMessagesByIds;
    public LongSparseArray<MessageObject> dialogMessagesByRandomIds;
    private SparseArray<ArrayList<TLRPC.Dialog>> dialogsByFolder;
    public ArrayList<TLRPC.Dialog> dialogsCanAddUsers;
    public ArrayList<TLRPC.Dialog> dialogsChannelsOnly;
    private SparseBooleanArray dialogsEndReached;
    public ArrayList<TLRPC.Dialog> dialogsForward;
    public ArrayList<TLRPC.Dialog> dialogsGroupsOnly;
    private boolean dialogsInTransaction;
    public boolean dialogsLoaded;
    public ArrayList<TLRPC.Dialog> dialogsServerOnly;
    public ArrayList<TLRPC.Dialog> dialogsUnreadOnly;
    public ArrayList<TLRPC.Dialog> dialogsUsersOnly;
    public LongSparseArray<TLRPC.Dialog> dialogs_dict;
    public ConcurrentHashMap<Long, Integer> dialogs_read_inbox_max;
    public ConcurrentHashMap<Long, Integer> dialogs_read_outbox_max;
    private SharedPreferences emojiPreferences;
    public boolean enableDigitCoin;
    public boolean enableHub;
    public boolean enableJoined;
    public boolean enableWallet;
    private ConcurrentHashMap<Integer, TLRPC.EncryptedChat> encryptedChats;
    private SparseArray<TLRPC.ExportedChatInvite> exportedChats;
    public boolean firstGettingTask;
    private SparseArray<TLRPC.ChatFull> fullChats;
    private SparseArray<TLRPC.UserFull> fullUsers;
    private boolean getDifferenceFirstSync;
    public boolean gettingDifference;
    private SparseBooleanArray gettingDifferenceChannels;
    private boolean gettingNewDeleteTask;
    private SparseBooleanArray gettingUnknownChannels;
    private LongSparseArray<Boolean> gettingUnknownDialogs;
    public String gifSearchBot;
    public ArrayList<TLRPC.RecentMeUrl> hintDialogs;
    public String imageSearchBot;
    private String installReferer;
    private boolean isLeftProxyChannel;
    private ArrayList<Integer> joiningToChannels;
    private int lastCheckProxyId;
    private int lastPrintingStringCount;
    private long lastPushRegisterSendTime;
    private LongSparseArray<Long> lastScheduledServerQueryTime;
    private long lastStatusUpdateTime;
    private long lastViewsCheckTime;
    public String linkPrefix;
    private ArrayList<Integer> loadedFullChats;
    private ArrayList<Integer> loadedFullParticipants;
    private ArrayList<Integer> loadedFullUsers;
    private boolean loadingAppConfig;
    public boolean loadingBlockedUsers;
    private SparseIntArray loadingChannelAdmins;
    private SparseBooleanArray loadingDialogs;
    private ArrayList<Integer> loadingFullChats;
    private ArrayList<Integer> loadingFullParticipants;
    private ArrayList<Integer> loadingFullUsers;
    private int loadingNotificationSettings;
    private boolean loadingNotificationSignUpSettings;
    private LongSparseArray<Boolean> loadingPeerSettings;
    private SparseIntArray loadingPinnedDialogs;
    private boolean loadingUnreadDialogs;
    private SharedPreferences mainPreferences;
    public String mapKey;
    public int mapProvider;
    public int maxBroadcastCount;
    public int maxCaptionLength;
    public int maxEditTime;
    public int maxFaveStickersCount;
    public int maxFolderPinnedDialogsCount;
    public int maxGroupCount;
    public int maxMegagroupCount;
    public int maxMessageLength;
    public int maxPinnedDialogsCount;
    public int maxRecentGifsCount;
    public int maxRecentStickersCount;
    private SparseIntArray migratedChats;
    private boolean migratingDialogs;
    public int minGroupConvertSize;
    private SparseIntArray needShortPollChannels;
    private SparseIntArray needShortPollOnlines;
    private SparseIntArray nextDialogsCacheOffset;
    private int nextProxyInfoCheckTime;
    private int nextTosCheckTime;
    private SharedPreferences notificationsPreferences;
    private ConcurrentHashMap<String, TLObject> objectsByUsernames;
    private boolean offlineSent;
    public ConcurrentHashMap<Integer, Integer> onlinePrivacy;
    private Runnable passwordCheckRunnable;
    private LongSparseArray<SparseArray<MessageObject>> pollsToCheck;
    private int pollsToCheckSize;
    public boolean preloadFeaturedStickers;
    public LongSparseArray<CharSequence> printingStrings;
    public LongSparseArray<Integer> printingStringsTypes;
    public ConcurrentHashMap<Long, ArrayList<PrintingUser>> printingUsers;
    private TLRPC.Dialog proxyDialog;
    private String proxyDialogAddress;
    private long proxyDialogId;
    public int ratingDecay;
    private ArrayList<ReadTask> readTasks;
    private LongSparseArray<ReadTask> readTasksMap;
    public boolean registeringForPush;
    private LongSparseArray<ArrayList<Integer>> reloadingMessages;
    private HashMap<String, ArrayList<MessageObject>> reloadingScheduledWebpages;
    private LongSparseArray<ArrayList<MessageObject>> reloadingScheduledWebpagesPending;
    private HashMap<String, ArrayList<MessageObject>> reloadingWebpages;
    private LongSparseArray<ArrayList<MessageObject>> reloadingWebpagesPending;
    private TLRPC.messages_Dialogs resetDialogsAll;
    private TLRPC.TL_messages_peerDialogs resetDialogsPinned;
    private boolean resetingDialogs;
    public int revokeTimeLimit;
    public int revokeTimePmLimit;
    public int secretWebpagePreview;
    public SparseArray<LongSparseArray<Boolean>> sendingTypings;
    private SparseBooleanArray serverDialogsEndReached;
    public String sharePrefix;
    private SparseIntArray shortPollChannels;
    private SparseIntArray shortPollOnlines;
    private int statusRequest;
    private int statusSettingState;
    public boolean suggestContacts;
    public String suggestedLangCode;
    private Runnable themeCheckRunnable;
    public int totalBlockedCount;
    public int unreadUnmutedDialogs;
    private final Comparator<TLRPC.Update> updatesComparator;
    private SparseArray<ArrayList<TLRPC.Updates>> updatesQueueChannels;
    private ArrayList<TLRPC.Updates> updatesQueuePts;
    private ArrayList<TLRPC.Updates> updatesQueueQts;
    private ArrayList<TLRPC.Updates> updatesQueueSeq;
    private SparseLongArray updatesStartWaitTimeChannels;
    private long updatesStartWaitTimePts;
    private long updatesStartWaitTimeQts;
    private long updatesStartWaitTimeSeq;
    public boolean updatingState;
    private String uploadingAvatar;
    private HashMap<String, Theme.ThemeInfo> uploadingThemes;
    private String uploadingWallpaper;
    private boolean uploadingWallpaperBlurred;
    private boolean uploadingWallpaperMotion;
    private ConcurrentHashMap<Integer, TLRPC.User> users;
    public String venueSearchBot;
    private ArrayList<Long> visibleDialogMainThreadIds;
    private ArrayList<Long> visibleScheduledDialogMainThreadIds;
    public int webFileDatacenterId;

    public static class PrintingUser {
        public TLRPC.SendMessageAction action;
        public long lastTime;
        public int userId;
    }

    public void lambda$new$0$MessagesController() {
        getUserConfig().checkSavedPassword();
    }

    public static class UserActionUpdatesSeq extends TLRPC.Updates {
        private UserActionUpdatesSeq() {
        }
    }

    public static class UserActionUpdatesPts extends TLRPC.Updates {
        private UserActionUpdatesPts() {
        }
    }

    public class ReadTask {
        public long dialogId;
        public int maxDate;
        public int maxId;
        public long sendRequestTime;

        private ReadTask() {
            MessagesController.this = r1;
        }
    }

    public int lambda$new$1$MessagesController(TLRPC.Dialog dialog1, TLRPC.Dialog dialog2) {
        if (!(dialog1 instanceof TLRPC.TL_dialogFolder) || (dialog2 instanceof TLRPC.TL_dialogFolder)) {
            if ((dialog1 instanceof TLRPC.TL_dialogFolder) || !(dialog2 instanceof TLRPC.TL_dialogFolder)) {
                if (dialog1.pinned || !dialog2.pinned) {
                    if (!dialog1.pinned || dialog2.pinned) {
                        if (dialog1.pinned && dialog2.pinned) {
                            if (dialog1.pinnedNum < dialog2.pinnedNum) {
                                return 1;
                            }
                            return dialog1.pinnedNum > dialog2.pinnedNum ? -1 : 0;
                        }
                        TLRPC.DraftMessage draftMessage = getMediaDataController().getDraft(dialog1.id);
                        int date1 = (draftMessage == null || draftMessage.date < dialog1.last_message_date) ? dialog1.last_message_date : draftMessage.date;
                        TLRPC.DraftMessage draftMessage2 = getMediaDataController().getDraft(dialog2.id);
                        int date2 = (draftMessage2 == null || draftMessage2.date < dialog2.last_message_date) ? dialog2.last_message_date : draftMessage2.date;
                        if (date1 < date2) {
                            return 1;
                        }
                        return date1 > date2 ? -1 : 0;
                    }
                    return -1;
                }
                return 1;
            }
            return 1;
        }
        return -1;
    }

    public int lambda$new$2$MessagesController(TLRPC.Update lhs, TLRPC.Update rhs) {
        int ltype = getUpdateType(lhs);
        int rtype = getUpdateType(rhs);
        if (ltype != rtype) {
            return AndroidUtilities.compare(ltype, rtype);
        }
        if (ltype == 0) {
            return AndroidUtilities.compare(getUpdatePts(lhs), getUpdatePts(rhs));
        }
        if (ltype == 1) {
            return AndroidUtilities.compare(getUpdateQts(lhs), getUpdateQts(rhs));
        }
        if (ltype == 2) {
            int lChannel = getUpdateChannelId(lhs);
            int rChannel = getUpdateChannelId(rhs);
            if (lChannel == rChannel) {
                return AndroidUtilities.compare(getUpdatePts(lhs), getUpdatePts(rhs));
            }
            return AndroidUtilities.compare(lChannel, rChannel);
        }
        return 0;
    }

    public static MessagesController getInstance(int num) {
        MessagesController localInstance = Instance[num];
        if (localInstance == null) {
            synchronized (MessagesController.class) {
                localInstance = Instance[num];
                if (localInstance == null) {
                    MessagesController[] messagesControllerArr = Instance;
                    MessagesController messagesController = new MessagesController(num);
                    localInstance = messagesController;
                    messagesControllerArr[num] = messagesController;
                }
            }
        }
        return localInstance;
    }

    public static SharedPreferences getNotificationsSettings(int account) {
        return getInstance(account).notificationsPreferences;
    }

    public static SharedPreferences getGlobalNotificationsSettings() {
        return getInstance(0).notificationsPreferences;
    }

    public static SharedPreferences getMainSettings(int account) {
        return getInstance(account).mainPreferences;
    }

    public static SharedPreferences getGlobalMainSettings() {
        return getInstance(0).mainPreferences;
    }

    public static SharedPreferences getEmojiSettings(int account) {
        return getInstance(account).emojiPreferences;
    }

    public static SharedPreferences getGlobalEmojiSettings() {
        return getInstance(0).emojiPreferences;
    }

    public MessagesController(int num) {
        super(num);
        this.chats = new ConcurrentHashMap<>(100, 1.0f, 2);
        this.encryptedChats = new ConcurrentHashMap<>(10, 1.0f, 2);
        this.users = new ConcurrentHashMap<>(100, 1.0f, 2);
        this.objectsByUsernames = new ConcurrentHashMap<>(100, 1.0f, 2);
        this.joiningToChannels = new ArrayList<>();
        this.exportedChats = new SparseArray<>();
        this.hintDialogs = new ArrayList<>();
        this.dialogsByFolder = new SparseArray<>();
        this.allDialogs = new ArrayList<>();
        this.dialogsForward = new ArrayList<>();
        this.dialogsServerOnly = new ArrayList<>();
        this.dialogsCanAddUsers = new ArrayList<>();
        this.dialogsChannelsOnly = new ArrayList<>();
        this.dialogsUsersOnly = new ArrayList<>();
        this.dialogsGroupsOnly = new ArrayList<>();
        this.dialogsUnreadOnly = new ArrayList<>();
        this.dialogs_read_inbox_max = new ConcurrentHashMap<>(100, 1.0f, 2);
        this.dialogs_read_outbox_max = new ConcurrentHashMap<>(100, 1.0f, 2);
        this.dialogs_dict = new LongSparseArray<>();
        this.dialogMessage = new LongSparseArray<>();
        this.dialogMessagesByRandomIds = new LongSparseArray<>();
        this.deletedHistory = new LongSparseArray<>();
        this.dialogMessagesByIds = new SparseArray<>();
        this.printingUsers = new ConcurrentHashMap<>(20, 1.0f, 2);
        this.printingStrings = new LongSparseArray<>();
        this.printingStringsTypes = new LongSparseArray<>();
        this.sendingTypings = new SparseArray<>();
        this.onlinePrivacy = new ConcurrentHashMap<>(20, 1.0f, 2);
        this.loadingPeerSettings = new LongSparseArray<>();
        this.createdDialogIds = new ArrayList<>();
        this.createdScheduledDialogIds = new ArrayList<>();
        this.createdDialogMainThreadIds = new ArrayList<>();
        this.visibleDialogMainThreadIds = new ArrayList<>();
        this.visibleScheduledDialogMainThreadIds = new ArrayList<>();
        this.shortPollChannels = new SparseIntArray();
        this.needShortPollChannels = new SparseIntArray();
        this.shortPollOnlines = new SparseIntArray();
        this.needShortPollOnlines = new SparseIntArray();
        this.deletingDialogs = new LongSparseArray<>();
        this.clearingHistoryDialogs = new LongSparseArray<>();
        this.loadingBlockedUsers = false;
        this.blockedUsers = new SparseIntArray();
        this.totalBlockedCount = -1;
        this.channelViewsToSend = new SparseArray<>();
        this.pollsToCheck = new LongSparseArray<>();
        this.updatesQueueChannels = new SparseArray<>();
        this.updatesStartWaitTimeChannels = new SparseLongArray();
        this.channelsPts = new SparseIntArray();
        this.gettingDifferenceChannels = new SparseBooleanArray();
        this.gettingUnknownChannels = new SparseBooleanArray();
        this.gettingUnknownDialogs = new LongSparseArray<>();
        this.checkingLastMessagesDialogs = new SparseBooleanArray();
        this.updatesQueueSeq = new ArrayList<>();
        this.updatesQueuePts = new ArrayList<>();
        this.updatesQueueQts = new ArrayList<>();
        this.fullUsers = new SparseArray<>();
        this.fullChats = new SparseArray<>();
        this.loadingFullUsers = new ArrayList<>();
        this.loadedFullUsers = new ArrayList<>();
        this.loadingFullChats = new ArrayList<>();
        this.loadingFullParticipants = new ArrayList<>();
        this.loadedFullParticipants = new ArrayList<>();
        this.loadedFullChats = new ArrayList<>();
        this.channelAdmins = new SparseArray<>();
        this.loadingChannelAdmins = new SparseIntArray();
        this.migratedChats = new SparseIntArray();
        this.reloadingWebpages = new HashMap<>();
        this.reloadingWebpagesPending = new LongSparseArray<>();
        this.reloadingScheduledWebpages = new HashMap<>();
        this.reloadingScheduledWebpagesPending = new LongSparseArray<>();
        this.lastScheduledServerQueryTime = new LongSparseArray<>();
        this.reloadingMessages = new LongSparseArray<>();
        this.readTasks = new ArrayList<>();
        this.readTasksMap = new LongSparseArray<>();
        this.nextDialogsCacheOffset = new SparseIntArray();
        this.loadingDialogs = new SparseBooleanArray();
        this.dialogsEndReached = new SparseBooleanArray();
        this.serverDialogsEndReached = new SparseBooleanArray();
        this.getDifferenceFirstSync = true;
        this.loadingPinnedDialogs = new SparseIntArray();
        this.suggestContacts = true;
        this.themeCheckRunnable = new Runnable() {
            @Override
            public final void run() {
                Theme.checkAutoNightThemeConditions();
            }
        };
        this.passwordCheckRunnable = new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$new$0$MessagesController();
            }
        };
        this.uploadingThemes = new HashMap<>();
        this.maxBroadcastCount = 100;
        this.minGroupConvertSize = ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION;
        this.dialogComparator = new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                return MessagesController.this.lambda$new$1$MessagesController((TLRPC.Dialog) obj, (TLRPC.Dialog) obj2);
            }
        };
        this.updatesComparator = new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                return MessagesController.this.lambda$new$2$MessagesController((TLRPC.Update) obj, (TLRPC.Update) obj2);
            }
        };
        this.DIALOGS_LOAD_TYPE_CACHE = 1;
        this.DIALOGS_LOAD_TYPE_CHANNEL = 2;
        this.DIALOGS_LOAD_TYPE_UNKNOWN = 3;
        this.contactsGetDiff = false;
        this.currentAccount = num;
        ImageLoader.getInstance();
        getMessagesStorage();
        getLocationController();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$new$3$MessagesController();
            }
        });
        addSupportUser();
        if (this.currentAccount == 0) {
            this.notificationsPreferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", 0);
            this.mainPreferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0);
            this.emojiPreferences = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0);
        } else {
            Context context = ApplicationLoader.applicationContext;
            this.notificationsPreferences = context.getSharedPreferences("Notifications" + this.currentAccount, 0);
            Context context2 = ApplicationLoader.applicationContext;
            this.mainPreferences = context2.getSharedPreferences("mainconfig" + this.currentAccount, 0);
            Context context3 = ApplicationLoader.applicationContext;
            this.emojiPreferences = context3.getSharedPreferences("emoji" + this.currentAccount, 0);
        }
        this.enableJoined = this.notificationsPreferences.getBoolean("EnableContactJoined", true);
        this.secretWebpagePreview = this.mainPreferences.getInt("secretWebpage2", 2);
        this.maxGroupCount = this.mainPreferences.getInt("maxGroupCount", ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION);
        this.maxMegagroupCount = this.mainPreferences.getInt("maxMegagroupCount", 10000);
        this.maxRecentGifsCount = this.mainPreferences.getInt("maxRecentGifsCount", ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION);
        this.maxRecentStickersCount = this.mainPreferences.getInt("maxRecentStickersCount", 30);
        this.maxFaveStickersCount = this.mainPreferences.getInt("maxFaveStickersCount", 5);
        this.maxEditTime = this.mainPreferences.getInt("maxEditTime", 3600);
        this.ratingDecay = this.mainPreferences.getInt("ratingDecay", 2419200);
        this.linkPrefix = "m12345.cc";
        String defaultValue = BuildVars.RELEASE_VERSION ? "https://m12345.cc/install.html?appkey=aa717156fa6e34325d3d4a7004a6647a" : "http://www.shareinstall.com.cn/js-test.html?appkey=aa717156fa6e34325d3d4a7004a6647a";
        this.sharePrefix = this.mainPreferences.getString("sharePrefix", defaultValue);
        this.callReceiveTimeout = this.mainPreferences.getInt("callReceiveTimeout", 20000);
        this.callRingTimeout = this.mainPreferences.getInt("callRingTimeout", 90000);
        this.callConnectTimeout = this.mainPreferences.getInt("callConnectTimeout", UIMsg.m_AppUI.MSG_RADAR_SEARCH_RETURN_RESULT);
        this.callPacketTimeout = this.mainPreferences.getInt("callPacketTimeout", 10000);
        this.maxPinnedDialogsCount = this.mainPreferences.getInt("maxPinnedDialogsCount", 5);
        this.maxFolderPinnedDialogsCount = this.mainPreferences.getInt("maxFolderPinnedDialogsCount", 100);
        this.maxMessageLength = this.mainPreferences.getInt("maxMessageLength", 4096);
        this.maxCaptionLength = this.mainPreferences.getInt("maxCaptionLength", 1024);
        this.mapProvider = this.mainPreferences.getInt("mapProvider", 0);
        this.availableMapProviders = this.mainPreferences.getInt("availableMapProviders", 3);
        this.mapKey = this.mainPreferences.getString("pk", null);
        this.installReferer = this.mainPreferences.getString("installReferer", null);
        this.defaultP2pContacts = this.mainPreferences.getBoolean("defaultP2pContacts", false);
        this.revokeTimeLimit = this.mainPreferences.getInt("revokeTimeLimit", this.revokeTimeLimit);
        this.revokeTimePmLimit = this.mainPreferences.getInt("revokeTimePmLimit", this.revokeTimePmLimit);
        this.canRevokePmInbox = this.mainPreferences.getBoolean("canRevokePmInbox", this.canRevokePmInbox);
        this.preloadFeaturedStickers = this.mainPreferences.getBoolean("preloadFeaturedStickers", false);
        this.proxyDialogId = this.mainPreferences.getLong("proxy_dialog", 0L);
        this.proxyDialogAddress = this.mainPreferences.getString("proxyDialogAddress", null);
        this.nextTosCheckTime = this.notificationsPreferences.getInt("nextTosCheckTime", 0);
        this.venueSearchBot = this.mainPreferences.getString("venueSearchBot", "foursquare");
        this.gifSearchBot = this.mainPreferences.getString("gifSearchBot", "gif");
        this.imageSearchBot = this.mainPreferences.getString("imageSearchBot", "pic");
        this.blockedCountry = this.mainPreferences.getBoolean("blockedCountry", false);
        this.dcDomainName = this.mainPreferences.getString("dcDomainName2", ConnectionsManager.native_isTestBackend(this.currentAccount) != 0 ? "tapv3.stel.com" : "apv3.stel.com");
        this.webFileDatacenterId = this.mainPreferences.getInt("webFileDatacenterId", ConnectionsManager.native_isTestBackend(this.currentAccount) == 0 ? 4 : 2);
        this.suggestedLangCode = this.mainPreferences.getString("suggestedLangCode", "en");
        this.animatedEmojisZoom = this.mainPreferences.getFloat("animatedEmojisZoom", 0.625f);
        this.enableHub = this.mainPreferences.getBoolean("enable_hub", false);
        this.enableWallet = this.mainPreferences.getBoolean("enable_wallet", false);
        this.enableDigitCoin = this.mainPreferences.getBoolean("enable_digit_coin", false);
    }

    public void lambda$new$3$MessagesController() {
        MessagesController messagesController = getMessagesController();
        getNotificationCenter().addObserver(messagesController, NotificationCenter.FileDidUpload);
        getNotificationCenter().addObserver(messagesController, NotificationCenter.FileDidFailUpload);
        getNotificationCenter().addObserver(messagesController, NotificationCenter.fileDidLoad);
        getNotificationCenter().addObserver(messagesController, NotificationCenter.fileDidFailToLoad);
        getNotificationCenter().addObserver(messagesController, NotificationCenter.messageReceivedByServer);
        getNotificationCenter().addObserver(messagesController, NotificationCenter.updateMessageMedia);
    }

    private void loadAppConfig() {
        if (this.loadingAppConfig) {
            return;
        }
        this.loadingAppConfig = true;
        TLRPC.TL_help_getAppConfig req = new TLRPC.TL_help_getAppConfig();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadAppConfig$5$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$loadAppConfig$5$MessagesController(final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$4$MessagesController(response);
            }
        });
    }

    public void lambda$null$4$MessagesController(TLObject response) {
        if (response instanceof TLRPC.TL_jsonObject) {
            SharedPreferences.Editor editor = this.mainPreferences.edit();
            boolean changed = false;
            TLRPC.TL_jsonObject object = (TLRPC.TL_jsonObject) response;
            int N = object.value.size();
            for (int a = 0; a < N; a++) {
                TLRPC.TL_jsonObjectValue value = object.value.get(a);
                if ("emojies_animated_zoom".equals(value.key) && (value.value instanceof TLRPC.TL_jsonNumber)) {
                    TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
                    if (this.animatedEmojisZoom != number.value) {
                        float f = (float) number.value;
                        this.animatedEmojisZoom = f;
                        editor.putFloat("animatedEmojisZoom", f);
                        changed = true;
                    }
                }
            }
            if (changed) {
                editor.commit();
            }
        }
        this.loadingAppConfig = false;
    }

    public void updateConfig(final TLRPC.TL_config config) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$updateConfig$6$MessagesController(config);
            }
        });
    }

    public void lambda$updateConfig$6$MessagesController(TLRPC.TL_config config) {
        String str;
        getDownloadController().loadAutoDownloadConfig(false);
        loadAppConfig();
        this.maxMegagroupCount = config.megagroup_size_max;
        this.maxGroupCount = config.chat_size_max;
        this.maxEditTime = config.edit_time_limit;
        this.ratingDecay = config.rating_e_decay;
        this.maxRecentGifsCount = config.saved_gifs_limit;
        this.maxRecentStickersCount = config.stickers_recent_limit;
        this.maxFaveStickersCount = config.stickers_faved_limit;
        this.revokeTimeLimit = config.revoke_time_limit;
        this.revokeTimePmLimit = config.revoke_pm_time_limit;
        this.canRevokePmInbox = config.revoke_pm_inbox;
        this.linkPrefix = "m12345.cc";
        if ("m12345.cc".endsWith("/")) {
            String str2 = this.linkPrefix;
            this.linkPrefix = str2.substring(0, str2.length() - 1);
        }
        if (this.linkPrefix.startsWith("https://")) {
            this.linkPrefix = this.linkPrefix.substring(8);
        } else if (this.linkPrefix.startsWith("http://")) {
            this.linkPrefix = this.linkPrefix.substring(7);
        }
        this.linkPrefix = "m12345.cc";
        this.sharePrefix = config.me_url_prefix;
        this.callReceiveTimeout = config.call_receive_timeout_ms;
        this.callRingTimeout = config.call_ring_timeout_ms;
        this.callConnectTimeout = config.call_connect_timeout_ms;
        this.callPacketTimeout = config.call_packet_timeout_ms;
        this.maxPinnedDialogsCount = config.pinned_dialogs_count_max;
        this.maxFolderPinnedDialogsCount = config.pinned_infolder_count_max;
        this.maxMessageLength = config.message_length_max;
        this.maxCaptionLength = config.caption_length_max;
        this.defaultP2pContacts = config.default_p2p_contacts;
        this.preloadFeaturedStickers = config.preload_featured_stickers;
        this.enableHub = ((config.flags >> 19) & 1) != 0;
        this.enableWallet = ((config.flags >> 20) & 1) != 0;
        this.enableDigitCoin = ((config.flags >> 21) & 1) != 0;
        if (config.venue_search_username != null) {
            this.venueSearchBot = config.venue_search_username;
        }
        if (config.gif_search_username != null) {
            this.gifSearchBot = config.gif_search_username;
        }
        if (this.imageSearchBot != null) {
            this.imageSearchBot = config.img_search_username;
        }
        this.blockedCountry = config.blocked_mode;
        this.dcDomainName = config.dc_txt_domain_name;
        this.webFileDatacenterId = config.webfile_dc_id;
        if (config.suggested_lang_code != null && ((str = this.suggestedLangCode) == null || !str.equals(config.suggested_lang_code))) {
            this.suggestedLangCode = config.suggested_lang_code;
            LocaleController.getInstance().loadRemoteLanguages(this.currentAccount);
        }
        Theme.loadRemoteThemes(this.currentAccount, false);
        Theme.checkCurrentRemoteTheme(false);
        if (config.static_maps_provider == null) {
            config.static_maps_provider = "google";
        }
        this.mapKey = null;
        this.mapProvider = 2;
        this.availableMapProviders = 0;
        String[] providers = config.static_maps_provider.split(",");
        for (int a = 0; a < providers.length; a++) {
            String[] mapArgs = providers[a].split("\\+");
            if (mapArgs.length > 0) {
                String[] typeAndKey = mapArgs[0].split(LogUtils.COLON);
                if (typeAndKey.length > 0) {
                    if ("yandex".equals(typeAndKey[0])) {
                        if (a == 0) {
                            if (mapArgs.length > 1) {
                                this.mapProvider = 3;
                            } else {
                                this.mapProvider = 1;
                            }
                        }
                        this.availableMapProviders |= 4;
                    } else if ("google".equals(typeAndKey[0])) {
                        if (a == 0 && mapArgs.length > 1) {
                            this.mapProvider = 4;
                        }
                        this.availableMapProviders |= 1;
                    } else if ("hchat".equals(typeAndKey[0])) {
                        if (a == 0) {
                            this.mapProvider = 2;
                        }
                        this.availableMapProviders |= 2;
                    }
                    if (typeAndKey.length > 1) {
                        this.mapKey = typeAndKey[1];
                    }
                }
            }
        }
        SharedPreferences.Editor editor = this.mainPreferences.edit();
        editor.putInt("maxGroupCount", this.maxGroupCount);
        editor.putInt("maxMegagroupCount", this.maxMegagroupCount);
        editor.putInt("maxEditTime", this.maxEditTime);
        editor.putInt("ratingDecay", this.ratingDecay);
        editor.putInt("maxRecentGifsCount", this.maxRecentGifsCount);
        editor.putInt("maxRecentStickersCount", this.maxRecentStickersCount);
        editor.putInt("maxFaveStickersCount", this.maxFaveStickersCount);
        editor.putInt("callReceiveTimeout", this.callReceiveTimeout);
        editor.putInt("callRingTimeout", this.callRingTimeout);
        editor.putInt("callConnectTimeout", this.callConnectTimeout);
        editor.putInt("callPacketTimeout", this.callPacketTimeout);
        editor.putString("linkPrefix", this.linkPrefix);
        editor.putString("sharePrefix", this.sharePrefix);
        editor.putInt("maxPinnedDialogsCount", this.maxPinnedDialogsCount);
        editor.putInt("maxFolderPinnedDialogsCount", this.maxFolderPinnedDialogsCount);
        editor.putInt("maxMessageLength", this.maxMessageLength);
        editor.putInt("maxCaptionLength", this.maxCaptionLength);
        editor.putBoolean("defaultP2pContacts", this.defaultP2pContacts);
        editor.putBoolean("preloadFeaturedStickers", this.preloadFeaturedStickers);
        editor.putInt("revokeTimeLimit", this.revokeTimeLimit);
        editor.putInt("revokeTimePmLimit", this.revokeTimePmLimit);
        editor.putInt("mapProvider", this.mapProvider);
        String str3 = this.mapKey;
        if (str3 != null) {
            editor.putString("pk", str3);
        } else {
            editor.remove("pk");
        }
        editor.putBoolean("canRevokePmInbox", this.canRevokePmInbox);
        editor.putBoolean("blockedCountry", this.blockedCountry);
        editor.putString("venueSearchBot", this.venueSearchBot);
        editor.putString("gifSearchBot", this.gifSearchBot);
        editor.putString("imageSearchBot", this.imageSearchBot);
        editor.putString("dcDomainName2", this.dcDomainName);
        editor.putInt("webFileDatacenterId", this.webFileDatacenterId);
        editor.putString("suggestedLangCode", this.suggestedLangCode);
        editor.putBoolean("enable_hub", this.enableHub);
        editor.putBoolean("enable_wallet", this.enableWallet);
        editor.putBoolean("enable_digit_coin", this.enableDigitCoin);
        editor.commit();
        LocaleController.getInstance().checkUpdateForCurrentRemoteLocale(this.currentAccount, config.lang_pack_version, config.base_lang_pack_version);
        getNotificationCenter().postNotificationName(NotificationCenter.configLoaded, new Object[0]);
    }

    public void addSupportUser() {
        TLRPC.TL_userForeign_old2 user = new TLRPC.TL_userForeign_old2();
        user.phone = "333";
        user.id = 333000;
        user.first_name = "Cchen";
        user.last_name = "";
        user.status = null;
        user.photo = new TLRPC.TL_userProfilePhotoEmpty();
        putUser(user, true);
        TLRPC.TL_userForeign_old2 user2 = new TLRPC.TL_userForeign_old2();
        user2.phone = "42777";
        user2.id = 777000;
        user2.verified = true;
        user2.first_name = "Cchen";
        user2.last_name = "Notifications";
        user2.status = null;
        user2.photo = new TLRPC.TL_userProfilePhotoEmpty();
        putUser(user2, true);
    }

    public TLRPC.InputUser getInputUser(TLRPC.User user) {
        if (user == null) {
            return new TLRPC.TL_inputUserEmpty();
        }
        if (user.id == getUserConfig().getClientUserId()) {
            return new TLRPC.TL_inputUserSelf();
        }
        TLRPC.InputUser inputUser = new TLRPC.TL_inputUser();
        inputUser.user_id = user.id;
        inputUser.access_hash = user.access_hash;
        return inputUser;
    }

    public TLRPC.InputUser getInputUser(int user_id) {
        TLRPC.User user = getInstance(UserConfig.selectedAccount).getUser(Integer.valueOf(user_id));
        return getInputUser(user);
    }

    public static TLRPC.InputChannel getInputChannel(TLRPC.Chat chat) {
        if ((chat instanceof TLRPC.TL_channel) || (chat instanceof TLRPC.TL_channelForbidden)) {
            TLRPC.InputChannel inputChat = new TLRPC.TL_inputChannel();
            inputChat.channel_id = chat.id;
            inputChat.access_hash = chat.access_hash;
            return inputChat;
        }
        return new TLRPC.TL_inputChannelEmpty();
    }

    public TLRPC.InputChannel getInputChannel(int chatId) {
        return getInputChannel(getChat(Integer.valueOf(chatId)));
    }

    public TLRPC.InputPeer getInputPeer(int id) {
        if (id < 0) {
            TLRPC.Chat chat = getChat(Integer.valueOf(-id));
            if (ChatObject.isChannel(chat)) {
                TLRPC.InputPeer inputPeer = new TLRPC.TL_inputPeerChannel();
                inputPeer.channel_id = -id;
                inputPeer.access_hash = chat.access_hash;
                return inputPeer;
            }
            TLRPC.InputPeer inputPeer2 = new TLRPC.TL_inputPeerChat();
            inputPeer2.chat_id = -id;
            return inputPeer2;
        }
        TLRPC.User user = getUser(Integer.valueOf(id));
        TLRPC.InputPeer inputPeer3 = new TLRPC.TL_inputPeerUser();
        inputPeer3.user_id = id;
        if (user != null) {
            inputPeer3.access_hash = user.access_hash;
            return inputPeer3;
        }
        return inputPeer3;
    }

    public TLRPC.Peer getPeer(int id) {
        if (id < 0) {
            TLRPC.Chat chat = getChat(Integer.valueOf(-id));
            if ((chat instanceof TLRPC.TL_channel) || (chat instanceof TLRPC.TL_channelForbidden)) {
                TLRPC.Peer inputPeer = new TLRPC.TL_peerChannel();
                inputPeer.channel_id = -id;
                return inputPeer;
            }
            TLRPC.Peer inputPeer2 = new TLRPC.TL_peerChat();
            inputPeer2.chat_id = -id;
            return inputPeer2;
        }
        getUser(Integer.valueOf(id));
        TLRPC.Peer inputPeer3 = new TLRPC.TL_peerUser();
        inputPeer3.user_id = id;
        return inputPeer3;
    }

    @Override
    public void didReceivedNotification(int id, int account, Object... args) {
        if (id == NotificationCenter.FileDidUpload) {
            String location = (String) args[0];
            TLRPC.InputFile file = (TLRPC.InputFile) args[1];
            String str = this.uploadingAvatar;
            if (str != null && str.equals(location)) {
                TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
                req.file = file;
                getConnectionsManager().sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$didReceivedNotification$8$MessagesController(tLObject, tL_error);
                    }
                });
                return;
            }
            String str2 = this.uploadingWallpaper;
            if (str2 != null && str2.equals(location)) {
                TLRPC.TL_account_uploadWallPaper req2 = new TLRPC.TL_account_uploadWallPaper();
                req2.file = file;
                req2.mime_type = "image/jpeg";
                final TLRPC.TL_wallPaperSettings settings = new TLRPC.TL_wallPaperSettings();
                settings.blur = this.uploadingWallpaperBlurred;
                settings.motion = this.uploadingWallpaperMotion;
                req2.settings = settings;
                getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$didReceivedNotification$10$MessagesController(settings, tLObject, tL_error);
                    }
                });
                return;
            }
            final Theme.ThemeInfo themeInfo = this.uploadingThemes.get(location);
            if (themeInfo != null) {
                if (location.equals(themeInfo.uploadingThumb)) {
                    themeInfo.uploadedThumb = file;
                    themeInfo.uploadingThumb = null;
                } else if (location.equals(themeInfo.uploadingFile)) {
                    themeInfo.uploadedFile = file;
                    themeInfo.uploadingFile = null;
                }
                if (themeInfo.uploadedFile != null && themeInfo.uploadedThumb != null) {
                    new File(location);
                    TLRPC.TL_account_uploadTheme req3 = new TLRPC.TL_account_uploadTheme();
                    req3.mime_type = "application/x-tgtheme-android";
                    req3.file_name = "theme.attheme";
                    req3.file = themeInfo.uploadedFile;
                    req3.file.name = "theme.attheme";
                    req3.thumb = themeInfo.uploadedThumb;
                    req3.thumb.name = "theme-preview.jpg";
                    req3.flags = 1 | req3.flags;
                    themeInfo.uploadedFile = null;
                    themeInfo.uploadedThumb = null;
                    getConnectionsManager().sendRequest(req3, new RequestDelegate() {
                        @Override
                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                            MessagesController.this.lambda$didReceivedNotification$16$MessagesController(themeInfo, tLObject, tL_error);
                        }
                    });
                }
                this.uploadingThemes.remove(location);
            }
        } else if (id == NotificationCenter.FileDidFailUpload) {
            String location2 = (String) args[0];
            String str3 = this.uploadingAvatar;
            if (str3 != null && str3.equals(location2)) {
                this.uploadingAvatar = null;
                return;
            }
            String str4 = this.uploadingWallpaper;
            if (str4 != null && str4.equals(location2)) {
                this.uploadingWallpaper = null;
                return;
            }
            Theme.ThemeInfo themeInfo2 = this.uploadingThemes.remove(location2);
            if (themeInfo2 != null) {
                themeInfo2.uploadedFile = null;
                themeInfo2.uploadedThumb = null;
            }
        } else if (id == NotificationCenter.messageReceivedByServer) {
            Boolean scheduled = (Boolean) args[6];
            if (scheduled.booleanValue()) {
                return;
            }
            Integer msgId = (Integer) args[0];
            Integer newMsgId = (Integer) args[1];
            Long did = (Long) args[3];
            MessageObject obj = this.dialogMessage.get(did.longValue());
            if (obj != null && (obj.getId() == msgId.intValue() || obj.messageOwner.local_id == msgId.intValue())) {
                obj.messageOwner.id = newMsgId.intValue();
                obj.messageOwner.send_state = 0;
            }
            TLRPC.Dialog dialog = this.dialogs_dict.get(did.longValue());
            if (dialog != null && dialog.top_message == msgId.intValue()) {
                dialog.top_message = newMsgId.intValue();
                getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
            }
            MessageObject obj2 = this.dialogMessagesByIds.get(msgId.intValue());
            this.dialogMessagesByIds.remove(msgId.intValue());
            if (obj2 != null) {
                this.dialogMessagesByIds.put(newMsgId.intValue(), obj2);
            }
            int lowerId = (int) did.longValue();
            if (lowerId < 0) {
                TLRPC.ChatFull chatFull = this.fullChats.get(-lowerId);
                TLRPC.Chat chat = getChat(Integer.valueOf(-lowerId));
                if (chat != null && !ChatObject.hasAdminRights(chat) && chatFull != null && chatFull.slowmode_seconds != 0) {
                    chatFull.slowmode_next_send_date = ConnectionsManager.getInstance(this.currentAccount).getCurrentTime() + chatFull.slowmode_seconds;
                    chatFull.flags |= 262144;
                    getMessagesStorage().updateChatInfo(chatFull, false);
                }
            }
        } else if (id == NotificationCenter.updateMessageMedia) {
            TLRPC.Message message = (TLRPC.Message) args[0];
            MessageObject existMessageObject = this.dialogMessagesByIds.get(message.id);
            if (existMessageObject != null) {
                existMessageObject.messageOwner.media = message.media;
                if (message.media.ttl_seconds != 0) {
                    if ((message.media.photo instanceof TLRPC.TL_photoEmpty) || (message.media.document instanceof TLRPC.TL_documentEmpty)) {
                        existMessageObject.setType();
                        getNotificationCenter().postNotificationName(NotificationCenter.notificationsSettingsUpdated, new Object[0]);
                    }
                }
            }
        }
    }

    public void lambda$didReceivedNotification$8$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.User user = getUser(Integer.valueOf(getUserConfig().getClientUserId()));
            if (user == null) {
                user = getUserConfig().getCurrentUser();
                putUser(user, true);
            } else {
                getUserConfig().setCurrentUser(user);
            }
            if (user == null) {
                return;
            }
            TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
            ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
            TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100);
            TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000);
            user.photo = new TLRPC.TL_userProfilePhoto();
            user.photo.photo_id = photo.photo.id;
            if (smallSize != null) {
                user.photo.photo_small = smallSize.location;
            }
            if (bigSize != null) {
                user.photo.photo_big = bigSize.location;
            } else if (smallSize != null) {
                user.photo.photo_small = smallSize.location;
            }
            getMessagesStorage().clearUserPhotos(user.id);
            ArrayList<TLRPC.User> users = new ArrayList<>();
            users.add(user);
            getMessagesStorage().putUsersAndChats(users, null, false, true);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$7$MessagesController();
                }
            });
        }
    }

    public void lambda$null$7$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 2);
        getUserConfig().saveConfig(true);
    }

    public void lambda$didReceivedNotification$10$MessagesController(final TLRPC.TL_wallPaperSettings settings, TLObject response, TLRPC.TL_error error) {
        final TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) response;
        final File path = new File(ApplicationLoader.getFilesDirFixed(), this.uploadingWallpaperBlurred ? "wallpaper_original.jpg" : "wallpaper.jpg");
        if (wallPaper != null) {
            try {
                AndroidUtilities.copyFile(path, FileLoader.getPathToAttach(wallPaper.document, true));
            } catch (Exception e) {
            }
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$9$MessagesController(wallPaper, settings, path);
            }
        });
    }

    public void lambda$null$9$MessagesController(TLRPC.TL_wallPaper wallPaper, TLRPC.TL_wallPaperSettings settings, File path) {
        if (this.uploadingWallpaper != null && wallPaper != null) {
            wallPaper.settings = settings;
            wallPaper.flags |= 4;
            SharedPreferences preferences = getGlobalMainSettings();
            SharedPreferences.Editor editor = preferences.edit();
            editor.putLong("selectedBackground2", wallPaper.id);
            editor.putString("selectedBackgroundSlug", wallPaper.slug);
            editor.commit();
            ArrayList<TLRPC.WallPaper> wallpapers = new ArrayList<>();
            wallpapers.add(wallPaper);
            getMessagesStorage().putWallpapers(wallpapers, 2);
            TLRPC.PhotoSize image = FileLoader.getClosestPhotoSizeWithSize(wallPaper.document.thumbs, 320);
            if (image != null) {
                String newKey = image.location.volume_id + "_" + image.location.local_id + "@100_100";
                String oldKey = Utilities.MD5(path.getAbsolutePath()) + "@100_100";
                ImageLoader.getInstance().replaceImageInCache(oldKey, newKey, ImageLocation.getForDocument(image, wallPaper.document), false);
            }
            NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.wallpapersNeedReload, Long.valueOf(wallPaper.id));
        }
    }

    public void lambda$didReceivedNotification$16$MessagesController(final Theme.ThemeInfo themeInfo, TLObject response, TLRPC.TL_error error) {
        int index = themeInfo.name.lastIndexOf(".attheme");
        String n = themeInfo.name;
        if (index > 0) {
            n = n.substring(0, index);
        }
        if (response != null) {
            TLRPC.Document document = (TLRPC.Document) response;
            TLRPC.TL_inputDocument inputDocument = new TLRPC.TL_inputDocument();
            inputDocument.access_hash = document.access_hash;
            inputDocument.id = document.id;
            inputDocument.file_reference = document.file_reference;
            if (themeInfo.info == null || !themeInfo.info.creator) {
                TLRPC.TL_account_createTheme req2 = new TLRPC.TL_account_createTheme();
                req2.document = inputDocument;
                req2.slug = (themeInfo.info == null || TextUtils.isEmpty(themeInfo.info.slug)) ? "" : themeInfo.info.slug;
                req2.title = n;
                getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$null$12$MessagesController(themeInfo, tLObject, tL_error);
                    }
                });
                return;
            }
            TLRPC.TL_account_updateTheme req22 = new TLRPC.TL_account_updateTheme();
            TLRPC.TL_inputTheme inputTheme = new TLRPC.TL_inputTheme();
            inputTheme.id = themeInfo.info.id;
            inputTheme.access_hash = themeInfo.info.access_hash;
            req22.theme = inputTheme;
            req22.slug = themeInfo.info.slug;
            req22.flags |= 1;
            req22.title = n;
            req22.flags |= 2;
            req22.document = inputDocument;
            req22.flags |= 4;
            req22.format = "android";
            getConnectionsManager().sendRequest(req22, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$null$14$MessagesController(themeInfo, tLObject, tL_error);
                }
            });
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$15$MessagesController(themeInfo);
            }
        });
    }

    public void lambda$null$12$MessagesController(final Theme.ThemeInfo themeInfo, final TLObject response1, TLRPC.TL_error error1) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$11$MessagesController(response1, themeInfo);
            }
        });
    }

    public void lambda$null$11$MessagesController(TLObject response1, Theme.ThemeInfo themeInfo) {
        if (response1 instanceof TLRPC.TL_theme) {
            Theme.setThemeUploadInfo(themeInfo, (TLRPC.TL_theme) response1, false);
            installTheme(themeInfo, themeInfo == Theme.getCurrentNightTheme());
            getNotificationCenter().postNotificationName(NotificationCenter.themeUploadedToServer, themeInfo);
            return;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.themeUploadError, themeInfo);
    }

    public void lambda$null$14$MessagesController(final Theme.ThemeInfo themeInfo, final TLObject response1, TLRPC.TL_error error1) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$13$MessagesController(response1, themeInfo);
            }
        });
    }

    public void lambda$null$13$MessagesController(TLObject response1, Theme.ThemeInfo themeInfo) {
        if (response1 instanceof TLRPC.TL_theme) {
            Theme.setThemeUploadInfo(themeInfo, (TLRPC.TL_theme) response1, false);
            getNotificationCenter().postNotificationName(NotificationCenter.themeUploadedToServer, themeInfo);
            return;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.themeUploadError, themeInfo);
    }

    public void lambda$null$15$MessagesController(Theme.ThemeInfo themeInfo) {
        getNotificationCenter().postNotificationName(NotificationCenter.themeUploadError, themeInfo);
    }

    public void cleanup() {
        getContactsController().cleanup();
        MediaController.getInstance().cleanup();
        getNotificationsController().cleanup();
        getSendMessagesHelper().cleanup();
        getSecretChatHelper().cleanup();
        getLocationController().cleanup();
        getMediaDataController().cleanup();
        DialogsActivity.dialogsLoaded[this.currentAccount] = false;
        SharedPreferences.Editor editor = this.notificationsPreferences.edit();
        editor.clear().commit();
        SharedPreferences.Editor editor2 = this.emojiPreferences.edit();
        editor2.putLong("lastGifLoadTime", 0L).putLong("lastStickersLoadTime", 0L).putLong("lastStickersLoadTimeMask", 0L).putLong("lastStickersLoadTimeFavs", 0L).commit();
        SharedPreferences.Editor editor3 = this.mainPreferences.edit();
        editor3.remove("archivehint").remove("archivehint_l").remove("gifhint").remove("soundHint").remove("dcDomainName2").remove("webFileDatacenterId").remove("last_contacts_get_diff").remove("contacts_apply_id").remove("contacts_apply_hash").remove("contacts_apply_count").commit();
        this.lastScheduledServerQueryTime.clear();
        this.reloadingWebpages.clear();
        this.reloadingWebpagesPending.clear();
        this.reloadingScheduledWebpages.clear();
        this.reloadingScheduledWebpagesPending.clear();
        this.dialogs_dict.clear();
        this.dialogs_read_inbox_max.clear();
        this.loadingPinnedDialogs.clear();
        this.dialogs_read_outbox_max.clear();
        this.exportedChats.clear();
        this.fullUsers.clear();
        this.fullChats.clear();
        this.dialogsByFolder.clear();
        this.unreadUnmutedDialogs = 0;
        this.joiningToChannels.clear();
        this.migratedChats.clear();
        this.channelViewsToSend.clear();
        this.pollsToCheck.clear();
        this.pollsToCheckSize = 0;
        this.dialogsServerOnly.clear();
        this.dialogsForward.clear();
        this.allDialogs.clear();
        this.dialogsCanAddUsers.clear();
        this.dialogsChannelsOnly.clear();
        this.dialogsGroupsOnly.clear();
        this.dialogsUnreadOnly.clear();
        this.dialogsUsersOnly.clear();
        this.dialogMessagesByIds.clear();
        this.dialogMessagesByRandomIds.clear();
        this.channelAdmins.clear();
        this.loadingChannelAdmins.clear();
        this.users.clear();
        this.objectsByUsernames.clear();
        this.chats.clear();
        this.dialogMessage.clear();
        this.deletedHistory.clear();
        this.printingUsers.clear();
        this.printingStrings.clear();
        this.printingStringsTypes.clear();
        this.onlinePrivacy.clear();
        this.loadingPeerSettings.clear();
        this.deletingDialogs.clear();
        this.clearingHistoryDialogs.clear();
        this.lastPrintingStringCount = 0;
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$cleanup$17$MessagesController();
            }
        });
        this.createdDialogMainThreadIds.clear();
        this.visibleDialogMainThreadIds.clear();
        this.visibleScheduledDialogMainThreadIds.clear();
        this.blockedUsers.clear();
        this.sendingTypings.clear();
        this.loadingFullUsers.clear();
        this.loadedFullUsers.clear();
        this.reloadingMessages.clear();
        this.loadingFullChats.clear();
        this.loadingFullParticipants.clear();
        this.loadedFullParticipants.clear();
        this.loadedFullChats.clear();
        this.dialogsLoaded = false;
        this.nextDialogsCacheOffset.clear();
        this.loadingDialogs.clear();
        this.dialogsEndReached.clear();
        this.serverDialogsEndReached.clear();
        this.loadingAppConfig = false;
        this.checkingTosUpdate = false;
        this.nextTosCheckTime = 0;
        this.nextProxyInfoCheckTime = 0;
        this.checkingProxyInfo = false;
        this.loadingUnreadDialogs = false;
        this.currentDeletingTaskTime = 0;
        this.currentDeletingTaskMids = null;
        this.currentDeletingTaskChannelId = 0;
        this.gettingNewDeleteTask = false;
        this.loadingBlockedUsers = false;
        this.totalBlockedCount = -1;
        this.blockedEndReached = false;
        this.firstGettingTask = false;
        this.updatingState = false;
        this.resetingDialogs = false;
        this.lastStatusUpdateTime = 0L;
        this.offlineSent = false;
        this.registeringForPush = false;
        this.getDifferenceFirstSync = true;
        this.uploadingAvatar = null;
        this.uploadingWallpaper = null;
        this.uploadingThemes.clear();
        this.statusRequest = 0;
        this.statusSettingState = 0;
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$cleanup$18$MessagesController();
            }
        });
        if (this.currentDeleteTaskRunnable != null) {
            Utilities.stageQueue.cancelRunnable(this.currentDeleteTaskRunnable);
            this.currentDeleteTaskRunnable = null;
        }
        addSupportUser();
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        AppPreferenceUtil.putString("PublishFcBean", "");
        FcDBHelper.getInstance().deleteAll(HomeFcListBean.class);
        FcDBHelper.getInstance().deleteAll(RecommendFcListBean.class);
        FcDBHelper.getInstance().deleteAll(FollowedFcListBean.class);
    }

    public void lambda$cleanup$17$MessagesController() {
        this.readTasks.clear();
        this.readTasksMap.clear();
        this.updatesQueueSeq.clear();
        this.updatesQueuePts.clear();
        this.updatesQueueQts.clear();
        this.gettingUnknownChannels.clear();
        this.gettingUnknownDialogs.clear();
        this.updatesStartWaitTimeSeq = 0L;
        this.updatesStartWaitTimePts = 0L;
        this.updatesStartWaitTimeQts = 0L;
        this.createdDialogIds.clear();
        this.createdScheduledDialogIds.clear();
        this.gettingDifference = false;
        this.resetDialogsPinned = null;
        this.resetDialogsAll = null;
    }

    public void lambda$cleanup$18$MessagesController() {
        getConnectionsManager().setIsUpdating(false);
        this.updatesQueueChannels.clear();
        this.updatesStartWaitTimeChannels.clear();
        this.gettingDifferenceChannels.clear();
        this.channelsPts.clear();
        this.shortPollChannels.clear();
        this.needShortPollChannels.clear();
        this.shortPollOnlines.clear();
        this.needShortPollOnlines.clear();
    }

    public TLRPC.User getUser(Integer id) {
        return this.users.get(id);
    }

    public TLObject getUserOrChat(String username) {
        if (username == null || username.length() == 0) {
            return null;
        }
        return this.objectsByUsernames.get(username.toLowerCase());
    }

    public ConcurrentHashMap<Integer, TLRPC.User> getUsers() {
        return this.users;
    }

    public ConcurrentHashMap<Integer, TLRPC.Chat> getChats() {
        return this.chats;
    }

    public TLRPC.Chat getChat(Integer id) {
        return this.chats.get(id);
    }

    public TLRPC.EncryptedChat getEncryptedChat(Integer id) {
        return this.encryptedChats.get(id);
    }

    public TLRPC.EncryptedChat getEncryptedChatDB(int chat_id, boolean created) {
        TLRPC.EncryptedChat chat = this.encryptedChats.get(Integer.valueOf(chat_id));
        if (chat != null) {
            if (!created) {
                return chat;
            }
            if (!(chat instanceof TLRPC.TL_encryptedChatWaiting) && !(chat instanceof TLRPC.TL_encryptedChatRequested)) {
                return chat;
            }
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        ArrayList<TLObject> result = new ArrayList<>();
        getMessagesStorage().getEncryptedChat(chat_id, countDownLatch, result);
        try {
            countDownLatch.await();
        } catch (Exception e) {
            FileLog.e(e);
        }
        if (result.size() == 2) {
            TLRPC.EncryptedChat chat2 = (TLRPC.EncryptedChat) result.get(0);
            TLRPC.User user = (TLRPC.User) result.get(1);
            putEncryptedChat(chat2, false);
            putUser(user, true);
            return chat2;
        }
        return chat;
    }

    public boolean isDialogVisible(long dialog_id, boolean scheduled) {
        return (scheduled ? this.visibleScheduledDialogMainThreadIds : this.visibleDialogMainThreadIds).contains(Long.valueOf(dialog_id));
    }

    public void setLastVisibleDialogId(long dialog_id, boolean scheduled, boolean set) {
        ArrayList<Long> arrayList = scheduled ? this.visibleScheduledDialogMainThreadIds : this.visibleDialogMainThreadIds;
        if (set) {
            if (arrayList.contains(Long.valueOf(dialog_id))) {
                return;
            }
            arrayList.add(Long.valueOf(dialog_id));
            return;
        }
        arrayList.remove(Long.valueOf(dialog_id));
    }

    public void setLastCreatedDialogId(final long dialogId, final boolean scheduled, final boolean set) {
        if (!scheduled) {
            ArrayList<Long> arrayList = this.createdDialogMainThreadIds;
            if (set) {
                if (arrayList.contains(Long.valueOf(dialogId))) {
                    return;
                }
                arrayList.add(Long.valueOf(dialogId));
            } else {
                arrayList.remove(Long.valueOf(dialogId));
                SparseArray<MessageObject> array = this.pollsToCheck.get(dialogId);
                if (array != null) {
                    int N = array.size();
                    for (int a = 0; a < N; a++) {
                        MessageObject object = array.valueAt(a);
                        object.pollVisibleOnScreen = false;
                    }
                }
            }
        }
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$setLastCreatedDialogId$19$MessagesController(scheduled, set, dialogId);
            }
        });
    }

    public void lambda$setLastCreatedDialogId$19$MessagesController(boolean scheduled, boolean set, long dialogId) {
        ArrayList<Long> arrayList2 = scheduled ? this.createdScheduledDialogIds : this.createdDialogIds;
        if (set) {
            if (arrayList2.contains(Long.valueOf(dialogId))) {
                return;
            }
            arrayList2.add(Long.valueOf(dialogId));
            return;
        }
        arrayList2.remove(Long.valueOf(dialogId));
    }

    public TLRPC.ExportedChatInvite getExportedInvite(int chat_id) {
        return this.exportedChats.get(chat_id);
    }

    public boolean putUser(TLRPC.User user, boolean fromCache) {
        if (user == null) {
            return false;
        }
        boolean fromCache2 = (!fromCache || user.id / 1000 == 333 || user.id == 777000) ? false : true;
        TLRPC.User oldUser = this.users.get(Integer.valueOf(user.id));
        if (oldUser == user) {
            return false;
        }
        if (oldUser != null && !TextUtils.isEmpty(oldUser.username)) {
            this.objectsByUsernames.remove(oldUser.username.toLowerCase());
        }
        if (!TextUtils.isEmpty(user.username)) {
            this.objectsByUsernames.put(user.username.toLowerCase(), user);
        }
        if (user.min) {
            if (oldUser != null) {
                if (!fromCache2) {
                    if (user.bot) {
                        if (user.username != null) {
                            oldUser.username = user.username;
                            oldUser.flags |= 8;
                        } else {
                            oldUser.flags &= -9;
                            oldUser.username = null;
                        }
                    }
                    if (user.photo != null) {
                        oldUser.photo = user.photo;
                        oldUser.flags |= 32;
                    } else {
                        oldUser.flags &= -33;
                        oldUser.photo = null;
                    }
                }
            } else {
                this.users.put(Integer.valueOf(user.id), user);
            }
        } else if (!fromCache2) {
            this.users.put(Integer.valueOf(user.id), user);
            if (user.id == getUserConfig().getClientUserId()) {
                getUserConfig().setCurrentUser(user);
                getUserConfig().saveConfig(true);
            }
            if (oldUser != null && user.status != null && oldUser.status != null && user.status.expires != oldUser.status.expires) {
                return true;
            }
        } else if (oldUser == null) {
            this.users.put(Integer.valueOf(user.id), user);
        } else if (oldUser.min) {
            user.min = false;
            if (oldUser.bot) {
                if (oldUser.username != null) {
                    user.username = oldUser.username;
                    user.flags |= 8;
                } else {
                    user.flags &= -9;
                    user.username = null;
                }
            }
            if (oldUser.photo != null) {
                user.photo = oldUser.photo;
                user.flags |= 32;
            } else {
                user.flags &= -33;
                user.photo = null;
            }
            this.users.put(Integer.valueOf(user.id), user);
        }
        return false;
    }

    public void putUsers(ArrayList<TLRPC.User> users, boolean fromCache) {
        if (users == null || users.isEmpty()) {
            return;
        }
        boolean updateStatus = false;
        int count = users.size();
        for (int a = 0; a < count; a++) {
            TLRPC.User user = users.get(a);
            if (putUser(user, fromCache)) {
                updateStatus = true;
            }
        }
        if (updateStatus) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$putUsers$20$MessagesController();
                }
            });
        }
    }

    public void lambda$putUsers$20$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 4);
    }

    public void putChat(final TLRPC.Chat chat, boolean fromCache) {
        TLRPC.Chat oldChat;
        if (chat == null || (oldChat = this.chats.get(Integer.valueOf(chat.id))) == chat) {
            return;
        }
        if (oldChat != null && !TextUtils.isEmpty(oldChat.username)) {
            this.objectsByUsernames.remove(oldChat.username.toLowerCase());
        }
        if (!TextUtils.isEmpty(chat.username)) {
            this.objectsByUsernames.put(chat.username.toLowerCase(), chat);
        }
        if (chat.min) {
            if (oldChat != null) {
                if (!fromCache) {
                    oldChat.title = chat.title;
                    oldChat.photo = chat.photo;
                    oldChat.broadcast = chat.broadcast;
                    oldChat.verified = chat.verified;
                    oldChat.megagroup = chat.megagroup;
                    if (chat.default_banned_rights != null) {
                        oldChat.default_banned_rights = chat.default_banned_rights;
                        oldChat.flags |= 262144;
                    }
                    if (chat.admin_rights != null) {
                        oldChat.admin_rights = chat.admin_rights;
                        oldChat.flags |= 16384;
                    }
                    if (chat.banned_rights != null) {
                        oldChat.banned_rights = chat.banned_rights;
                        oldChat.flags |= 32768;
                    }
                    if (chat.username != null) {
                        oldChat.username = chat.username;
                        oldChat.flags |= 64;
                    } else {
                        oldChat.flags &= -65;
                        oldChat.username = null;
                    }
                    if (chat.participants_count != 0) {
                        oldChat.participants_count = chat.participants_count;
                        return;
                    }
                    return;
                }
                return;
            }
            this.chats.put(Integer.valueOf(chat.id), chat);
            return;
        }
        if (!fromCache) {
            if (oldChat != null) {
                if (chat.version != oldChat.version) {
                    this.loadedFullChats.remove(Integer.valueOf(chat.id));
                }
                if (oldChat.participants_count != 0 && chat.participants_count == 0) {
                    chat.participants_count = oldChat.participants_count;
                    chat.flags = 131072 | chat.flags;
                }
                int oldFlags = oldChat.banned_rights != null ? oldChat.banned_rights.flags : 0;
                int newFlags = chat.banned_rights != null ? chat.banned_rights.flags : 0;
                int oldFlags2 = oldChat.default_banned_rights != null ? oldChat.default_banned_rights.flags : 0;
                int newFlags2 = chat.default_banned_rights != null ? chat.default_banned_rights.flags : 0;
                oldChat.default_banned_rights = chat.default_banned_rights;
                if (oldChat.default_banned_rights == null) {
                    oldChat.flags &= -262145;
                } else {
                    oldChat.flags = 262144 | oldChat.flags;
                }
                oldChat.banned_rights = chat.banned_rights;
                if (oldChat.banned_rights == null) {
                    oldChat.flags &= -32769;
                } else {
                    oldChat.flags = 32768 | oldChat.flags;
                }
                oldChat.admin_rights = chat.admin_rights;
                if (oldChat.admin_rights == null) {
                    oldChat.flags &= -16385;
                } else {
                    oldChat.flags |= 16384;
                }
                if (oldFlags != newFlags || oldFlags2 != newFlags2) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            MessagesController.this.lambda$putChat$21$MessagesController(chat);
                        }
                    });
                }
            }
            this.chats.put(Integer.valueOf(chat.id), chat);
        } else if (oldChat == null) {
            this.chats.put(Integer.valueOf(chat.id), chat);
        } else if (oldChat.min) {
            chat.min = false;
            chat.title = oldChat.title;
            chat.photo = oldChat.photo;
            chat.broadcast = oldChat.broadcast;
            chat.verified = oldChat.verified;
            chat.megagroup = oldChat.megagroup;
            if (oldChat.default_banned_rights != null) {
                chat.default_banned_rights = oldChat.default_banned_rights;
                chat.flags = 262144 | chat.flags;
            }
            if (oldChat.admin_rights != null) {
                chat.admin_rights = oldChat.admin_rights;
                chat.flags |= 16384;
            }
            if (oldChat.banned_rights != null) {
                chat.banned_rights = oldChat.banned_rights;
                chat.flags = 32768 | chat.flags;
            }
            if (oldChat.username != null) {
                chat.username = oldChat.username;
                chat.flags |= 64;
            } else {
                chat.flags &= -65;
                chat.username = null;
            }
            if (oldChat.participants_count != 0 && chat.participants_count == 0) {
                chat.participants_count = oldChat.participants_count;
                chat.flags = 131072 | chat.flags;
            }
            this.chats.put(Integer.valueOf(chat.id), chat);
        }
    }

    public void lambda$putChat$21$MessagesController(TLRPC.Chat chat) {
        getNotificationCenter().postNotificationName(NotificationCenter.channelRightsUpdated, chat);
    }

    public void putChats(ArrayList<TLRPC.Chat> chats, boolean fromCache) {
        if (chats == null || chats.isEmpty()) {
            return;
        }
        int count = chats.size();
        for (int a = 0; a < count; a++) {
            TLRPC.Chat chat = chats.get(a);
            putChat(chat, fromCache);
        }
    }

    public void setReferer(String referer) {
        if (referer == null) {
            return;
        }
        this.installReferer = referer;
        this.mainPreferences.edit().putString("installReferer", referer).commit();
    }

    public void putEncryptedChat(TLRPC.EncryptedChat encryptedChat, boolean fromCache) {
        if (encryptedChat == null) {
            return;
        }
        if (fromCache) {
            this.encryptedChats.putIfAbsent(Integer.valueOf(encryptedChat.id), encryptedChat);
        } else {
            this.encryptedChats.put(Integer.valueOf(encryptedChat.id), encryptedChat);
        }
    }

    public void putEncryptedChats(ArrayList<TLRPC.EncryptedChat> encryptedChats, boolean fromCache) {
        if (encryptedChats == null || encryptedChats.isEmpty()) {
            return;
        }
        int count = encryptedChats.size();
        for (int a = 0; a < count; a++) {
            TLRPC.EncryptedChat encryptedChat = encryptedChats.get(a);
            putEncryptedChat(encryptedChat, fromCache);
        }
    }

    public TLRPC.UserFull getUserFull(int uid) {
        return this.fullUsers.get(uid);
    }

    public TLRPC.ChatFull getChatFull(int chatId) {
        return this.fullChats.get(chatId);
    }

    public void cancelLoadFullUser(int uid) {
        this.loadingFullUsers.remove(Integer.valueOf(uid));
    }

    public void cancelLoadFullChat(int cid) {
        this.loadingFullChats.remove(Integer.valueOf(cid));
    }

    public void clearFullUsers() {
        this.loadedFullUsers.clear();
        this.loadedFullChats.clear();
    }

    private void reloadDialogsReadValue(ArrayList<TLRPC.Dialog> dialogs, long did) {
        if (did == 0 && (dialogs == null || dialogs.isEmpty())) {
            return;
        }
        TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
        if (dialogs != null) {
            for (int a = 0; a < dialogs.size(); a++) {
                TLRPC.InputPeer inputPeer = getInputPeer((int) dialogs.get(a).id);
                if (!(inputPeer instanceof TLRPC.TL_inputPeerChannel) || inputPeer.access_hash != 0) {
                    TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
                    inputDialogPeer.peer = inputPeer;
                    req.peers.add(inputDialogPeer);
                }
            }
        } else {
            TLRPC.InputPeer inputPeer2 = getInputPeer((int) did);
            if ((inputPeer2 instanceof TLRPC.TL_inputPeerChannel) && inputPeer2.access_hash == 0) {
                return;
            }
            TLRPC.TL_inputDialogPeer inputDialogPeer2 = new TLRPC.TL_inputDialogPeer();
            inputDialogPeer2.peer = inputPeer2;
            req.peers.add(inputDialogPeer2);
        }
        if (req.peers.isEmpty()) {
            return;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$reloadDialogsReadValue$22$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$reloadDialogsReadValue$22$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
            ArrayList<TLRPC.Update> arrayList = new ArrayList<>();
            for (int a = 0; a < res.dialogs.size(); a++) {
                TLRPC.Dialog dialog = res.dialogs.get(a);
                if (dialog.read_inbox_max_id == 0) {
                    dialog.read_inbox_max_id = 1;
                }
                if (dialog.read_outbox_max_id == 0) {
                    dialog.read_outbox_max_id = 1;
                }
                DialogObject.initDialog(dialog);
                Integer value = this.dialogs_read_inbox_max.get(Long.valueOf(dialog.id));
                if (value == null) {
                    value = 0;
                }
                this.dialogs_read_inbox_max.put(Long.valueOf(dialog.id), Integer.valueOf(Math.max(dialog.read_inbox_max_id, value.intValue())));
                if (value.intValue() == 0) {
                    if (dialog.peer.channel_id != 0) {
                        TLRPC.TL_updateReadChannelInbox update = new TLRPC.TL_updateReadChannelInbox();
                        update.channel_id = dialog.peer.channel_id;
                        update.max_id = dialog.read_inbox_max_id;
                        arrayList.add(update);
                    } else {
                        TLRPC.TL_updateReadHistoryInbox update2 = new TLRPC.TL_updateReadHistoryInbox();
                        update2.peer = dialog.peer;
                        update2.max_id = dialog.read_inbox_max_id;
                        arrayList.add(update2);
                    }
                }
                Integer value2 = this.dialogs_read_outbox_max.get(Long.valueOf(dialog.id));
                if (value2 == null) {
                    value2 = 0;
                }
                this.dialogs_read_outbox_max.put(Long.valueOf(dialog.id), Integer.valueOf(Math.max(dialog.read_outbox_max_id, value2.intValue())));
                if (value2.intValue() == 0) {
                    if (dialog.peer.channel_id != 0) {
                        TLRPC.TL_updateReadChannelOutbox update3 = new TLRPC.TL_updateReadChannelOutbox();
                        update3.channel_id = dialog.peer.channel_id;
                        update3.max_id = dialog.read_outbox_max_id;
                        arrayList.add(update3);
                    } else {
                        TLRPC.TL_updateReadHistoryOutbox update4 = new TLRPC.TL_updateReadHistoryOutbox();
                        update4.peer = dialog.peer;
                        update4.max_id = dialog.read_outbox_max_id;
                        arrayList.add(update4);
                    }
                }
            }
            if (!arrayList.isEmpty()) {
                processUpdateArray(arrayList, null, null, false, 0);
            }
        }
    }

    public String getAdminRank(int chatId, int uid) {
        SparseArray<String> array = this.channelAdmins.get(chatId);
        if (array == null) {
            return null;
        }
        return array.get(uid);
    }

    public boolean isChannelAdminsLoaded(int chatId) {
        return this.channelAdmins.get(chatId) != null;
    }

    public void loadChannelAdmins(final int chatId, boolean cache) {
        int loadTime = this.loadingChannelAdmins.get(chatId);
        if (SystemClock.uptimeMillis() - loadTime < 60) {
            return;
        }
        this.loadingChannelAdmins.put(chatId, (int) (SystemClock.uptimeMillis() / 1000));
        if (cache) {
            getMessagesStorage().loadChannelAdmins(chatId);
            return;
        }
        TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants();
        req.channel = getInputChannel(chatId);
        req.limit = 100;
        req.filter = new TLRPC.TL_channelParticipantsAdmins();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadChannelAdmins$23$MessagesController(chatId, tLObject, tL_error);
            }
        });
    }

    public void lambda$loadChannelAdmins$23$MessagesController(int chatId, TLObject response, TLRPC.TL_error error) {
        if (response instanceof TLRPC.TL_channels_channelParticipants) {
            processLoadedAdminsResponse(chatId, (TLRPC.TL_channels_channelParticipants) response);
        }
    }

    public void processLoadedAdminsResponse(int chatId, TLRPC.TL_channels_channelParticipants participants) {
        SparseArray<String> array1 = new SparseArray<>(participants.participants.size());
        for (int a = 0; a < participants.participants.size(); a++) {
            TLRPC.ChannelParticipant participant = participants.participants.get(a);
            array1.put(participant.user_id, participant.rank != null ? participant.rank : "");
        }
        processLoadedChannelAdmins(array1, chatId, false);
    }

    public void processLoadedChannelAdmins(final SparseArray<String> array, final int chatId, final boolean cache) {
        if (!cache) {
            getMessagesStorage().putChannelAdmins(chatId, array);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processLoadedChannelAdmins$24$MessagesController(chatId, array, cache);
            }
        });
    }

    public void lambda$processLoadedChannelAdmins$24$MessagesController(int chatId, SparseArray array, boolean cache) {
        this.channelAdmins.put(chatId, array);
        if (cache) {
            this.loadingChannelAdmins.delete(chatId);
            loadChannelAdmins(chatId, false);
        }
    }

    public void loadUsers(int[] userIds, long[] accessHashs, int classGuid) {
        if (userIds == null || accessHashs == null || userIds.length != accessHashs.length) {
            return;
        }
        ArrayList<Integer> emptyResult = new ArrayList<>();
        if (this.users != null) {
            for (int userId : userIds) {
                TLRPC.User user = this.users.get(Integer.valueOf(userId));
                if (user != null) {
                    getNotificationCenter().postNotificationName(NotificationCenter.userInfoDidLoad, Integer.valueOf(user.id), user);
                } else {
                    emptyResult.add(Integer.valueOf(userId));
                }
            }
            if (emptyResult.size() > 0) {
                loadUsers(emptyResult, accessHashs, classGuid);
            }
        }
    }

    public void loadUsers(ArrayList<Integer> idList, long[] accessHashs, int classGuid) {
        if (idList == null || accessHashs == null || idList.size() != accessHashs.length) {
            return;
        }
        ArrayList<TLRPC.InputUser> list = new ArrayList<>();
        for (int i = 0; i < idList.size(); i++) {
            TLRPC.InputUser user = new TLRPC.TL_inputUser();
            user.user_id = idList.get(i).intValue();
            user.access_hash = accessHashs[i];
            list.add(user);
        }
        loadUsers(list, classGuid);
    }

    public void loadUsers(ArrayList<TLRPC.InputUser> users, int classGuid) {
        if (users == null) {
            return;
        }
        TLRPC.TL_users_getUsers req = new TLRPC.TL_users_getUsers();
        req.id.addAll(users);
        getConnectionsManager().bindRequestToGuid(getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadUsers$26$MessagesController(tLObject, tL_error);
            }
        }), classGuid);
    }

    public void lambda$loadUsers$26$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (response instanceof TLRPC.Vector) {
            TLRPC.Vector vector = (TLRPC.Vector) response;
            if (!vector.objects.isEmpty()) {
                for (int i = 0; i < vector.objects.size(); i++) {
                    ArrayList<TLRPC.User> arrayList1 = new ArrayList<>();
                    final TLRPC.User user = (TLRPC.User) vector.objects.get(i);
                    arrayList1.add(user);
                    getMessagesStorage().putUsersAndChats(arrayList1, null, false, true);
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            MessagesController.this.lambda$null$25$MessagesController(user);
                        }
                    });
                }
            }
        }
    }

    public void lambda$null$25$MessagesController(TLRPC.User user) {
        putUser(user, false);
        getNotificationCenter().postNotificationName(NotificationCenter.userInfoDidLoad, Integer.valueOf(user.id), user);
    }

    public void loadFullChat(final int chat_id, final int classGuid, boolean force) {
        TLObject request;
        boolean loaded = this.loadedFullChats.contains(Integer.valueOf(chat_id));
        if (this.loadingFullChats.contains(Integer.valueOf(chat_id))) {
            return;
        }
        if (!force && loaded) {
            return;
        }
        this.loadingFullChats.add(Integer.valueOf(chat_id));
        final long dialog_id = -chat_id;
        final TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
        if (ChatObject.isChannel(chat)) {
            TLRPC.TL_channels_getFullChannel req = new TLRPC.TL_channels_getFullChannel();
            req.channel = getInputChannel(chat);
            if (chat.megagroup) {
                loadChannelAdmins(chat_id, !loaded);
            }
            request = req;
        } else {
            TLRPC.TL_messages_getFullChat req2 = new TLRPC.TL_messages_getFullChat();
            req2.chat_id = chat_id;
            if (this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id)) == null || this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id)) == null) {
                reloadDialogsReadValue(null, dialog_id);
            }
            request = req2;
        }
        int reqId = getConnectionsManager().sendRequest(request, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadFullChat$29$MessagesController(chat, dialog_id, chat_id, classGuid, tLObject, tL_error);
            }
        });
        if (classGuid != 0) {
            getConnectionsManager().bindRequestToGuid(reqId, classGuid);
        }
    }

    public void lambda$loadFullChat$29$MessagesController(TLRPC.Chat chat, long dialog_id, final int chat_id, final int classGuid, TLObject response, final TLRPC.TL_error error) {
        Integer value;
        Integer value2;
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$28$MessagesController(error, chat_id);
                }
            });
            return;
        }
        final TLRPC.TL_messages_chatFull res = (TLRPC.TL_messages_chatFull) response;
        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
        getMessagesStorage().updateChatInfo(res.full_chat, false);
        if (ChatObject.isChannel(chat)) {
            Integer value3 = this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id));
            if (value3 != null) {
                value = value3;
            } else {
                value = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, dialog_id));
            }
            this.dialogs_read_inbox_max.put(Long.valueOf(dialog_id), Integer.valueOf(Math.max(res.full_chat.read_inbox_max_id, value.intValue())));
            if (value.intValue() == 0) {
                ArrayList<TLRPC.Update> arrayList = new ArrayList<>();
                TLRPC.TL_updateReadChannelInbox update = new TLRPC.TL_updateReadChannelInbox();
                update.channel_id = chat_id;
                update.max_id = res.full_chat.read_inbox_max_id;
                arrayList.add(update);
                processUpdateArray(arrayList, null, null, false, 0);
            }
            Integer value4 = this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id));
            if (value4 != null) {
                value2 = value4;
            } else {
                value2 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, dialog_id));
            }
            this.dialogs_read_outbox_max.put(Long.valueOf(dialog_id), Integer.valueOf(Math.max(res.full_chat.read_outbox_max_id, value2.intValue())));
            if (value2.intValue() == 0) {
                ArrayList<TLRPC.Update> arrayList2 = new ArrayList<>();
                TLRPC.TL_updateReadChannelOutbox update2 = new TLRPC.TL_updateReadChannelOutbox();
                update2.channel_id = chat_id;
                update2.max_id = res.full_chat.read_outbox_max_id;
                arrayList2.add(update2);
                processUpdateArray(arrayList2, null, null, false, 0);
            }
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$27$MessagesController(chat_id, res, classGuid);
            }
        });
    }

    public void lambda$null$27$MessagesController(int chat_id, TLRPC.TL_messages_chatFull res, int classGuid) {
        this.fullChats.put(chat_id, res.full_chat);
        applyDialogNotificationsSettings(-chat_id, res.full_chat.notify_settings);
        for (int a = 0; a < res.full_chat.bot_info.size(); a++) {
            TLRPC.BotInfo botInfo = res.full_chat.bot_info.get(a);
            getMediaDataController().putBotInfo(botInfo);
        }
        this.exportedChats.put(chat_id, res.full_chat.exported_invite);
        this.loadingFullChats.remove(Integer.valueOf(chat_id));
        this.loadedFullChats.add(Integer.valueOf(chat_id));
        putUsers(res.users, false);
        putChats(res.chats, false);
        if (res.full_chat.stickerset != null) {
            getMediaDataController().getGroupStickerSetById(res.full_chat.stickerset);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, res.full_chat, Integer.valueOf(classGuid), false, null);
    }

    public void lambda$null$28$MessagesController(TLRPC.TL_error error, int chat_id) {
        checkChannelError(error.text, chat_id);
        this.loadingFullChats.remove(Integer.valueOf(chat_id));
    }

    public void loadFullUser(TLRPC.User user, int classGuid, boolean force) {
        loadFullUser(user, 0, classGuid, force);
    }

    public void loadFullUser(int userId, int classGuid, boolean force) {
        loadFullUser(null, userId, classGuid, force);
    }

    public void loadFullUser(final TLRPC.User user, int userId, final int classGuid, boolean force) {
        if (user == null || this.loadingFullUsers.contains(Integer.valueOf(user.id)) || (!force && this.loadedFullUsers.contains(Integer.valueOf(user.id)))) {
            if (userId == 0 || this.loadingFullUsers.contains(Integer.valueOf(userId))) {
                return;
            }
            if (!force && this.loadedFullUsers.contains(Integer.valueOf(userId))) {
                return;
            }
        }
        final int searchId = user != null ? user.id : userId;
        this.loadingFullUsers.add(Integer.valueOf(searchId));
        TLRPCContacts.CL_user_getFulluser req = new TLRPCContacts.CL_user_getFulluser();
        req.inputUser = user != null ? getInputUser(user) : getInputUser(userId);
        long dialog_id = searchId;
        if (this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id)) == null || this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id)) == null) {
            reloadDialogsReadValue(null, dialog_id);
        }
        int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadFullUser$32$MessagesController(searchId, user, classGuid, tLObject, tL_error);
            }
        });
        getConnectionsManager().bindRequestToGuid(reqId, classGuid);
    }

    public void lambda$loadFullUser$32$MessagesController(final int searchId, final TLRPC.User user, final int classGuid, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            final TLRPC.UserFull userFull = (TLRPC.UserFull) response;
            getMessagesStorage().updateUserInfo(userFull, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$30$MessagesController(userFull, searchId, user, classGuid);
                }
            });
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$31$MessagesController(searchId);
            }
        });
    }

    public void lambda$null$30$MessagesController(TLRPC.UserFull userFull, int searchId, TLRPC.User user, int classGuid) {
        String names;
        savePeerSettings(userFull.user.id, userFull.settings, false);
        applyDialogNotificationsSettings(searchId, userFull.notify_settings);
        if (userFull.bot_info instanceof TLRPC.TL_botInfo) {
            getMediaDataController().putBotInfo(userFull.bot_info);
        }
        int index = this.blockedUsers.indexOfKey(searchId);
        if (userFull.blocked) {
            if (index < 0) {
                this.blockedUsers.put(searchId, 1);
                getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad, new Object[0]);
            }
        } else if (index >= 0) {
            this.blockedUsers.removeAt(index);
            getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad, new Object[0]);
        }
        this.fullUsers.put(searchId, userFull);
        this.loadingFullUsers.remove(Integer.valueOf(searchId));
        this.loadedFullUsers.add(Integer.valueOf(searchId));
        if (user != null) {
            names = user.first_name + user.last_name + user.username;
        } else {
            names = null;
        }
        ArrayList<TLRPC.User> users = new ArrayList<>();
        users.add(userFull.user);
        putUsers(users, false);
        getMessagesStorage().putUsersAndChats(users, null, false, true);
        if (names != null) {
            if (!names.equals(userFull.user.first_name + userFull.user.last_name + userFull.user.username)) {
                getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 1);
            }
        }
        if (userFull.bot_info instanceof TLRPC.TL_botInfo) {
            getNotificationCenter().postNotificationName(NotificationCenter.botInfoDidLoad, userFull.bot_info, Integer.valueOf(classGuid));
        }
        getNotificationCenter().postNotificationName(NotificationCenter.userFullInfoDidLoad, Integer.valueOf(searchId), userFull, 0);
    }

    public void lambda$null$31$MessagesController(int searchId) {
        this.loadingFullUsers.remove(Integer.valueOf(searchId));
    }

    private void reloadMessages(ArrayList<Integer> mids, final long dialog_id, final boolean scheduled) {
        TLObject request;
        ArrayList<Integer> arrayList;
        if (mids.isEmpty()) {
            return;
        }
        final ArrayList<Integer> result = new ArrayList<>();
        final TLRPC.Chat chat = ChatObject.getChatByDialog(dialog_id, this.currentAccount);
        if (ChatObject.isChannel(chat)) {
            TLRPC.TL_channels_getMessages req = new TLRPC.TL_channels_getMessages();
            req.channel = getInputChannel(chat);
            req.id = result;
            request = req;
        } else {
            TLRPC.TL_messages_getMessages req2 = new TLRPC.TL_messages_getMessages();
            req2.id = result;
            request = req2;
        }
        ArrayList<Integer> arrayList2 = this.reloadingMessages.get(dialog_id);
        for (int a = 0; a < mids.size(); a++) {
            Integer mid = mids.get(a);
            if (arrayList2 == null || !arrayList2.contains(mid)) {
                result.add(mid);
            }
        }
        if (result.isEmpty()) {
            return;
        }
        if (arrayList2 != null) {
            arrayList = arrayList2;
        } else {
            ArrayList<Integer> arrayList3 = new ArrayList<>();
            this.reloadingMessages.put(dialog_id, arrayList3);
            arrayList = arrayList3;
        }
        arrayList.addAll(result);
        getConnectionsManager().sendRequest(request, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$reloadMessages$34$MessagesController(dialog_id, chat, scheduled, result, tLObject, tL_error);
            }
        });
    }

    public void lambda$reloadMessages$34$MessagesController(final long dialog_id, TLRPC.Chat chat, boolean scheduled, final ArrayList result, TLObject response, TLRPC.TL_error error) {
        Integer inboxValue;
        Integer outboxValue;
        if (error == null) {
            TLRPC.messages_Messages messagesRes = (TLRPC.messages_Messages) response;
            SparseArray<TLRPC.User> usersLocal = new SparseArray<>();
            for (int a = 0; a < messagesRes.users.size(); a++) {
                TLRPC.User u = messagesRes.users.get(a);
                usersLocal.put(u.id, u);
            }
            SparseArray<TLRPC.Chat> chatsLocal = new SparseArray<>();
            for (int a2 = 0; a2 < messagesRes.chats.size(); a2++) {
                TLRPC.Chat c = messagesRes.chats.get(a2);
                chatsLocal.put(c.id, c);
            }
            Integer inboxValue2 = this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id));
            if (inboxValue2 == null) {
                Integer inboxValue3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, dialog_id));
                this.dialogs_read_inbox_max.put(Long.valueOf(dialog_id), inboxValue3);
                inboxValue = inboxValue3;
            } else {
                inboxValue = inboxValue2;
            }
            Integer outboxValue2 = this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id));
            if (outboxValue2 == null) {
                Integer outboxValue3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, dialog_id));
                this.dialogs_read_outbox_max.put(Long.valueOf(dialog_id), outboxValue3);
                outboxValue = outboxValue3;
            } else {
                outboxValue = outboxValue2;
            }
            final ArrayList<MessageObject> objects = new ArrayList<>();
            for (int a3 = 0; a3 < messagesRes.messages.size(); a3++) {
                TLRPC.Message message = messagesRes.messages.get(a3);
                if (chat != null && chat.megagroup) {
                    message.flags |= Integer.MIN_VALUE;
                }
                message.dialog_id = dialog_id;
                if (!scheduled) {
                    message.unread = (message.out ? outboxValue : inboxValue).intValue() < message.id;
                }
                objects.add(new MessageObject(this.currentAccount, message, usersLocal, chatsLocal, true));
            }
            ImageLoader.saveMessagesThumbs(messagesRes.messages);
            getMessagesStorage().putMessages(messagesRes, dialog_id, -1, 0, false, scheduled);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$33$MessagesController(dialog_id, result, objects);
                }
            });
        }
    }

    public void lambda$null$33$MessagesController(long dialog_id, ArrayList result, ArrayList objects) {
        ArrayList<Integer> arrayList1 = this.reloadingMessages.get(dialog_id);
        if (arrayList1 != null) {
            arrayList1.removeAll(result);
            if (arrayList1.isEmpty()) {
                this.reloadingMessages.remove(dialog_id);
            }
        }
        MessageObject dialogObj = this.dialogMessage.get(dialog_id);
        if (dialogObj != null) {
            int a = 0;
            while (true) {
                if (a >= objects.size()) {
                    break;
                }
                MessageObject obj = (MessageObject) objects.get(a);
                if (dialogObj == null || dialogObj.getId() != obj.getId()) {
                    a++;
                } else {
                    this.dialogMessage.put(dialog_id, obj);
                    if (obj.messageOwner.to_id.channel_id == 0) {
                        MessageObject obj2 = this.dialogMessagesByIds.get(obj.getId());
                        this.dialogMessagesByIds.remove(obj.getId());
                        if (obj2 != null) {
                            this.dialogMessagesByIds.put(obj2.getId(), obj2);
                        }
                    }
                    getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
                }
            }
        }
        getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(dialog_id), objects);
    }

    public void hidePeerSettingsBar(long dialogId, TLRPC.User currentUser, TLRPC.Chat currentChat) {
        if (currentUser == null && currentChat == null) {
            return;
        }
        SharedPreferences.Editor editor = this.notificationsPreferences.edit();
        editor.putInt("dialog_bar_vis3" + dialogId, 3);
        editor.commit();
        if (((int) dialogId) != 0) {
            TLRPC.TL_messages_hidePeerSettingsBar req = new TLRPC.TL_messages_hidePeerSettingsBar();
            if (currentUser != null) {
                req.peer = getInputPeer(currentUser.id);
            } else if (currentChat != null) {
                req.peer = getInputPeer(-currentChat.id);
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$hidePeerSettingsBar$35(tLObject, tL_error);
                }
            });
        }
    }

    public static void lambda$hidePeerSettingsBar$35(TLObject response, TLRPC.TL_error error) {
    }

    public void reportSpam(long dialogId, TLRPC.User currentUser, TLRPC.Chat currentChat, TLRPC.EncryptedChat currentEncryptedChat, boolean geo) {
        if (currentUser == null && currentChat == null && currentEncryptedChat == null) {
            return;
        }
        SharedPreferences.Editor editor = this.notificationsPreferences.edit();
        editor.putInt("dialog_bar_vis3" + dialogId, 3);
        editor.commit();
        if (((int) dialogId) == 0) {
            if (currentEncryptedChat == null || currentEncryptedChat.access_hash == 0) {
                return;
            }
            TLRPC.TL_messages_reportEncryptedSpam req = new TLRPC.TL_messages_reportEncryptedSpam();
            req.peer = new TLRPC.TL_inputEncryptedChat();
            req.peer.chat_id = currentEncryptedChat.id;
            req.peer.access_hash = currentEncryptedChat.access_hash;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$reportSpam$36(tLObject, tL_error);
                }
            }, 2);
            return;
        }
        TLRPC.TL_account_reportPeer req2 = new TLRPC.TL_account_reportPeer();
        if (currentChat != null) {
            req2.peer = getInputPeer(-currentChat.id);
        } else if (currentUser != null) {
            req2.peer = getInputPeer(currentUser.id);
        }
        if (geo) {
            req2.reason = new TLRPC.TL_inputReportReasonGeoIrrelevant();
        } else {
            req2.reason = new TLRPC.TL_inputReportReasonSpam();
        }
        getConnectionsManager().sendRequest(req2, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.lambda$reportSpam$37(tLObject, tL_error);
            }
        }, 2);
    }

    public static void lambda$reportSpam$36(TLObject response, TLRPC.TL_error error) {
    }

    public static void lambda$reportSpam$37(TLObject response, TLRPC.TL_error error) {
    }

    private void savePeerSettings(long dialogId, TLRPC.TL_peerSettings settings, boolean update) {
        if (settings != null) {
            SharedPreferences sharedPreferences = this.notificationsPreferences;
            if (sharedPreferences.getInt("dialog_bar_vis3" + dialogId, 0) == 3) {
                return;
            }
            SharedPreferences.Editor editor = this.notificationsPreferences.edit();
            boolean bar_hidden = (settings.report_spam || settings.add_contact || settings.block_contact || settings.share_contact || settings.report_geo) ? false : true;
            editor.putInt("dialog_bar_vis3" + dialogId, bar_hidden ? 1 : 2);
            editor.putBoolean("dialog_bar_share" + dialogId, settings.share_contact);
            editor.putBoolean("dialog_bar_report" + dialogId, settings.report_spam);
            editor.putBoolean("dialog_bar_add" + dialogId, settings.add_contact);
            editor.putBoolean("dialog_bar_block" + dialogId, settings.block_contact);
            editor.putBoolean("dialog_bar_exception" + dialogId, settings.need_contacts_exception);
            editor.putBoolean("dialog_bar_location" + dialogId, settings.report_geo);
            editor.commit();
            getNotificationCenter().postNotificationName(NotificationCenter.peerSettingsDidLoad, Long.valueOf(dialogId));
        }
    }

    public void loadPeerSettings(TLRPC.User currentUser, TLRPC.Chat currentChat) {
        final long dialogId;
        if (currentUser == null && currentChat == null) {
            return;
        }
        if (currentUser != null) {
            dialogId = currentUser.id;
        } else {
            dialogId = -currentChat.id;
        }
        if (this.loadingPeerSettings.indexOfKey(dialogId) >= 0) {
            return;
        }
        this.loadingPeerSettings.put(dialogId, true);
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("request spam button for " + dialogId);
        }
        int vis = this.notificationsPreferences.getInt("dialog_bar_vis3" + dialogId, 0);
        if (vis == 1 || vis == 3) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("dialog bar already hidden for " + dialogId);
                return;
            }
            return;
        }
        TLRPC.TL_messages_getPeerSettings req = new TLRPC.TL_messages_getPeerSettings();
        if (currentUser != null) {
            req.peer = getInputPeer(currentUser.id);
        } else if (currentChat != null) {
            req.peer = getInputPeer(-currentChat.id);
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadPeerSettings$39$MessagesController(dialogId, tLObject, tL_error);
            }
        });
    }

    public void lambda$loadPeerSettings$39$MessagesController(final long dialogId, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$38$MessagesController(dialogId, response);
            }
        });
    }

    public void lambda$null$38$MessagesController(long dialogId, TLObject response) {
        this.loadingPeerSettings.remove(dialogId);
        if (response != null) {
            savePeerSettings(dialogId, (TLRPC.TL_peerSettings) response, false);
        }
    }

    public void processNewChannelDifferenceParams(int pts, int pts_count, int channelId) {
        int channelPts = this.channelsPts.get(channelId);
        if (channelPts == 0) {
            channelPts = getMessagesStorage().getChannelPtsSync(channelId);
            if (channelPts == 0) {
                channelPts = 1;
            }
            this.channelsPts.put(channelId, channelPts);
        }
        if (channelPts + pts_count == pts) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("APPLY CHANNEL PTS");
            }
            this.channelsPts.put(channelId, pts);
            getMessagesStorage().saveChannelPts(channelId, pts);
        } else if (channelPts != pts) {
            long updatesStartWaitTime = this.updatesStartWaitTimeChannels.get(channelId);
            boolean gettingDifferenceChannel = this.gettingDifferenceChannels.get(channelId);
            if (gettingDifferenceChannel || updatesStartWaitTime == 0 || Math.abs(System.currentTimeMillis() - updatesStartWaitTime) <= 1500) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("ADD CHANNEL UPDATE TO QUEUE pts = " + pts + " pts_count = " + pts_count);
                }
                if (updatesStartWaitTime == 0) {
                    this.updatesStartWaitTimeChannels.put(channelId, System.currentTimeMillis());
                }
                UserActionUpdatesPts updates = new UserActionUpdatesPts();
                updates.pts = pts;
                updates.pts_count = pts_count;
                updates.chat_id = channelId;
                ArrayList<TLRPC.Updates> arrayList = this.updatesQueueChannels.get(channelId);
                if (arrayList == null) {
                    arrayList = new ArrayList<>();
                    this.updatesQueueChannels.put(channelId, arrayList);
                }
                arrayList.add(updates);
                return;
            }
            getChannelDifference(channelId);
        }
    }

    public void processNewDifferenceParams(int seq, int pts, int date, int pts_count) {
        if (pts != -1) {
            if (getMessagesStorage().getLastPtsValue() + pts_count == pts) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("APPLY PTS");
                }
                getMessagesStorage().setLastPtsValue(pts);
                getMessagesStorage().saveDiffParams(getMessagesStorage().getLastSeqValue(), getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue());
            } else if (getMessagesStorage().getLastPtsValue() != pts) {
                if (this.gettingDifference || this.updatesStartWaitTimePts == 0 || Math.abs(System.currentTimeMillis() - this.updatesStartWaitTimePts) <= 1500) {
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("ADD UPDATE TO QUEUE pts = " + pts + " pts_count = " + pts_count);
                    }
                    if (this.updatesStartWaitTimePts == 0) {
                        this.updatesStartWaitTimePts = System.currentTimeMillis();
                    }
                    UserActionUpdatesPts updates = new UserActionUpdatesPts();
                    updates.pts = pts;
                    updates.pts_count = pts_count;
                    this.updatesQueuePts.add(updates);
                } else {
                    getDifference();
                }
            }
        }
        if (seq != -1) {
            if (getMessagesStorage().getLastSeqValue() + 1 == seq) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("APPLY SEQ");
                }
                getMessagesStorage().setLastSeqValue(seq);
                if (date != -1) {
                    getMessagesStorage().setLastDateValue(date);
                }
                getMessagesStorage().saveDiffParams(getMessagesStorage().getLastSeqValue(), getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue());
            } else if (getMessagesStorage().getLastSeqValue() != seq) {
                if (this.gettingDifference || this.updatesStartWaitTimeSeq == 0 || Math.abs(System.currentTimeMillis() - this.updatesStartWaitTimeSeq) <= 1500) {
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("ADD UPDATE TO QUEUE seq = " + seq);
                    }
                    if (this.updatesStartWaitTimeSeq == 0) {
                        this.updatesStartWaitTimeSeq = System.currentTimeMillis();
                    }
                    UserActionUpdatesSeq updates2 = new UserActionUpdatesSeq();
                    updates2.seq = seq;
                    this.updatesQueueSeq.add(updates2);
                    return;
                }
                getDifference();
            }
        }
    }

    public void didAddedNewTask(final int minDate, final SparseArray<ArrayList<Long>> mids) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$didAddedNewTask$40$MessagesController(minDate);
            }
        });
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$didAddedNewTask$41$MessagesController(mids);
            }
        });
    }

    public void lambda$didAddedNewTask$40$MessagesController(int minDate) {
        int i;
        if ((this.currentDeletingTaskMids == null && !this.gettingNewDeleteTask) || ((i = this.currentDeletingTaskTime) != 0 && minDate < i)) {
            getNewDeleteTask(null, 0);
        }
    }

    public void lambda$didAddedNewTask$41$MessagesController(SparseArray mids) {
        getNotificationCenter().postNotificationName(NotificationCenter.didCreatedNewDeleteTask, mids);
    }

    public void getNewDeleteTask(final ArrayList<Integer> oldTask, final int channelId) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$getNewDeleteTask$42$MessagesController(oldTask, channelId);
            }
        });
    }

    public void lambda$getNewDeleteTask$42$MessagesController(ArrayList oldTask, int channelId) {
        this.gettingNewDeleteTask = true;
        getMessagesStorage().getNewTask(oldTask, channelId);
    }

    private boolean checkDeletingTask(boolean runnable) {
        int i;
        int currentServerTime = getConnectionsManager().getCurrentTime();
        if (this.currentDeletingTaskMids == null || (!runnable && ((i = this.currentDeletingTaskTime) == 0 || i > currentServerTime))) {
            return false;
        }
        this.currentDeletingTaskTime = 0;
        if (this.currentDeleteTaskRunnable != null && !runnable) {
            Utilities.stageQueue.cancelRunnable(this.currentDeleteTaskRunnable);
        }
        this.currentDeleteTaskRunnable = null;
        final ArrayList<Integer> mids = new ArrayList<>(this.currentDeletingTaskMids);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$checkDeletingTask$44$MessagesController(mids);
            }
        });
        return true;
    }

    public void lambda$checkDeletingTask$44$MessagesController(final ArrayList mids) {
        if (!mids.isEmpty() && ((Integer) mids.get(0)).intValue() > 0) {
            getMessagesStorage().emptyMessagesMedia(mids);
        } else {
            deleteMessages(mids, null, null, 0L, 0, false, false);
        }
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$43$MessagesController(mids);
            }
        });
    }

    public void lambda$null$43$MessagesController(ArrayList mids) {
        getNewDeleteTask(mids, this.currentDeletingTaskChannelId);
        this.currentDeletingTaskTime = 0;
        this.currentDeletingTaskMids = null;
    }

    public void processLoadedDeleteTask(final int taskTime, final ArrayList<Integer> messages, int channelId) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processLoadedDeleteTask$46$MessagesController(messages, taskTime);
            }
        });
    }

    public void lambda$processLoadedDeleteTask$46$MessagesController(ArrayList messages, int taskTime) {
        this.gettingNewDeleteTask = false;
        if (messages != null) {
            this.currentDeletingTaskTime = taskTime;
            this.currentDeletingTaskMids = messages;
            if (this.currentDeleteTaskRunnable != null) {
                Utilities.stageQueue.cancelRunnable(this.currentDeleteTaskRunnable);
                this.currentDeleteTaskRunnable = null;
            }
            if (!checkDeletingTask(false)) {
                this.currentDeleteTaskRunnable = new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$45$MessagesController();
                    }
                };
                int currentServerTime = getConnectionsManager().getCurrentTime();
                Utilities.stageQueue.postRunnable(this.currentDeleteTaskRunnable, Math.abs(currentServerTime - this.currentDeletingTaskTime) * 1000);
                return;
            }
            return;
        }
        this.currentDeletingTaskTime = 0;
        this.currentDeletingTaskMids = null;
    }

    public void lambda$null$45$MessagesController() {
        checkDeletingTask(true);
    }

    public void loadDialogPhotos(final int did, final int count, final long max_id, boolean fromCache, final int classGuid) {
        if (fromCache) {
            getMessagesStorage().getDialogPhotos(did, count, max_id, classGuid);
        } else if (did > 0) {
            TLRPC.User user = getUser(Integer.valueOf(did));
            if (user == null) {
                return;
            }
            TLRPC.TL_photos_getUserPhotos req = new TLRPC.TL_photos_getUserPhotos();
            req.limit = count;
            req.offset = 0;
            req.max_id = (int) max_id;
            req.user_id = getInputUser(user);
            int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$loadDialogPhotos$47$MessagesController(did, count, max_id, classGuid, tLObject, tL_error);
                }
            });
            getConnectionsManager().bindRequestToGuid(reqId, classGuid);
        } else if (did < 0) {
            TLRPC.TL_messages_search req2 = new TLRPC.TL_messages_search();
            req2.filter = new TLRPC.TL_inputMessagesFilterChatPhotos();
            req2.limit = count;
            req2.offset_id = (int) max_id;
            req2.q = "";
            req2.peer = getInputPeer(did);
            int reqId2 = getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$loadDialogPhotos$48$MessagesController(did, count, max_id, classGuid, tLObject, tL_error);
                }
            });
            getConnectionsManager().bindRequestToGuid(reqId2, classGuid);
        }
    }

    public void lambda$loadDialogPhotos$47$MessagesController(int did, int count, long max_id, int classGuid, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.photos_Photos res = (TLRPC.photos_Photos) response;
            processLoadedUserPhotos(res, did, count, max_id, false, classGuid);
        }
    }

    public void lambda$loadDialogPhotos$48$MessagesController(int did, int count, long max_id, int classGuid, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.messages_Messages messages = (TLRPC.messages_Messages) response;
            TLRPC.TL_photos_photos res = new TLRPC.TL_photos_photos();
            res.count = messages.count;
            res.users.addAll(messages.users);
            for (int a = 0; a < messages.messages.size(); a++) {
                TLRPC.Message message = messages.messages.get(a);
                if (message.action != null && message.action.photo != null) {
                    res.photos.add(message.action.photo);
                }
            }
            processLoadedUserPhotos(res, did, count, max_id, false, classGuid);
        }
    }

    public void blockUser(int user_id) {
        TLRPC.User user = getUser(Integer.valueOf(user_id));
        if (user == null || this.blockedUsers.indexOfKey(user_id) >= 0) {
            return;
        }
        this.blockedUsers.put(user_id, 1);
        if (user.bot) {
            getMediaDataController().removeInline(user_id);
        } else {
            getMediaDataController().removePeer(user_id);
        }
        int i = this.totalBlockedCount;
        if (i >= 0) {
            this.totalBlockedCount = i + 1;
        }
        getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad, new Object[0]);
        TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
        req.id = getInputUser(user);
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.lambda$blockUser$49(tLObject, tL_error);
            }
        });
    }

    public static void lambda$blockUser$49(TLObject response, TLRPC.TL_error error) {
    }

    public void setUserBannedRole(final int chatId, TLRPC.User user, TLRPC.TL_chatBannedRights rights, final boolean isChannel, final BaseFragment parentFragment) {
        if (user == null || rights == null) {
            return;
        }
        final TLRPC.TL_channels_editBanned req = new TLRPC.TL_channels_editBanned();
        req.channel = getInputChannel(chatId);
        req.user_id = getInputUser(user);
        req.banned_rights = rights;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$setUserBannedRole$52$MessagesController(chatId, parentFragment, req, isChannel, tLObject, tL_error);
            }
        });
    }

    public void lambda$setUserBannedRole$52$MessagesController(final int chatId, final BaseFragment parentFragment, final TLRPC.TL_channels_editBanned req, final boolean isChannel, TLObject response, final TLRPC.TL_error error) {
        if (error == null) {
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$50$MessagesController(chatId);
                }
            }, 1000L);
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$51$MessagesController(error, parentFragment, req, isChannel);
            }
        });
    }

    public void lambda$null$50$MessagesController(int chatId) {
        loadFullChat(chatId, 0, true);
    }

    public void lambda$null$51$MessagesController(TLRPC.TL_error error, BaseFragment parentFragment, TLRPC.TL_channels_editBanned req, boolean isChannel) {
        AlertsCreator.processError(this.currentAccount, error, parentFragment, req, Boolean.valueOf(isChannel));
    }

    public void setChannelSlowMode(final int chatId, int seconds) {
        TLRPC.TL_channels_toggleSlowMode req = new TLRPC.TL_channels_toggleSlowMode();
        req.seconds = seconds;
        req.channel = getInputChannel(chatId);
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$setChannelSlowMode$54$MessagesController(chatId, tLObject, tL_error);
            }
        });
    }

    public void lambda$setChannelSlowMode$54$MessagesController(final int chatId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            getMessagesController().processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$53$MessagesController(chatId);
                }
            }, 1000L);
        }
    }

    public void lambda$null$53$MessagesController(int chatId) {
        loadFullChat(chatId, 0, true);
    }

    public void setDefaultBannedRole(final int chatId, TLRPC.TL_chatBannedRights rights, final boolean isChannel, final BaseFragment parentFragment) {
        if (rights == null) {
            return;
        }
        final TLRPC.TL_messages_editChatDefaultBannedRights req = new TLRPC.TL_messages_editChatDefaultBannedRights();
        req.peer = getInputPeer(-chatId);
        req.banned_rights = rights;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$setDefaultBannedRole$57$MessagesController(chatId, parentFragment, req, isChannel, tLObject, tL_error);
            }
        });
    }

    public void lambda$setDefaultBannedRole$57$MessagesController(final int chatId, final BaseFragment parentFragment, final TLRPC.TL_messages_editChatDefaultBannedRights req, final boolean isChannel, TLObject response, final TLRPC.TL_error error) {
        if (error == null) {
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$55$MessagesController(chatId);
                }
            }, 1000L);
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$56$MessagesController(error, parentFragment, req, isChannel);
            }
        });
    }

    public void lambda$null$55$MessagesController(int chatId) {
        loadFullChat(chatId, 0, true);
    }

    public void lambda$null$56$MessagesController(TLRPC.TL_error error, BaseFragment parentFragment, TLRPC.TL_messages_editChatDefaultBannedRights req, boolean isChannel) {
        AlertsCreator.processError(this.currentAccount, error, parentFragment, req, Boolean.valueOf(isChannel));
    }

    public void setUserAdminRole(final int chatId, TLRPC.User user, TLRPC.TL_chatAdminRights rights, String rank, final boolean isChannel, final BaseFragment parentFragment, boolean addingNew) {
        if (user != null && rights != null) {
            TLRPC.Chat chat = getChat(Integer.valueOf(chatId));
            if (ChatObject.isChannel(chat)) {
                final TLRPC.TL_channels_editAdmin req = new TLRPC.TL_channels_editAdmin();
                req.channel = getInputChannel(chat);
                req.user_id = getInputUser(user);
                req.admin_rights = rights;
                req.rank = rank;
                getConnectionsManager().sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$setUserAdminRole$60$MessagesController(chatId, parentFragment, req, isChannel, tLObject, tL_error);
                    }
                });
                return;
            }
            final TLRPC.TL_messages_editChatAdmin req2 = new TLRPC.TL_messages_editChatAdmin();
            req2.chat_id = chatId;
            req2.user_id = getInputUser(user);
            req2.is_admin = rights.change_info || rights.delete_messages || rights.ban_users || rights.invite_users || rights.pin_messages || rights.add_admins;
            final RequestDelegate requestDelegate = new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$setUserAdminRole$63$MessagesController(chatId, parentFragment, req2, tLObject, tL_error);
                }
            };
            if (req2.is_admin && addingNew) {
                addUserToChat(chatId, user, null, 0, null, parentFragment, new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$setUserAdminRole$64$MessagesController(req2, requestDelegate);
                    }
                });
            } else {
                getConnectionsManager().sendRequest(req2, requestDelegate);
            }
        }
    }

    public void lambda$setUserAdminRole$60$MessagesController(final int chatId, final BaseFragment parentFragment, final TLRPC.TL_channels_editAdmin req, final boolean isChannel, TLObject response, final TLRPC.TL_error error) {
        if (error == null) {
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$58$MessagesController(chatId);
                }
            }, 1000L);
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$59$MessagesController(error, parentFragment, req, isChannel);
            }
        });
    }

    public void lambda$null$58$MessagesController(int chatId) {
        loadFullChat(chatId, 0, true);
    }

    public void lambda$null$59$MessagesController(TLRPC.TL_error error, BaseFragment parentFragment, TLRPC.TL_channels_editAdmin req, boolean isChannel) {
        AlertsCreator.processError(this.currentAccount, error, parentFragment, req, Boolean.valueOf(isChannel));
    }

    public void lambda$setUserAdminRole$63$MessagesController(final int chatId, final BaseFragment parentFragment, final TLRPC.TL_messages_editChatAdmin req, TLObject response, final TLRPC.TL_error error) {
        if (error == null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$61$MessagesController(chatId);
                }
            }, 1000L);
        } else {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$62$MessagesController(error, parentFragment, req);
                }
            });
        }
    }

    public void lambda$null$61$MessagesController(int chatId) {
        loadFullChat(chatId, 0, true);
    }

    public void lambda$null$62$MessagesController(TLRPC.TL_error error, BaseFragment parentFragment, TLRPC.TL_messages_editChatAdmin req) {
        AlertsCreator.processError(this.currentAccount, error, parentFragment, req, false);
    }

    public void lambda$setUserAdminRole$64$MessagesController(TLRPC.TL_messages_editChatAdmin req, RequestDelegate requestDelegate) {
        getConnectionsManager().sendRequest(req, requestDelegate);
    }

    public void unblockUser(int user_id) {
        TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock();
        TLRPC.User user = getUser(Integer.valueOf(user_id));
        if (user == null) {
            return;
        }
        this.totalBlockedCount--;
        this.blockedUsers.delete(user.id);
        req.id = getInputUser(user);
        getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad, new Object[0]);
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.lambda$unblockUser$65(tLObject, tL_error);
            }
        });
    }

    public static void lambda$unblockUser$65(TLObject response, TLRPC.TL_error error) {
    }

    public void getBlockedUsers(final boolean reset) {
        if (!getUserConfig().isClientActivated() || this.loadingBlockedUsers) {
            return;
        }
        this.loadingBlockedUsers = true;
        final TLRPC.TL_contacts_getBlocked req = new TLRPC.TL_contacts_getBlocked();
        req.offset = reset ? 0 : this.blockedUsers.size();
        req.limit = reset ? 20 : 100;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$getBlockedUsers$67$MessagesController(reset, req, tLObject, tL_error);
            }
        });
    }

    public void lambda$getBlockedUsers$67$MessagesController(final boolean reset, final TLRPC.TL_contacts_getBlocked req, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$66$MessagesController(response, reset, req);
            }
        });
    }

    public void lambda$null$66$MessagesController(TLObject response, boolean reset, TLRPC.TL_contacts_getBlocked req) {
        if (response != null) {
            TLRPC.contacts_Blocked res = (TLRPC.contacts_Blocked) response;
            putUsers(res.users, false);
            getMessagesStorage().putUsersAndChats(res.users, null, true, true);
            if (reset) {
                this.blockedUsers.clear();
            }
            this.totalBlockedCount = Math.max(res.count, res.blocked.size());
            this.blockedEndReached = res.blocked.size() < req.limit;
            int N = res.blocked.size();
            for (int a = 0; a < N; a++) {
                TLRPC.TL_contactBlocked blocked = res.blocked.get(a);
                this.blockedUsers.put(blocked.user_id, 1);
            }
            this.loadingBlockedUsers = false;
            getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad, new Object[0]);
        }
    }

    public void deleteUserPhoto(TLRPC.InputPhoto photo) {
        if (photo == null) {
            TLRPC.TL_photos_updateProfilePhoto req = new TLRPC.TL_photos_updateProfilePhoto();
            req.id = new TLRPC.TL_inputPhotoEmpty();
            getUserConfig().getCurrentUser().photo = new TLRPC.TL_userProfilePhotoEmpty();
            TLRPC.User user = getUser(Integer.valueOf(getUserConfig().getClientUserId()));
            if (user == null) {
                user = getUserConfig().getCurrentUser();
            }
            if (user == null) {
                return;
            }
            user.photo = getUserConfig().getCurrentUser().photo;
            getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, Integer.valueOf((int) UPDATE_MASK_ALL));
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$deleteUserPhoto$69$MessagesController(tLObject, tL_error);
                }
            });
            return;
        }
        TLRPC.TL_photos_deletePhotos req2 = new TLRPC.TL_photos_deletePhotos();
        req2.id.add(photo);
        getConnectionsManager().sendRequest(req2, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.lambda$deleteUserPhoto$70(tLObject, tL_error);
            }
        });
    }

    public void lambda$deleteUserPhoto$69$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.User user1 = getUser(Integer.valueOf(getUserConfig().getClientUserId()));
            if (user1 == null) {
                user1 = getUserConfig().getCurrentUser();
                putUser(user1, false);
            } else {
                getUserConfig().setCurrentUser(user1);
            }
            if (user1 == null) {
                return;
            }
            getMessagesStorage().clearUserPhotos(user1.id);
            ArrayList<TLRPC.User> users = new ArrayList<>();
            users.add(user1);
            getMessagesStorage().putUsersAndChats(users, null, false, true);
            user1.photo = (TLRPC.UserProfilePhoto) response;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$68$MessagesController();
                }
            });
        }
    }

    public void lambda$null$68$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, Integer.valueOf((int) UPDATE_MASK_ALL));
        getUserConfig().saveConfig(true);
    }

    public static void lambda$deleteUserPhoto$70(TLObject response, TLRPC.TL_error error) {
    }

    public void processLoadedUserPhotos(final TLRPC.photos_Photos res, final int did, final int count, long max_id, final boolean fromCache, final int classGuid) {
        if (!fromCache) {
            getMessagesStorage().putUsersAndChats(res.users, null, true, true);
            getMessagesStorage().putDialogPhotos(did, res);
        } else if (res == null || res.photos.isEmpty()) {
            loadDialogPhotos(did, count, max_id, false, classGuid);
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processLoadedUserPhotos$71$MessagesController(res, fromCache, did, count, classGuid);
            }
        });
    }

    public void lambda$processLoadedUserPhotos$71$MessagesController(TLRPC.photos_Photos res, boolean fromCache, int did, int count, int classGuid) {
        putUsers(res.users, fromCache);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogPhotosLoaded, Integer.valueOf(did), Integer.valueOf(count), Boolean.valueOf(fromCache), Integer.valueOf(classGuid), res.photos);
    }

    public void uploadAndApplyUserAvatar(TLRPC.FileLocation location) {
        if (location == null) {
            return;
        }
        this.uploadingAvatar = FileLoader.getDirectory(4) + "/" + location.volume_id + "_" + location.local_id + ".jpg";
        getFileLoader().uploadFile(this.uploadingAvatar, false, true, 16777216);
    }

    public void uploadAvatar(TLRPC.FileLocation location) {
        if (location == null) {
            return;
        }
        this.uploadingAvatar = FileLoader.getDirectory(4) + "/" + location.volume_id + "_" + location.local_id + ".jpg";
        getFileLoader().uploadFile(this.uploadingAvatar, false, true, 16777216, false);
    }

    public void saveTheme(Theme.ThemeInfo themeInfo, boolean night, boolean unsave) {
        if (themeInfo.info != null) {
            TLRPC.TL_account_saveTheme req = new TLRPC.TL_account_saveTheme();
            TLRPC.TL_inputTheme inputTheme = new TLRPC.TL_inputTheme();
            inputTheme.id = themeInfo.info.id;
            inputTheme.access_hash = themeInfo.info.access_hash;
            req.theme = inputTheme;
            req.unsave = unsave;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$saveTheme$72(tLObject, tL_error);
                }
            });
        }
        if (!unsave) {
            installTheme(themeInfo, night);
        }
    }

    public static void lambda$saveTheme$72(TLObject response, TLRPC.TL_error error) {
    }

    public void installTheme(Theme.ThemeInfo themeInfo, boolean night) {
        TLRPC.TL_account_installTheme req = new TLRPC.TL_account_installTheme();
        req.dark = night;
        if (themeInfo.info != null) {
            req.format = "android";
            TLRPC.TL_inputTheme inputTheme = new TLRPC.TL_inputTheme();
            inputTheme.id = themeInfo.info.id;
            inputTheme.access_hash = themeInfo.info.access_hash;
            req.theme = inputTheme;
            req.flags |= 2;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.lambda$installTheme$73(tLObject, tL_error);
            }
        });
        if (!TextUtils.isEmpty(themeInfo.slug)) {
            TLRPC.TL_account_installWallPaper req2 = new TLRPC.TL_account_installWallPaper();
            TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
            inputWallPaperSlug.slug = themeInfo.slug;
            req2.wallpaper = inputWallPaperSlug;
            req2.settings = new TLRPC.TL_wallPaperSettings();
            req2.settings.blur = themeInfo.isBlured;
            req2.settings.motion = themeInfo.isMotion;
            getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$installTheme$74(tLObject, tL_error);
                }
            });
        }
    }

    public static void lambda$installTheme$73(TLObject response, TLRPC.TL_error error) {
    }

    public static void lambda$installTheme$74(TLObject response, TLRPC.TL_error error) {
    }

    public void saveThemeToServer(final Theme.ThemeInfo themeInfo) {
        if (themeInfo == null || this.uploadingThemes.containsKey(themeInfo.pathToFile)) {
            return;
        }
        this.uploadingThemes.put(themeInfo.pathToFile, themeInfo);
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$saveThemeToServer$76$MessagesController(themeInfo);
            }
        });
    }

    public void lambda$saveThemeToServer$76$MessagesController(final Theme.ThemeInfo themeInfo) {
        final String thumbPath = Theme.createThemePreviewImage(themeInfo);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$75$MessagesController(thumbPath, themeInfo);
            }
        });
    }

    public void lambda$null$75$MessagesController(String thumbPath, Theme.ThemeInfo themeInfo) {
        if (thumbPath == null) {
            this.uploadingThemes.remove(themeInfo.pathToFile);
            return;
        }
        themeInfo.uploadingFile = themeInfo.pathToFile;
        themeInfo.uploadingThumb = thumbPath;
        this.uploadingThemes.put(thumbPath, themeInfo);
        File f = new File(themeInfo.pathToFile);
        f.length();
        File f2 = new File(thumbPath);
        f2.length();
        getFileLoader().uploadFile(themeInfo.pathToFile, false, true, ConnectionsManager.FileTypeFile);
        getFileLoader().uploadFile(thumbPath, false, true, 16777216);
    }

    public void saveWallpaperToServer(File path, final long wallPaperId, final String slug, long accessHash, boolean isBlurred, boolean isMotion, int backgroundColor, float intesity, final boolean install, long taskId) {
        TLObject req;
        long newTaskId;
        if (this.uploadingWallpaper != null) {
            File finalPath = new File(ApplicationLoader.getFilesDirFixed(), this.uploadingWallpaperBlurred ? "wallpaper_original.jpg" : "wallpaper.jpg");
            if (path == null || (!path.getAbsolutePath().equals(this.uploadingWallpaper) && !path.equals(finalPath))) {
                getFileLoader().cancelUploadFile(this.uploadingWallpaper, false);
                this.uploadingWallpaper = null;
            } else {
                this.uploadingWallpaperMotion = isMotion;
                this.uploadingWallpaperBlurred = isBlurred;
                return;
            }
        }
        if (path != null) {
            this.uploadingWallpaper = path.getAbsolutePath();
            this.uploadingWallpaperMotion = isMotion;
            this.uploadingWallpaperBlurred = isBlurred;
            getFileLoader().uploadFile(this.uploadingWallpaper, false, true, 16777216);
        } else if (accessHash != 0) {
            TLRPC.TL_inputWallPaper inputWallPaper = new TLRPC.TL_inputWallPaper();
            inputWallPaper.id = wallPaperId;
            inputWallPaper.access_hash = accessHash;
            TLRPC.TL_wallPaperSettings settings = new TLRPC.TL_wallPaperSettings();
            settings.blur = isBlurred;
            settings.motion = isMotion;
            if (backgroundColor != 0) {
                settings.background_color = backgroundColor;
                settings.flags = 1 | settings.flags;
                settings.intensity = (int) (100.0f * intesity);
                settings.flags |= 8;
            }
            if (install) {
                TLRPC.TL_account_installWallPaper request = new TLRPC.TL_account_installWallPaper();
                request.wallpaper = inputWallPaper;
                request.settings = settings;
                req = request;
            } else {
                TLRPC.TL_account_saveWallPaper request2 = new TLRPC.TL_account_saveWallPaper();
                request2.wallpaper = inputWallPaper;
                request2.settings = settings;
                req = request2;
            }
            if (taskId != 0) {
                newTaskId = taskId;
            } else {
                NativeByteBuffer data = null;
                try {
                    try {
                        data = new NativeByteBuffer(1024);
                    } catch (Exception e) {
                        e = e;
                        data = null;
                    }
                } catch (Exception e2) {
                    e = e2;
                }
                try {
                    data.writeInt32(19);
                    data.writeInt64(wallPaperId);
                    data.writeInt64(accessHash);
                    data.writeBool(isBlurred);
                    data.writeBool(isMotion);
                    data.writeInt32(backgroundColor);
                    data.writeDouble(intesity);
                    data.writeBool(install);
                    if (slug != null) {
                        data.writeString(slug);
                    } else {
                        data.writeString("");
                    }
                    data.limit(data.position());
                } catch (Exception e3) {
                    e = e3;
                    FileLog.e(e);
                    newTaskId = getMessagesStorage().createPendingTask(data);
                    final long j = newTaskId;
                    getConnectionsManager().sendRequest(req, new RequestDelegate() {
                        @Override
                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                            MessagesController.this.lambda$saveWallpaperToServer$77$MessagesController(j, install, wallPaperId, slug, tLObject, tL_error);
                        }
                    });
                }
                newTaskId = getMessagesStorage().createPendingTask(data);
            }
            final long j2 = newTaskId;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$saveWallpaperToServer$77$MessagesController(j2, install, wallPaperId, slug, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$saveWallpaperToServer$77$MessagesController(long newTaskId, boolean install, long wallPaperId, String slug, TLObject response, TLRPC.TL_error error) {
        getMessagesStorage().removePendingTask(newTaskId);
        if (!install && this.uploadingWallpaper != null) {
            SharedPreferences preferences = getGlobalMainSettings();
            SharedPreferences.Editor editor = preferences.edit();
            editor.putLong("selectedBackground2", wallPaperId);
            if (!TextUtils.isEmpty(slug)) {
                editor.putString("selectedBackgroundSlug", slug);
            } else {
                editor.remove("selectedBackgroundSlug");
            }
            editor.commit();
        }
    }

    public void markChannelDialogMessageAsDeleted(ArrayList<Integer> messages, int channelId) {
        MessageObject obj = this.dialogMessage.get(-channelId);
        if (obj != null) {
            for (int a = 0; a < messages.size(); a++) {
                Integer id = messages.get(a);
                if (obj.getId() == id.intValue()) {
                    obj.deleted = true;
                    return;
                }
            }
        }
    }

    public void deleteMessages(ArrayList<Integer> messages, ArrayList<Long> randoms, TLRPC.EncryptedChat encryptedChat, long dialogId, int channelId, boolean forAll, boolean scheduled) {
        deleteMessages(messages, randoms, encryptedChat, dialogId, channelId, forAll, scheduled, 0L, null);
    }

    public void deleteMessages(ArrayList<Integer> messages, ArrayList<Long> randoms, TLRPC.EncryptedChat encryptedChat, long dialogId, final int channelId, boolean forAll, boolean scheduled, long taskId, TLObject taskRequest) {
        ArrayList<Integer> toSend;
        final long newTaskId;
        TLRPC.TL_messages_deleteMessages req;
        TLRPC.TL_channels_deleteMessages req2;
        final long newTaskId2;
        TLRPC.TL_messages_deleteScheduledMessages req3;
        final long newTaskId3;
        if ((messages == null || messages.isEmpty()) && taskRequest == null) {
            return;
        }
        if (taskId != 0) {
            toSend = null;
        } else {
            ArrayList<Integer> toSend2 = new ArrayList<>();
            for (int a = 0; a < messages.size(); a++) {
                Integer mid = messages.get(a);
                if (mid.intValue() > 0) {
                    toSend2.add(mid);
                }
            }
            if (scheduled) {
                getMessagesStorage().markMessagesAsDeleted(messages, true, channelId, false, true);
            } else {
                if (channelId == 0) {
                    for (int a2 = 0; a2 < messages.size(); a2++) {
                        Integer id = messages.get(a2);
                        MessageObject obj = this.dialogMessagesByIds.get(id.intValue());
                        if (obj != null) {
                            obj.deleted = true;
                        }
                    }
                } else {
                    markChannelDialogMessageAsDeleted(messages, channelId);
                }
                getMessagesStorage().markMessagesAsDeleted(messages, true, channelId, forAll, false);
                getMessagesStorage().updateDialogsWithDeletedMessages(messages, null, true, channelId);
            }
            getNotificationCenter().postNotificationName(NotificationCenter.messagesDeleted, messages, Integer.valueOf(channelId), Boolean.valueOf(scheduled));
            toSend = toSend2;
        }
        if (scheduled) {
            if (taskRequest != null) {
                req3 = (TLRPC.TL_messages_deleteScheduledMessages) taskRequest;
                newTaskId3 = taskId;
            } else {
                TLRPC.TL_messages_deleteScheduledMessages req4 = new TLRPC.TL_messages_deleteScheduledMessages();
                req4.id = toSend;
                req4.peer = getInputPeer((int) dialogId);
                NativeByteBuffer data = null;
                try {
                    data = new NativeByteBuffer(req4.getObjectSize() + 16);
                    data.writeInt32(18);
                    data.writeInt64(dialogId);
                    data.writeInt32(channelId);
                    req4.serializeToStream(data);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                req3 = req4;
                newTaskId3 = MessagesStorage.getInstance(this.currentAccount).createPendingTask(data);
            }
            ConnectionsManager.getInstance(this.currentAccount).sendRequest(req3, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$deleteMessages$78$MessagesController(newTaskId3, tLObject, tL_error);
                }
            });
        } else if (channelId != 0) {
            if (taskRequest != null) {
                req2 = (TLRPC.TL_channels_deleteMessages) taskRequest;
                newTaskId2 = taskId;
            } else {
                TLRPC.TL_channels_deleteMessages req5 = new TLRPC.TL_channels_deleteMessages();
                req5.id = toSend;
                req5.channel = getInputChannel(channelId);
                NativeByteBuffer data2 = null;
                try {
                    data2 = new NativeByteBuffer(req5.getObjectSize() + 8);
                    data2.writeInt32(7);
                    data2.writeInt32(channelId);
                    req5.serializeToStream(data2);
                } catch (Exception e2) {
                    FileLog.e(e2);
                }
                req2 = req5;
                newTaskId2 = getMessagesStorage().createPendingTask(data2);
            }
            getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$deleteMessages$79$MessagesController(channelId, newTaskId2, tLObject, tL_error);
                }
            });
        } else {
            if (randoms != null && encryptedChat != null && !randoms.isEmpty()) {
                getSecretChatHelper().sendMessagesDeleteMessage(encryptedChat, randoms, null);
            }
            if (taskRequest != null) {
                req = (TLRPC.TL_messages_deleteMessages) taskRequest;
                newTaskId = taskId;
            } else {
                TLRPC.TL_messages_deleteMessages req6 = new TLRPC.TL_messages_deleteMessages();
                req6.id = toSend;
                req6.revoke = forAll;
                NativeByteBuffer data3 = null;
                try {
                    data3 = new NativeByteBuffer(req6.getObjectSize() + 8);
                    data3.writeInt32(7);
                    data3.writeInt32(channelId);
                    req6.serializeToStream(data3);
                } catch (Exception e3) {
                    FileLog.e(e3);
                }
                newTaskId = getMessagesStorage().createPendingTask(data3);
                req = req6;
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$deleteMessages$80$MessagesController(newTaskId, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$deleteMessages$78$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.Updates updates = (TLRPC.Updates) response;
            processUpdates(updates, false);
        }
        if (newTaskId != 0) {
            MessagesStorage.getInstance(this.currentAccount).removePendingTask(newTaskId);
        }
    }

    public void lambda$deleteMessages$79$MessagesController(int channelId, long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
            processNewChannelDifferenceParams(res.pts, res.pts_count, channelId);
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void lambda$deleteMessages$80$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
            processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void pinMessage(TLRPC.Chat chat, TLRPC.User user, int id, boolean notify) {
        if (chat == null && user == null) {
            return;
        }
        TLRPC.TL_messages_updatePinnedMessage req = new TLRPC.TL_messages_updatePinnedMessage();
        req.peer = getInputPeer(chat != null ? -chat.id : user.id);
        req.id = id;
        req.silent = !notify;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$pinMessage$81$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$pinMessage$81$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.Updates updates = (TLRPC.Updates) response;
            processUpdates(updates, false);
        }
    }

    public void deleteUserChannelHistory(final TLRPC.Chat chat, final TLRPC.User user, int offset) {
        if (offset == 0) {
            getMessagesStorage().deleteUserChannelHistory(chat.id, user.id);
        }
        TLRPC.TL_channels_deleteUserHistory req = new TLRPC.TL_channels_deleteUserHistory();
        req.channel = getInputChannel(chat);
        req.user_id = getInputUser(user);
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$deleteUserChannelHistory$82$MessagesController(chat, user, tLObject, tL_error);
            }
        });
    }

    public void lambda$deleteUserChannelHistory$82$MessagesController(TLRPC.Chat chat, TLRPC.User user, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response;
            if (res.offset > 0) {
                deleteUserChannelHistory(chat, user, res.offset);
            }
            processNewChannelDifferenceParams(res.pts, res.pts_count, chat.id);
        }
    }

    public ArrayList<TLRPC.Dialog> getAllDialogs() {
        return this.allDialogs;
    }

    public boolean isDialogsEndReached(int folderId) {
        return this.dialogsEndReached.get(folderId);
    }

    public boolean isLoadingDialogs(int folderId) {
        return this.loadingDialogs.get(folderId);
    }

    public boolean isServerDialogsEndReached(int folderId) {
        return this.serverDialogsEndReached.get(folderId);
    }

    public boolean hasHiddenArchive() {
        return SharedConfig.archiveHidden && this.dialogs_dict.get(DialogObject.makeFolderDialogId(1)) != null;
    }

    public ArrayList<TLRPC.Dialog> getDialogs(int folderId) {
        ArrayList<TLRPC.Dialog> dialogs = this.dialogsByFolder.get(folderId);
        if (dialogs == null) {
            return new ArrayList<>();
        }
        return dialogs;
    }

    private void removeDialog(TLRPC.Dialog dialog) {
        if (dialog == null) {
            return;
        }
        final long did = dialog.id;
        if (this.dialogsServerOnly.remove(dialog) && DialogObject.isChannel(dialog)) {
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$removeDialog$83$MessagesController(did);
                }
            });
        }
        this.allDialogs.remove(dialog);
        this.dialogsCanAddUsers.remove(dialog);
        this.dialogsChannelsOnly.remove(dialog);
        this.dialogsGroupsOnly.remove(dialog);
        this.dialogsUnreadOnly.remove(dialog);
        this.dialogsUsersOnly.remove(dialog);
        this.dialogsForward.remove(dialog);
        this.dialogs_dict.remove(did);
        this.dialogs_read_inbox_max.remove(Long.valueOf(did));
        this.dialogs_read_outbox_max.remove(Long.valueOf(did));
        ArrayList<TLRPC.Dialog> dialogs = this.dialogsByFolder.get(dialog.folder_id);
        if (dialogs != null) {
            dialogs.remove(dialog);
        }
    }

    public void lambda$removeDialog$83$MessagesController(long did) {
        this.channelsPts.delete(-((int) did));
        this.shortPollChannels.delete(-((int) did));
        this.needShortPollChannels.delete(-((int) did));
        this.shortPollOnlines.delete(-((int) did));
        this.needShortPollOnlines.delete(-((int) did));
    }

    public void deleteDialog(long did, int onlyHistory) {
        deleteDialog(did, onlyHistory, false);
    }

    public void deleteDialog(long did, int onlyHistory, boolean revoke) {
        deleteDialog(did, true, onlyHistory, 0, revoke, null, 0L);
    }

    public void setDialogsInTransaction(boolean transaction) {
        this.dialogsInTransaction = transaction;
        if (!transaction) {
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
        }
    }

    public void deleteDialog(final long did, boolean first, final int onlyHistory, int max_id, final boolean revoke, TLRPC.InputPeer peer, long taskId) {
        int max_id_delete;
        TLRPC.InputPeer peer2;
        long newTaskId;
        int high_id;
        int max_id_delete2;
        boolean z;
        TLRPC.Chat chat;
        int lastMessageId;
        if (onlyHistory == 2) {
            getMessagesStorage().deleteDialog(did, onlyHistory);
            return;
        }
        if (onlyHistory == 0 || onlyHistory == 3) {
            getMediaDataController().uninstallShortcut(did);
        }
        int lower_part = (int) did;
        int high_id2 = (int) (did >> 32);
        int max_id_delete3 = max_id;
        if (!first) {
            max_id_delete = max_id_delete3;
        } else {
            boolean isProxyDialog = false;
            getMessagesStorage().deleteDialog(did, onlyHistory);
            TLRPC.Dialog dialog = this.dialogs_dict.get(did);
            if (onlyHistory == 0 || onlyHistory == 3) {
                getNotificationsController().deleteNotificationChannel(did);
            }
            if (dialog != null) {
                if (max_id_delete3 == 0) {
                    max_id_delete3 = Math.max(Math.max(Math.max(0, dialog.top_message), dialog.read_inbox_max_id), dialog.read_outbox_max_id);
                }
                if (onlyHistory == 0 || onlyHistory == 3) {
                    TLRPC.Dialog dialog2 = this.proxyDialog;
                    if (dialog2 != null) {
                        max_id_delete2 = max_id_delete3;
                        if (dialog2.id == did) {
                            z = true;
                            isProxyDialog = z;
                            if (!z) {
                                this.isLeftProxyChannel = true;
                                if (this.proxyDialog.id < 0 && (chat = getChat(Integer.valueOf(-((int) this.proxyDialog.id)))) != null) {
                                    chat.left = true;
                                }
                                sortDialogs(null);
                            } else {
                                removeDialog(dialog);
                                int offset = this.nextDialogsCacheOffset.get(dialog.folder_id, 0);
                                if (offset > 0) {
                                    this.nextDialogsCacheOffset.put(dialog.folder_id, offset - 1);
                                }
                            }
                        }
                    } else {
                        max_id_delete2 = max_id_delete3;
                    }
                    z = false;
                    isProxyDialog = z;
                    if (!z) {
                    }
                } else {
                    dialog.unread_count = 0;
                    max_id_delete2 = max_id_delete3;
                }
                if (!isProxyDialog) {
                    MessageObject object = this.dialogMessage.get(dialog.id);
                    this.dialogMessage.remove(dialog.id);
                    if (object != null) {
                        lastMessageId = object.getId();
                        this.dialogMessagesByIds.remove(object.getId());
                    } else {
                        lastMessageId = dialog.top_message;
                        object = this.dialogMessagesByIds.get(dialog.top_message);
                        this.dialogMessagesByIds.remove(dialog.top_message);
                    }
                    if (object != null && object.messageOwner.random_id != 0) {
                        this.dialogMessagesByRandomIds.remove(object.messageOwner.random_id);
                    }
                    if (onlyHistory == 1 && lower_part != 0 && lastMessageId > 0) {
                        TLRPC.TL_messageService message = new TLRPC.TL_messageService();
                        message.id = dialog.top_message;
                        message.out = ((long) getUserConfig().getClientUserId()) == did;
                        message.from_id = getUserConfig().getClientUserId();
                        message.flags |= 256;
                        message.action = new TLRPC.TL_messageActionHistoryClear();
                        message.date = dialog.last_message_date;
                        lower_part = lower_part;
                        message.dialog_id = lower_part;
                        if (lower_part > 0) {
                            message.to_id = new TLRPC.TL_peerUser();
                            message.to_id.user_id = lower_part;
                        } else if (ChatObject.isChannel(getChat(Integer.valueOf(-lower_part)))) {
                            message.to_id = new TLRPC.TL_peerChannel();
                            message.to_id.channel_id = -lower_part;
                        } else {
                            message.to_id = new TLRPC.TL_peerChat();
                            message.to_id.chat_id = -lower_part;
                        }
                        MessageObject obj = new MessageObject(this.currentAccount, message, this.createdDialogIds.contains(Long.valueOf(message.dialog_id)));
                        ArrayList<MessageObject> objArr = new ArrayList<>();
                        objArr.add(obj);
                        ArrayList<TLRPC.Message> arr = new ArrayList<>();
                        arr.add(message);
                        updateInterfaceWithMessages(did, objArr, false);
                        getMessagesStorage().putMessages(arr, false, true, false, 0, false);
                    } else {
                        lower_part = lower_part;
                        dialog.top_message = 0;
                    }
                }
                max_id_delete3 = max_id_delete2;
            }
            if (!this.dialogsInTransaction) {
                if (isProxyDialog) {
                    getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
                } else {
                    getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
                    getNotificationCenter().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, Long.valueOf(did), false);
                }
            }
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$deleteDialog$85$MessagesController(did);
                }
            });
            max_id_delete = max_id_delete3;
        }
        if (onlyHistory == 3) {
            return;
        }
        if (lower_part == 0) {
            if (onlyHistory == 1) {
                getSecretChatHelper().sendClearHistoryMessage(getEncryptedChat(Integer.valueOf(high_id2)), null);
            } else {
                getSecretChatHelper().declineSecretChat(high_id2);
            }
            return;
        }
        if (peer != null) {
            peer2 = peer;
        } else {
            peer2 = getInputPeer(lower_part);
        }
        if (peer2 == null) {
            return;
        }
        if (!(peer2 instanceof TLRPC.TL_inputPeerChannel) || onlyHistory != 0) {
            if (max_id_delete > 0 && max_id_delete != Integer.MAX_VALUE) {
                this.deletedHistory.put(did, Integer.valueOf(max_id_delete));
            }
            if (taskId == 0) {
                NativeByteBuffer data = null;
                try {
                    data = new NativeByteBuffer(peer2.getObjectSize() + 28);
                    data.writeInt32(13);
                    data.writeInt64(did);
                    data.writeBool(first);
                    data.writeInt32(onlyHistory);
                    data.writeInt32(max_id_delete);
                    data.writeBool(revoke);
                    peer2.serializeToStream(data);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                long newTaskId2 = getMessagesStorage().createPendingTask(data);
                newTaskId = newTaskId2;
            } else {
                newTaskId = taskId;
            }
        } else {
            newTaskId = taskId;
        }
        if (peer2 instanceof TLRPC.TL_inputPeerChannel) {
            if (onlyHistory == 0) {
                if (newTaskId != 0) {
                    getMessagesStorage().removePendingTask(newTaskId);
                    return;
                }
                return;
            }
            TLRPC.TL_channels_deleteHistory req = new TLRPC.TL_channels_deleteHistory();
            req.channel = new TLRPC.TL_inputChannel();
            req.channel.channel_id = peer2.channel_id;
            int max_id_delete4 = max_id_delete;
            req.channel.access_hash = peer2.access_hash;
            req.max_id = max_id_delete4 > 0 ? max_id_delete4 : Integer.MAX_VALUE;
            final long j = newTaskId;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$deleteDialog$87$MessagesController(j, did, tLObject, tL_error);
                }
            }, 64);
            high_id = high_id2;
        } else {
            final int max_id_delete5 = max_id_delete;
            final TLRPC.InputPeer peer3 = peer2;
            TLRPC.TL_messages_deleteHistory req2 = new TLRPC.TL_messages_deleteHistory();
            req2.peer = peer3;
            req2.max_id = onlyHistory == 0 ? Integer.MAX_VALUE : max_id_delete5;
            req2.just_clear = onlyHistory != 0;
            req2.revoke = revoke;
            final long j2 = newTaskId;
            high_id = high_id2;
            getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$deleteDialog$88$MessagesController(j2, did, onlyHistory, max_id_delete5, revoke, peer3, tLObject, tL_error);
                }
            }, 64);
        }
    }

    public void lambda$deleteDialog$85$MessagesController(final long did) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$84$MessagesController(did);
            }
        });
    }

    public void lambda$null$84$MessagesController(long did) {
        getNotificationsController().removeNotificationsForDialog(did);
    }

    public void lambda$deleteDialog$87$MessagesController(long newTaskId, final long did, TLObject response, TLRPC.TL_error error) {
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$86$MessagesController(did);
            }
        });
    }

    public void lambda$null$86$MessagesController(long did) {
        this.deletedHistory.remove(did);
    }

    public void lambda$deleteDialog$88$MessagesController(long newTaskId, long did, int onlyHistory, int max_id_delete_final, boolean revoke, TLRPC.InputPeer peerFinal, TLObject response, TLRPC.TL_error error) {
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        if (error == null) {
            TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response;
            if (res.offset > 0) {
                deleteDialog(did, false, onlyHistory, max_id_delete_final, revoke, peerFinal, 0L);
            }
            processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
            getMessagesStorage().onDeleteQueryComplete(did);
        }
    }

    public void saveGif(final Object parentObject, TLRPC.Document document) {
        if (parentObject == null || !MessageObject.isGifDocument(document)) {
            return;
        }
        final TLRPC.TL_messages_saveGif req = new TLRPC.TL_messages_saveGif();
        req.id = new TLRPC.TL_inputDocument();
        req.id.id = document.id;
        req.id.access_hash = document.access_hash;
        req.id.file_reference = document.file_reference;
        if (req.id.file_reference == null) {
            req.id.file_reference = new byte[0];
        }
        req.unsave = false;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$saveGif$89$MessagesController(parentObject, req, tLObject, tL_error);
            }
        });
    }

    public void lambda$saveGif$89$MessagesController(Object parentObject, TLRPC.TL_messages_saveGif req, TLObject response, TLRPC.TL_error error) {
        if (error != null && FileRefController.isFileRefError(error.text) && parentObject != null) {
            getFileRefController().requestReference(parentObject, req);
        }
    }

    public void saveRecentSticker(final Object parentObject, TLRPC.Document document, boolean asMask) {
        if (parentObject == null || document == null) {
            return;
        }
        final TLRPC.TL_messages_saveRecentSticker req = new TLRPC.TL_messages_saveRecentSticker();
        req.id = new TLRPC.TL_inputDocument();
        req.id.id = document.id;
        req.id.access_hash = document.access_hash;
        req.id.file_reference = document.file_reference;
        if (req.id.file_reference == null) {
            req.id.file_reference = new byte[0];
        }
        req.unsave = false;
        req.attached = asMask;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$saveRecentSticker$90$MessagesController(parentObject, req, tLObject, tL_error);
            }
        });
    }

    public void lambda$saveRecentSticker$90$MessagesController(Object parentObject, TLRPC.TL_messages_saveRecentSticker req, TLObject response, TLRPC.TL_error error) {
        if (error != null && FileRefController.isFileRefError(error.text) && parentObject != null) {
            getFileRefController().requestReference(parentObject, req);
        }
    }

    public void loadChannelParticipants(final Integer chat_id) {
        if (this.loadingFullParticipants.contains(chat_id) || this.loadedFullParticipants.contains(chat_id)) {
            return;
        }
        this.loadingFullParticipants.add(chat_id);
        TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants();
        req.channel = getInputChannel(chat_id.intValue());
        req.filter = new TLRPC.TL_channelParticipantsRecent();
        req.offset = 0;
        req.limit = 32;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadChannelParticipants$92$MessagesController(chat_id, tLObject, tL_error);
            }
        });
    }

    public void lambda$loadChannelParticipants$92$MessagesController(final Integer chat_id, final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$91$MessagesController(error, response, chat_id);
            }
        });
    }

    public void lambda$null$91$MessagesController(TLRPC.TL_error error, TLObject response, Integer chat_id) {
        if (error == null && (response instanceof TLRPC.TL_channels_channelParticipants)) {
            TLRPC.TL_channels_channelParticipants res = (TLRPC.TL_channels_channelParticipants) response;
            putUsers(res.users, false);
            getMessagesStorage().putUsersAndChats(res.users, null, true, true);
            getMessagesStorage().updateChannelUsers(chat_id.intValue(), res.participants);
            this.loadedFullParticipants.add(chat_id);
        }
        this.loadingFullParticipants.remove(chat_id);
    }

    public void processChatInfo(final int chat_id, final TLRPC.ChatFull info, final ArrayList<TLRPC.User> usersArr, final boolean fromCache, final boolean force, final boolean byChannelUsers, final MessageObject pinnedMessageObject) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processChatInfo$93$MessagesController(fromCache, chat_id, byChannelUsers, force, info, usersArr, pinnedMessageObject);
            }
        });
    }

    public void lambda$processChatInfo$93$MessagesController(boolean fromCache, int chat_id, boolean byChannelUsers, boolean force, TLRPC.ChatFull info, ArrayList usersArr, MessageObject pinnedMessageObject) {
        if (fromCache && chat_id > 0 && !byChannelUsers) {
            loadFullChat(chat_id, 0, force);
        }
        if (info != null) {
            if (this.fullChats.get(chat_id) == null) {
                this.fullChats.put(chat_id, info);
            }
            putUsers(usersArr, fromCache);
            if (info.stickerset != null) {
                getMediaDataController().getGroupStickerSetById(info.stickerset);
            }
            getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, Boolean.valueOf(byChannelUsers), pinnedMessageObject);
        }
    }

    public void loadUserInfo(TLRPC.User user, boolean force, int classGuid) {
        getMessagesStorage().loadUserInfo(user, force, classGuid);
    }

    public void processUserInfo(final TLRPC.User user, final TLRPC.UserFull info, final boolean fromCache, final boolean force, final MessageObject pinnedMessageObject, final int classGuid) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processUserInfo$94$MessagesController(fromCache, user, classGuid, force, info, pinnedMessageObject);
            }
        });
    }

    public void lambda$processUserInfo$94$MessagesController(boolean fromCache, TLRPC.User user, int classGuid, boolean force, TLRPC.UserFull info, MessageObject pinnedMessageObject) {
        if (fromCache) {
            loadFullUser(user, classGuid, force);
        }
        if (info != null) {
            if (this.fullUsers.get(user.id) == null) {
                this.fullUsers.put(user.id, info);
                if (info.blocked) {
                    this.blockedUsers.put(user.id, 1);
                } else {
                    this.blockedUsers.delete(user.id);
                }
            }
            getNotificationCenter().postNotificationName(NotificationCenter.userFullInfoDidLoad, Integer.valueOf(user.id), info, pinnedMessageObject);
        }
    }

    public void updateTimerProc() {
        int timeToRemove;
        long currentTime = System.currentTimeMillis();
        checkDeletingTask(false);
        checkReadTasks();
        if (getUserConfig().isClientActivated()) {
            if (getConnectionsManager().getPauseTime() == 0 && ApplicationLoader.isScreenOn && !ApplicationLoader.mainInterfacePausedStageQueue) {
                if (ApplicationLoader.mainInterfacePausedStageQueueTime != 0 && Math.abs(ApplicationLoader.mainInterfacePausedStageQueueTime - System.currentTimeMillis()) > 1000 && this.statusSettingState != 1 && (this.lastStatusUpdateTime == 0 || Math.abs(System.currentTimeMillis() - this.lastStatusUpdateTime) >= 55000 || this.offlineSent)) {
                    this.statusSettingState = 1;
                    if (this.statusRequest != 0) {
                        getConnectionsManager().cancelRequest(this.statusRequest, true);
                    }
                    TLRPC.TL_account_updateStatus req = new TLRPC.TL_account_updateStatus();
                    req.offline = false;
                    this.statusRequest = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                        @Override
                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                            MessagesController.this.lambda$updateTimerProc$95$MessagesController(tLObject, tL_error);
                        }
                    });
                }
            } else if (this.statusSettingState != 2 && !this.offlineSent && Math.abs(System.currentTimeMillis() - getConnectionsManager().getPauseTime()) >= AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS) {
                this.statusSettingState = 2;
                if (this.statusRequest != 0) {
                    getConnectionsManager().cancelRequest(this.statusRequest, true);
                }
                TLRPC.TL_account_updateStatus req2 = new TLRPC.TL_account_updateStatus();
                req2.offline = true;
                this.statusRequest = getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$updateTimerProc$96$MessagesController(tLObject, tL_error);
                    }
                });
            }
            if (this.updatesQueueChannels.size() != 0) {
                for (int a = 0; a < this.updatesQueueChannels.size(); a++) {
                    int key = this.updatesQueueChannels.keyAt(a);
                    long updatesStartWaitTime = this.updatesStartWaitTimeChannels.valueAt(a);
                    if (updatesStartWaitTime + 1500 < currentTime) {
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("QUEUE CHANNEL " + key + " UPDATES WAIT TIMEOUT - CHECK QUEUE");
                        }
                        processChannelsUpdatesQueue(key, 0);
                    }
                }
            }
            for (int a2 = 0; a2 < 3; a2++) {
                if (getUpdatesStartTime(a2) != 0 && getUpdatesStartTime(a2) + 1500 < currentTime) {
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d(a2 + " QUEUE UPDATES WAIT TIMEOUT - CHECK QUEUE");
                    }
                    processUpdatesQueue(a2, 0);
                }
            }
        }
        if (Math.abs(System.currentTimeMillis() - this.lastViewsCheckTime) >= DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS) {
            this.lastViewsCheckTime = System.currentTimeMillis();
            if (this.channelViewsToSend.size() != 0) {
                int a3 = 0;
                while (a3 < this.channelViewsToSend.size()) {
                    final int key2 = this.channelViewsToSend.keyAt(a3);
                    final TLRPC.TL_messages_getMessagesViews req3 = new TLRPC.TL_messages_getMessagesViews();
                    req3.peer = getInputPeer(key2);
                    req3.id = this.channelViewsToSend.valueAt(a3);
                    req3.increment = a3 == 0;
                    getConnectionsManager().sendRequest(req3, new RequestDelegate() {
                        @Override
                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                            MessagesController.this.lambda$updateTimerProc$98$MessagesController(key2, req3, tLObject, tL_error);
                        }
                    });
                    a3++;
                }
                this.channelViewsToSend.clear();
            }
            if (this.pollsToCheckSize > 0) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$updateTimerProc$100$MessagesController();
                    }
                });
            }
        }
        if (!this.onlinePrivacy.isEmpty()) {
            ArrayList<Integer> toRemove = null;
            int currentServerTime = getConnectionsManager().getCurrentTime();
            for (Map.Entry<Integer, Integer> entry : this.onlinePrivacy.entrySet()) {
                if (entry.getValue().intValue() < currentServerTime - 30) {
                    if (toRemove == null) {
                        toRemove = new ArrayList<>();
                    }
                    toRemove.add(entry.getKey());
                }
            }
            if (toRemove != null) {
                Iterator<Integer> it = toRemove.iterator();
                while (it.hasNext()) {
                    Integer uid = it.next();
                    this.onlinePrivacy.remove(uid);
                }
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$updateTimerProc$101$MessagesController();
                    }
                });
            }
        }
        if (this.shortPollChannels.size() != 0) {
            int a4 = 0;
            while (a4 < this.shortPollChannels.size()) {
                int key3 = this.shortPollChannels.keyAt(a4);
                int timeout = this.shortPollChannels.valueAt(a4);
                if (timeout < System.currentTimeMillis() / 1000) {
                    this.shortPollChannels.delete(key3);
                    a4--;
                    if (this.needShortPollChannels.indexOfKey(key3) >= 0) {
                        getChannelDifference(key3);
                    }
                }
                a4++;
            }
        }
        if (this.shortPollOnlines.size() != 0) {
            long time = SystemClock.uptimeMillis() / 1000;
            int a5 = 0;
            while (a5 < this.shortPollOnlines.size()) {
                final int key4 = this.shortPollOnlines.keyAt(a5);
                int timeout2 = this.shortPollOnlines.valueAt(a5);
                if (timeout2 < time) {
                    if (this.needShortPollChannels.indexOfKey(key4) >= 0) {
                        this.shortPollOnlines.put(key4, (int) (300 + time));
                    } else {
                        this.shortPollOnlines.delete(key4);
                        a5--;
                    }
                    TLRPC.TL_messages_getOnlines req4 = new TLRPC.TL_messages_getOnlines();
                    req4.peer = getInputPeer(-key4);
                    getConnectionsManager().sendRequest(req4, new RequestDelegate() {
                        @Override
                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                            MessagesController.this.lambda$updateTimerProc$103$MessagesController(key4, tLObject, tL_error);
                        }
                    });
                }
                a5++;
            }
        }
        if (!this.printingUsers.isEmpty() || this.lastPrintingStringCount != this.printingUsers.size()) {
            boolean updated = false;
            ArrayList<Long> keys = new ArrayList<>(this.printingUsers.keySet());
            int b = 0;
            while (b < keys.size()) {
                long key5 = keys.get(b).longValue();
                ArrayList<PrintingUser> arr = this.printingUsers.get(Long.valueOf(key5));
                if (arr != null) {
                    int a6 = 0;
                    while (a6 < arr.size()) {
                        PrintingUser user = arr.get(a6);
                        if (user.action instanceof TLRPC.TL_sendMessageGamePlayAction) {
                            timeToRemove = UIMsg.m_AppUI.MSG_RADAR_SEARCH_RETURN_RESULT;
                        } else {
                            timeToRemove = 5900;
                        }
                        boolean updated2 = updated;
                        if (user.lastTime + timeToRemove >= currentTime) {
                            updated = updated2;
                        } else {
                            arr.remove(user);
                            a6--;
                            updated = true;
                        }
                        a6++;
                    }
                }
                if (arr == null || arr.isEmpty()) {
                    this.printingUsers.remove(Long.valueOf(key5));
                    keys.remove(b);
                    b--;
                }
                b++;
            }
            updatePrintingStrings();
            if (updated) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$updateTimerProc$104$MessagesController();
                    }
                });
            }
        }
        if (Theme.selectedAutoNightType == 1 && Math.abs(currentTime - lastThemeCheckTime) >= 60) {
            AndroidUtilities.runOnUIThread(this.themeCheckRunnable);
            lastThemeCheckTime = currentTime;
        }
        if (getUserConfig().savedPasswordHash != null && Math.abs(currentTime - lastPasswordCheckTime) >= 60) {
            AndroidUtilities.runOnUIThread(this.passwordCheckRunnable);
            lastPasswordCheckTime = currentTime;
        }
        if (this.lastPushRegisterSendTime != 0 && Math.abs(SystemClock.elapsedRealtime() - this.lastPushRegisterSendTime) >= 10800000) {
            GcmPushListenerService.sendRegistrationToServer(SharedConfig.pushString);
        }
        getLocationController().update();
        lambda$checkProxyInfo$107$MessagesController(false);
        checkTosUpdate();
    }

    public void lambda$updateTimerProc$95$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            this.lastStatusUpdateTime = System.currentTimeMillis();
            this.offlineSent = false;
            this.statusSettingState = 0;
        } else {
            long j = this.lastStatusUpdateTime;
            if (j != 0) {
                this.lastStatusUpdateTime = j + DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS;
            }
        }
        this.statusRequest = 0;
    }

    public void lambda$updateTimerProc$96$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            this.offlineSent = true;
        } else {
            long j = this.lastStatusUpdateTime;
            if (j != 0) {
                this.lastStatusUpdateTime = j + DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS;
            }
        }
        this.statusRequest = 0;
    }

    public void lambda$updateTimerProc$98$MessagesController(int key, TLRPC.TL_messages_getMessagesViews req, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.Vector vector = (TLRPC.Vector) response;
            final SparseArray<SparseIntArray> channelViews = new SparseArray<>();
            SparseIntArray array = channelViews.get(key);
            if (array == null) {
                array = new SparseIntArray();
                channelViews.put(key, array);
            }
            for (int a1 = 0; a1 < req.id.size() && a1 < vector.objects.size(); a1++) {
                array.put(req.id.get(a1).intValue(), ((Integer) vector.objects.get(a1)).intValue());
            }
            getMessagesStorage().putChannelViews(channelViews, req.peer instanceof TLRPC.TL_inputPeerChannel);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$97$MessagesController(channelViews);
                }
            });
        }
    }

    public void lambda$null$97$MessagesController(SparseArray channelViews) {
        getNotificationCenter().postNotificationName(NotificationCenter.didUpdatedMessagesViews, channelViews);
    }

    public void lambda$updateTimerProc$100$MessagesController() {
        long time = SystemClock.uptimeMillis();
        int a = 0;
        int N = this.pollsToCheck.size();
        while (a < N) {
            SparseArray<MessageObject> array = this.pollsToCheck.valueAt(a);
            if (array != null) {
                int b = 0;
                int N2 = array.size();
                while (b < N2) {
                    MessageObject messageObject = array.valueAt(b);
                    if (Math.abs(time - messageObject.pollLastCheckTime) < 30000) {
                        if (!messageObject.pollVisibleOnScreen) {
                            array.remove(messageObject.getId());
                            N2--;
                            b--;
                        }
                    } else {
                        messageObject.pollLastCheckTime = time;
                        TLRPC.TL_messages_getPollResults req = new TLRPC.TL_messages_getPollResults();
                        req.peer = getInputPeer((int) messageObject.getDialogId());
                        req.msg_id = messageObject.getId();
                        getConnectionsManager().sendRequest(req, new RequestDelegate() {
                            @Override
                            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                MessagesController.this.lambda$null$99$MessagesController(tLObject, tL_error);
                            }
                        });
                    }
                    b++;
                }
                int b2 = array.size();
                if (b2 == 0) {
                    LongSparseArray<SparseArray<MessageObject>> longSparseArray = this.pollsToCheck;
                    longSparseArray.remove(longSparseArray.keyAt(a));
                    N--;
                    a--;
                }
            }
            a++;
        }
        this.pollsToCheckSize = this.pollsToCheck.size();
    }

    public void lambda$null$99$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            processUpdates((TLRPC.Updates) response, false);
        }
    }

    public void lambda$updateTimerProc$101$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 4);
    }

    public void lambda$updateTimerProc$103$MessagesController(final int key, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            final TLRPC.TL_chatOnlines res = (TLRPC.TL_chatOnlines) response;
            getMessagesStorage().updateChatOnlineCount(key, res.onlines);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$102$MessagesController(key, res);
                }
            });
        }
    }

    public void lambda$null$102$MessagesController(int key, TLRPC.TL_chatOnlines res) {
        getNotificationCenter().postNotificationName(NotificationCenter.chatOnlineCountDidLoad, Integer.valueOf(key), Integer.valueOf(res.onlines));
    }

    public void lambda$updateTimerProc$104$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 64);
    }

    private void checkTosUpdate() {
        if (this.nextTosCheckTime > getConnectionsManager().getCurrentTime() || this.checkingTosUpdate || !getUserConfig().isClientActivated()) {
            return;
        }
        this.checkingTosUpdate = true;
        TLRPC.TL_help_getTermsOfServiceUpdate req = new TLRPC.TL_help_getTermsOfServiceUpdate();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$checkTosUpdate$106$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$checkTosUpdate$106$MessagesController(TLObject response, TLRPC.TL_error error) {
        this.checkingTosUpdate = false;
        if (response instanceof TLRPC.TL_help_termsOfServiceUpdateEmpty) {
            this.nextTosCheckTime = ((TLRPC.TL_help_termsOfServiceUpdateEmpty) response).expires;
        } else if (response instanceof TLRPC.TL_help_termsOfServiceUpdate) {
            final TLRPC.TL_help_termsOfServiceUpdate res = (TLRPC.TL_help_termsOfServiceUpdate) response;
            this.nextTosCheckTime = res.expires;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$105$MessagesController(res);
                }
            });
        } else {
            this.nextTosCheckTime = getConnectionsManager().getCurrentTime() + 3600;
        }
        this.notificationsPreferences.edit().putInt("nextTosCheckTime", this.nextTosCheckTime).commit();
    }

    public void lambda$null$105$MessagesController(TLRPC.TL_help_termsOfServiceUpdate res) {
        getNotificationCenter().postNotificationName(NotificationCenter.needShowAlert, 4, res.terms_of_service);
    }

    public void checkProxyInfo(final boolean reset) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$checkProxyInfo$107$MessagesController(reset);
            }
        });
    }

    public void lambda$checkProxyInfo$107$MessagesController(boolean reset) {
        String str;
        if (reset && this.checkingProxyInfo) {
            this.checkingProxyInfo = false;
        }
        if ((!reset && this.nextProxyInfoCheckTime > getConnectionsManager().getCurrentTime()) || this.checkingProxyInfo) {
            return;
        }
        if (this.checkingProxyInfoRequestId != 0) {
            getConnectionsManager().cancelRequest(this.checkingProxyInfoRequestId, true);
            this.checkingProxyInfoRequestId = 0;
        }
        SharedPreferences preferences = getGlobalMainSettings();
        boolean enabled = preferences.getBoolean("proxy_enabled", false);
        final String proxyAddress = preferences.getString("proxy_ip", "");
        final String proxySecret = preferences.getString("proxy_secret", "");
        int removeCurrent = 0;
        if (this.proxyDialogId != 0 && (str = this.proxyDialogAddress) != null) {
            if (!str.equals(proxyAddress + proxySecret)) {
                removeCurrent = 1;
            }
        }
        this.lastCheckProxyId++;
        if (enabled && !TextUtils.isEmpty(proxyAddress) && !TextUtils.isEmpty(proxySecret)) {
            this.checkingProxyInfo = true;
            final int checkProxyId = this.lastCheckProxyId;
            TLRPC.TL_help_getProxyData req = new TLRPC.TL_help_getProxyData();
            this.checkingProxyInfoRequestId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$checkProxyInfoInternal$112$MessagesController(checkProxyId, proxyAddress, proxySecret, tLObject, tL_error);
                }
            });
        } else {
            removeCurrent = 2;
        }
        if (removeCurrent != 0) {
            this.proxyDialogId = 0L;
            this.proxyDialogAddress = null;
            getGlobalMainSettings().edit().putLong("proxy_dialog", this.proxyDialogId).remove("proxyDialogAddress").commit();
            this.nextProxyInfoCheckTime = getConnectionsManager().getCurrentTime() + 3600;
            if (removeCurrent == 2) {
                this.checkingProxyInfo = false;
                if (this.checkingProxyInfoRequestId != 0) {
                    getConnectionsManager().cancelRequest(this.checkingProxyInfoRequestId, true);
                    this.checkingProxyInfoRequestId = 0;
                }
            }
            AndroidUtilities.runOnUIThread(new $$Lambda$MessagesController$XarzeHk2CEkN4B17SHxAlePUXk(this));
        }
    }

    public void lambda$checkProxyInfoInternal$112$MessagesController(final int checkProxyId, String proxyAddress, String proxySecret, TLObject response, TLRPC.TL_error error) {
        boolean noDialog;
        boolean noDialog2;
        long did;
        if (checkProxyId != this.lastCheckProxyId) {
            return;
        }
        boolean noDialog3 = false;
        if (response instanceof TLRPC.TL_help_proxyDataEmpty) {
            this.nextProxyInfoCheckTime = ((TLRPC.TL_help_proxyDataEmpty) response).expires;
            noDialog = true;
        } else if (!(response instanceof TLRPC.TL_help_proxyDataPromo)) {
            this.nextProxyInfoCheckTime = getConnectionsManager().getCurrentTime() + 3600;
            noDialog = true;
        } else {
            final TLRPC.TL_help_proxyDataPromo res = (TLRPC.TL_help_proxyDataPromo) response;
            if (res.peer.user_id != 0) {
                noDialog2 = false;
                did = res.peer.user_id;
            } else if (res.peer.chat_id != 0) {
                long did2 = -res.peer.chat_id;
                int a = 0;
                while (true) {
                    if (a >= res.chats.size()) {
                        break;
                    }
                    TLRPC.Chat chat = res.chats.get(a);
                    if (chat.id != res.peer.chat_id) {
                        a++;
                    } else if (chat.kicked || chat.restricted) {
                        noDialog3 = true;
                    }
                }
                noDialog2 = noDialog3;
                did = did2;
            } else {
                long did3 = -res.peer.channel_id;
                int a2 = 0;
                while (true) {
                    if (a2 >= res.chats.size()) {
                        break;
                    }
                    TLRPC.Chat chat2 = res.chats.get(a2);
                    if (chat2.id != res.peer.channel_id) {
                        a2++;
                    } else if (chat2.kicked || chat2.restricted) {
                        noDialog2 = true;
                        did = did3;
                    }
                }
                noDialog2 = false;
                did = did3;
            }
            this.proxyDialogId = did;
            this.proxyDialogAddress = proxyAddress + proxySecret;
            getGlobalMainSettings().edit().putLong("proxy_dialog", this.proxyDialogId).putString("proxyDialogAddress", this.proxyDialogAddress).commit();
            this.nextProxyInfoCheckTime = res.expires;
            if (!noDialog2) {
                final long j = did;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$111$MessagesController(j, res, checkProxyId);
                    }
                });
            }
            noDialog = noDialog2;
        }
        if (noDialog) {
            this.proxyDialogId = 0L;
            getGlobalMainSettings().edit().putLong("proxy_dialog", this.proxyDialogId).remove("proxyDialogAddress").commit();
            this.checkingProxyInfoRequestId = 0;
            this.checkingProxyInfo = false;
            AndroidUtilities.runOnUIThread(new $$Lambda$MessagesController$XarzeHk2CEkN4B17SHxAlePUXk(this));
        }
    }

    public void lambda$null$111$MessagesController(final long did, final TLRPC.TL_help_proxyDataPromo res, final int checkProxyId) {
        TLRPC.Dialog dialog = this.proxyDialog;
        if (dialog != null && did != dialog.id) {
            removeProxyDialog();
        }
        TLRPC.Dialog dialog2 = this.dialogs_dict.get(did);
        this.proxyDialog = dialog2;
        if (dialog2 != null) {
            this.checkingProxyInfo = false;
            sortDialogs(null);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
            return;
        }
        SparseArray<TLRPC.User> usersDict = new SparseArray<>();
        SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>();
        for (int a = 0; a < res.users.size(); a++) {
            TLRPC.User u = res.users.get(a);
            usersDict.put(u.id, u);
        }
        for (int a2 = 0; a2 < res.chats.size(); a2++) {
            TLRPC.Chat c = res.chats.get(a2);
            chatsDict.put(c.id, c);
        }
        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 chat2 = chatsDict.get(res.peer.channel_id);
            if (chat2 != null) {
                peer.peer.access_hash = chat2.access_hash;
            }
        }
        req1.peers.add(peer);
        this.checkingProxyInfoRequestId = getConnectionsManager().sendRequest(req1, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$null$110$MessagesController(checkProxyId, res, did, tLObject, tL_error);
            }
        });
    }

    public void lambda$null$110$MessagesController(int checkProxyId, final TLRPC.TL_help_proxyDataPromo res, final long did, TLObject response1, TLRPC.TL_error error1) {
        if (checkProxyId == this.lastCheckProxyId) {
            this.checkingProxyInfoRequestId = 0;
            final 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(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$108$MessagesController(res, res2, did);
                    }
                });
            } else {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$109$MessagesController();
                    }
                });
            }
            this.checkingProxyInfo = false;
        }
    }

    public void lambda$null$108$MessagesController(TLRPC.TL_help_proxyDataPromo res, TLRPC.TL_messages_peerDialogs res2, long did) {
        putUsers(res.users, false);
        putChats(res.chats, false);
        putUsers(res2.users, false);
        putChats(res2.chats, false);
        TLRPC.Dialog dialog = this.proxyDialog;
        if (dialog != null) {
            int lowerId = (int) dialog.id;
            if (lowerId < 0) {
                TLRPC.Chat chat = getChat(Integer.valueOf(-lowerId));
                if (ChatObject.isNotInChat(chat) || chat.restricted) {
                    removeDialog(this.proxyDialog);
                }
            } else {
                removeDialog(this.proxyDialog);
            }
        }
        TLRPC.Dialog dialog2 = res2.dialogs.get(0);
        this.proxyDialog = dialog2;
        dialog2.id = did;
        this.proxyDialog.folder_id = 0;
        if (DialogObject.isChannel(this.proxyDialog)) {
            this.channelsPts.put(-((int) this.proxyDialog.id), this.proxyDialog.pts);
        }
        Integer value = this.dialogs_read_inbox_max.get(Long.valueOf(this.proxyDialog.id));
        if (value == null) {
            value = 0;
        }
        this.dialogs_read_inbox_max.put(Long.valueOf(this.proxyDialog.id), Integer.valueOf(Math.max(value.intValue(), this.proxyDialog.read_inbox_max_id)));
        Integer value2 = this.dialogs_read_outbox_max.get(Long.valueOf(this.proxyDialog.id));
        if (value2 == null) {
            value2 = 0;
        }
        this.dialogs_read_outbox_max.put(Long.valueOf(this.proxyDialog.id), Integer.valueOf(Math.max(value2.intValue(), this.proxyDialog.read_outbox_max_id)));
        this.dialogs_dict.put(did, this.proxyDialog);
        if (!res2.messages.isEmpty()) {
            SparseArray<TLRPC.User> usersDict1 = new SparseArray<>();
            SparseArray<TLRPC.Chat> chatsDict1 = new SparseArray<>();
            for (int a = 0; a < res2.users.size(); a++) {
                TLRPC.User u = res2.users.get(a);
                usersDict1.put(u.id, u);
            }
            for (int a2 = 0; a2 < res2.chats.size(); a2++) {
                TLRPC.Chat c = res2.chats.get(a2);
                chatsDict1.put(c.id, c);
            }
            MessageObject messageObject = new MessageObject(this.currentAccount, res2.messages.get(0), usersDict1, chatsDict1, false);
            this.dialogMessage.put(did, messageObject);
            if (this.proxyDialog.last_message_date == 0) {
                this.proxyDialog.last_message_date = messageObject.messageOwner.date;
            }
        }
        sortDialogs(null);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
    }

    public void lambda$null$109$MessagesController() {
        TLRPC.Dialog dialog = this.proxyDialog;
        if (dialog != null) {
            int lowerId = (int) dialog.id;
            if (lowerId < 0) {
                TLRPC.Chat chat = getChat(Integer.valueOf(-lowerId));
                if (ChatObject.isNotInChat(chat) || chat.restricted) {
                    removeDialog(this.proxyDialog);
                }
            } else {
                removeDialog(this.proxyDialog);
            }
            this.proxyDialog = null;
            sortDialogs(null);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        }
    }

    public void removeProxyDialog() {
        TLRPC.Dialog dialog = this.proxyDialog;
        if (dialog == null) {
            return;
        }
        int lowerId = (int) dialog.id;
        if (lowerId < 0) {
            TLRPC.Chat chat = getChat(Integer.valueOf(-lowerId));
            if (ChatObject.isNotInChat(chat) || chat.restricted) {
                removeDialog(this.proxyDialog);
            }
        } else {
            removeDialog(this.proxyDialog);
        }
        this.proxyDialog = null;
        sortDialogs(null);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public boolean isProxyDialog(long did, boolean checkLeft) {
        TLRPC.Dialog dialog = this.proxyDialog;
        return dialog != null && dialog.id == did && (!checkLeft || this.isLeftProxyChannel);
    }

    private String getUserNameForTyping(TLRPC.User user) {
        if (user == null) {
            return "";
        }
        if (user.first_name != null && user.first_name.length() > 0) {
            return user.first_name;
        }
        if (user.last_name == null || user.last_name.length() <= 0) {
            return "";
        }
        return user.last_name;
    }

    private void updatePrintingStrings() {
        int i;
        char c;
        int i2;
        int i3;
        final LongSparseArray<CharSequence> newPrintingStrings = new LongSparseArray<>();
        final LongSparseArray<Integer> newPrintingStringsTypes = new LongSparseArray<>();
        for (Map.Entry<Long, ArrayList<PrintingUser>> entry : this.printingUsers.entrySet()) {
            long key = entry.getKey().longValue();
            ArrayList<PrintingUser> arr = entry.getValue();
            int lower_id = (int) key;
            if (lower_id > 0 || lower_id == 0) {
                i = 0;
            } else if (arr.size() == 1) {
                i = 0;
            } else {
                int count = 0;
                StringBuilder label = new StringBuilder();
                Iterator<PrintingUser> it = arr.iterator();
                while (it.hasNext()) {
                    TLRPC.User user = getUser(Integer.valueOf(it.next().userId));
                    if (user != null) {
                        if (label.length() != 0) {
                            label.append(", ");
                        }
                        label.append(getUserNameForTyping(user));
                        count++;
                    }
                    if (count == 2) {
                        break;
                    }
                }
                if (label.length() != 0) {
                    if (count == 1) {
                        newPrintingStrings.put(key, LocaleController.formatString("IsTypingGroup", R.string.IsTypingGroup, label.toString()));
                        i3 = 0;
                    } else if (arr.size() > 2) {
                        String plural = LocaleController.getPluralString("AndMoreTypingGroup", arr.size() - 2);
                        try {
                            newPrintingStrings.put(key, String.format(plural, label.toString(), Integer.valueOf(arr.size() - 2)));
                        } catch (Exception e) {
                            newPrintingStrings.put(key, "LOC_ERR: AndMoreTypingGroup");
                        }
                        i3 = 0;
                    } else {
                        i3 = 0;
                        newPrintingStrings.put(key, LocaleController.formatString("AreTypingGroup", R.string.AreTypingGroup, label.toString()));
                    }
                    newPrintingStringsTypes.put(key, Integer.valueOf(i3));
                }
            }
            PrintingUser pu = arr.get(i);
            TLRPC.User user2 = getUser(Integer.valueOf(pu.userId));
            if (user2 != null) {
                if (pu.action instanceof TLRPC.TL_sendMessageRecordAudioAction) {
                    if (lower_id < 0) {
                        newPrintingStrings.put(key, LocaleController.formatString("IsRecordingAudio", R.string.IsRecordingAudio, getUserNameForTyping(user2)));
                    } else {
                        newPrintingStrings.put(key, LocaleController.getString("RecordingAudio", R.string.RecordingAudio));
                    }
                    newPrintingStringsTypes.put(key, 1);
                } else if ((pu.action instanceof TLRPC.TL_sendMessageRecordRoundAction) || (pu.action instanceof TLRPC.TL_sendMessageUploadRoundAction)) {
                    if (lower_id < 0) {
                        newPrintingStrings.put(key, LocaleController.formatString("IsRecordingRound", R.string.IsRecordingRound, getUserNameForTyping(user2)));
                    } else {
                        newPrintingStrings.put(key, LocaleController.getString("RecordingRound", R.string.RecordingRound));
                    }
                    newPrintingStringsTypes.put(key, 4);
                } else if (pu.action instanceof TLRPC.TL_sendMessageUploadAudioAction) {
                    if (lower_id < 0) {
                        newPrintingStrings.put(key, LocaleController.formatString("IsSendingAudio", R.string.IsSendingAudio, getUserNameForTyping(user2)));
                    } else {
                        newPrintingStrings.put(key, LocaleController.getString("SendingAudio", R.string.SendingAudio));
                    }
                    newPrintingStringsTypes.put(key, 2);
                } else {
                    if (pu.action instanceof TLRPC.TL_sendMessageUploadVideoAction) {
                        c = 0;
                    } else if (pu.action instanceof TLRPC.TL_sendMessageRecordVideoAction) {
                        c = 0;
                    } else if (pu.action instanceof TLRPC.TL_sendMessageUploadDocumentAction) {
                        if (lower_id < 0) {
                            newPrintingStrings.put(key, LocaleController.formatString("IsSendingFile", R.string.IsSendingFile, getUserNameForTyping(user2)));
                        } else {
                            newPrintingStrings.put(key, LocaleController.getString("SendingFile", R.string.SendingFile));
                        }
                        newPrintingStringsTypes.put(key, 2);
                    } else if (pu.action instanceof TLRPC.TL_sendMessageUploadPhotoAction) {
                        if (lower_id < 0) {
                            newPrintingStrings.put(key, LocaleController.formatString("IsSendingPhoto", R.string.IsSendingPhoto, getUserNameForTyping(user2)));
                        } else {
                            newPrintingStrings.put(key, LocaleController.getString("SendingPhoto", R.string.SendingPhoto));
                        }
                        newPrintingStringsTypes.put(key, 2);
                    } else if (pu.action instanceof TLRPC.TL_sendMessageGamePlayAction) {
                        if (lower_id < 0) {
                            newPrintingStrings.put(key, LocaleController.formatString("IsSendingGame", R.string.IsSendingGame, getUserNameForTyping(user2)));
                        } else {
                            newPrintingStrings.put(key, LocaleController.getString("SendingGame", R.string.SendingGame));
                        }
                        newPrintingStringsTypes.put(key, 3);
                    } else {
                        if (lower_id < 0) {
                            i2 = 0;
                            newPrintingStrings.put(key, LocaleController.formatString("IsTypingGroup", R.string.IsTypingGroup, getUserNameForTyping(user2)));
                        } else {
                            i2 = 0;
                            newPrintingStrings.put(key, LocaleController.getString("Typing", R.string.Typing));
                        }
                        newPrintingStringsTypes.put(key, Integer.valueOf(i2));
                    }
                    if (lower_id < 0) {
                        Object[] objArr = new Object[1];
                        objArr[c] = getUserNameForTyping(user2);
                        newPrintingStrings.put(key, LocaleController.formatString("IsSendingVideo", R.string.IsSendingVideo, objArr));
                    } else {
                        newPrintingStrings.put(key, LocaleController.getString("SendingVideoStatus", R.string.SendingVideoStatus));
                    }
                    newPrintingStringsTypes.put(key, 2);
                }
            }
        }
        this.lastPrintingStringCount = newPrintingStrings.size();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$updatePrintingStrings$113$MessagesController(newPrintingStrings, newPrintingStringsTypes);
            }
        });
    }

    public void lambda$updatePrintingStrings$113$MessagesController(LongSparseArray newPrintingStrings, LongSparseArray newPrintingStringsTypes) {
        this.printingStrings = newPrintingStrings;
        this.printingStringsTypes = newPrintingStringsTypes;
    }

    public void cancelTyping(int action, long dialog_id) {
        LongSparseArray<Boolean> typings = this.sendingTypings.get(action);
        if (typings != null) {
            typings.remove(dialog_id);
        }
    }

    public void sendTyping(final long dialog_id, final int action, int classGuid) {
        TLRPC.Chat chat;
        if (dialog_id == 0) {
            return;
        }
        LongSparseArray<Boolean> typings = this.sendingTypings.get(action);
        if (typings != null && typings.get(dialog_id) != null) {
            return;
        }
        if (typings == null) {
            typings = new LongSparseArray<>();
            this.sendingTypings.put(action, typings);
        }
        int lower_part = (int) dialog_id;
        int high_id = (int) (dialog_id >> 32);
        if (lower_part != 0) {
            TLRPC.TL_messages_setTyping req = new TLRPC.TL_messages_setTyping();
            req.peer = getInputPeer(lower_part);
            if (((req.peer instanceof TLRPC.TL_inputPeerChannel) && ((chat = getChat(Integer.valueOf(req.peer.channel_id))) == null || !chat.megagroup)) || req.peer == null) {
                return;
            }
            if (action == 0) {
                req.action = new TLRPC.TL_sendMessageTypingAction();
            } else if (action == 1) {
                req.action = new TLRPC.TL_sendMessageRecordAudioAction();
            } else if (action == 2) {
                req.action = new TLRPC.TL_sendMessageCancelAction();
            } else if (action == 3) {
                req.action = new TLRPC.TL_sendMessageUploadDocumentAction();
            } else if (action == 4) {
                req.action = new TLRPC.TL_sendMessageUploadPhotoAction();
            } else if (action == 5) {
                req.action = new TLRPC.TL_sendMessageUploadVideoAction();
            } else if (action == 6) {
                req.action = new TLRPC.TL_sendMessageGamePlayAction();
            } else if (action == 7) {
                req.action = new TLRPC.TL_sendMessageRecordRoundAction();
            } else if (action == 8) {
                req.action = new TLRPC.TL_sendMessageUploadRoundAction();
            } else if (action == 9) {
                req.action = new TLRPC.TL_sendMessageUploadAudioAction();
            }
            typings.put(dialog_id, true);
            int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$sendTyping$115$MessagesController(action, dialog_id, tLObject, tL_error);
                }
            }, 2);
            if (classGuid != 0) {
                getConnectionsManager().bindRequestToGuid(reqId, classGuid);
            }
        } else if (action != 0) {
        } else {
            TLRPC.EncryptedChat chat2 = getEncryptedChat(Integer.valueOf(high_id));
            if (chat2.auth_key != null && chat2.auth_key.length > 1 && (chat2 instanceof TLRPC.TL_encryptedChat)) {
                TLRPC.TL_messages_setEncryptedTyping req2 = new TLRPC.TL_messages_setEncryptedTyping();
                req2.peer = new TLRPC.TL_inputEncryptedChat();
                req2.peer.chat_id = chat2.id;
                req2.peer.access_hash = chat2.access_hash;
                req2.typing = true;
                typings.put(dialog_id, true);
                int reqId2 = getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$sendTyping$117$MessagesController(action, dialog_id, tLObject, tL_error);
                    }
                }, 2);
                if (classGuid != 0) {
                    getConnectionsManager().bindRequestToGuid(reqId2, classGuid);
                }
            }
        }
    }

    public void lambda$sendTyping$115$MessagesController(final int action, final long dialog_id, TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$114$MessagesController(action, dialog_id);
            }
        });
    }

    public void lambda$null$114$MessagesController(int action, long dialog_id) {
        LongSparseArray<Boolean> typings1 = this.sendingTypings.get(action);
        if (typings1 != null) {
            typings1.remove(dialog_id);
        }
    }

    public void lambda$sendTyping$117$MessagesController(final int action, final long dialog_id, TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$116$MessagesController(action, dialog_id);
            }
        });
    }

    public void lambda$null$116$MessagesController(int action, long dialog_id) {
        LongSparseArray<Boolean> typings12 = this.sendingTypings.get(action);
        if (typings12 != null) {
            typings12.remove(dialog_id);
        }
    }

    public void removeDeletedMessagesFromArray(long dialog_id, ArrayList<TLRPC.Message> messages) {
        int maxDeletedId = this.deletedHistory.get(dialog_id, 0).intValue();
        if (maxDeletedId == 0) {
            return;
        }
        int a = 0;
        int N = messages.size();
        while (a < N) {
            TLRPC.Message message = messages.get(a);
            if (message.id <= maxDeletedId) {
                messages.remove(a);
                a--;
                N--;
            }
            a++;
        }
    }

    public void loadMessages(long dialog_id, int count, int max_id, int offset_date, boolean fromCache, int midDate, int classGuid, int load_type, int last_message_id, boolean isChannel, boolean scheduled, int loadIndex) {
        loadMessages(dialog_id, count, max_id, offset_date, fromCache, midDate, classGuid, load_type, last_message_id, isChannel, scheduled, loadIndex, 0, 0, 0, false, 0);
    }

    public void loadMessages(long dialog_id, int count, int max_id, int offset_date, boolean fromCache, int midDate, int classGuid, int load_type, int last_message_id, boolean isChannel, boolean scheduled, int loadIndex, int first_unread, int unread_count, int last_date, boolean queryFromServer, int mentionsCount) {
        loadMessagesInternal(dialog_id, count, max_id, offset_date, fromCache, midDate, classGuid, load_type, last_message_id, isChannel, scheduled, loadIndex, first_unread, unread_count, last_date, queryFromServer, mentionsCount, true);
    }

    private void loadMessagesInternal(final long dialog_id, final int count, final int max_id, final int offset_date, boolean fromCache, final int minDate, final int classGuid, final int load_type, final int last_message_id, final boolean isChannel, boolean scheduled, final int loadIndex, final int first_unread, final int unread_count, final int last_date, final boolean queryFromServer, final int mentionsCount, boolean loadDialog) {
        int i;
        int i2;
        int lower_part = (int) dialog_id;
        if (!fromCache && lower_part != 0) {
            if (scheduled) {
                TLRPC.TL_messages_getScheduledHistory req = new TLRPC.TL_messages_getScheduledHistory();
                req.peer = getInputPeer(lower_part);
                req.hash = minDate;
                int reqId = ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$loadMessagesInternal$118$MessagesController(max_id, offset_date, dialog_id, count, classGuid, first_unread, last_message_id, unread_count, last_date, load_type, isChannel, loadIndex, queryFromServer, mentionsCount, tLObject, tL_error);
                    }
                });
                ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(reqId, classGuid);
                return;
            } else if (loadDialog && ((load_type == 3 || load_type == 2) && last_message_id == 0)) {
                TLRPC.TL_messages_getPeerDialogs req2 = new TLRPC.TL_messages_getPeerDialogs();
                TLRPC.InputPeer inputPeer = getInputPeer((int) dialog_id);
                TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
                inputDialogPeer.peer = inputPeer;
                req2.peers.add(inputDialogPeer);
                getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$loadMessagesInternal$119$MessagesController(dialog_id, count, max_id, offset_date, minDate, classGuid, load_type, isChannel, loadIndex, first_unread, last_date, queryFromServer, tLObject, tL_error);
                    }
                });
                return;
            } else {
                TLRPC.TL_messages_getHistory req3 = new TLRPC.TL_messages_getHistory();
                req3.peer = getInputPeer(lower_part);
                if (load_type == 4) {
                    i = count;
                    req3.add_offset = (-i) + 5;
                    i2 = max_id;
                } else {
                    i = count;
                    if (load_type == 3) {
                        req3.add_offset = (-i) / 2;
                        i2 = max_id;
                    } else if (load_type == 1) {
                        req3.add_offset = (-i) - 1;
                        i2 = max_id;
                    } else {
                        if (load_type == 2) {
                            i2 = max_id;
                            if (i2 != 0) {
                                req3.add_offset = (-i) + 6;
                            }
                        } else {
                            i2 = max_id;
                        }
                        if (lower_part < 0 && i2 != 0) {
                            TLRPC.Chat chat = getChat(Integer.valueOf(-lower_part));
                            if (ChatObject.isChannel(chat)) {
                                req3.add_offset = -1;
                                req3.limit++;
                            }
                        }
                    }
                }
                req3.limit = i;
                req3.offset_id = i2;
                req3.offset_date = offset_date;
                int reqId2 = getConnectionsManager().sendRequest(req3, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$loadMessagesInternal$120$MessagesController(dialog_id, count, max_id, offset_date, classGuid, first_unread, last_message_id, unread_count, last_date, load_type, isChannel, loadIndex, queryFromServer, mentionsCount, tLObject, tL_error);
                    }
                });
                getConnectionsManager().bindRequestToGuid(reqId2, classGuid);
                return;
            }
        }
        getMessagesStorage().getMessages(dialog_id, count, max_id, offset_date, minDate, classGuid, load_type, isChannel, scheduled, loadIndex);
    }

    public void lambda$loadMessagesInternal$118$MessagesController(int max_id, int offset_date, long dialog_id, int count, int classGuid, int first_unread, int last_message_id, int unread_count, int last_date, int load_type, boolean isChannel, int loadIndex, boolean queryFromServer, int mentionsCount, TLObject response, TLRPC.TL_error error) {
        int mid;
        if (response != null) {
            TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
            if (res instanceof TLRPC.TL_messages_messagesNotModified) {
                return;
            }
            if (offset_date != 0 && !res.messages.isEmpty()) {
                int mid2 = res.messages.get(res.messages.size() - 1).id;
                int a = res.messages.size() - 1;
                while (true) {
                    if (a < 0) {
                        mid = mid2;
                        break;
                    }
                    TLRPC.Message message = res.messages.get(a);
                    if (message.date <= offset_date) {
                        a--;
                    } else {
                        int mid3 = message.id;
                        mid = mid3;
                        break;
                    }
                }
            } else {
                mid = max_id;
            }
            processLoadedMessages(res, dialog_id, count, mid, offset_date, false, classGuid, first_unread, last_message_id, unread_count, last_date, load_type, isChannel, false, true, loadIndex, queryFromServer, mentionsCount);
        }
    }

    public void lambda$loadMessagesInternal$119$MessagesController(long dialog_id, int count, int max_id, int offset_date, int minDate, int classGuid, int load_type, boolean isChannel, int loadIndex, int first_unread, int last_date, boolean queryFromServer, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
            if (!res.dialogs.isEmpty()) {
                TLRPC.Dialog dialog = res.dialogs.get(0);
                if (dialog.top_message != 0) {
                    TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
                    dialogs.chats = res.chats;
                    dialogs.users = res.users;
                    dialogs.dialogs = res.dialogs;
                    dialogs.messages = res.messages;
                    getMessagesStorage().putDialogs(dialogs, 0);
                }
                loadMessagesInternal(dialog_id, count, max_id, offset_date, false, minDate, classGuid, load_type, dialog.top_message, isChannel, false, loadIndex, first_unread, dialog.unread_count, last_date, queryFromServer, dialog.unread_mentions_count, false);
                return;
            }
            loadMessagesInternal(dialog_id, count, max_id, offset_date, false, minDate, classGuid, load_type, -1, isChannel, false, loadIndex, first_unread, res.state.unread_count, last_date, queryFromServer, 0, false);
        }
    }

    public void lambda$loadMessagesInternal$120$MessagesController(long dialog_id, int count, int max_id, int offset_date, int classGuid, int first_unread, int last_message_id, int unread_count, int last_date, int load_type, boolean isChannel, int loadIndex, boolean queryFromServer, int mentionsCount, TLObject response, TLRPC.TL_error error) {
        int mid;
        if (response != null) {
            TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
            removeDeletedMessagesFromArray(dialog_id, res.messages);
            if (res.messages.size() > count) {
                res.messages.remove(0);
            }
            if (offset_date != 0 && !res.messages.isEmpty()) {
                int mid2 = res.messages.get(res.messages.size() - 1).id;
                int a = res.messages.size() - 1;
                while (true) {
                    if (a < 0) {
                        mid = mid2;
                        break;
                    }
                    TLRPC.Message message = res.messages.get(a);
                    if (message.date <= offset_date) {
                        a--;
                    } else {
                        int mid3 = message.id;
                        mid = mid3;
                        break;
                    }
                }
            } else {
                mid = max_id;
            }
            processLoadedMessages(res, dialog_id, count, mid, offset_date, false, classGuid, first_unread, last_message_id, unread_count, last_date, load_type, isChannel, false, false, loadIndex, queryFromServer, mentionsCount);
        }
    }

    public void reloadWebPages(final long dialog_id, HashMap<String, ArrayList<MessageObject>> webpagesToReload, final boolean scheduled) {
        HashMap<String, ArrayList<MessageObject>> map = scheduled ? this.reloadingScheduledWebpages : this.reloadingWebpages;
        final LongSparseArray<ArrayList<MessageObject>> array = scheduled ? this.reloadingScheduledWebpagesPending : this.reloadingWebpagesPending;
        for (Map.Entry<String, ArrayList<MessageObject>> entry : webpagesToReload.entrySet()) {
            final String url = entry.getKey();
            ArrayList<MessageObject> messages = entry.getValue();
            ArrayList<MessageObject> arrayList = map.get(url);
            if (arrayList == null) {
                arrayList = new ArrayList<>();
                map.put(url, arrayList);
            }
            arrayList.addAll(messages);
            TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview();
            req.message = url;
            final HashMap<String, ArrayList<MessageObject>> hashMap = map;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$reloadWebPages$122$MessagesController(hashMap, url, array, dialog_id, scheduled, tLObject, tL_error);
                }
            });
            map = map;
        }
    }

    public void lambda$reloadWebPages$122$MessagesController(final HashMap map, final String url, final LongSparseArray array, final long dialog_id, final boolean scheduled, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$121$MessagesController(map, url, response, array, dialog_id, scheduled);
            }
        });
    }

    public void lambda$null$121$MessagesController(HashMap map, String url, TLObject response, LongSparseArray array, long dialog_id, boolean scheduled) {
        ArrayList<MessageObject> arrayList1 = (ArrayList) map.remove(url);
        if (arrayList1 == null) {
            return;
        }
        TLRPC.TL_messages_messages messagesRes = new TLRPC.TL_messages_messages();
        if (!(response instanceof TLRPC.TL_messageMediaWebPage)) {
            for (int a = 0; a < arrayList1.size(); a++) {
                arrayList1.get(a).messageOwner.media.webpage = new TLRPC.TL_webPageEmpty();
                messagesRes.messages.add(arrayList1.get(a).messageOwner);
            }
        } else {
            TLRPC.TL_messageMediaWebPage media = (TLRPC.TL_messageMediaWebPage) response;
            if (!(media.webpage instanceof TLRPC.TL_webPage) && !(media.webpage instanceof TLRPC.TL_webPageEmpty)) {
                array.put(media.webpage.id, arrayList1);
            }
            for (int a2 = 0; a2 < arrayList1.size(); a2++) {
                arrayList1.get(a2).messageOwner.media.webpage = media.webpage;
                if (a2 == 0) {
                    ImageLoader.saveMessageThumbs(arrayList1.get(a2).messageOwner);
                }
                messagesRes.messages.add(arrayList1.get(a2).messageOwner);
            }
        }
        if (!messagesRes.messages.isEmpty()) {
            getMessagesStorage().putMessages((TLRPC.messages_Messages) messagesRes, dialog_id, -2, 0, false, scheduled);
            getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(dialog_id), arrayList1);
        }
    }

    public void processLoadedMessages(final TLRPC.messages_Messages messagesRes, final long dialog_id, final int count, final int max_id, final int offset_date, final boolean isCache, final int classGuid, final int first_unread, final int last_message_id, final int unread_count, final int last_date, final int load_type, final boolean isChannel, final boolean isEnd, final boolean scheduled, final int loadIndex, final boolean queryFromServer, final int mentionsCount) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processLoadedMessages$125$MessagesController(messagesRes, dialog_id, scheduled, isCache, count, load_type, queryFromServer, first_unread, max_id, offset_date, classGuid, last_message_id, isChannel, loadIndex, unread_count, last_date, mentionsCount, isEnd);
            }
        });
    }

    public void lambda$processLoadedMessages$125$MessagesController(final TLRPC.messages_Messages messagesRes, final long dialog_id, final boolean scheduled, final boolean isCache, final int count, final int load_type, final boolean queryFromServer, final int first_unread, final int max_id, final int offset_date, final int classGuid, final int last_message_id, final boolean isChannel, final int loadIndex, final int unread_count, final int last_date, final int mentionsCount, final boolean isEnd) {
        boolean createDialog;
        boolean isMegagroup;
        TLRPC.messages_Messages messages_messages;
        MessagesController messagesController;
        long j;
        boolean z;
        Integer inboxValue;
        Integer outboxValue;
        TLRPC.User user;
        int high_id;
        int hash;
        TLRPC.Message message;
        int high_id2;
        boolean createDialog2 = false;
        if (!(messagesRes instanceof TLRPC.TL_messages_channelMessages)) {
            createDialog = false;
            isMegagroup = false;
        } else {
            int channelId = -((int) dialog_id);
            if (!scheduled) {
                int channelPts = this.channelsPts.get(channelId);
                if (channelPts == 0) {
                    int channelPts2 = getMessagesStorage().getChannelPtsSync(channelId);
                    if (channelPts2 == 0) {
                        this.channelsPts.put(channelId, messagesRes.pts);
                        if (this.needShortPollChannels.indexOfKey(channelId) >= 0 && this.shortPollChannels.indexOfKey(channelId) < 0) {
                            getChannelDifference(channelId, 2, 0L, null);
                        } else {
                            getChannelDifference(channelId);
                        }
                        createDialog2 = true;
                    }
                }
            }
            int a = 0;
            while (true) {
                if (a >= messagesRes.chats.size()) {
                    createDialog = createDialog2;
                    isMegagroup = false;
                    break;
                }
                TLRPC.Chat chat = messagesRes.chats.get(a);
                if (chat.id != channelId) {
                    a++;
                } else {
                    boolean isMegagroup2 = chat.megagroup;
                    createDialog = createDialog2;
                    isMegagroup = isMegagroup2;
                    break;
                }
            }
        }
        int lower_id = (int) dialog_id;
        int high_id3 = (int) (dialog_id >> 32);
        if (!isCache) {
            ImageLoader.saveMessagesThumbs(messagesRes.messages);
        }
        if (high_id3 == 1 || lower_id == 0 || !isCache) {
            messages_messages = messagesRes;
        } else {
            if (messagesRes.messages.size() != 0) {
                if (!scheduled) {
                    messages_messages = messagesRes;
                } else if (SystemClock.uptimeMillis() - this.lastScheduledServerQueryTime.get(dialog_id, 0L).longValue() <= DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS) {
                    messages_messages = messagesRes;
                }
            }
            if (scheduled) {
                this.lastScheduledServerQueryTime.put(dialog_id, Long.valueOf(SystemClock.uptimeMillis()));
                long h = 0;
                int a2 = 0;
                int N = messagesRes.messages.size();
                while (a2 < N) {
                    if (messagesRes.messages.get(a2).id < 0) {
                        high_id2 = high_id3;
                    } else {
                        high_id2 = high_id3;
                        h = (((20261 * ((((((((h * 20261) + 2147483648L) + message.id) % 2147483648L) * 20261) + 2147483648L) + message.edit_date) % 2147483648L)) + 2147483648L) + message.date) % 2147483648L;
                    }
                    a2++;
                    high_id3 = high_id2;
                }
                high_id = high_id3;
                int a3 = (int) h;
                int hash2 = a3 - 1;
                hash = hash2;
            } else {
                high_id = high_id3;
                hash = 0;
            }
            final int lower_id2 = hash;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$123$MessagesController(dialog_id, count, load_type, queryFromServer, first_unread, max_id, offset_date, lower_id2, classGuid, last_message_id, isChannel, scheduled, loadIndex, unread_count, last_date, mentionsCount);
                }
            });
            messages_messages = messagesRes;
            if (messages_messages.messages.isEmpty()) {
                return;
            }
        }
        SparseArray<TLRPC.User> usersDict = new SparseArray<>();
        SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>();
        for (int a4 = 0; a4 < messages_messages.users.size(); a4++) {
            TLRPC.User u = messages_messages.users.get(a4);
            usersDict.put(u.id, u);
        }
        for (int a5 = 0; a5 < messages_messages.chats.size(); a5++) {
            TLRPC.Chat c = messages_messages.chats.get(a5);
            chatsDict.put(c.id, c);
        }
        int size = messages_messages.messages.size();
        if (isCache) {
            messagesController = this;
            j = dialog_id;
            z = scheduled;
        } else {
            messagesController = this;
            Integer inboxValue2 = messagesController.dialogs_read_inbox_max.get(Long.valueOf(dialog_id));
            if (inboxValue2 == null) {
                j = dialog_id;
                Integer inboxValue3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, j));
                messagesController.dialogs_read_inbox_max.put(Long.valueOf(dialog_id), inboxValue3);
                inboxValue = inboxValue3;
            } else {
                j = dialog_id;
                inboxValue = inboxValue2;
            }
            Integer outboxValue2 = messagesController.dialogs_read_outbox_max.get(Long.valueOf(dialog_id));
            if (outboxValue2 == null) {
                Integer outboxValue3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, j));
                messagesController.dialogs_read_outbox_max.put(Long.valueOf(dialog_id), outboxValue3);
                outboxValue = outboxValue3;
            } else {
                outboxValue = outboxValue2;
            }
            for (int a6 = 0; a6 < size; a6++) {
                TLRPC.Message message2 = messages_messages.messages.get(a6);
                if (isMegagroup) {
                    message2.flags |= Integer.MIN_VALUE;
                }
                if (!scheduled) {
                    if ((message2.action instanceof TLRPC.TL_messageActionChatDeleteUser) && (user = usersDict.get(message2.action.user_id)) != null && user.bot) {
                        message2.reply_markup = new TLRPC.TL_replyKeyboardHide();
                        message2.flags |= 64;
                    }
                    if ((message2.action instanceof TLRPC.TL_messageActionChatMigrateTo) || (message2.action instanceof TLRPC.TL_messageActionChannelCreate)) {
                        message2.unread = false;
                        message2.media_unread = false;
                    } else {
                        message2.unread = (message2.out ? outboxValue : inboxValue).intValue() < message2.id;
                    }
                }
            }
            z = scheduled;
            getMessagesStorage().putMessages(messagesRes, dialog_id, load_type, max_id, createDialog, scheduled);
        }
        final ArrayList<MessageObject> objects = new ArrayList<>();
        final ArrayList<Integer> messagesToReload = new ArrayList<>();
        HashMap<String, ArrayList<MessageObject>> webpagesToReload = new HashMap<>();
        int a7 = 0;
        while (a7 < size) {
            TLRPC.Message message3 = messages_messages.messages.get(a7);
            message3.dialog_id = j;
            int a8 = a7;
            HashMap<String, ArrayList<MessageObject>> webpagesToReload2 = webpagesToReload;
            MessageObject messageObject = new MessageObject(messagesController.currentAccount, message3, usersDict, chatsDict, true);
            messageObject.scheduled = z;
            objects.add(messageObject);
            if (isCache) {
                if (message3.legacy && message3.layer < 105) {
                    messagesToReload.add(Integer.valueOf(message3.id));
                } else if (message3.media instanceof TLRPC.TL_messageMediaUnsupported) {
                    if (message3.media.bytes != null) {
                        if (message3.media.bytes.length != 0) {
                            if (message3.media.bytes.length == 1) {
                            }
                        }
                        messagesToReload.add(Integer.valueOf(message3.id));
                    }
                }
                if (message3.media instanceof TLRPC.TL_messageMediaWebPage) {
                    if ((message3.media.webpage instanceof TLRPC.TL_webPagePending) && message3.media.webpage.date <= getConnectionsManager().getCurrentTime()) {
                        messagesToReload.add(Integer.valueOf(message3.id));
                    } else if (message3.media.webpage instanceof TLRPC.TL_webPageUrlPending) {
                        ArrayList<MessageObject> arrayList = webpagesToReload2.get(message3.media.webpage.url);
                        if (arrayList == null) {
                            arrayList = new ArrayList<>();
                            webpagesToReload2.put(message3.media.webpage.url, arrayList);
                        }
                        arrayList.add(messageObject);
                    }
                }
            }
            a7 = a8 + 1;
            webpagesToReload = webpagesToReload2;
            messages_messages = messagesRes;
        }
        final HashMap<String, ArrayList<MessageObject>> webpagesToReload3 = webpagesToReload;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$124$MessagesController(messagesRes, isCache, scheduled, queryFromServer, load_type, first_unread, count, dialog_id, objects, last_message_id, unread_count, last_date, isEnd, classGuid, loadIndex, max_id, mentionsCount, messagesToReload, webpagesToReload3);
            }
        });
    }

    public void lambda$null$123$MessagesController(long dialog_id, int count, int load_type, boolean queryFromServer, int first_unread, int max_id, int offset_date, int hash, int classGuid, int last_message_id, boolean isChannel, boolean scheduled, int loadIndex, int unread_count, int last_date, int mentionsCount) {
        loadMessages(dialog_id, count, (load_type == 2 && queryFromServer) ? first_unread : max_id, offset_date, false, hash, classGuid, load_type, last_message_id, isChannel, scheduled, loadIndex, first_unread, unread_count, last_date, queryFromServer, mentionsCount);
    }

    public void lambda$null$124$MessagesController(TLRPC.messages_Messages messagesRes, boolean isCache, boolean scheduled, boolean queryFromServer, int load_type, int first_unread, int count, long dialog_id, ArrayList objects, int last_message_id, int unread_count, int last_date, boolean isEnd, int classGuid, int loadIndex, int max_id, int mentionsCount, ArrayList messagesToReload, HashMap webpagesToReload) {
        int first_unread_final;
        putUsers(messagesRes.users, isCache);
        putChats(messagesRes.chats, isCache);
        if (scheduled) {
            first_unread_final = 0;
        } else {
            first_unread_final = Integer.MAX_VALUE;
            if (queryFromServer && load_type == 2) {
                for (int a = 0; a < messagesRes.messages.size(); a++) {
                    TLRPC.Message message = messagesRes.messages.get(a);
                    if ((!message.out || message.from_scheduled) && message.id > first_unread && message.id < first_unread_final) {
                        first_unread_final = message.id;
                    }
                }
                if (first_unread_final == Integer.MAX_VALUE) {
                    first_unread_final = first_unread;
                }
            }
            if (first_unread_final == Integer.MAX_VALUE) {
            }
        }
        if (scheduled && count == 1) {
            getNotificationCenter().postNotificationName(NotificationCenter.scheduledMessagesUpdated, Long.valueOf(dialog_id), Integer.valueOf(objects.size()));
        }
        getNotificationCenter().postNotificationName(NotificationCenter.messagesDidLoad, Long.valueOf(dialog_id), Integer.valueOf(count), objects, Boolean.valueOf(isCache), Integer.valueOf(first_unread_final), Integer.valueOf(last_message_id), Integer.valueOf(unread_count), Integer.valueOf(last_date), Integer.valueOf(load_type), Boolean.valueOf(isEnd), Integer.valueOf(classGuid), Integer.valueOf(loadIndex), Integer.valueOf(max_id), Integer.valueOf(mentionsCount), Boolean.valueOf(scheduled));
        if (!messagesToReload.isEmpty()) {
            reloadMessages(messagesToReload, dialog_id, scheduled);
        }
        if (!webpagesToReload.isEmpty()) {
            reloadWebPages(dialog_id, webpagesToReload, scheduled);
        }
    }

    public void loadHintDialogs() {
        if (!this.hintDialogs.isEmpty() || TextUtils.isEmpty(this.installReferer)) {
            return;
        }
        TLRPC.TL_help_getRecentMeUrls req = new TLRPC.TL_help_getRecentMeUrls();
        req.referer = this.installReferer;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadHintDialogs$127$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$loadHintDialogs$127$MessagesController(final TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$126$MessagesController(response);
                }
            });
        }
    }

    public void lambda$null$126$MessagesController(TLObject response) {
        TLRPC.TL_help_recentMeUrls res = (TLRPC.TL_help_recentMeUrls) response;
        putUsers(res.users, false);
        putChats(res.chats, false);
        this.hintDialogs.clear();
        this.hintDialogs.addAll(res.urls);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    private TLRPC.TL_dialogFolder ensureFolderDialogExists(int folderId, boolean[] folderCreated) {
        if (folderId == 0) {
            return null;
        }
        long folderDialogId = DialogObject.makeFolderDialogId(folderId);
        TLRPC.Dialog dialog = this.dialogs_dict.get(folderDialogId);
        if (dialog instanceof TLRPC.TL_dialogFolder) {
            if (folderCreated != null) {
                folderCreated[0] = false;
            }
            return (TLRPC.TL_dialogFolder) dialog;
        }
        if (folderCreated != null) {
            folderCreated[0] = true;
        }
        TLRPC.TL_dialogFolder dialogFolder = new TLRPC.TL_dialogFolder();
        dialogFolder.id = folderDialogId;
        dialogFolder.peer = new TLRPC.TL_peerUser();
        dialogFolder.folder = new TLRPC.TL_folder();
        dialogFolder.folder.id = folderId;
        dialogFolder.folder.title = LocaleController.getString("ArchivedChats", R.string.ArchivedChats);
        dialogFolder.pinned = true;
        int maxPinnedNum = 0;
        for (int a = 0; a < this.allDialogs.size(); a++) {
            TLRPC.Dialog d = this.allDialogs.get(a);
            if (!d.pinned) {
                break;
            }
            maxPinnedNum = Math.max(d.pinnedNum, maxPinnedNum);
        }
        int a2 = maxPinnedNum + 1;
        dialogFolder.pinnedNum = a2;
        TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
        dialogs.dialogs.add(dialogFolder);
        getMessagesStorage().putDialogs(dialogs, 1);
        this.dialogs_dict.put(folderDialogId, dialogFolder);
        this.allDialogs.add(0, dialogFolder);
        return dialogFolder;
    }

    public void lambda$onFolderEmpty$128$MessagesController(int folderId) {
        long dialogId = DialogObject.makeFolderDialogId(folderId);
        TLRPC.Dialog dialog = this.dialogs_dict.get(dialogId);
        if (dialog == null) {
            return;
        }
        this.dialogs_dict.remove(dialogId);
        this.allDialogs.remove(dialog);
        sortDialogs(null);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.folderBecomeEmpty, Integer.valueOf(folderId));
    }

    public void onFolderEmpty(final int folderId) {
        int[] dialogsLoadOffset = getUserConfig().getDialogLoadOffsets(folderId);
        if (dialogsLoadOffset[0] == Integer.MAX_VALUE) {
            lambda$onFolderEmpty$128$MessagesController(folderId);
        } else {
            loadDialogs(folderId, 0, 10, false, new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$onFolderEmpty$128$MessagesController(folderId);
                }
            });
        }
    }

    public void checkIfFolderEmpty(int folderId) {
        if (folderId == 0) {
            return;
        }
        getMessagesStorage().checkIfFolderEmpty(folderId);
    }

    public int addDialogToFolder(long dialogId, int folderId, int pinnedNum, long taskId) {
        ArrayList<Long> arrayList = new ArrayList<>(1);
        arrayList.add(Long.valueOf(dialogId));
        return addDialogToFolder(arrayList, folderId, pinnedNum, null, taskId);
    }

    public int addDialogToFolder(ArrayList<Long> dialogIds, int folderId, int pinnedNum, ArrayList<TLRPC.TL_inputFolderPeer> peers, long taskId) {
        final long newTaskId;
        long newTaskId2;
        TLRPC.Dialog dialog;
        boolean[] folderCreated;
        TLRPC.TL_folders_editPeerFolders req = new TLRPC.TL_folders_editPeerFolders();
        boolean[] folderCreated2 = null;
        int i = 1;
        if (taskId == 0) {
            int selfUserId = getUserConfig().getClientUserId();
            int N = dialogIds.size();
            int size = 0;
            int size2 = 0;
            boolean[] folderCreated3 = null;
            int a = 0;
            while (a < N) {
                long dialogId = dialogIds.get(a).longValue();
                if ((DialogObject.isPeerDialogId(dialogId) || DialogObject.isSecretDialogId(dialogId)) && ((folderId != i || (dialogId != selfUserId && dialogId != 777000 && !isProxyDialog(dialogId, false))) && (dialog = this.dialogs_dict.get(dialogId)) != null)) {
                    dialog.folder_id = folderId;
                    if (pinnedNum > 0) {
                        dialog.pinned = true;
                        dialog.pinnedNum = pinnedNum;
                    } else {
                        dialog.pinned = false;
                        dialog.pinnedNum = 0;
                    }
                    if (folderCreated3 == null) {
                        boolean[] folderCreated4 = new boolean[1];
                        ensureFolderDialogExists(folderId, folderCreated4);
                        folderCreated = folderCreated4;
                    } else {
                        folderCreated = folderCreated3;
                    }
                    if (DialogObject.isSecretDialogId(dialogId)) {
                        getMessagesStorage().setDialogsFolderId(null, null, dialogId, folderId);
                        size2 = 1;
                        folderCreated3 = folderCreated;
                    } else {
                        TLRPC.TL_inputFolderPeer folderPeer = new TLRPC.TL_inputFolderPeer();
                        folderPeer.folder_id = folderId;
                        folderPeer.peer = getInputPeer((int) dialogId);
                        req.folder_peers.add(folderPeer);
                        size += folderPeer.getObjectSize();
                        size2 = 1;
                        folderCreated3 = folderCreated;
                    }
                }
                a++;
                i = 1;
            }
            if (size2 != 0) {
                sortDialogs(null);
                getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
                if (size != 0) {
                    NativeByteBuffer data = null;
                    try {
                        data = new NativeByteBuffer(size + 12);
                        data.writeInt32(17);
                        data.writeInt32(folderId);
                        data.writeInt32(req.folder_peers.size());
                        int N2 = req.folder_peers.size();
                        for (int a2 = 0; a2 < N2; a2++) {
                            req.folder_peers.get(a2).serializeToStream(data);
                        }
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    newTaskId2 = getMessagesStorage().createPendingTask(data);
                } else {
                    newTaskId2 = 0;
                }
                folderCreated2 = folderCreated3;
                newTaskId = newTaskId2;
            } else {
                return 0;
            }
        } else {
            req.folder_peers = peers;
            newTaskId = taskId;
        }
        if (!req.folder_peers.isEmpty()) {
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$addDialogToFolder$129$MessagesController(newTaskId, tLObject, tL_error);
                }
            });
            getMessagesStorage().setDialogsFolderId(null, req.folder_peers, 0L, folderId);
        }
        if (folderCreated2 == null) {
            return 0;
        }
        return folderCreated2[0] ? 2 : 1;
    }

    public void lambda$addDialogToFolder$129$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            processUpdates((TLRPC.Updates) response, false);
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void loadDialogs(int folderId, int offset, int count, boolean fromCache) {
        loadDialogs(folderId, offset, count, fromCache, null);
    }

    public void loadDialogs(final int folderId, int offset, final int count, boolean fromCache, final Runnable onEmptyCallback) {
        MessageObject message;
        int id;
        if (!this.loadingDialogs.get(folderId) && !this.resetingDialogs) {
            this.loadingDialogs.put(folderId, true);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
            if (fromCache) {
                getMessagesStorage().getDialogs(folderId, offset != 0 ? this.nextDialogsCacheOffset.get(folderId, 0) : 0, count);
                return;
            }
            TLRPC.TL_messages_getDialogs req = new TLRPC.TL_messages_getDialogs();
            req.limit = count;
            req.exclude_pinned = true;
            if (folderId != 0) {
                req.flags |= 2;
                req.folder_id = folderId;
            }
            int[] dialogsLoadOffset = getUserConfig().getDialogLoadOffsets(folderId);
            if (dialogsLoadOffset[0] != -1) {
                if (dialogsLoadOffset[0] == Integer.MAX_VALUE) {
                    this.dialogsEndReached.put(folderId, true);
                    this.serverDialogsEndReached.put(folderId, true);
                    this.loadingDialogs.put(folderId, false);
                    getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
                    return;
                }
                req.offset_id = dialogsLoadOffset[0];
                req.offset_date = dialogsLoadOffset[1];
                if (req.offset_id == 0) {
                    req.offset_peer = new TLRPC.TL_inputPeerEmpty();
                } else {
                    if (dialogsLoadOffset[4] != 0) {
                        req.offset_peer = new TLRPC.TL_inputPeerChannel();
                        req.offset_peer.channel_id = dialogsLoadOffset[4];
                    } else if (dialogsLoadOffset[2] != 0) {
                        req.offset_peer = new TLRPC.TL_inputPeerUser();
                        req.offset_peer.user_id = dialogsLoadOffset[2];
                    } else {
                        req.offset_peer = new TLRPC.TL_inputPeerChat();
                        req.offset_peer.chat_id = dialogsLoadOffset[3];
                    }
                    req.offset_peer.access_hash = (dialogsLoadOffset[5] << 32) | dialogsLoadOffset[5];
                }
            } else {
                boolean found = false;
                ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
                int a = dialogs.size() - 1;
                while (true) {
                    if (a < 0) {
                        break;
                    }
                    TLRPC.Dialog dialog = dialogs.get(a);
                    if (!dialog.pinned) {
                        int lower_id = (int) dialog.id;
                        int high_id = (int) (dialog.id >> 32);
                        if (lower_id != 0 && high_id != 1 && dialog.top_message > 0 && (message = this.dialogMessage.get(dialog.id)) != null && message.getId() > 0) {
                            req.offset_date = message.messageOwner.date;
                            req.offset_id = message.messageOwner.id;
                            if (message.messageOwner.to_id.channel_id != 0) {
                                id = -message.messageOwner.to_id.channel_id;
                            } else if (message.messageOwner.to_id.chat_id != 0) {
                                id = -message.messageOwner.to_id.chat_id;
                            } else {
                                id = message.messageOwner.to_id.user_id;
                            }
                            req.offset_peer = getInputPeer(id);
                            found = true;
                        }
                    }
                    a--;
                }
                if (!found) {
                    req.offset_peer = new TLRPC.TL_inputPeerEmpty();
                }
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$loadDialogs$130$MessagesController(folderId, count, onEmptyCallback, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$loadDialogs$130$MessagesController(int folderId, int count, Runnable onEmptyCallback, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.messages_Dialogs dialogsRes = (TLRPC.messages_Dialogs) response;
            processLoadedDialogs(dialogsRes, null, folderId, 0, count, 0, false, false, false);
            if (onEmptyCallback != null && dialogsRes.dialogs.isEmpty()) {
                AndroidUtilities.runOnUIThread(onEmptyCallback);
            }
        }
    }

    public void loadGlobalNotificationsSettings() {
        if (this.loadingNotificationSettings == 0 && !getUserConfig().notificationsSettingsLoaded) {
            SharedPreferences preferences = getNotificationsSettings(this.currentAccount);
            SharedPreferences.Editor editor1 = null;
            if (preferences.contains("EnableGroup")) {
                boolean enabled = preferences.getBoolean("EnableGroup", true);
                if (0 == 0) {
                    editor1 = preferences.edit();
                }
                if (!enabled) {
                    editor1.putInt("EnableGroup2", Integer.MAX_VALUE);
                    editor1.putInt("EnableChannel2", Integer.MAX_VALUE);
                }
                editor1.remove("EnableGroup").commit();
            }
            if (preferences.contains("EnableAll")) {
                boolean enabled2 = preferences.getBoolean("EnableAll", true);
                if (editor1 == null) {
                    editor1 = preferences.edit();
                }
                if (!enabled2) {
                    editor1.putInt("EnableAll2", Integer.MAX_VALUE);
                }
                editor1.remove("EnableAll").commit();
            }
            if (editor1 != null) {
                editor1.commit();
            }
            this.loadingNotificationSettings = 3;
            for (int a = 0; a < 3; a++) {
                TLRPC.TL_account_getNotifySettings req = new TLRPC.TL_account_getNotifySettings();
                if (a == 0) {
                    req.peer = new TLRPC.TL_inputNotifyChats();
                } else if (a == 1) {
                    req.peer = new TLRPC.TL_inputNotifyUsers();
                } else if (a == 2) {
                    req.peer = new TLRPC.TL_inputNotifyBroadcasts();
                }
                final int type = a;
                getConnectionsManager().sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$loadGlobalNotificationsSettings$132$MessagesController(type, tLObject, tL_error);
                    }
                });
            }
        }
        if (!getUserConfig().notificationsSignUpSettingsLoaded) {
            loadSignUpNotificationsSettings();
        }
    }

    public void lambda$loadGlobalNotificationsSettings$132$MessagesController(final int type, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$131$MessagesController(response, type);
            }
        });
    }

    public void lambda$null$131$MessagesController(TLObject response, int type) {
        if (response != null) {
            this.loadingNotificationSettings--;
            TLRPC.TL_peerNotifySettings notify_settings = (TLRPC.TL_peerNotifySettings) response;
            SharedPreferences.Editor editor = this.notificationsPreferences.edit();
            if (type == 0) {
                if ((notify_settings.flags & 1) != 0) {
                    editor.putBoolean("EnablePreviewGroup", notify_settings.show_previews);
                }
                int i = notify_settings.flags;
                if ((notify_settings.flags & 4) != 0) {
                    editor.putInt("EnableGroup2", notify_settings.mute_until);
                }
            } else if (type == 1) {
                if ((notify_settings.flags & 1) != 0) {
                    editor.putBoolean("EnablePreviewAll", notify_settings.show_previews);
                }
                int i2 = notify_settings.flags;
                if ((notify_settings.flags & 4) != 0) {
                    editor.putInt("EnableAll2", notify_settings.mute_until);
                }
            } else if (type == 2) {
                if ((notify_settings.flags & 1) != 0) {
                    editor.putBoolean("EnablePreviewChannel", notify_settings.show_previews);
                }
                int i3 = notify_settings.flags;
                if ((notify_settings.flags & 4) != 0) {
                    editor.putInt("EnableChannel2", notify_settings.mute_until);
                }
            }
            editor.commit();
            if (this.loadingNotificationSettings == 0) {
                getUserConfig().notificationsSettingsLoaded = true;
                getUserConfig().saveConfig(false);
            }
        }
    }

    public void loadSignUpNotificationsSettings() {
        if (!this.loadingNotificationSignUpSettings) {
            this.loadingNotificationSignUpSettings = true;
            TLRPC.TL_account_getContactSignUpNotification req = new TLRPC.TL_account_getContactSignUpNotification();
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$loadSignUpNotificationsSettings$134$MessagesController(tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$loadSignUpNotificationsSettings$134$MessagesController(final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$133$MessagesController(response);
            }
        });
    }

    public void lambda$null$133$MessagesController(TLObject response) {
        this.loadingNotificationSignUpSettings = false;
        SharedPreferences.Editor editor = this.notificationsPreferences.edit();
        boolean z = response instanceof TLRPC.TL_boolFalse;
        this.enableJoined = z;
        editor.putBoolean("EnableContactJoined", z);
        editor.commit();
        getUserConfig().notificationsSignUpSettingsLoaded = true;
        getUserConfig().saveConfig(false);
    }

    public void forceResetDialogs() {
        resetDialogs(true, getMessagesStorage().getLastSeqValue(), getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue());
        getNotificationsController().deleteAllNotificationChannels();
    }

    public void loadUnknownDialog(TLRPC.InputPeer peer, long taskId) {
        long newTaskId;
        if (peer == null) {
            return;
        }
        final long dialogId = DialogObject.getPeerDialogId(peer);
        if (this.gettingUnknownDialogs.indexOfKey(dialogId) >= 0) {
            return;
        }
        this.gettingUnknownDialogs.put(dialogId, true);
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("load unknown dialog " + dialogId);
        }
        TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
        TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
        inputDialogPeer.peer = peer;
        req.peers.add(inputDialogPeer);
        if (taskId == 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(peer.getObjectSize() + 4);
                data.writeInt32(15);
                peer.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            long newTaskId2 = getMessagesStorage().createPendingTask(data);
            newTaskId = newTaskId2;
        } else {
            newTaskId = taskId;
        }
        final long j = newTaskId;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadUnknownDialog$135$MessagesController(j, dialogId, tLObject, tL_error);
            }
        });
    }

    public void lambda$loadUnknownDialog$135$MessagesController(long newTaskId, long dialogId, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
            if (!res.dialogs.isEmpty() && !(res.dialogs.get(0) instanceof TLRPC.TL_dialogFolder)) {
                TLRPC.TL_dialog dialog = (TLRPC.TL_dialog) res.dialogs.get(0);
                TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
                dialogs.dialogs.addAll(res.dialogs);
                dialogs.messages.addAll(res.messages);
                dialogs.users.addAll(res.users);
                dialogs.chats.addAll(res.chats);
                processLoadedDialogs(dialogs, null, dialog.folder_id, 0, 1, this.DIALOGS_LOAD_TYPE_UNKNOWN, false, false, false);
            }
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        this.gettingUnknownDialogs.delete(dialogId);
    }

    private void fetchFolderInLoadedPinnedDialogs(TLRPC.TL_messages_peerDialogs res) {
        int N;
        TLRPC.InputPeer inputPeer;
        int a = 0;
        int N2 = res.dialogs.size();
        while (a < N2) {
            TLRPC.Dialog dialog = res.dialogs.get(a);
            if (!(dialog instanceof TLRPC.TL_dialogFolder)) {
                N = N2;
            } else {
                TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
                long folderTopDialogId = DialogObject.getPeerDialogId(dialog.peer);
                if (dialogFolder.top_message != 0) {
                    long folderTopDialogId2 = 0;
                    if (folderTopDialogId != 0) {
                        int b = 0;
                        int N22 = res.messages.size();
                        while (b < N22) {
                            TLRPC.Message message = res.messages.get(b);
                            long messageDialogId = MessageObject.getDialogId(message);
                            if (folderTopDialogId != messageDialogId || dialog.top_message != message.id) {
                                b++;
                                folderTopDialogId2 = folderTopDialogId2;
                                N2 = N2;
                                folderTopDialogId = folderTopDialogId;
                            } else {
                                TLRPC.TL_dialog newDialog = new TLRPC.TL_dialog();
                                newDialog.peer = dialog.peer;
                                newDialog.top_message = dialog.top_message;
                                newDialog.folder_id = dialogFolder.folder.id;
                                newDialog.flags |= 16;
                                res.dialogs.add(newDialog);
                                if (!(dialog.peer instanceof TLRPC.TL_peerChannel)) {
                                    if (dialog.peer instanceof TLRPC.TL_peerChat) {
                                        inputPeer = new TLRPC.TL_inputPeerChat();
                                        inputPeer.chat_id = dialog.peer.chat_id;
                                    } else {
                                        inputPeer = new TLRPC.TL_inputPeerUser();
                                        inputPeer.user_id = dialog.peer.user_id;
                                        int c = 0;
                                        int N3 = res.users.size();
                                        while (true) {
                                            if (c >= N3) {
                                                break;
                                            }
                                            TLRPC.User user = res.users.get(c);
                                            if (user.id != inputPeer.user_id) {
                                                c++;
                                            } else {
                                                inputPeer.access_hash = user.access_hash;
                                                break;
                                            }
                                        }
                                    }
                                } else {
                                    inputPeer = new TLRPC.TL_inputPeerChannel();
                                    inputPeer.channel_id = dialog.peer.channel_id;
                                    int c2 = 0;
                                    int N32 = res.chats.size();
                                    while (true) {
                                        if (c2 >= N32) {
                                            break;
                                        }
                                        int N4 = N2;
                                        TLRPC.Chat chat = res.chats.get(c2);
                                        long folderTopDialogId3 = folderTopDialogId;
                                        if (chat.id != inputPeer.channel_id) {
                                            c2++;
                                            N2 = N4;
                                            folderTopDialogId = folderTopDialogId3;
                                        } else {
                                            inputPeer.access_hash = chat.access_hash;
                                            break;
                                        }
                                    }
                                }
                                loadUnknownDialog(inputPeer, 0L);
                                return;
                            }
                        }
                        return;
                    }
                    N = N2;
                } else {
                    N = N2;
                }
                res.dialogs.remove(dialogFolder);
            }
            a++;
            N2 = N;
        }
    }

    private void resetDialogs(boolean query, final int seq, final int newPts, final int date, final int qts) {
        TLRPC.messages_Dialogs messages_dialogs;
        int messagesCount;
        TLRPC.User user;
        TLRPC.Chat chat;
        Integer value;
        Integer value2;
        MessageObject mess;
        TLRPC.Chat chat2;
        int a;
        if (query) {
            if (this.resetingDialogs) {
                return;
            }
            getUserConfig().setPinnedDialogsLoaded(1, false);
            this.resetingDialogs = true;
            TLRPC.TL_messages_getPinnedDialogs req = new TLRPC.TL_messages_getPinnedDialogs();
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$resetDialogs$136$MessagesController(seq, newPts, date, qts, tLObject, tL_error);
                }
            });
            TLRPC.TL_messages_getDialogs req2 = new TLRPC.TL_messages_getDialogs();
            req2.limit = 100;
            req2.exclude_pinned = true;
            req2.offset_peer = new TLRPC.TL_inputPeerEmpty();
            getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$resetDialogs$137$MessagesController(seq, newPts, date, qts, tLObject, tL_error);
                }
            });
        } else if (this.resetDialogsPinned != null && (messages_dialogs = this.resetDialogsAll) != null) {
            int messagesCount2 = messages_dialogs.messages.size();
            int dialogsCount = this.resetDialogsAll.dialogs.size();
            fetchFolderInLoadedPinnedDialogs(this.resetDialogsPinned);
            this.resetDialogsAll.dialogs.addAll(this.resetDialogsPinned.dialogs);
            this.resetDialogsAll.messages.addAll(this.resetDialogsPinned.messages);
            this.resetDialogsAll.users.addAll(this.resetDialogsPinned.users);
            this.resetDialogsAll.chats.addAll(this.resetDialogsPinned.chats);
            LongSparseArray<TLRPC.Dialog> new_dialogs_dict = new LongSparseArray<>();
            LongSparseArray<MessageObject> new_dialogMessage = new LongSparseArray<>();
            SparseArray<TLRPC.User> usersDict = new SparseArray<>();
            SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>();
            for (int a2 = 0; a2 < this.resetDialogsAll.users.size(); a2++) {
                TLRPC.User u = this.resetDialogsAll.users.get(a2);
                usersDict.put(u.id, u);
            }
            for (int a3 = 0; a3 < this.resetDialogsAll.chats.size(); a3++) {
                TLRPC.Chat c = this.resetDialogsAll.chats.get(a3);
                chatsDict.put(c.id, c);
            }
            TLRPC.Message lastMessage = null;
            int a4 = 0;
            while (a4 < this.resetDialogsAll.messages.size()) {
                TLRPC.Message message = this.resetDialogsAll.messages.get(a4);
                if (a4 < messagesCount2 && (lastMessage == null || message.date < lastMessage.date)) {
                    lastMessage = message;
                }
                if (message.to_id.channel_id != 0) {
                    TLRPC.Chat chat3 = chatsDict.get(message.to_id.channel_id);
                    if (chat3 != null && chat3.left) {
                        a = a4;
                    } else {
                        if (chat3 != null && chat3.megagroup) {
                            message.flags |= Integer.MIN_VALUE;
                        }
                        a = a4;
                        MessageObject messageObject = new MessageObject(this.currentAccount, message, usersDict, chatsDict, false);
                        new_dialogMessage.put(messageObject.getDialogId(), messageObject);
                    }
                } else {
                    if (message.to_id.chat_id != 0 && (chat2 = chatsDict.get(message.to_id.chat_id)) != null && chat2.migrated_to != null) {
                        a = a4;
                    }
                    a = a4;
                    MessageObject messageObject2 = new MessageObject(this.currentAccount, message, usersDict, chatsDict, false);
                    new_dialogMessage.put(messageObject2.getDialogId(), messageObject2);
                }
                a4 = a + 1;
            }
            for (int a5 = 0; a5 < this.resetDialogsAll.dialogs.size(); a5++) {
                TLRPC.Dialog d = this.resetDialogsAll.dialogs.get(a5);
                DialogObject.initDialog(d);
                if (d.id != 0) {
                    if (d.last_message_date == 0 && (mess = new_dialogMessage.get(d.id)) != null) {
                        d.last_message_date = mess.messageOwner.date;
                    }
                    if (DialogObject.isChannel(d)) {
                        TLRPC.Chat chat4 = chatsDict.get(-((int) d.id));
                        if (chat4 == null || !chat4.left) {
                            this.channelsPts.put(-((int) d.id), d.pts);
                            new_dialogs_dict.put(d.id, d);
                            value = this.dialogs_read_inbox_max.get(Long.valueOf(d.id));
                            if (value == null) {
                                value = 0;
                            }
                            this.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
                            value2 = this.dialogs_read_outbox_max.get(Long.valueOf(d.id));
                            if (value2 == null) {
                                value2 = 0;
                            }
                            this.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
                        }
                    } else {
                        if (((int) d.id) < 0 && (chat = chatsDict.get(-((int) d.id))) != null && chat.migrated_to != null) {
                        }
                        new_dialogs_dict.put(d.id, d);
                        value = this.dialogs_read_inbox_max.get(Long.valueOf(d.id));
                        if (value == null) {
                        }
                        this.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
                        value2 = this.dialogs_read_outbox_max.get(Long.valueOf(d.id));
                        if (value2 == null) {
                        }
                        this.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
                    }
                }
            }
            ImageLoader.saveMessagesThumbs(this.resetDialogsAll.messages);
            int a6 = 0;
            while (a6 < this.resetDialogsAll.messages.size()) {
                TLRPC.Message message2 = this.resetDialogsAll.messages.get(a6);
                if ((message2.action instanceof TLRPC.TL_messageActionChatDeleteUser) && (user = usersDict.get(message2.action.user_id)) != null && user.bot) {
                    message2.reply_markup = new TLRPC.TL_replyKeyboardHide();
                    message2.flags |= 64;
                }
                if (message2.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                    messagesCount = messagesCount2;
                } else if (message2.action instanceof TLRPC.TL_messageActionChannelCreate) {
                    messagesCount = messagesCount2;
                } else {
                    ConcurrentHashMap<Long, Integer> read_max = message2.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                    Integer value3 = read_max.get(Long.valueOf(message2.dialog_id));
                    if (value3 != null) {
                        messagesCount = messagesCount2;
                    } else {
                        messagesCount = messagesCount2;
                        value3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(message2.out, message2.dialog_id));
                        read_max.put(Long.valueOf(message2.dialog_id), value3);
                    }
                    message2.unread = value3.intValue() < message2.id;
                    a6++;
                    messagesCount2 = messagesCount;
                }
                message2.unread = false;
                message2.media_unread = false;
                a6++;
                messagesCount2 = messagesCount;
            }
            getMessagesStorage().resetDialogs(this.resetDialogsAll, messagesCount2, seq, newPts, date, qts, new_dialogs_dict, new_dialogMessage, lastMessage, dialogsCount);
            this.resetDialogsPinned = null;
            this.resetDialogsAll = null;
        }
    }

    public void lambda$resetDialogs$136$MessagesController(int seq, int newPts, int date, int qts, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            this.resetDialogsPinned = (TLRPC.TL_messages_peerDialogs) response;
            for (int a = 0; a < this.resetDialogsPinned.dialogs.size(); a++) {
                TLRPC.Dialog d = this.resetDialogsPinned.dialogs.get(a);
                d.pinned = true;
            }
            resetDialogs(false, seq, newPts, date, qts);
        }
    }

    public void lambda$resetDialogs$137$MessagesController(int seq, int newPts, int date, int qts, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            this.resetDialogsAll = (TLRPC.messages_Dialogs) response;
            resetDialogs(false, seq, newPts, date, qts);
        }
    }

    public void completeDialogsReset(final TLRPC.messages_Dialogs dialogsRes, int messagesCount, int seq, final int newPts, final int date, final int qts, final LongSparseArray<TLRPC.Dialog> new_dialogs_dict, final LongSparseArray<MessageObject> new_dialogMessage, TLRPC.Message lastMessage) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$completeDialogsReset$139$MessagesController(newPts, date, qts, dialogsRes, new_dialogs_dict, new_dialogMessage);
            }
        });
    }

    public void lambda$completeDialogsReset$139$MessagesController(int newPts, int date, int qts, final TLRPC.messages_Dialogs dialogsRes, final LongSparseArray new_dialogs_dict, final LongSparseArray new_dialogMessage) {
        this.gettingDifference = false;
        getMessagesStorage().setLastPtsValue(newPts);
        getMessagesStorage().setLastDateValue(date);
        getMessagesStorage().setLastQtsValue(qts);
        getDifference();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$138$MessagesController(dialogsRes, new_dialogs_dict, new_dialogMessage);
            }
        });
    }

    public void lambda$null$138$MessagesController(TLRPC.messages_Dialogs dialogsRes, LongSparseArray new_dialogs_dict, LongSparseArray new_dialogMessage) {
        this.resetingDialogs = false;
        applyDialogsNotificationsSettings(dialogsRes.dialogs);
        if (!getUserConfig().draftsLoaded) {
            getMediaDataController().loadDrafts();
        }
        putUsers(dialogsRes.users, false);
        putChats(dialogsRes.chats, false);
        for (int a = 0; a < this.allDialogs.size(); a++) {
            TLRPC.Dialog oldDialog = this.allDialogs.get(a);
            if (!DialogObject.isSecretDialogId(oldDialog.id)) {
                this.dialogs_dict.remove(oldDialog.id);
                MessageObject messageObject = this.dialogMessage.get(oldDialog.id);
                this.dialogMessage.remove(oldDialog.id);
                if (messageObject != null) {
                    this.dialogMessagesByIds.remove(messageObject.getId());
                    if (messageObject.messageOwner.random_id != 0) {
                        this.dialogMessagesByRandomIds.remove(messageObject.messageOwner.random_id);
                    }
                }
            }
        }
        for (int a2 = 0; a2 < new_dialogs_dict.size(); a2++) {
            long key = new_dialogs_dict.keyAt(a2);
            TLRPC.Dialog value = (TLRPC.Dialog) new_dialogs_dict.valueAt(a2);
            if (value.draft instanceof TLRPC.TL_draftMessage) {
                getMediaDataController().saveDraft(value.id, value.draft, null, false);
            }
            this.dialogs_dict.put(key, value);
            MessageObject messageObject2 = (MessageObject) new_dialogMessage.get(value.id);
            this.dialogMessage.put(key, messageObject2);
            if (messageObject2 != null && messageObject2.messageOwner.to_id.channel_id == 0) {
                this.dialogMessagesByIds.put(messageObject2.getId(), messageObject2);
                if (messageObject2.messageOwner.random_id != 0) {
                    this.dialogMessagesByRandomIds.put(messageObject2.messageOwner.random_id, messageObject2);
                }
            }
        }
        this.allDialogs.clear();
        int size = this.dialogs_dict.size();
        for (int a3 = 0; a3 < size; a3++) {
            this.allDialogs.add(this.dialogs_dict.valueAt(a3));
        }
        sortDialogs(null);
        this.dialogsEndReached.put(0, true);
        this.serverDialogsEndReached.put(0, false);
        this.dialogsEndReached.put(1, true);
        this.serverDialogsEndReached.put(1, false);
        int totalDialogsLoadCount = getUserConfig().getTotalDialogsCount(0);
        int[] dialogsLoadOffset = getUserConfig().getDialogLoadOffsets(0);
        if (totalDialogsLoadCount < 400 && dialogsLoadOffset[0] != -1 && dialogsLoadOffset[0] != Integer.MAX_VALUE) {
            loadDialogs(0, 100, 0, false);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    private void migrateDialogs(final int offset, int offsetDate, int offsetUser, int offsetChat, int offsetChannel, long accessPeer) {
        if (this.migratingDialogs || offset == -1) {
            return;
        }
        this.migratingDialogs = true;
        TLRPC.TL_messages_getDialogs req = new TLRPC.TL_messages_getDialogs();
        req.exclude_pinned = true;
        req.limit = 100;
        req.offset_id = offset;
        req.offset_date = offsetDate;
        if (offset == 0) {
            req.offset_peer = new TLRPC.TL_inputPeerEmpty();
        } else {
            if (offsetChannel != 0) {
                req.offset_peer = new TLRPC.TL_inputPeerChannel();
                req.offset_peer.channel_id = offsetChannel;
            } else if (offsetUser != 0) {
                req.offset_peer = new TLRPC.TL_inputPeerUser();
                req.offset_peer.user_id = offsetUser;
            } else {
                req.offset_peer = new TLRPC.TL_inputPeerChat();
                req.offset_peer.chat_id = offsetChat;
            }
            req.offset_peer.access_hash = accessPeer;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$migrateDialogs$143$MessagesController(offset, tLObject, tL_error);
            }
        });
    }

    public void lambda$migrateDialogs$143$MessagesController(final int offset, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            final TLRPC.messages_Dialogs dialogsRes = (TLRPC.messages_Dialogs) response;
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$141$MessagesController(dialogsRes, offset);
                }
            });
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$142$MessagesController();
            }
        });
    }

    public void lambda$null$141$MessagesController(TLRPC.messages_Dialogs dialogsRes, int offset) {
        int offsetId;
        int offsetId2;
        int totalDialogsLoadCount;
        TLRPC.Message lastMessage;
        StringBuilder dids;
        int i = offset;
        try {
            int i2 = 0;
            int totalDialogsLoadCount2 = getUserConfig().getTotalDialogsCount(0);
            getUserConfig().setTotalDialogsCount(0, dialogsRes.dialogs.size() + totalDialogsLoadCount2);
            TLRPC.Message lastMessage2 = null;
            for (int a = 0; a < dialogsRes.messages.size(); a++) {
                TLRPC.Message message = dialogsRes.messages.get(a);
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("search migrate id " + message.id + " date " + LocaleController.getInstance().formatterStats.format(message.date * 1000));
                }
                if (lastMessage2 == null || message.date < lastMessage2.date) {
                    lastMessage2 = message;
                }
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("migrate step with id " + lastMessage2.id + " date " + LocaleController.getInstance().formatterStats.format(lastMessage2.date * 1000));
            }
            if (dialogsRes.dialogs.size() >= 100) {
                offsetId = lastMessage2.id;
            } else {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("migrate stop due to not 100 dialogs");
                }
                for (int i3 = 0; i3 < 2; i3++) {
                    getUserConfig().setDialogsLoadOffset(i3, Integer.MAX_VALUE, getUserConfig().migrateOffsetDate, getUserConfig().migrateOffsetUserId, getUserConfig().migrateOffsetChatId, getUserConfig().migrateOffsetChannelId, getUserConfig().migrateOffsetAccess);
                }
                offsetId = -1;
            }
            StringBuilder dids2 = new StringBuilder(dialogsRes.dialogs.size() * 12);
            LongSparseArray<TLRPC.Dialog> dialogHashMap = new LongSparseArray<>();
            for (int a2 = 0; a2 < dialogsRes.dialogs.size(); a2++) {
                TLRPC.Dialog dialog = dialogsRes.dialogs.get(a2);
                DialogObject.initDialog(dialog);
                if (dids2.length() > 0) {
                    dids2.append(",");
                }
                dids2.append(dialog.id);
                dialogHashMap.put(dialog.id, dialog);
            }
            int i4 = 1;
            SQLiteCursor cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT did, folder_id FROM dialogs WHERE did IN (%s)", dids2.toString()), new Object[0]);
            while (cursor.next()) {
                long did = cursor.longValue(i2);
                int folder_id = cursor.intValue(i4);
                TLRPC.Dialog dialog2 = dialogHashMap.get(did);
                if (dialog2.folder_id == folder_id) {
                    dialogHashMap.remove(did);
                    if (dialog2 != null) {
                        dialogsRes.dialogs.remove(dialog2);
                        int a3 = 0;
                        while (true) {
                            if (a3 >= dialogsRes.messages.size()) {
                                break;
                            }
                            TLRPC.Message message2 = dialogsRes.messages.get(a3);
                            if (MessageObject.getDialogId(message2) == did) {
                                dialogsRes.messages.remove(a3);
                                a3--;
                                if (message2.id == dialog2.top_message) {
                                    dialog2.top_message = 0;
                                    break;
                                }
                            }
                            a3++;
                        }
                    }
                    i2 = 0;
                    i4 = 1;
                }
            }
            cursor.dispose();
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("migrate found missing dialogs " + dialogsRes.dialogs.size());
            }
            SQLiteCursor cursor2 = getMessagesStorage().getDatabase().queryFinalized("SELECT min(date) FROM dialogs WHERE date != 0 AND did >> 32 IN (0, -1)", new Object[0]);
            if (cursor2.next()) {
                int date = Math.max(1441062000, cursor2.intValue(0));
                int a4 = 0;
                while (a4 < dialogsRes.messages.size()) {
                    try {
                        TLRPC.Message message3 = dialogsRes.messages.get(a4);
                        if (message3.date >= date) {
                            totalDialogsLoadCount = totalDialogsLoadCount2;
                            lastMessage = lastMessage2;
                            dids = dids2;
                        } else {
                            if (i == -1) {
                                totalDialogsLoadCount = totalDialogsLoadCount2;
                                lastMessage = lastMessage2;
                                dids = dids2;
                            } else {
                                int i5 = 0;
                                while (i5 < 2) {
                                    getUserConfig().setDialogsLoadOffset(i5, getUserConfig().migrateOffsetId, getUserConfig().migrateOffsetDate, getUserConfig().migrateOffsetUserId, getUserConfig().migrateOffsetChatId, getUserConfig().migrateOffsetChannelId, getUserConfig().migrateOffsetAccess);
                                    i5++;
                                    totalDialogsLoadCount2 = totalDialogsLoadCount2;
                                    offsetId = offsetId;
                                    dids2 = dids2;
                                    lastMessage2 = lastMessage2;
                                }
                                totalDialogsLoadCount = totalDialogsLoadCount2;
                                lastMessage = lastMessage2;
                                dids = dids2;
                                offsetId = -1;
                                if (BuildVars.LOGS_ENABLED) {
                                    FileLog.d("migrate stop due to reached loaded dialogs " + LocaleController.getInstance().formatterStats.format(date * 1000));
                                }
                            }
                            dialogsRes.messages.remove(a4);
                            a4--;
                            long did2 = MessageObject.getDialogId(message3);
                            TLRPC.Dialog dialog3 = dialogHashMap.get(did2);
                            dialogHashMap.remove(did2);
                            if (dialog3 != null) {
                                dialogsRes.dialogs.remove(dialog3);
                            }
                        }
                        a4++;
                        i = offset;
                        totalDialogsLoadCount2 = totalDialogsLoadCount;
                        dids2 = dids;
                        lastMessage2 = lastMessage;
                    } catch (Exception e) {
                        e = e;
                        FileLog.e(e);
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                MessagesController.this.lambda$null$140$MessagesController();
                            }
                        });
                        return;
                    }
                }
                offsetId2 = offsetId;
                TLRPC.Message lastMessage3 = lastMessage2;
                if (lastMessage3 != null) {
                    lastMessage2 = lastMessage3;
                    if (lastMessage2.date < date && offset != -1) {
                        for (int i6 = 0; i6 < 2; i6++) {
                            getUserConfig().setDialogsLoadOffset(i6, getUserConfig().migrateOffsetId, getUserConfig().migrateOffsetDate, getUserConfig().migrateOffsetUserId, getUserConfig().migrateOffsetChatId, getUserConfig().migrateOffsetChannelId, getUserConfig().migrateOffsetAccess);
                        }
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("migrate stop due to reached loaded dialogs " + LocaleController.getInstance().formatterStats.format(date * 1000));
                        }
                        offsetId2 = -1;
                    }
                } else {
                    lastMessage2 = lastMessage3;
                }
            } else {
                offsetId2 = offsetId;
            }
            cursor2.dispose();
            getUserConfig().migrateOffsetDate = lastMessage2.date;
            if (lastMessage2.to_id.channel_id != 0) {
                getUserConfig().migrateOffsetChannelId = lastMessage2.to_id.channel_id;
                getUserConfig().migrateOffsetChatId = 0;
                getUserConfig().migrateOffsetUserId = 0;
                int a5 = 0;
                while (true) {
                    if (a5 >= dialogsRes.chats.size()) {
                        break;
                    }
                    TLRPC.Chat chat = dialogsRes.chats.get(a5);
                    if (chat.id != getUserConfig().migrateOffsetChannelId) {
                        a5++;
                    } else {
                        getUserConfig().migrateOffsetAccess = chat.access_hash;
                        break;
                    }
                }
            } else if (lastMessage2.to_id.chat_id != 0) {
                getUserConfig().migrateOffsetChatId = lastMessage2.to_id.chat_id;
                getUserConfig().migrateOffsetChannelId = 0;
                getUserConfig().migrateOffsetUserId = 0;
                int a6 = 0;
                while (true) {
                    if (a6 >= dialogsRes.chats.size()) {
                        break;
                    }
                    TLRPC.Chat chat2 = dialogsRes.chats.get(a6);
                    if (chat2.id != getUserConfig().migrateOffsetChatId) {
                        a6++;
                    } else {
                        getUserConfig().migrateOffsetAccess = chat2.access_hash;
                        break;
                    }
                }
            } else if (lastMessage2.to_id.user_id != 0) {
                getUserConfig().migrateOffsetUserId = lastMessage2.to_id.user_id;
                getUserConfig().migrateOffsetChatId = 0;
                getUserConfig().migrateOffsetChannelId = 0;
                int a7 = 0;
                while (true) {
                    if (a7 >= dialogsRes.users.size()) {
                        break;
                    }
                    TLRPC.User user = dialogsRes.users.get(a7);
                    if (user.id != getUserConfig().migrateOffsetUserId) {
                        a7++;
                    } else {
                        getUserConfig().migrateOffsetAccess = user.access_hash;
                        break;
                    }
                }
            }
            processLoadedDialogs(dialogsRes, null, 0, offsetId2, 0, 0, false, true, false);
        } catch (Exception e2) {
            e = e2;
        }
    }

    public void lambda$null$140$MessagesController() {
        this.migratingDialogs = false;
    }

    public void lambda$null$142$MessagesController() {
        this.migratingDialogs = false;
    }

    public void processLoadedDialogs(final TLRPC.messages_Dialogs dialogsRes, final ArrayList<TLRPC.EncryptedChat> encChats, final int folderId, final int offset, final int count, final int loadType, final boolean resetEnd, final boolean migrate, final boolean fromCache) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processLoadedDialogs$146$MessagesController(folderId, loadType, dialogsRes, resetEnd, count, encChats, offset, fromCache, migrate);
            }
        });
    }

    public void lambda$processLoadedDialogs$146$MessagesController(final int folderId, final int loadType, final TLRPC.messages_Dialogs dialogsRes, final boolean resetEnd, final int count, final ArrayList encChats, final int offset, final boolean fromCache, final boolean migrate) {
        SparseArray<TLRPC.EncryptedChat> enc_chats_dict;
        SparseArray<TLRPC.User> usersDict;
        LongSparseArray<TLRPC.Dialog> new_dialogs_dict;
        LongSparseArray<MessageObject> new_dialogMessage;
        int i;
        SparseArray<TLRPC.User> usersDict2;
        SparseArray<TLRPC.Chat> chatsDict;
        TLRPC.Chat chat;
        LongSparseArray<MessageObject> new_dialogMessage2;
        Integer value;
        Integer value2;
        MessageObject mess;
        SparseArray<TLRPC.User> usersDict3;
        int dialogsLoadOffsetDate;
        int dialogsLoadOffsetId;
        int totalDialogsLoadCount;
        int dialogsLoadOffsetUserId;
        long dialogsLoadOffsetAccess;
        int totalDialogsLoadCount2;
        int dialogsLoadOffsetChannelId;
        int totalDialogsLoadCount3;
        int a;
        TLRPC.Chat chat2;
        SparseArray<TLRPC.Chat> chatsDict2;
        TLRPC.Message lastMessage;
        SparseArray<TLRPC.EncryptedChat> enc_chats_dict2;
        if (!this.firstGettingTask) {
            getNewDeleteTask(null, 0);
            this.firstGettingTask = true;
        }
        final int[] dialogsLoadOffset = getUserConfig().getDialogLoadOffsets(folderId);
        if (loadType == this.DIALOGS_LOAD_TYPE_CACHE && dialogsRes.dialogs.size() == 0) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$144$MessagesController(dialogsRes, folderId, resetEnd, dialogsLoadOffset, count);
                }
            });
            return;
        }
        LongSparseArray<TLRPC.Dialog> new_dialogs_dict2 = new LongSparseArray<>();
        LongSparseArray<MessageObject> new_dialogMessage3 = new LongSparseArray<>();
        SparseArray<TLRPC.User> usersDict4 = new SparseArray<>();
        SparseArray<TLRPC.Chat> chatsDict3 = new SparseArray<>();
        for (int a2 = 0; a2 < dialogsRes.users.size(); a2++) {
            TLRPC.User u = dialogsRes.users.get(a2);
            usersDict4.put(u.id, u);
        }
        for (int a3 = 0; a3 < dialogsRes.chats.size(); a3++) {
            TLRPC.Chat c = dialogsRes.chats.get(a3);
            chatsDict3.put(c.id, c);
        }
        if (encChats != null) {
            SparseArray<TLRPC.EncryptedChat> enc_chats_dict3 = new SparseArray<>();
            int N = encChats.size();
            for (int a4 = 0; a4 < N; a4++) {
                TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat) encChats.get(a4);
                enc_chats_dict3.put(encryptedChat.id, encryptedChat);
            }
            enc_chats_dict = enc_chats_dict3;
        } else {
            enc_chats_dict = null;
        }
        if (loadType == this.DIALOGS_LOAD_TYPE_CACHE) {
            this.nextDialogsCacheOffset.put(folderId, offset + count);
        }
        TLRPC.Message lastMessage2 = null;
        int a5 = 0;
        while (a5 < dialogsRes.messages.size()) {
            TLRPC.Message message = dialogsRes.messages.get(a5);
            TLRPC.Message lastMessage3 = (lastMessage2 == null || message.date < lastMessage2.date) ? message : lastMessage2;
            if (message.to_id.channel_id != 0) {
                TLRPC.Chat chat3 = chatsDict3.get(message.to_id.channel_id);
                if (chat3 == null || !chat3.left) {
                    a = a5;
                } else {
                    long j = this.proxyDialogId;
                    if (j != 0) {
                        a = a5;
                        if (j != (-chat3.id)) {
                            chatsDict2 = chatsDict3;
                            lastMessage = lastMessage3;
                            enc_chats_dict2 = enc_chats_dict;
                        }
                    } else {
                        a = a5;
                        chatsDict2 = chatsDict3;
                        lastMessage = lastMessage3;
                        enc_chats_dict2 = enc_chats_dict;
                    }
                }
                if (chat3 != null && chat3.megagroup) {
                    message.flags |= Integer.MIN_VALUE;
                }
                lastMessage = lastMessage3;
                enc_chats_dict2 = enc_chats_dict;
                chatsDict2 = chatsDict3;
                MessageObject messageObject = new MessageObject(this.currentAccount, message, usersDict4, chatsDict3, false);
                new_dialogMessage3.put(messageObject.getDialogId(), messageObject);
            } else {
                a = a5;
                if (message.to_id.chat_id != 0 && (chat2 = chatsDict3.get(message.to_id.chat_id)) != null && chat2.migrated_to != null) {
                    chatsDict2 = chatsDict3;
                    lastMessage = lastMessage3;
                    enc_chats_dict2 = enc_chats_dict;
                }
                lastMessage = lastMessage3;
                enc_chats_dict2 = enc_chats_dict;
                chatsDict2 = chatsDict3;
                MessageObject messageObject2 = new MessageObject(this.currentAccount, message, usersDict4, chatsDict3, false);
                new_dialogMessage3.put(messageObject2.getDialogId(), messageObject2);
            }
            a5 = a + 1;
            enc_chats_dict = enc_chats_dict2;
            lastMessage2 = lastMessage;
            chatsDict3 = chatsDict2;
        }
        SparseArray<TLRPC.EncryptedChat> enc_chats_dict4 = enc_chats_dict;
        SparseArray<TLRPC.Chat> chatsDict4 = chatsDict3;
        if (fromCache || migrate || dialogsLoadOffset[0] == -1 || loadType != 0) {
            usersDict = usersDict4;
            new_dialogs_dict = new_dialogs_dict2;
            new_dialogMessage = new_dialogMessage3;
        } else {
            int totalDialogsLoadCount4 = getUserConfig().getTotalDialogsCount(folderId);
            long dialogsLoadOffsetAccess2 = 0;
            if (lastMessage2 != null) {
                usersDict3 = usersDict4;
                int i2 = lastMessage2.id;
                dialogsLoadOffsetDate = 0;
                int dialogsLoadOffsetDate2 = dialogsLoadOffset[0];
                if (i2 != dialogsLoadOffsetDate2) {
                    int totalDialogsLoadCount5 = totalDialogsLoadCount4 + dialogsRes.dialogs.size();
                    int dialogsLoadOffsetId2 = lastMessage2.id;
                    int dialogsLoadOffsetDate3 = lastMessage2.date;
                    dialogsLoadOffsetId = dialogsLoadOffsetId2;
                    if (lastMessage2.to_id.channel_id != 0) {
                        int dialogsLoadOffsetChannelId2 = lastMessage2.to_id.channel_id;
                        int a6 = 0;
                        while (true) {
                            totalDialogsLoadCount3 = totalDialogsLoadCount5;
                            if (a6 >= dialogsRes.chats.size()) {
                                dialogsLoadOffsetDate = dialogsLoadOffsetDate3;
                                break;
                            }
                            TLRPC.Chat chat4 = dialogsRes.chats.get(a6);
                            dialogsLoadOffsetDate = dialogsLoadOffsetDate3;
                            int dialogsLoadOffsetDate4 = chat4.id;
                            if (dialogsLoadOffsetDate4 != dialogsLoadOffsetChannelId2) {
                                a6++;
                                dialogsLoadOffsetDate3 = dialogsLoadOffsetDate;
                                totalDialogsLoadCount5 = totalDialogsLoadCount3;
                            } else {
                                dialogsLoadOffsetAccess2 = chat4.access_hash;
                                break;
                            }
                        }
                        dialogsLoadOffsetUserId = 0;
                        dialogsLoadOffsetAccess = dialogsLoadOffsetAccess2;
                        totalDialogsLoadCount2 = totalDialogsLoadCount3;
                        dialogsLoadOffsetChannelId = dialogsLoadOffsetChannelId2;
                        totalDialogsLoadCount = 0;
                    } else {
                        dialogsLoadOffsetDate = dialogsLoadOffsetDate3;
                        if (lastMessage2.to_id.chat_id != 0) {
                            int dialogsLoadOffsetChatId = lastMessage2.to_id.chat_id;
                            int a7 = 0;
                            while (true) {
                                if (a7 >= dialogsRes.chats.size()) {
                                    break;
                                }
                                TLRPC.Chat chat5 = dialogsRes.chats.get(a7);
                                if (chat5.id != dialogsLoadOffsetChatId) {
                                    a7++;
                                } else {
                                    dialogsLoadOffsetAccess2 = chat5.access_hash;
                                    break;
                                }
                            }
                            dialogsLoadOffsetUserId = 0;
                            dialogsLoadOffsetAccess = dialogsLoadOffsetAccess2;
                            totalDialogsLoadCount2 = totalDialogsLoadCount5;
                            dialogsLoadOffsetChannelId = 0;
                            totalDialogsLoadCount = dialogsLoadOffsetChatId;
                        } else if (lastMessage2.to_id.user_id == 0) {
                            dialogsLoadOffsetUserId = 0;
                            dialogsLoadOffsetAccess = 0;
                            totalDialogsLoadCount2 = totalDialogsLoadCount5;
                            dialogsLoadOffsetChannelId = 0;
                            totalDialogsLoadCount = 0;
                        } else {
                            int dialogsLoadOffsetUserId2 = lastMessage2.to_id.user_id;
                            int a8 = 0;
                            while (true) {
                                if (a8 >= dialogsRes.users.size()) {
                                    break;
                                }
                                TLRPC.User user = dialogsRes.users.get(a8);
                                if (user.id != dialogsLoadOffsetUserId2) {
                                    a8++;
                                } else {
                                    dialogsLoadOffsetAccess2 = user.access_hash;
                                    break;
                                }
                            }
                            dialogsLoadOffsetUserId = dialogsLoadOffsetUserId2;
                            dialogsLoadOffsetAccess = dialogsLoadOffsetAccess2;
                            totalDialogsLoadCount2 = totalDialogsLoadCount5;
                            dialogsLoadOffsetChannelId = 0;
                            totalDialogsLoadCount = 0;
                        }
                    }
                    usersDict = usersDict3;
                    int i3 = dialogsLoadOffsetChannelId;
                    new_dialogMessage = new_dialogMessage3;
                    new_dialogs_dict = new_dialogs_dict2;
                    getUserConfig().setDialogsLoadOffset(folderId, dialogsLoadOffsetId, dialogsLoadOffsetDate, dialogsLoadOffsetUserId, totalDialogsLoadCount, i3, dialogsLoadOffsetAccess);
                    getUserConfig().setTotalDialogsCount(folderId, totalDialogsLoadCount2);
                    getUserConfig().saveConfig(false);
                }
            } else {
                usersDict3 = usersDict4;
                dialogsLoadOffsetDate = 0;
            }
            dialogsLoadOffsetId = Integer.MAX_VALUE;
            totalDialogsLoadCount = 0;
            dialogsLoadOffsetUserId = 0;
            dialogsLoadOffsetAccess = 0;
            totalDialogsLoadCount2 = totalDialogsLoadCount4;
            dialogsLoadOffsetChannelId = 0;
            usersDict = usersDict3;
            int i32 = dialogsLoadOffsetChannelId;
            new_dialogMessage = new_dialogMessage3;
            new_dialogs_dict = new_dialogs_dict2;
            getUserConfig().setDialogsLoadOffset(folderId, dialogsLoadOffsetId, dialogsLoadOffsetDate, dialogsLoadOffsetUserId, totalDialogsLoadCount, i32, dialogsLoadOffsetAccess);
            getUserConfig().setTotalDialogsCount(folderId, totalDialogsLoadCount2);
            getUserConfig().saveConfig(false);
        }
        final ArrayList<TLRPC.Dialog> dialogsToReload = new ArrayList<>();
        int a9 = 0;
        while (a9 < dialogsRes.dialogs.size()) {
            TLRPC.Dialog d = dialogsRes.dialogs.get(a9);
            DialogObject.initDialog(d);
            if (d.id == 0) {
                new_dialogMessage2 = new_dialogMessage;
                chatsDict = chatsDict4;
            } else {
                int lower_id = (int) d.id;
                int high_id = (int) (d.id >> 32);
                if (lower_id == 0 && enc_chats_dict4 != null && enc_chats_dict4.get(high_id) == null) {
                    new_dialogMessage2 = new_dialogMessage;
                    chatsDict = chatsDict4;
                } else {
                    long j2 = this.proxyDialogId;
                    if (j2 != 0 && j2 == d.id) {
                        this.proxyDialog = d;
                    }
                    if (d.last_message_date == 0 && (mess = new_dialogMessage.get(d.id)) != null) {
                        d.last_message_date = mess.messageOwner.date;
                    }
                    boolean allowCheck = true;
                    if (DialogObject.isChannel(d)) {
                        chatsDict = chatsDict4;
                        TLRPC.Chat chat6 = chatsDict.get(-((int) d.id));
                        if (chat6 != null) {
                            if (!chat6.megagroup) {
                                allowCheck = false;
                            }
                            if (chat6.left) {
                                long j3 = this.proxyDialogId;
                                if (j3 == 0) {
                                    new_dialogMessage2 = new_dialogMessage;
                                } else if (j3 != d.id) {
                                    new_dialogMessage2 = new_dialogMessage;
                                }
                            }
                        }
                        this.channelsPts.put(-((int) d.id), d.pts);
                        new_dialogs_dict.put(d.id, d);
                        if (!allowCheck) {
                            new_dialogMessage2 = new_dialogMessage;
                            if (loadType == this.DIALOGS_LOAD_TYPE_CACHE && ((d.read_outbox_max_id == 0 || d.read_inbox_max_id == 0) && d.top_message != 0)) {
                                dialogsToReload.add(d);
                            }
                        } else {
                            new_dialogMessage2 = new_dialogMessage;
                        }
                        value = this.dialogs_read_inbox_max.get(Long.valueOf(d.id));
                        if (value == null) {
                            value = 0;
                        }
                        this.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
                        value2 = this.dialogs_read_outbox_max.get(Long.valueOf(d.id));
                        if (value2 == null) {
                            value2 = 0;
                        }
                        this.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
                    } else {
                        chatsDict = chatsDict4;
                        if (((int) d.id) < 0 && (chat = chatsDict.get(-((int) d.id))) != null && chat.migrated_to != null) {
                            new_dialogMessage2 = new_dialogMessage;
                        }
                        new_dialogs_dict.put(d.id, d);
                        if (!allowCheck) {
                        }
                        value = this.dialogs_read_inbox_max.get(Long.valueOf(d.id));
                        if (value == null) {
                        }
                        this.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
                        value2 = this.dialogs_read_outbox_max.get(Long.valueOf(d.id));
                        if (value2 == null) {
                        }
                        this.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
                    }
                }
            }
            a9++;
            chatsDict4 = chatsDict;
            new_dialogMessage = new_dialogMessage2;
        }
        final LongSparseArray<MessageObject> new_dialogMessage4 = new_dialogMessage;
        final SparseArray<TLRPC.Chat> chatsDict5 = chatsDict4;
        int a10 = this.DIALOGS_LOAD_TYPE_CACHE;
        if (loadType == a10) {
            i = 0;
        } else {
            ImageLoader.saveMessagesThumbs(dialogsRes.messages);
            for (int a11 = 0; a11 < dialogsRes.messages.size(); a11++) {
                TLRPC.Message message2 = dialogsRes.messages.get(a11);
                if (!(message2.action instanceof TLRPC.TL_messageActionChatDeleteUser)) {
                    usersDict2 = usersDict;
                } else {
                    usersDict2 = usersDict;
                    TLRPC.User user2 = usersDict2.get(message2.action.user_id);
                    if (user2 != null && user2.bot) {
                        message2.reply_markup = new TLRPC.TL_replyKeyboardHide();
                        message2.flags |= 64;
                    }
                }
                if (message2.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                    usersDict = usersDict2;
                } else if (message2.action instanceof TLRPC.TL_messageActionChannelCreate) {
                    usersDict = usersDict2;
                } else {
                    ConcurrentHashMap<Long, Integer> read_max = message2.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                    Integer value3 = read_max.get(Long.valueOf(message2.dialog_id));
                    if (value3 != null) {
                        usersDict = usersDict2;
                    } else {
                        usersDict = usersDict2;
                        value3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(message2.out, message2.dialog_id));
                        read_max.put(Long.valueOf(message2.dialog_id), value3);
                    }
                    message2.unread = value3.intValue() < message2.id;
                }
                message2.unread = false;
                message2.media_unread = false;
            }
            i = 0;
            getMessagesStorage().putDialogs(dialogsRes, 0);
        }
        if (loadType == this.DIALOGS_LOAD_TYPE_CHANNEL) {
            TLRPC.Chat chat7 = dialogsRes.chats.get(i);
            getChannelDifference(chat7.id);
            checkChannelInviter(chat7.id);
        }
        final LongSparseArray<TLRPC.Dialog> longSparseArray = new_dialogs_dict;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$145$MessagesController(loadType, dialogsRes, encChats, migrate, folderId, longSparseArray, new_dialogMessage4, chatsDict5, count, fromCache, offset, dialogsToReload);
            }
        });
    }

    public void lambda$null$144$MessagesController(TLRPC.messages_Dialogs dialogsRes, int folderId, boolean resetEnd, int[] dialogsLoadOffset, int count) {
        putUsers(dialogsRes.users, true);
        this.loadingDialogs.put(folderId, false);
        if (resetEnd) {
            this.dialogsEndReached.put(folderId, false);
            this.serverDialogsEndReached.put(folderId, false);
        } else if (dialogsLoadOffset[0] == Integer.MAX_VALUE) {
            this.dialogsEndReached.put(folderId, true);
            this.serverDialogsEndReached.put(folderId, true);
        } else {
            loadDialogs(folderId, 0, count, false);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public void lambda$null$145$MessagesController(int loadType, TLRPC.messages_Dialogs dialogsRes, ArrayList encChats, boolean migrate, int folderId, LongSparseArray new_dialogs_dict, LongSparseArray new_dialogMessage, SparseArray chatsDict, int count, boolean fromCache, int offset, ArrayList dialogsToReload) {
        int i;
        boolean z;
        TLRPC.Dialog currentDialog;
        int lastDialogDate;
        int lastDialogDate2;
        int archivedDialogsCount;
        if (loadType != this.DIALOGS_LOAD_TYPE_CACHE) {
            applyDialogsNotificationsSettings(dialogsRes.dialogs);
            if (!getUserConfig().draftsLoaded) {
                getMediaDataController().loadDrafts();
            }
        }
        putUsers(dialogsRes.users, loadType == this.DIALOGS_LOAD_TYPE_CACHE);
        putChats(dialogsRes.chats, loadType == this.DIALOGS_LOAD_TYPE_CACHE);
        if (encChats != null) {
            for (int a = 0; a < encChats.size(); a++) {
                TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat) encChats.get(a);
                if ((encryptedChat instanceof TLRPC.TL_encryptedChat) && AndroidUtilities.getMyLayerVersion(encryptedChat.layer) < 101) {
                    getSecretChatHelper().sendNotifyLayerMessage(encryptedChat, null);
                }
                putEncryptedChat(encryptedChat, true);
            }
        }
        if (!migrate && loadType != this.DIALOGS_LOAD_TYPE_UNKNOWN && loadType != this.DIALOGS_LOAD_TYPE_CHANNEL) {
            this.loadingDialogs.put(folderId, false);
        }
        this.dialogsLoaded = true;
        if (!migrate || this.allDialogs.isEmpty()) {
            i = 0;
        } else {
            ArrayList<TLRPC.Dialog> arrayList = this.allDialogs;
            i = arrayList.get(arrayList.size() - 1).last_message_date;
        }
        int lastDialogDate3 = i;
        int a2 = 0;
        boolean added = false;
        int archivedDialogsCount2 = 0;
        while (a2 < new_dialogs_dict.size()) {
            long key = new_dialogs_dict.keyAt(a2);
            TLRPC.Dialog value = (TLRPC.Dialog) new_dialogs_dict.valueAt(a2);
            if (loadType != this.DIALOGS_LOAD_TYPE_UNKNOWN) {
                currentDialog = this.dialogs_dict.get(key);
            } else {
                currentDialog = null;
            }
            if (migrate && currentDialog != null) {
                currentDialog.folder_id = value.folder_id;
            }
            if (migrate && lastDialogDate3 != 0 && value.last_message_date < lastDialogDate3) {
                lastDialogDate = lastDialogDate3;
            } else {
                if (loadType != this.DIALOGS_LOAD_TYPE_CACHE && (value.draft instanceof TLRPC.TL_draftMessage)) {
                    getMediaDataController().saveDraft(value.id, value.draft, null, false);
                }
                if (value.folder_id != folderId) {
                    archivedDialogsCount2++;
                }
                if (currentDialog == null) {
                    this.dialogs_dict.put(key, value);
                    MessageObject messageObject = (MessageObject) new_dialogMessage.get(value.id);
                    this.dialogMessage.put(key, messageObject);
                    if (messageObject != null && messageObject.messageOwner.to_id.channel_id == 0) {
                        added = true;
                        this.dialogMessagesByIds.put(messageObject.getId(), messageObject);
                        lastDialogDate2 = lastDialogDate3;
                        archivedDialogsCount = archivedDialogsCount2;
                        if (messageObject.messageOwner.random_id != 0) {
                            this.dialogMessagesByRandomIds.put(messageObject.messageOwner.random_id, messageObject);
                        }
                    } else {
                        added = true;
                        lastDialogDate2 = lastDialogDate3;
                        archivedDialogsCount = archivedDialogsCount2;
                    }
                    lastDialogDate = lastDialogDate2;
                    archivedDialogsCount2 = archivedDialogsCount;
                } else {
                    int lastDialogDate4 = lastDialogDate3;
                    int archivedDialogsCount3 = archivedDialogsCount2;
                    if (loadType != this.DIALOGS_LOAD_TYPE_CACHE) {
                        currentDialog.notify_settings = value.notify_settings;
                    }
                    currentDialog.pinned = value.pinned;
                    currentDialog.pinnedNum = value.pinnedNum;
                    MessageObject oldMsg = this.dialogMessage.get(key);
                    if (oldMsg == null || !oldMsg.deleted) {
                        if (oldMsg == null) {
                            lastDialogDate = lastDialogDate4;
                            if (value.top_message >= currentDialog.top_message) {
                                this.dialogs_dict.put(key, value);
                                MessageObject messageObject2 = (MessageObject) new_dialogMessage.get(value.id);
                                this.dialogMessage.put(key, messageObject2);
                                if (messageObject2 != null && messageObject2.messageOwner.to_id.channel_id == 0) {
                                    this.dialogMessagesByIds.put(messageObject2.getId(), messageObject2);
                                    if (messageObject2 != null && messageObject2.messageOwner.random_id != 0) {
                                        this.dialogMessagesByRandomIds.put(messageObject2.messageOwner.random_id, messageObject2);
                                    }
                                }
                                if (oldMsg != null) {
                                    this.dialogMessagesByIds.remove(oldMsg.getId());
                                    if (oldMsg.messageOwner.random_id != 0) {
                                        this.dialogMessagesByRandomIds.remove(oldMsg.messageOwner.random_id);
                                    }
                                }
                            }
                            archivedDialogsCount2 = archivedDialogsCount3;
                        } else if (currentDialog.top_message <= 0) {
                            MessageObject newMsg = (MessageObject) new_dialogMessage.get(value.id);
                            if (oldMsg.deleted || newMsg == null || newMsg.messageOwner.date > oldMsg.messageOwner.date) {
                                this.dialogs_dict.put(key, value);
                                this.dialogMessage.put(key, newMsg);
                                if (newMsg == null || newMsg.messageOwner.to_id.channel_id != 0) {
                                    lastDialogDate = lastDialogDate4;
                                } else {
                                    this.dialogMessagesByIds.put(newMsg.getId(), newMsg);
                                    if (newMsg != null) {
                                        lastDialogDate = lastDialogDate4;
                                        if (newMsg.messageOwner.random_id != 0) {
                                            this.dialogMessagesByRandomIds.put(newMsg.messageOwner.random_id, newMsg);
                                        }
                                    } else {
                                        lastDialogDate = lastDialogDate4;
                                    }
                                }
                                this.dialogMessagesByIds.remove(oldMsg.getId());
                                if (oldMsg.messageOwner.random_id != 0) {
                                    this.dialogMessagesByRandomIds.remove(oldMsg.messageOwner.random_id);
                                }
                            } else {
                                lastDialogDate = lastDialogDate4;
                            }
                            archivedDialogsCount2 = archivedDialogsCount3;
                        }
                    }
                    lastDialogDate = lastDialogDate4;
                    if (value.top_message >= currentDialog.top_message) {
                    }
                    archivedDialogsCount2 = archivedDialogsCount3;
                }
            }
            a2++;
            lastDialogDate3 = lastDialogDate;
        }
        this.allDialogs.clear();
        int size = this.dialogs_dict.size();
        for (int a3 = 0; a3 < size; a3++) {
            this.allDialogs.add(this.dialogs_dict.valueAt(a3));
        }
        sortDialogs(migrate ? chatsDict : null);
        if (loadType != this.DIALOGS_LOAD_TYPE_CHANNEL && loadType != this.DIALOGS_LOAD_TYPE_UNKNOWN) {
            if (!migrate) {
                this.dialogsEndReached.put(folderId, (dialogsRes.dialogs.size() == 0 || dialogsRes.dialogs.size() != count) && loadType == 0);
                if (archivedDialogsCount2 <= 0 || archivedDialogsCount2 >= 20 || folderId != 0) {
                    z = true;
                } else {
                    z = true;
                    this.dialogsEndReached.put(1, true);
                    int[] dialogsLoadOffsetArchived = getUserConfig().getDialogLoadOffsets(folderId);
                    if (dialogsLoadOffsetArchived[0] == Integer.MAX_VALUE) {
                        this.serverDialogsEndReached.put(1, true);
                    }
                }
                if (!fromCache) {
                    SparseBooleanArray sparseBooleanArray = this.serverDialogsEndReached;
                    if ((dialogsRes.dialogs.size() != 0 && dialogsRes.dialogs.size() == count) || loadType != 0) {
                        z = false;
                    }
                    sparseBooleanArray.put(folderId, z);
                }
            }
        }
        int totalDialogsLoadCount = getUserConfig().getTotalDialogsCount(folderId);
        int[] dialogsLoadOffset2 = getUserConfig().getDialogLoadOffsets(folderId);
        if (!fromCache && !migrate && totalDialogsLoadCount < 400 && dialogsLoadOffset2[0] != -1 && dialogsLoadOffset2[0] != Integer.MAX_VALUE) {
            loadDialogs(0, 100, folderId, false);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        if (migrate) {
            getUserConfig().migrateOffsetId = offset;
            getUserConfig().saveConfig(false);
            this.migratingDialogs = false;
            getNotificationCenter().postNotificationName(NotificationCenter.needReloadRecentDialogsSearch, new Object[0]);
        } else {
            generateUpdateMessage();
            if (!added && loadType == this.DIALOGS_LOAD_TYPE_CACHE) {
                loadDialogs(folderId, 0, count, false);
            }
        }
        migrateDialogs(getUserConfig().migrateOffsetId, getUserConfig().migrateOffsetDate, getUserConfig().migrateOffsetUserId, getUserConfig().migrateOffsetChatId, getUserConfig().migrateOffsetChannelId, getUserConfig().migrateOffsetAccess);
        if (!dialogsToReload.isEmpty()) {
            reloadDialogsReadValue(dialogsToReload, 0L);
        }
        loadUnreadDialogs();
    }

    private void applyDialogNotificationsSettings(long dialog_id, TLRPC.PeerNotifySettings notify_settings) {
        boolean updated;
        int i;
        if (notify_settings == null) {
            return;
        }
        int currentValue = this.notificationsPreferences.getInt("notify2_" + dialog_id, -1);
        int currentValue2 = this.notificationsPreferences.getInt("notifyuntil_" + dialog_id, 0);
        SharedPreferences.Editor editor = this.notificationsPreferences.edit();
        TLRPC.Dialog dialog = this.dialogs_dict.get(dialog_id);
        if (dialog != null) {
            dialog.notify_settings = notify_settings;
        }
        if ((notify_settings.flags & 2) != 0) {
            editor.putBoolean("silent_" + dialog_id, notify_settings.silent);
        } else {
            editor.remove("silent_" + dialog_id);
        }
        boolean updated2 = false;
        if ((notify_settings.flags & 4) != 0) {
            if (notify_settings.mute_until > getConnectionsManager().getCurrentTime()) {
                int until = 0;
                if (notify_settings.mute_until > getConnectionsManager().getCurrentTime() + 31536000) {
                    if (currentValue == 2) {
                        updated = false;
                    } else {
                        updated = true;
                        editor.putInt("notify2_" + dialog_id, 2);
                        if (dialog != null) {
                            dialog.notify_settings.mute_until = Integer.MAX_VALUE;
                        }
                    }
                } else {
                    if (currentValue == 3 && currentValue2 == notify_settings.mute_until) {
                        updated = false;
                    } else {
                        updated = true;
                        editor.putInt("notify2_" + dialog_id, 3);
                        editor.putInt("notifyuntil_" + dialog_id, notify_settings.mute_until);
                        if (dialog != null) {
                            dialog.notify_settings.mute_until = 0;
                        }
                    }
                    until = notify_settings.mute_until;
                }
                getMessagesStorage().setDialogFlags(dialog_id, (until << 32) | 1);
                getNotificationsController().removeNotificationsForDialog(dialog_id);
            } else {
                if (currentValue != 0 && currentValue != 1) {
                    if (dialog == null) {
                        i = 0;
                    } else {
                        i = 0;
                        dialog.notify_settings.mute_until = 0;
                    }
                    editor.putInt("notify2_" + dialog_id, i);
                    updated2 = true;
                }
                getMessagesStorage().setDialogFlags(dialog_id, 0L);
                updated = updated2;
            }
        } else {
            if (currentValue != -1) {
                if (dialog != null) {
                    dialog.notify_settings.mute_until = 0;
                }
                editor.remove("notify2_" + dialog_id);
                updated2 = true;
            }
            getMessagesStorage().setDialogFlags(dialog_id, 0L);
            updated = updated2;
        }
        editor.commit();
        if (updated) {
            getNotificationCenter().postNotificationName(NotificationCenter.notificationsSettingsUpdated, new Object[0]);
        }
    }

    private void applyDialogsNotificationsSettings(ArrayList<TLRPC.Dialog> dialogs) {
        int dialog_id;
        SharedPreferences.Editor editor = null;
        for (int a = 0; a < dialogs.size(); a++) {
            TLRPC.Dialog dialog = dialogs.get(a);
            if (dialog.peer != null && (dialog.notify_settings instanceof TLRPC.TL_peerNotifySettings)) {
                if (editor == null) {
                    editor = this.notificationsPreferences.edit();
                }
                if (dialog.peer.user_id != 0) {
                    dialog_id = dialog.peer.user_id;
                } else if (dialog.peer.chat_id != 0) {
                    dialog_id = -dialog.peer.chat_id;
                } else {
                    dialog_id = -dialog.peer.channel_id;
                }
                if ((dialog.notify_settings.flags & 2) != 0) {
                    editor.putBoolean("silent_" + dialog_id, dialog.notify_settings.silent);
                } else {
                    editor.remove("silent_" + dialog_id);
                }
                if ((dialog.notify_settings.flags & 4) == 0) {
                    editor.remove("notify2_" + dialog_id);
                } else if (dialog.notify_settings.mute_until <= getConnectionsManager().getCurrentTime()) {
                    editor.putInt("notify2_" + dialog_id, 0);
                } else if (dialog.notify_settings.mute_until > getConnectionsManager().getCurrentTime() + 31536000) {
                    editor.putInt("notify2_" + dialog_id, 2);
                    dialog.notify_settings.mute_until = Integer.MAX_VALUE;
                } else {
                    editor.putInt("notify2_" + dialog_id, 3);
                    editor.putInt("notifyuntil_" + dialog_id, dialog.notify_settings.mute_until);
                }
            }
        }
        if (editor != null) {
            editor.commit();
        }
    }

    public void reloadMentionsCountForChannels(final ArrayList<Integer> arrayList) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$reloadMentionsCountForChannels$149$MessagesController(arrayList);
            }
        });
    }

    public void lambda$reloadMentionsCountForChannels$149$MessagesController(ArrayList arrayList) {
        for (int a = 0; a < arrayList.size(); a++) {
            final long dialog_id = -((Integer) arrayList.get(a)).intValue();
            TLRPC.TL_messages_getUnreadMentions req = new TLRPC.TL_messages_getUnreadMentions();
            req.peer = getInputPeer((int) dialog_id);
            req.limit = 1;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$null$148$MessagesController(dialog_id, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$null$148$MessagesController(final long dialog_id, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$147$MessagesController(response, dialog_id);
            }
        });
    }

    public void lambda$null$147$MessagesController(TLObject response, long dialog_id) {
        int newCount;
        TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
        if (res != null) {
            if (res.count != 0) {
                newCount = res.count;
            } else {
                newCount = res.messages.size();
            }
            getMessagesStorage().resetMentionsCount(dialog_id, newCount);
        }
    }

    public void processDialogsUpdateRead(final LongSparseArray<Integer> dialogsToUpdate, final LongSparseArray<Integer> dialogsMentionsToUpdate) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processDialogsUpdateRead$150$MessagesController(dialogsToUpdate, dialogsMentionsToUpdate);
            }
        });
    }

    public void lambda$processDialogsUpdateRead$150$MessagesController(LongSparseArray dialogsToUpdate, LongSparseArray dialogsMentionsToUpdate) {
        if (dialogsToUpdate != null) {
            for (int a = 0; a < dialogsToUpdate.size(); a++) {
                long dialogId = dialogsToUpdate.keyAt(a);
                TLRPC.Dialog currentDialog = this.dialogs_dict.get(dialogId);
                if (currentDialog != null) {
                    int prevCount = currentDialog.unread_count;
                    currentDialog.unread_count = ((Integer) dialogsToUpdate.valueAt(a)).intValue();
                    if (prevCount != 0 && currentDialog.unread_count == 0 && !isDialogMuted(dialogId)) {
                        this.unreadUnmutedDialogs--;
                    } else if (prevCount == 0 && !currentDialog.unread_mark && currentDialog.unread_count != 0) {
                        this.dialogsUnreadOnly.add(currentDialog);
                        if (!isDialogMuted(dialogId)) {
                            this.unreadUnmutedDialogs++;
                        }
                    }
                }
            }
        }
        if (dialogsMentionsToUpdate != null) {
            for (int a2 = 0; a2 < dialogsMentionsToUpdate.size(); a2++) {
                TLRPC.Dialog currentDialog2 = this.dialogs_dict.get(dialogsMentionsToUpdate.keyAt(a2));
                if (currentDialog2 != null) {
                    currentDialog2.unread_mentions_count = ((Integer) dialogsMentionsToUpdate.valueAt(a2)).intValue();
                    if (this.createdDialogMainThreadIds.contains(Long.valueOf(currentDialog2.id))) {
                        getNotificationCenter().postNotificationName(NotificationCenter.updateMentionsCount, Long.valueOf(currentDialog2.id), Integer.valueOf(currentDialog2.unread_mentions_count));
                    }
                }
            }
        }
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 256);
        if (dialogsToUpdate != null) {
            getNotificationsController().processDialogsUpdateRead(dialogsToUpdate);
        }
    }

    public void checkLastDialogMessage(final TLRPC.Dialog dialog, TLRPC.InputPeer peer, long taskId) {
        long newTaskId;
        final int lower_id = (int) dialog.id;
        if (lower_id == 0 || this.checkingLastMessagesDialogs.indexOfKey(lower_id) >= 0) {
            return;
        }
        TLRPC.TL_messages_getHistory req = new TLRPC.TL_messages_getHistory();
        req.peer = peer == null ? getInputPeer(lower_id) : peer;
        if (req.peer == null) {
            return;
        }
        req.limit = 1;
        this.checkingLastMessagesDialogs.put(lower_id, true);
        if (taskId == 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(req.peer.getObjectSize() + 60);
                data.writeInt32(14);
                data.writeInt64(dialog.id);
                data.writeInt32(dialog.top_message);
                data.writeInt32(dialog.read_inbox_max_id);
                data.writeInt32(dialog.read_outbox_max_id);
                data.writeInt32(dialog.unread_count);
                data.writeInt32(dialog.last_message_date);
                data.writeInt32(dialog.pts);
                data.writeInt32(dialog.flags);
                data.writeBool(dialog.pinned);
                data.writeInt32(dialog.pinnedNum);
                data.writeInt32(dialog.unread_mentions_count);
                data.writeBool(dialog.unread_mark);
                data.writeInt32(dialog.folder_id);
                peer.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            long newTaskId2 = getMessagesStorage().createPendingTask(data);
            newTaskId = newTaskId2;
        } else {
            newTaskId = taskId;
        }
        final long j = newTaskId;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$checkLastDialogMessage$153$MessagesController(lower_id, dialog, j, tLObject, tL_error);
            }
        });
    }

    public void lambda$checkLastDialogMessage$153$MessagesController(final int lower_id, final TLRPC.Dialog dialog, long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
            removeDeletedMessagesFromArray(lower_id, res.messages);
            if (res.messages.isEmpty()) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$151$MessagesController(dialog);
                    }
                });
            } else {
                TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
                TLRPC.Message newMessage = res.messages.get(0);
                TLRPC.Dialog newDialog = new TLRPC.TL_dialog();
                newDialog.flags = dialog.flags;
                newDialog.top_message = newMessage.id;
                newDialog.last_message_date = newMessage.date;
                newDialog.notify_settings = dialog.notify_settings;
                newDialog.pts = dialog.pts;
                newDialog.unread_count = dialog.unread_count;
                newDialog.unread_mark = dialog.unread_mark;
                newDialog.unread_mentions_count = dialog.unread_mentions_count;
                newDialog.read_inbox_max_id = dialog.read_inbox_max_id;
                newDialog.read_outbox_max_id = dialog.read_outbox_max_id;
                newDialog.pinned = dialog.pinned;
                newDialog.pinnedNum = dialog.pinnedNum;
                newDialog.folder_id = dialog.folder_id;
                long j = dialog.id;
                newDialog.id = j;
                newMessage.dialog_id = j;
                dialogs.users.addAll(res.users);
                dialogs.chats.addAll(res.chats);
                dialogs.dialogs.add(newDialog);
                dialogs.messages.addAll(res.messages);
                dialogs.count = 1;
                processDialogsUpdate(dialogs, null);
                getMessagesStorage().putMessages(res.messages, true, true, false, getDownloadController().getAutodownloadMask(), true);
            }
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$152$MessagesController(lower_id);
            }
        });
    }

    public void lambda$null$151$MessagesController(TLRPC.Dialog dialog) {
        TLRPC.Dialog currentDialog = this.dialogs_dict.get(dialog.id);
        if (currentDialog != null && currentDialog.top_message == 0) {
            deleteDialog(dialog.id, 3);
        }
    }

    public void lambda$null$152$MessagesController(int lower_id) {
        this.checkingLastMessagesDialogs.delete(lower_id);
    }

    public void processDialogsUpdate(final TLRPC.messages_Dialogs dialogsRes, ArrayList<TLRPC.EncryptedChat> encChats) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processDialogsUpdate$155$MessagesController(dialogsRes);
            }
        });
    }

    public void lambda$processDialogsUpdate$155$MessagesController(final TLRPC.messages_Dialogs dialogsRes) {
        int a;
        long j;
        TLRPC.Chat chat;
        MessageObject mess;
        TLRPC.Chat chat2;
        final LongSparseArray<TLRPC.Dialog> new_dialogs_dict = new LongSparseArray<>();
        final LongSparseArray<MessageObject> new_dialogMessage = new LongSparseArray<>();
        SparseArray<TLRPC.User> usersDict = new SparseArray<>(dialogsRes.users.size());
        SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>(dialogsRes.chats.size());
        final LongSparseArray<Integer> dialogsToUpdate = new LongSparseArray<>();
        for (int a2 = 0; a2 < dialogsRes.users.size(); a2++) {
            TLRPC.User u = dialogsRes.users.get(a2);
            usersDict.put(u.id, u);
        }
        for (int a3 = 0; a3 < dialogsRes.chats.size(); a3++) {
            TLRPC.Chat c = dialogsRes.chats.get(a3);
            chatsDict.put(c.id, c);
        }
        while (true) {
            j = 0;
            if (a >= dialogsRes.messages.size()) {
                break;
            }
            TLRPC.Message message = dialogsRes.messages.get(a);
            long j2 = this.proxyDialogId;
            if (j2 == 0 || j2 != message.dialog_id) {
                if (message.to_id.channel_id != 0) {
                    TLRPC.Chat chat3 = chatsDict.get(message.to_id.channel_id);
                    a = (chat3 != null && chat3.left) ? a + 1 : 0;
                } else if (message.to_id.chat_id != 0 && (chat2 = chatsDict.get(message.to_id.chat_id)) != null && chat2.migrated_to != null) {
                }
            }
            MessageObject messageObject = new MessageObject(this.currentAccount, message, usersDict, chatsDict, false);
            new_dialogMessage.put(messageObject.getDialogId(), messageObject);
        }
        int a4 = 0;
        while (a4 < dialogsRes.dialogs.size()) {
            TLRPC.Dialog d = dialogsRes.dialogs.get(a4);
            DialogObject.initDialog(d);
            long j3 = this.proxyDialogId;
            if (j3 == j || j3 != d.id) {
                if (DialogObject.isChannel(d)) {
                    TLRPC.Chat chat4 = chatsDict.get(-((int) d.id));
                    if (chat4 != null && chat4.left) {
                        a4++;
                        j = 0;
                    }
                } else if (((int) d.id) < 0 && (chat = chatsDict.get(-((int) d.id))) != null && chat.migrated_to != null) {
                    a4++;
                    j = 0;
                }
            }
            if (d.last_message_date == 0 && (mess = new_dialogMessage.get(d.id)) != null) {
                d.last_message_date = mess.messageOwner.date;
            }
            new_dialogs_dict.put(d.id, d);
            dialogsToUpdate.put(d.id, Integer.valueOf(d.unread_count));
            Integer value = this.dialogs_read_inbox_max.get(Long.valueOf(d.id));
            if (value == null) {
                value = 0;
            }
            this.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
            Integer value2 = this.dialogs_read_outbox_max.get(Long.valueOf(d.id));
            if (value2 == null) {
                value2 = 0;
            }
            this.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
            a4++;
            j = 0;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$154$MessagesController(dialogsRes, new_dialogs_dict, new_dialogMessage, dialogsToUpdate);
            }
        });
    }

    public void lambda$null$154$MessagesController(TLRPC.messages_Dialogs dialogsRes, LongSparseArray new_dialogs_dict, LongSparseArray new_dialogMessage, LongSparseArray dialogsToUpdate) {
        TLRPC.Dialog value;
        TLRPC.Dialog value2;
        int i = 1;
        putUsers(dialogsRes.users, true);
        putChats(dialogsRes.chats, true);
        int a = 0;
        while (a < new_dialogs_dict.size()) {
            long key = new_dialogs_dict.keyAt(a);
            TLRPC.Dialog value3 = (TLRPC.Dialog) new_dialogs_dict.valueAt(a);
            TLRPC.Dialog currentDialog = this.dialogs_dict.get(key);
            if (currentDialog == null) {
                int offset = this.nextDialogsCacheOffset.get(value3.folder_id, 0) + i;
                this.nextDialogsCacheOffset.put(value3.folder_id, offset);
                this.dialogs_dict.put(key, value3);
                MessageObject messageObject = (MessageObject) new_dialogMessage.get(value3.id);
                this.dialogMessage.put(key, messageObject);
                if (messageObject != null && messageObject.messageOwner.to_id.channel_id == 0) {
                    this.dialogMessagesByIds.put(messageObject.getId(), messageObject);
                    if (messageObject.messageOwner.random_id != 0) {
                        this.dialogMessagesByRandomIds.put(messageObject.messageOwner.random_id, messageObject);
                    }
                }
            } else {
                currentDialog.unread_count = value3.unread_count;
                if (currentDialog.unread_mentions_count == value3.unread_mentions_count) {
                    value = value3;
                } else {
                    currentDialog.unread_mentions_count = value3.unread_mentions_count;
                    if (!this.createdDialogMainThreadIds.contains(Long.valueOf(currentDialog.id))) {
                        value = value3;
                    } else {
                        value = value3;
                        getNotificationCenter().postNotificationName(NotificationCenter.updateMentionsCount, Long.valueOf(currentDialog.id), Integer.valueOf(currentDialog.unread_mentions_count));
                    }
                }
                MessageObject oldMsg = this.dialogMessage.get(key);
                if (oldMsg == null) {
                    value2 = value;
                } else if (currentDialog.top_message > 0) {
                    value2 = value;
                } else {
                    TLRPC.Dialog value4 = value;
                    MessageObject newMsg = (MessageObject) new_dialogMessage.get(value4.id);
                    if (oldMsg.deleted || newMsg == null || newMsg.messageOwner.date > oldMsg.messageOwner.date) {
                        this.dialogs_dict.put(key, value4);
                        this.dialogMessage.put(key, newMsg);
                        if (newMsg != null && newMsg.messageOwner.to_id.channel_id == 0) {
                            this.dialogMessagesByIds.put(newMsg.getId(), newMsg);
                            if (newMsg.messageOwner.random_id != 0) {
                                this.dialogMessagesByRandomIds.put(newMsg.messageOwner.random_id, newMsg);
                            }
                        }
                        this.dialogMessagesByIds.remove(oldMsg.getId());
                        if (oldMsg.messageOwner.random_id != 0) {
                            this.dialogMessagesByRandomIds.remove(oldMsg.messageOwner.random_id);
                        }
                    }
                }
                if ((oldMsg != null && oldMsg.deleted) || value2.top_message > currentDialog.top_message) {
                    this.dialogs_dict.put(key, value2);
                    MessageObject messageObject2 = (MessageObject) new_dialogMessage.get(value2.id);
                    this.dialogMessage.put(key, messageObject2);
                    if (messageObject2 != null && messageObject2.messageOwner.to_id.channel_id == 0) {
                        this.dialogMessagesByIds.put(messageObject2.getId(), messageObject2);
                        if (messageObject2.messageOwner.random_id != 0) {
                            this.dialogMessagesByRandomIds.put(messageObject2.messageOwner.random_id, messageObject2);
                        }
                    }
                    if (oldMsg != null) {
                        this.dialogMessagesByIds.remove(oldMsg.getId());
                        if (oldMsg.messageOwner.random_id != 0) {
                            this.dialogMessagesByRandomIds.remove(oldMsg.messageOwner.random_id);
                        }
                    }
                    if (messageObject2 == null) {
                        checkLastDialogMessage(value2, null, 0L);
                    }
                }
            }
            a++;
            i = 1;
        }
        this.allDialogs.clear();
        int size = this.dialogs_dict.size();
        for (int a2 = 0; a2 < size; a2++) {
            this.allDialogs.add(this.dialogs_dict.valueAt(a2));
        }
        sortDialogs(null);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        getNotificationsController().processDialogsUpdateRead(dialogsToUpdate);
    }

    public void addToViewsQueue(final MessageObject messageObject) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$addToViewsQueue$156$MessagesController(messageObject);
            }
        });
    }

    public void lambda$addToViewsQueue$156$MessagesController(MessageObject messageObject) {
        int peer = (int) messageObject.getDialogId();
        int id = messageObject.getId();
        ArrayList<Integer> ids = this.channelViewsToSend.get(peer);
        if (ids == null) {
            ids = new ArrayList<>();
            this.channelViewsToSend.put(peer, ids);
        }
        if (!ids.contains(Integer.valueOf(id))) {
            ids.add(Integer.valueOf(id));
        }
    }

    public void addToPollsQueue(long dialogId, ArrayList<MessageObject> visibleObjects) {
        SparseArray<MessageObject> array = this.pollsToCheck.get(dialogId);
        if (array == null) {
            array = new SparseArray<>();
            this.pollsToCheck.put(dialogId, array);
            this.pollsToCheckSize++;
        }
        int N = array.size();
        for (int a = 0; a < N; a++) {
            array.valueAt(a).pollVisibleOnScreen = false;
        }
        int N2 = visibleObjects.size();
        for (int a2 = 0; a2 < N2; a2++) {
            MessageObject messageObject = visibleObjects.get(a2);
            if (messageObject.type == 17) {
                int id = messageObject.getId();
                MessageObject object = array.get(id);
                if (object != null) {
                    object.pollVisibleOnScreen = true;
                } else {
                    array.put(id, messageObject);
                }
            }
        }
    }

    public void markMessageContentAsRead(MessageObject messageObject) {
        if (messageObject.scheduled) {
            return;
        }
        ArrayList<Long> arrayList = new ArrayList<>();
        long messageId = messageObject.getId();
        if (messageObject.messageOwner.to_id.channel_id != 0) {
            messageId |= messageObject.messageOwner.to_id.channel_id << 32;
        }
        if (messageObject.messageOwner.mentioned) {
            getMessagesStorage().markMentionMessageAsRead(messageObject.getId(), messageObject.messageOwner.to_id.channel_id, messageObject.getDialogId());
        }
        arrayList.add(Long.valueOf(messageId));
        getMessagesStorage().markMessagesContentAsRead(arrayList, 0);
        getNotificationCenter().postNotificationName(NotificationCenter.messagesReadContent, arrayList);
        if (messageObject.getId() < 0) {
            markMessageAsRead(messageObject.getDialogId(), messageObject.messageOwner.random_id, Integer.MIN_VALUE);
        } else if (messageObject.messageOwner.to_id.channel_id != 0) {
            TLRPC.TL_channels_readMessageContents req = new TLRPC.TL_channels_readMessageContents();
            req.channel = getInputChannel(messageObject.messageOwner.to_id.channel_id);
            if (req.channel == null) {
                return;
            }
            req.id.add(Integer.valueOf(messageObject.getId()));
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$markMessageContentAsRead$157(tLObject, tL_error);
                }
            });
        } else {
            TLRPC.TL_messages_readMessageContents req2 = new TLRPC.TL_messages_readMessageContents();
            req2.id.add(Integer.valueOf(messageObject.getId()));
            getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$markMessageContentAsRead$158$MessagesController(tLObject, tL_error);
                }
            });
        }
    }

    public static void lambda$markMessageContentAsRead$157(TLObject response, TLRPC.TL_error error) {
    }

    public void lambda$markMessageContentAsRead$158$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
            processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
        }
    }

    public void markMentionMessageAsRead(int mid, int channelId, long did) {
        getMessagesStorage().markMentionMessageAsRead(mid, channelId, did);
        if (channelId != 0) {
            TLRPC.TL_channels_readMessageContents req = new TLRPC.TL_channels_readMessageContents();
            req.channel = getInputChannel(channelId);
            if (req.channel == null) {
                return;
            }
            req.id.add(Integer.valueOf(mid));
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$markMentionMessageAsRead$159(tLObject, tL_error);
                }
            });
            return;
        }
        TLRPC.TL_messages_readMessageContents req2 = new TLRPC.TL_messages_readMessageContents();
        req2.id.add(Integer.valueOf(mid));
        getConnectionsManager().sendRequest(req2, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$markMentionMessageAsRead$160$MessagesController(tLObject, tL_error);
            }
        });
    }

    public static void lambda$markMentionMessageAsRead$159(TLObject response, TLRPC.TL_error error) {
    }

    public void lambda$markMentionMessageAsRead$160$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
            processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
        }
    }

    public void markMessageAsRead(int mid, int channelId, TLRPC.InputChannel inputChannel, int ttl, long taskId) {
        TLRPC.InputChannel inputChannel2;
        final long newTaskId;
        if (mid == 0 || ttl <= 0) {
            return;
        }
        if (channelId != 0 && inputChannel == null) {
            TLRPC.InputChannel inputChannel3 = getInputChannel(channelId);
            if (inputChannel3 != null) {
                inputChannel2 = inputChannel3;
            } else {
                return;
            }
        } else {
            inputChannel2 = inputChannel;
        }
        if (taskId == 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(16 + (inputChannel2 != null ? inputChannel2.getObjectSize() : 0));
                data.writeInt32(11);
                data.writeInt32(mid);
                data.writeInt32(channelId);
                data.writeInt32(ttl);
                if (channelId != 0) {
                    inputChannel2.serializeToStream(data);
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            long newTaskId2 = getMessagesStorage().createPendingTask(data);
            newTaskId = newTaskId2;
        } else {
            newTaskId = taskId;
        }
        int time = getConnectionsManager().getCurrentTime();
        getMessagesStorage().createTaskForMid(mid, channelId, time, time, ttl, false);
        if (channelId != 0) {
            TLRPC.TL_channels_readMessageContents req = new TLRPC.TL_channels_readMessageContents();
            req.channel = inputChannel2;
            req.id.add(Integer.valueOf(mid));
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$markMessageAsRead$161$MessagesController(newTaskId, tLObject, tL_error);
                }
            });
            return;
        }
        TLRPC.TL_messages_readMessageContents req2 = new TLRPC.TL_messages_readMessageContents();
        req2.id.add(Integer.valueOf(mid));
        getConnectionsManager().sendRequest(req2, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$markMessageAsRead$162$MessagesController(newTaskId, tLObject, tL_error);
            }
        });
    }

    public void lambda$markMessageAsRead$161$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void lambda$markMessageAsRead$162$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
            processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void markMessageAsRead(long dialog_id, long random_id, int ttl) {
        TLRPC.EncryptedChat chat;
        if (random_id == 0 || dialog_id == 0) {
            return;
        }
        if (ttl <= 0 && ttl != Integer.MIN_VALUE) {
            return;
        }
        int lower_part = (int) dialog_id;
        int high_id = (int) (dialog_id >> 32);
        if (lower_part != 0 || (chat = getEncryptedChat(Integer.valueOf(high_id))) == null) {
            return;
        }
        ArrayList<Long> random_ids = new ArrayList<>();
        random_ids.add(Long.valueOf(random_id));
        getSecretChatHelper().sendMessagesReadMessage(chat, random_ids, null);
        if (ttl > 0) {
            int time = getConnectionsManager().getCurrentTime();
            getMessagesStorage().createTaskForSecretChat(chat.id, time, time, 0, random_ids);
        }
    }

    private void completeReadTask(ReadTask task) {
        TLObject req;
        int lower_part = (int) task.dialogId;
        int high_id = (int) (task.dialogId >> 32);
        if (lower_part != 0) {
            TLRPC.InputPeer inputPeer = getInputPeer(lower_part);
            if (inputPeer instanceof TLRPC.TL_inputPeerChannel) {
                TLRPC.TL_channels_readHistory request = new TLRPC.TL_channels_readHistory();
                request.channel = getInputChannel(-lower_part);
                request.max_id = task.maxId;
                req = request;
            } else {
                TLRPC.TL_messages_readHistory request2 = new TLRPC.TL_messages_readHistory();
                request2.peer = inputPeer;
                request2.max_id = task.maxId;
                req = request2;
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$completeReadTask$163$MessagesController(tLObject, tL_error);
                }
            });
            return;
        }
        TLRPC.EncryptedChat chat = getEncryptedChat(Integer.valueOf(high_id));
        if (chat.auth_key != null && chat.auth_key.length > 1 && (chat instanceof TLRPC.TL_encryptedChat)) {
            TLRPC.TL_messages_readEncryptedHistory req2 = new TLRPC.TL_messages_readEncryptedHistory();
            req2.peer = new TLRPC.TL_inputEncryptedChat();
            req2.peer.chat_id = chat.id;
            req2.peer.access_hash = chat.access_hash;
            req2.max_date = task.maxDate;
            getConnectionsManager().sendRequest(req2, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$completeReadTask$164(tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$completeReadTask$163$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null && (response instanceof TLRPC.TL_messages_affectedMessages)) {
            TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
            processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
        }
    }

    public static void lambda$completeReadTask$164(TLObject response, TLRPC.TL_error error) {
    }

    private void checkReadTasks() {
        long time = SystemClock.elapsedRealtime();
        int a = 0;
        int size = this.readTasks.size();
        while (a < size) {
            ReadTask task = this.readTasks.get(a);
            if (task.sendRequestTime <= time) {
                completeReadTask(task);
                this.readTasks.remove(a);
                this.readTasksMap.remove(task.dialogId);
                a--;
                size--;
            }
            a++;
        }
    }

    public void markDialogAsReadNow(final long dialogId) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$markDialogAsReadNow$165$MessagesController(dialogId);
            }
        });
    }

    public void lambda$markDialogAsReadNow$165$MessagesController(long dialogId) {
        ReadTask currentReadTask = this.readTasksMap.get(dialogId);
        if (currentReadTask == null) {
            return;
        }
        completeReadTask(currentReadTask);
        this.readTasks.remove(currentReadTask);
        this.readTasksMap.remove(dialogId);
    }

    public void markMentionsAsRead(long dialogId) {
        if (((int) dialogId) == 0) {
            return;
        }
        getMessagesStorage().resetMentionsCount(dialogId, 0);
        TLRPC.TL_messages_readMentions req = new TLRPC.TL_messages_readMentions();
        req.peer = getInputPeer((int) dialogId);
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.lambda$markMentionsAsRead$166(tLObject, tL_error);
            }
        });
    }

    public static void lambda$markMentionsAsRead$166(TLObject response, TLRPC.TL_error error) {
    }

    public void markDialogAsRead(final long dialogId, final int maxPositiveId, final int maxNegativeId, final int maxDate, final boolean popup, final int countDiff, final boolean readNow, int scheduledCount) {
        boolean createReadTask;
        boolean isChannel;
        long minMessageId;
        boolean isChannel2;
        long maxMessageId;
        Integer value;
        Integer value2;
        int lower_part = (int) dialogId;
        int high_id = (int) (dialogId >> 32);
        final boolean countMessages = getNotificationsController().showBadgeMessages;
        if (lower_part != 0) {
            if (maxPositiveId == 0) {
                return;
            }
            long maxMessageId2 = maxPositiveId;
            long minMessageId2 = maxNegativeId;
            if (lower_part >= 0) {
                isChannel = false;
            } else if (ChatObject.isChannel(getChat(Integer.valueOf(-lower_part)))) {
                maxMessageId = maxMessageId2 | ((-lower_part) << 32);
                minMessageId = minMessageId2 | ((-lower_part) << 32);
                isChannel2 = true;
                value = this.dialogs_read_inbox_max.get(Long.valueOf(dialogId));
                if (value == null) {
                    value2 = value;
                } else {
                    value2 = 0;
                }
                this.dialogs_read_inbox_max.put(Long.valueOf(dialogId), Integer.valueOf(Math.max(value2.intValue(), maxPositiveId)));
                getMessagesStorage().processPendingRead(dialogId, maxMessageId, minMessageId, isChannel2, scheduledCount);
                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$markDialogAsRead$168$MessagesController(dialogId, countDiff, maxPositiveId, countMessages, popup);
                    }
                });
                createReadTask = maxPositiveId != Integer.MAX_VALUE;
            } else {
                isChannel = false;
            }
            minMessageId = minMessageId2;
            isChannel2 = isChannel;
            maxMessageId = maxMessageId2;
            value = this.dialogs_read_inbox_max.get(Long.valueOf(dialogId));
            if (value == null) {
            }
            this.dialogs_read_inbox_max.put(Long.valueOf(dialogId), Integer.valueOf(Math.max(value2.intValue(), maxPositiveId)));
            getMessagesStorage().processPendingRead(dialogId, maxMessageId, minMessageId, isChannel2, scheduledCount);
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$markDialogAsRead$168$MessagesController(dialogId, countDiff, maxPositiveId, countMessages, popup);
                }
            });
            createReadTask = maxPositiveId != Integer.MAX_VALUE;
        } else if (maxDate != 0) {
            TLRPC.EncryptedChat chat = getEncryptedChat(Integer.valueOf(high_id));
            getMessagesStorage().processPendingRead(dialogId, maxPositiveId, maxNegativeId, false, scheduledCount);
            createReadTask = true;
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$markDialogAsRead$170$MessagesController(dialogId, maxDate, popup, countDiff, maxNegativeId, countMessages);
                }
            });
            if (chat != null && chat.ttl > 0) {
                int serverTime = Math.max(getConnectionsManager().getCurrentTime(), maxDate);
                getMessagesStorage().createTaskForSecretChat(chat.id, serverTime, serverTime, 0, null);
            }
        } else {
            return;
        }
        if (createReadTask) {
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$markDialogAsRead$171$MessagesController(dialogId, readNow, maxDate, maxPositiveId);
                }
            });
        }
    }

    public void lambda$markDialogAsRead$168$MessagesController(final long dialogId, final int countDiff, final int maxPositiveId, final boolean countMessages, final boolean popup) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$167$MessagesController(dialogId, countDiff, maxPositiveId, countMessages, popup);
            }
        });
    }

    public void lambda$null$167$MessagesController(long dialogId, int countDiff, int maxPositiveId, boolean countMessages, boolean popup) {
        TLRPC.Dialog folder;
        TLRPC.Dialog dialog = this.dialogs_dict.get(dialogId);
        if (dialog != null) {
            int prevCount = dialog.unread_count;
            if (countDiff != 0 && maxPositiveId < dialog.top_message) {
                dialog.unread_count = Math.max(dialog.unread_count - countDiff, 0);
                if (maxPositiveId != Integer.MIN_VALUE && dialog.unread_count > dialog.top_message - maxPositiveId) {
                    dialog.unread_count = dialog.top_message - maxPositiveId;
                }
            } else {
                dialog.unread_count = 0;
            }
            if (dialog.folder_id != 0 && (folder = this.dialogs_dict.get(DialogObject.makeFolderDialogId(dialog.folder_id))) != null) {
                if (countMessages) {
                    if (isDialogMuted(dialog.id)) {
                        folder.unread_count -= prevCount - dialog.unread_count;
                    } else {
                        folder.unread_mentions_count -= prevCount - dialog.unread_count;
                    }
                } else if (dialog.unread_count == 0) {
                    if (isDialogMuted(dialog.id)) {
                        folder.unread_count--;
                    } else {
                        folder.unread_mentions_count--;
                    }
                }
            }
            if ((prevCount != 0 || dialog.unread_mark) && dialog.unread_count == 0 && !isDialogMuted(dialogId)) {
                this.unreadUnmutedDialogs--;
            }
            if (dialog.unread_mark) {
                dialog.unread_mark = false;
                getMessagesStorage().setDialogUnread(dialog.id, false);
            }
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 256);
        }
        if (!popup) {
            getNotificationsController().processReadMessages(null, dialogId, 0, maxPositiveId, false);
            LongSparseArray<Integer> dialogsToUpdate = new LongSparseArray<>(1);
            dialogsToUpdate.put(dialogId, 0);
            getNotificationsController().processDialogsUpdateRead(dialogsToUpdate);
            return;
        }
        getNotificationsController().processReadMessages(null, dialogId, 0, maxPositiveId, true);
        LongSparseArray<Integer> dialogsToUpdate2 = new LongSparseArray<>(1);
        dialogsToUpdate2.put(dialogId, -1);
        getNotificationsController().processDialogsUpdateRead(dialogsToUpdate2);
    }

    public void lambda$markDialogAsRead$170$MessagesController(final long dialogId, final int maxDate, final boolean popup, final int countDiff, final int maxNegativeId, final boolean countMessages) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$169$MessagesController(dialogId, maxDate, popup, countDiff, maxNegativeId, countMessages);
            }
        });
    }

    public void lambda$null$169$MessagesController(long dialogId, int maxDate, boolean popup, int countDiff, int maxNegativeId, boolean countMessages) {
        TLRPC.Dialog folder;
        getNotificationsController().processReadMessages(null, dialogId, maxDate, 0, popup);
        TLRPC.Dialog dialog = this.dialogs_dict.get(dialogId);
        if (dialog != null) {
            int prevCount = dialog.unread_count;
            if (countDiff == 0 || maxNegativeId <= dialog.top_message) {
                dialog.unread_count = 0;
            } else {
                dialog.unread_count = Math.max(dialog.unread_count - countDiff, 0);
                if (maxNegativeId != Integer.MAX_VALUE && dialog.unread_count > maxNegativeId - dialog.top_message) {
                    dialog.unread_count = maxNegativeId - dialog.top_message;
                }
            }
            if (dialog.folder_id != 0 && (folder = this.dialogs_dict.get(DialogObject.makeFolderDialogId(dialog.folder_id))) != null) {
                if (countMessages) {
                    if (isDialogMuted(dialog.id)) {
                        folder.unread_count -= prevCount - dialog.unread_count;
                    } else {
                        folder.unread_mentions_count -= prevCount - dialog.unread_count;
                    }
                } else if (dialog.unread_count == 0) {
                    if (isDialogMuted(dialog.id)) {
                        folder.unread_count--;
                    } else {
                        folder.unread_mentions_count--;
                    }
                }
            }
            if ((prevCount != 0 || dialog.unread_mark) && dialog.unread_count == 0 && !isDialogMuted(dialogId)) {
                this.unreadUnmutedDialogs--;
            }
            if (dialog.unread_mark) {
                dialog.unread_mark = false;
                getMessagesStorage().setDialogUnread(dialog.id, false);
            }
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 256);
        }
        LongSparseArray<Integer> dialogsToUpdate = new LongSparseArray<>(1);
        dialogsToUpdate.put(dialogId, 0);
        getNotificationsController().processDialogsUpdateRead(dialogsToUpdate);
    }

    public void lambda$markDialogAsRead$171$MessagesController(long dialogId, boolean readNow, int maxDate, int maxPositiveId) {
        ReadTask currentReadTask = this.readTasksMap.get(dialogId);
        if (currentReadTask == null) {
            currentReadTask = new ReadTask();
            currentReadTask.dialogId = dialogId;
            currentReadTask.sendRequestTime = SystemClock.elapsedRealtime() + DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS;
            if (!readNow) {
                this.readTasksMap.put(dialogId, currentReadTask);
                this.readTasks.add(currentReadTask);
            }
        }
        currentReadTask.maxDate = maxDate;
        currentReadTask.maxId = maxPositiveId;
        if (readNow) {
            completeReadTask(currentReadTask);
        }
    }

    public int createChat(String title, ArrayList<Integer> selectedContacts, String about, int type, BDLocation location, String locationAddress, final BaseFragment fragment) {
        if (type != 0) {
            if (type == 2 || type == 4) {
                final TLRPC.TL_channels_createChannel req = new TLRPC.TL_channels_createChannel();
                req.title = title;
                req.about = about != null ? about : "";
                if (type == 4) {
                    req.megagroup = true;
                } else {
                    req.broadcast = true;
                }
                if (location != null) {
                    req.geo_point = new TLRPC.TL_inputGeoPoint();
                    req.geo_point.lat = location.getLatitude();
                    req.geo_point._long = location.getLongitude();
                    req.address = locationAddress;
                    req.flags = 4 | req.flags;
                }
                return getConnectionsManager().sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$createChat$177$MessagesController(fragment, req, tLObject, tL_error);
                    }
                }, 2);
            }
            return 0;
        }
        final TLRPC.TL_messages_createChat req2 = new TLRPC.TL_messages_createChat();
        req2.title = title;
        for (int a = 0; a < selectedContacts.size(); a++) {
            TLRPC.User user = getUser(selectedContacts.get(a));
            if (user != null) {
                req2.users.add(getInputUser(user));
            }
        }
        return getConnectionsManager().sendRequest(req2, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$createChat$174$MessagesController(fragment, req2, tLObject, tL_error);
            }
        }, 2);
    }

    public void lambda$createChat$174$MessagesController(final BaseFragment fragment, final TLRPC.TL_messages_createChat req, TLObject response, final TLRPC.TL_error error) {
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$172$MessagesController(error, fragment, req);
                }
            });
            return;
        }
        final TLRPC.Updates updates = (TLRPC.Updates) response;
        processUpdates(updates, false);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$173$MessagesController(updates);
            }
        });
    }

    public void lambda$null$172$MessagesController(TLRPC.TL_error error, BaseFragment fragment, TLRPC.TL_messages_createChat req) {
        AlertsCreator.processError(this.currentAccount, error, fragment, req, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.chatDidFailCreate, new Object[0]);
    }

    public void lambda$null$173$MessagesController(TLRPC.Updates updates) {
        putUsers(updates.users, false);
        putChats(updates.chats, false);
        if (updates.chats != null && !updates.chats.isEmpty()) {
            getNotificationCenter().postNotificationName(NotificationCenter.chatDidCreated, Integer.valueOf(updates.chats.get(0).id));
        } else {
            getNotificationCenter().postNotificationName(NotificationCenter.chatDidFailCreate, new Object[0]);
        }
    }

    public void lambda$createChat$177$MessagesController(final BaseFragment fragment, final TLRPC.TL_channels_createChannel req, TLObject response, final TLRPC.TL_error error) {
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$175$MessagesController(error, fragment, req);
                }
            });
            return;
        }
        final TLRPC.Updates updates = (TLRPC.Updates) response;
        processUpdates(updates, false);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$176$MessagesController(updates);
            }
        });
    }

    public void lambda$null$175$MessagesController(TLRPC.TL_error error, BaseFragment fragment, TLRPC.TL_channels_createChannel req) {
        AlertsCreator.processError(this.currentAccount, error, fragment, req, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.chatDidFailCreate, new Object[0]);
    }

    public void lambda$null$176$MessagesController(TLRPC.Updates updates) {
        putUsers(updates.users, false);
        putChats(updates.chats, false);
        if (updates.chats != null && !updates.chats.isEmpty()) {
            getNotificationCenter().postNotificationName(NotificationCenter.chatDidCreated, Integer.valueOf(updates.chats.get(0).id));
        } else {
            getNotificationCenter().postNotificationName(NotificationCenter.chatDidFailCreate, new Object[0]);
        }
    }

    public int createMegaGroup(String title, final ArrayList<Integer> selectedContacts, String about, int type, BDLocation location, String locationAddress, final BaseFragment fragment, boolean forbidContact) {
        if (type == 2 || type == 4) {
            final TLRPCChats.TL_channels_createChannel_v1 req = new TLRPCChats.TL_channels_createChannel_v1();
            req.title = title;
            req.about = about != null ? about : "";
            req.ban_add_contact = forbidContact;
            if (type == 4) {
                req.megagroup = true;
            } else {
                req.broadcast = true;
            }
            if (location != null) {
                req.geo_point = new TLRPC.TL_inputGeoPoint();
                req.geo_point.lat = location.getLatitude();
                req.geo_point._long = location.getLongitude();
                req.address = locationAddress;
                req.flags = 4 | req.flags;
            }
            return getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$createMegaGroup$180$MessagesController(fragment, req, selectedContacts, tLObject, tL_error);
                }
            }, 2);
        }
        return 0;
    }

    public void lambda$createMegaGroup$180$MessagesController(final BaseFragment fragment, final TLRPCChats.TL_channels_createChannel_v1 req, ArrayList selectedContacts, TLObject response, final TLRPC.TL_error error) {
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$178$MessagesController(error, fragment, req);
                }
            });
            return;
        }
        final TLRPC.Updates updates = (TLRPC.Updates) response;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$179$MessagesController(updates);
            }
        });
        ArrayList<TLRPC.InputUser> result = new ArrayList<>();
        for (int a = 0; a < selectedContacts.size(); a++) {
            TLRPC.InputUser user = getInstance(this.currentAccount).getInputUser(getInstance(this.currentAccount).getUser((Integer) selectedContacts.get(a)));
            if (user != null) {
                result.add(user);
            }
        }
        int a2 = this.currentAccount;
        getInstance(a2).addUsersToChannelWithCreate(updates.chats.get(0), result, null);
        processUpdates(updates, false);
    }

    public void lambda$null$178$MessagesController(TLRPC.TL_error error, BaseFragment fragment, TLRPCChats.TL_channels_createChannel_v1 req) {
        AlertsCreator.processError(this.currentAccount, error, fragment, req, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.chatDidFailCreate, new Object[0]);
    }

    public void lambda$null$179$MessagesController(TLRPC.Updates updates) {
        putUsers(updates.users, false);
        putChats(updates.chats, false);
        if (updates.chats != null && !updates.chats.isEmpty()) {
            getNotificationCenter().postNotificationName(NotificationCenter.chatDidCreated, Integer.valueOf(updates.chats.get(0).id));
        } else {
            getNotificationCenter().postNotificationName(NotificationCenter.chatDidFailCreate, new Object[0]);
        }
    }

    public void addUsersToChannelWithCreate(TLRPC.Chat chat, ArrayList<TLRPC.InputUser> users, final BaseFragment fragment) {
        if (users == null || users.isEmpty()) {
            return;
        }
        final TLRPC.TL_channels_inviteToChannel req = new TLRPC.TL_channels_inviteToChannel();
        req.channel = getInputChannel(chat);
        req.users = users;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$addUsersToChannelWithCreate$182$MessagesController(fragment, req, tLObject, tL_error);
            }
        });
    }

    public void lambda$addUsersToChannelWithCreate$182$MessagesController(final BaseFragment fragment, final TLRPC.TL_channels_inviteToChannel req, TLObject response, final TLRPC.TL_error error) {
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$181$MessagesController(error, fragment, req);
                }
            });
        } else {
            processUpdates((TLRPC.Updates) response, false);
        }
    }

    public void lambda$null$181$MessagesController(TLRPC.TL_error error, BaseFragment fragment, TLRPC.TL_channels_inviteToChannel req) {
        AlertsCreator.processError(this.currentAccount, error, fragment, req, true);
    }

    public void convertToMegaGroup(final Context context, int chat_id, final BaseFragment fragment, final MessagesStorage.IntCallback convertRunnable) {
        final TLRPC.TL_messages_migrateChat req = new TLRPC.TL_messages_migrateChat();
        req.chat_id = chat_id;
        final AlertDialog progressDialog = new AlertDialog(context, 3);
        final int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$convertToMegaGroup$186$MessagesController(context, progressDialog, convertRunnable, fragment, req, tLObject, tL_error);
            }
        });
        progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public final void onCancel(DialogInterface dialogInterface) {
                MessagesController.this.lambda$convertToMegaGroup$187$MessagesController(reqId, dialogInterface);
            }
        });
        try {
            progressDialog.show();
        } catch (Exception e) {
        }
    }

    public void lambda$convertToMegaGroup$186$MessagesController(final Context context, final AlertDialog progressDialog, final MessagesStorage.IntCallback convertRunnable, final BaseFragment fragment, final TLRPC.TL_messages_migrateChat req, TLObject response, final TLRPC.TL_error error) {
        if (error == null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.lambda$null$183(context, progressDialog);
                }
            });
            final TLRPC.Updates updates = (TLRPC.Updates) response;
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.lambda$null$184(MessagesStorage.IntCallback.this, updates);
                }
            });
            return;
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$185$MessagesController(convertRunnable, context, progressDialog, error, fragment, req);
            }
        });
    }

    public static void lambda$null$183(Context context, AlertDialog progressDialog) {
        if (!((Activity) context).isFinishing()) {
            try {
                progressDialog.dismiss();
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    }

    public static void lambda$null$184(MessagesStorage.IntCallback convertRunnable, TLRPC.Updates updates) {
        if (convertRunnable != null) {
            for (int a = 0; a < updates.chats.size(); a++) {
                TLRPC.Chat chat = updates.chats.get(a);
                if (ChatObject.isChannel(chat)) {
                    convertRunnable.run(chat.id);
                    return;
                }
            }
        }
    }

    public void lambda$null$185$MessagesController(MessagesStorage.IntCallback convertRunnable, Context context, AlertDialog progressDialog, TLRPC.TL_error error, BaseFragment fragment, TLRPC.TL_messages_migrateChat req) {
        if (convertRunnable != null) {
            convertRunnable.run(0);
        }
        if (!((Activity) context).isFinishing()) {
            try {
                progressDialog.dismiss();
            } catch (Exception e) {
                FileLog.e(e);
            }
            AlertsCreator.processError(this.currentAccount, error, fragment, req, false);
        }
    }

    public void lambda$convertToMegaGroup$187$MessagesController(int reqId, DialogInterface dialog) {
        getConnectionsManager().cancelRequest(reqId, true);
    }

    public void addUsersToChannel(int chat_id, ArrayList<TLRPC.InputUser> users, final BaseFragment fragment) {
        if (users == null || users.isEmpty()) {
            return;
        }
        final TLRPC.TL_channels_inviteToChannel req = new TLRPC.TL_channels_inviteToChannel();
        req.channel = getInputChannel(chat_id);
        req.users = users;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$addUsersToChannel$189$MessagesController(fragment, req, tLObject, tL_error);
            }
        });
    }

    public void lambda$addUsersToChannel$189$MessagesController(final BaseFragment fragment, final TLRPC.TL_channels_inviteToChannel req, TLObject response, final TLRPC.TL_error error) {
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$188$MessagesController(error, fragment, req);
                }
            });
        } else {
            processUpdates((TLRPC.Updates) response, false);
        }
    }

    public void lambda$null$188$MessagesController(TLRPC.TL_error error, BaseFragment fragment, TLRPC.TL_channels_inviteToChannel req) {
        AlertsCreator.processError(this.currentAccount, error, fragment, req, true);
    }

    public void toogleChannelSignatures(int chat_id, boolean enabled) {
        TLRPC.TL_channels_toggleSignatures req = new TLRPC.TL_channels_toggleSignatures();
        req.channel = getInputChannel(chat_id);
        req.enabled = enabled;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$toogleChannelSignatures$191$MessagesController(tLObject, tL_error);
            }
        }, 64);
    }

    public void lambda$toogleChannelSignatures$191$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$190$MessagesController();
                }
            });
        }
    }

    public void lambda$null$190$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 8192);
    }

    public void toogleChannelInvitesHistory(int chat_id, boolean enabled) {
        TLRPC.TL_channels_togglePreHistoryHidden req = new TLRPC.TL_channels_togglePreHistoryHidden();
        req.channel = getInputChannel(chat_id);
        req.enabled = enabled;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$toogleChannelInvitesHistory$193$MessagesController(tLObject, tL_error);
            }
        }, 64);
    }

    public void lambda$toogleChannelInvitesHistory$193$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$192$MessagesController();
                }
            });
        }
    }

    public void lambda$null$192$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 8192);
    }

    public void updateChatAbout(int chat_id, final String about, final TLRPC.ChatFull info) {
        if (info == null) {
            return;
        }
        TLRPC.TL_messages_editChatAbout req = new TLRPC.TL_messages_editChatAbout();
        req.peer = getInputPeer(-chat_id);
        req.about = about;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$updateChatAbout$195$MessagesController(info, about, tLObject, tL_error);
            }
        }, 64);
    }

    public void lambda$updateChatAbout$195$MessagesController(final TLRPC.ChatFull info, final String about, TLObject response, TLRPC.TL_error error) {
        if (response instanceof TLRPC.TL_boolTrue) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$194$MessagesController(info, about);
                }
            });
        }
    }

    public void lambda$null$194$MessagesController(TLRPC.ChatFull info, String about) {
        info.about = about;
        getMessagesStorage().updateChatInfo(info, false);
        getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, 0);
    }

    public void updateChannelUserName(final int chat_id, final String userName) {
        TLRPC.TL_channels_updateUsername req = new TLRPC.TL_channels_updateUsername();
        req.channel = getInputChannel(chat_id);
        req.username = userName;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$updateChannelUserName$197$MessagesController(chat_id, userName, tLObject, tL_error);
            }
        }, 64);
    }

    public void lambda$updateChannelUserName$197$MessagesController(final int chat_id, final String userName, TLObject response, TLRPC.TL_error error) {
        if (response instanceof TLRPC.TL_boolTrue) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$196$MessagesController(chat_id, userName);
                }
            });
        }
    }

    public void lambda$null$196$MessagesController(int chat_id, String userName) {
        TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
        if (userName.length() != 0) {
            chat.flags |= 64;
        } else {
            chat.flags &= -65;
        }
        chat.username = userName;
        ArrayList<TLRPC.Chat> arrayList = new ArrayList<>();
        arrayList.add(chat);
        getMessagesStorage().putUsersAndChats(null, arrayList, true, true);
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 8192);
    }

    public void sendBotStart(TLRPC.User user, String botHash) {
        if (user == null) {
            return;
        }
        TLRPC.TL_messages_startBot req = new TLRPC.TL_messages_startBot();
        req.bot = getInputUser(user);
        req.peer = getInputPeer(user.id);
        req.start_param = botHash;
        req.random_id = Utilities.random.nextLong();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$sendBotStart$198$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$sendBotStart$198$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error != null) {
            return;
        }
        processUpdates((TLRPC.Updates) response, false);
    }

    public boolean isJoiningChannel(int chat_id) {
        return this.joiningToChannels.contains(Integer.valueOf(chat_id));
    }

    public void addUserToChat(final int chat_id, TLRPC.User user, TLRPC.ChatFull info, int count_fwd, String botHash, final BaseFragment fragment, final Runnable onFinishRunnable) {
        final TLObject request;
        if (user == null) {
            return;
        }
        boolean z = false;
        if (chat_id > 0) {
            final boolean isChannel = ChatObject.isChannel(chat_id, this.currentAccount);
            if (isChannel && getChat(Integer.valueOf(chat_id)).megagroup) {
                z = true;
            }
            final boolean isMegagroup = z;
            final TLRPC.InputUser inputUser = getInputUser(user);
            if (botHash == null || (isChannel && !isMegagroup)) {
                if (isChannel) {
                    if (inputUser instanceof TLRPC.TL_inputUserSelf) {
                        if (this.joiningToChannels.contains(Integer.valueOf(chat_id))) {
                            return;
                        }
                        TLRPC.TL_channels_joinChannel req = new TLRPC.TL_channels_joinChannel();
                        req.channel = getInputChannel(chat_id);
                        this.joiningToChannels.add(Integer.valueOf(chat_id));
                        request = req;
                    } else {
                        TLRPC.TL_channels_inviteToChannel req2 = new TLRPC.TL_channels_inviteToChannel();
                        req2.channel = getInputChannel(chat_id);
                        req2.users.add(inputUser);
                        request = req2;
                    }
                } else {
                    TLRPC.TL_messages_addChatUser req3 = new TLRPC.TL_messages_addChatUser();
                    req3.chat_id = chat_id;
                    req3.fwd_limit = count_fwd;
                    req3.user_id = inputUser;
                    request = req3;
                }
            } else {
                TLRPC.TL_messages_startBot req4 = new TLRPC.TL_messages_startBot();
                req4.bot = inputUser;
                if (isChannel) {
                    req4.peer = getInputPeer(-chat_id);
                } else {
                    req4.peer = new TLRPC.TL_inputPeerChat();
                    req4.peer.chat_id = chat_id;
                }
                req4.start_param = botHash;
                req4.random_id = Utilities.random.nextLong();
                request = req4;
            }
            getConnectionsManager().sendRequest(request, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$addUserToChat$202$MessagesController(isChannel, inputUser, chat_id, fragment, request, isMegagroup, onFinishRunnable, tLObject, tL_error);
                }
            });
        } else if (info instanceof TLRPC.TL_chatFull) {
            for (int a = 0; a < info.participants.participants.size(); a++) {
                if (info.participants.participants.get(a).user_id == user.id) {
                    return;
                }
            }
            TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
            chat.participants_count++;
            ArrayList<TLRPC.Chat> chatArrayList = new ArrayList<>();
            chatArrayList.add(chat);
            getMessagesStorage().putUsersAndChats(null, chatArrayList, true, true);
            TLRPC.TL_chatParticipant newPart = new TLRPC.TL_chatParticipant();
            newPart.user_id = user.id;
            newPart.inviter_id = getUserConfig().getClientUserId();
            newPart.date = getConnectionsManager().getCurrentTime();
            info.participants.participants.add(0, newPart);
            getMessagesStorage().updateChatInfo(info, true);
            getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, 0);
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 32);
        }
    }

    public void lambda$addUserToChat$202$MessagesController(final boolean isChannel, final TLRPC.InputUser inputUser, final int chat_id, final BaseFragment fragment, final TLObject request, final boolean isMegagroup, Runnable onFinishRunnable, TLObject response, final TLRPC.TL_error error) {
        if (isChannel && (inputUser instanceof TLRPC.TL_inputUserSelf)) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$199$MessagesController(chat_id);
                }
            });
        }
        if (error != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$200$MessagesController(error, fragment, request, isChannel, isMegagroup, inputUser);
                }
            });
            return;
        }
        boolean hasJoinMessage = false;
        TLRPC.Updates updates = (TLRPC.Updates) response;
        int a = 0;
        while (true) {
            if (a >= updates.updates.size()) {
                break;
            }
            TLRPC.Update update = updates.updates.get(a);
            if (!(update instanceof TLRPC.TL_updateNewChannelMessage) || !(((TLRPC.TL_updateNewChannelMessage) update).message.action instanceof TLRPC.TL_messageActionChatAddUser)) {
                a++;
            } else {
                hasJoinMessage = true;
                break;
            }
        }
        processUpdates(updates, false);
        if (isChannel) {
            if (!hasJoinMessage && (inputUser instanceof TLRPC.TL_inputUserSelf)) {
                generateJoinMessage(chat_id, true);
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$201$MessagesController(chat_id);
                }
            }, 1000L);
        }
        if (isChannel && (inputUser instanceof TLRPC.TL_inputUserSelf)) {
            getMessagesStorage().updateDialogsWithDeletedMessages(new ArrayList<>(), null, true, chat_id);
        }
        if (onFinishRunnable != null) {
            AndroidUtilities.runOnUIThread(onFinishRunnable);
        }
    }

    public void lambda$null$199$MessagesController(int chat_id) {
        this.joiningToChannels.remove(Integer.valueOf(chat_id));
    }

    public void lambda$null$200$MessagesController(TLRPC.TL_error error, BaseFragment fragment, TLObject request, boolean isChannel, boolean isMegagroup, TLRPC.InputUser inputUser) {
        int i = this.currentAccount;
        Object[] objArr = new Object[1];
        objArr[0] = Boolean.valueOf(isChannel && !isMegagroup);
        AlertsCreator.processError(i, error, fragment, request, objArr);
        if (isChannel && (inputUser instanceof TLRPC.TL_inputUserSelf)) {
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 8192);
        }
    }

    public void lambda$null$201$MessagesController(int chat_id) {
        loadFullChat(chat_id, 0, true);
    }

    public void deleteUserFromChat(int chat_id, TLRPC.User user, TLRPC.ChatFull info) {
        deleteUserFromChat(chat_id, user, info, false, false);
    }

    public void deleteUserFromChat(final int chat_id, TLRPC.User user, TLRPC.ChatFull info, boolean forceDelete, boolean revoke) {
        TLObject request;
        if (user == null) {
            return;
        }
        if (chat_id <= 0) {
            if (info instanceof TLRPC.TL_chatFull) {
                TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
                chat.participants_count--;
                ArrayList<TLRPC.Chat> chatArrayList = new ArrayList<>();
                chatArrayList.add(chat);
                getMessagesStorage().putUsersAndChats(null, chatArrayList, true, true);
                boolean changed = false;
                int a = 0;
                while (true) {
                    if (a >= info.participants.participants.size()) {
                        break;
                    }
                    TLRPC.ChatParticipant p = info.participants.participants.get(a);
                    if (p.user_id != user.id) {
                        a++;
                    } else {
                        info.participants.participants.remove(a);
                        changed = true;
                        break;
                    }
                }
                if (changed) {
                    getMessagesStorage().updateChatInfo(info, true);
                    getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, null);
                }
                getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 32);
                return;
            }
            return;
        }
        final TLRPC.InputUser inputUser = getInputUser(user);
        TLRPC.Chat chat2 = getChat(Integer.valueOf(chat_id));
        final boolean isChannel = ChatObject.isChannel(chat2);
        if (isChannel) {
            if (inputUser instanceof TLRPC.TL_inputUserSelf) {
                if (chat2.creator && forceDelete) {
                    TLRPC.TL_channels_deleteChannel req = new TLRPC.TL_channels_deleteChannel();
                    req.channel = getInputChannel(chat2);
                    request = req;
                } else {
                    TLRPC.TL_channels_leaveChannel req2 = new TLRPC.TL_channels_leaveChannel();
                    req2.channel = getInputChannel(chat2);
                    request = req2;
                }
            } else {
                TLRPC.TL_channels_editBanned req3 = new TLRPC.TL_channels_editBanned();
                req3.channel = getInputChannel(chat2);
                req3.user_id = inputUser;
                req3.banned_rights = new TLRPC.TL_chatBannedRights();
                req3.banned_rights.view_messages = true;
                req3.banned_rights.send_media = true;
                req3.banned_rights.send_messages = true;
                req3.banned_rights.send_stickers = true;
                req3.banned_rights.send_gifs = true;
                req3.banned_rights.send_games = true;
                req3.banned_rights.send_inline = true;
                req3.banned_rights.embed_links = true;
                req3.banned_rights.pin_messages = true;
                req3.banned_rights.send_polls = true;
                req3.banned_rights.invite_users = true;
                req3.banned_rights.change_info = true;
                request = req3;
            }
        } else {
            TLRPC.TL_messages_deleteChatUser req4 = new TLRPC.TL_messages_deleteChatUser();
            req4.chat_id = chat_id;
            req4.user_id = getInputUser(user);
            request = req4;
        }
        if (user.id == getUserConfig().getClientUserId()) {
            deleteDialog(-chat_id, 0, revoke);
        }
        getConnectionsManager().sendRequest(request, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$deleteUserFromChat$204$MessagesController(isChannel, inputUser, chat_id, tLObject, tL_error);
            }
        }, 64);
    }

    public void lambda$deleteUserFromChat$204$MessagesController(boolean isChannel, TLRPC.InputUser inputUser, final int chat_id, TLObject response, TLRPC.TL_error error) {
        if (error != null) {
            return;
        }
        TLRPC.Updates updates = (TLRPC.Updates) response;
        processUpdates(updates, false);
        if (isChannel && !(inputUser instanceof TLRPC.TL_inputUserSelf)) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$203$MessagesController(chat_id);
                }
            }, 1000L);
        }
    }

    public void lambda$null$203$MessagesController(int chat_id) {
        loadFullChat(chat_id, 0, true);
    }

    public void changeChatTitle(int chat_id, String title) {
        TLObject request;
        if (chat_id > 0) {
            if (ChatObject.isChannel(chat_id, this.currentAccount)) {
                TLRPC.TL_channels_editTitle req = new TLRPC.TL_channels_editTitle();
                req.channel = getInputChannel(chat_id);
                req.title = title;
                request = req;
            } else {
                TLRPC.TL_messages_editChatTitle req2 = new TLRPC.TL_messages_editChatTitle();
                req2.chat_id = chat_id;
                req2.title = title;
                request = req2;
            }
            getConnectionsManager().sendRequest(request, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$changeChatTitle$205$MessagesController(tLObject, tL_error);
                }
            }, 64);
            return;
        }
        TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
        chat.title = title;
        ArrayList<TLRPC.Chat> chatArrayList = new ArrayList<>();
        chatArrayList.add(chat);
        getMessagesStorage().putUsersAndChats(null, chatArrayList, true, true);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 16);
    }

    public void lambda$changeChatTitle$205$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error != null) {
            return;
        }
        processUpdates((TLRPC.Updates) response, false);
    }

    public void changeChatAvatar(int chat_id, TLRPC.InputFile uploadedAvatar, final TLRPC.FileLocation smallSize, final TLRPC.FileLocation bigSize) {
        TLObject request;
        if (ChatObject.isChannel(chat_id, this.currentAccount)) {
            TLRPC.TL_channels_editPhoto req = new TLRPC.TL_channels_editPhoto();
            req.channel = getInputChannel(chat_id);
            if (uploadedAvatar != null) {
                req.photo = new TLRPC.TL_inputChatUploadedPhoto();
                req.photo.file = uploadedAvatar;
                request = req;
            } else {
                req.photo = new TLRPC.TL_inputChatPhotoEmpty();
                request = req;
            }
        } else {
            TLRPC.TL_messages_editChatPhoto req2 = new TLRPC.TL_messages_editChatPhoto();
            req2.chat_id = chat_id;
            if (uploadedAvatar != null) {
                req2.photo = new TLRPC.TL_inputChatUploadedPhoto();
                req2.photo.file = uploadedAvatar;
            } else {
                req2.photo = new TLRPC.TL_inputChatPhotoEmpty();
            }
            request = req2;
        }
        getConnectionsManager().sendRequest(request, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$changeChatAvatar$206$MessagesController(smallSize, bigSize, tLObject, tL_error);
            }
        }, 64);
    }

    public void lambda$changeChatAvatar$206$MessagesController(TLRPC.FileLocation smallSize, TLRPC.FileLocation bigSize, TLObject response, TLRPC.TL_error error) {
        if (error != null) {
            return;
        }
        TLRPC.Updates updates = (TLRPC.Updates) response;
        TLRPC.Photo photo = null;
        int a = 0;
        int N = updates.updates.size();
        while (true) {
            if (a >= N) {
                break;
            }
            TLRPC.Update update = updates.updates.get(a);
            if (update instanceof TLRPC.TL_updateNewChannelMessage) {
                TLRPC.Message message = ((TLRPC.TL_updateNewChannelMessage) update).message;
                if ((message.action instanceof TLRPC.TL_messageActionChatEditPhoto) && (message.action.photo instanceof TLRPC.TL_photo)) {
                    photo = message.action.photo;
                    break;
                }
                a++;
            } else {
                if (update instanceof TLRPC.TL_updateNewMessage) {
                    TLRPC.Message message2 = ((TLRPC.TL_updateNewMessage) update).message;
                    if ((message2.action instanceof TLRPC.TL_messageActionChatEditPhoto) && (message2.action.photo instanceof TLRPC.TL_photo)) {
                        photo = message2.action.photo;
                        break;
                    }
                } else {
                    continue;
                }
                a++;
            }
        }
        if (photo != null) {
            TLRPC.PhotoSize small = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 150);
            if (small != null && smallSize != null) {
                File destFile = FileLoader.getPathToAttach(small, true);
                File src = FileLoader.getPathToAttach(smallSize, true);
                src.renameTo(destFile);
                String oldKey = smallSize.volume_id + "_" + smallSize.local_id + "@50_50";
                String newKey = small.location.volume_id + "_" + small.location.local_id + "@50_50";
                ImageLoader.getInstance().replaceImageInCache(oldKey, newKey, ImageLocation.getForPhoto(small, photo), true);
            }
            TLRPC.PhotoSize big = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, CodeUtils.DEFAULT_REQ_HEIGHT);
            if (big != null && bigSize != null) {
                File destFile2 = FileLoader.getPathToAttach(big, true);
                File src2 = FileLoader.getPathToAttach(bigSize, true);
                src2.renameTo(destFile2);
            }
        }
        processUpdates(updates, false);
    }

    public void unregistedPush() {
        if (getUserConfig().registeredForPush && SharedConfig.pushString.length() == 0) {
            TLRPC.TL_account_unregisterDevice req = new TLRPC.TL_account_unregisterDevice();
            req.token = SharedConfig.pushString;
            req.token_type = 2;
            for (int a = 0; a < 3; a++) {
                UserConfig userConfig = UserConfig.getInstance(a);
                if (a != this.currentAccount && userConfig.isClientActivated()) {
                    req.other_uids.add(Integer.valueOf(userConfig.getClientUserId()));
                }
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$unregistedPush$207(tLObject, tL_error);
                }
            });
        }
    }

    public static void lambda$unregistedPush$207(TLObject response, TLRPC.TL_error error) {
    }

    public void generateUpdateMessage() {
        if (BuildVars.DEBUG_VERSION || SharedConfig.lastUpdateVersion == null || SharedConfig.lastUpdateVersion.equals(BuildVars.BUILD_VERSION_STRING)) {
            return;
        }
        TLRPC.TL_help_getAppChangelog req = new TLRPC.TL_help_getAppChangelog();
        req.prev_app_version = SharedConfig.lastUpdateVersion;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$generateUpdateMessage$208$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$generateUpdateMessage$208$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            SharedConfig.lastUpdateVersion = BuildVars.BUILD_VERSION_STRING;
            SharedConfig.saveConfig();
        }
        if (response instanceof TLRPC.Updates) {
            processUpdates((TLRPC.Updates) response, false);
        }
    }

    public void performLogout(int type) {
        if (type == 1) {
            unregistedPush();
            TLRPC.TL_auth_logOut req = new TLRPC.TL_auth_logOut();
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$performLogout$209$MessagesController(tLObject, tL_error);
                }
            });
        } else {
            getConnectionsManager().cleanup(type == 2);
        }
        getUserConfig().clearConfig();
        getNotificationCenter().postNotificationName(NotificationCenter.appDidLogout, new Object[0]);
        getMessagesStorage().cleanup(false);
        cleanup();
        getContactsController().deleteUnknownAppAccounts();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                GcmPushListenerService.sendUPushRegistrationToServer("");
            }
        });
    }

    public void lambda$performLogout$209$MessagesController(TLObject response, TLRPC.TL_error error) {
        getConnectionsManager().cleanup(false);
    }

    public void registerForPush(final String regid) {
        if (TextUtils.isEmpty(regid) || this.registeringForPush || getUserConfig().getClientUserId() == 0) {
            return;
        }
        if (getUserConfig().registeredForPush && regid.equals(SharedConfig.pushString)) {
            return;
        }
        this.registeringForPush = true;
        this.lastPushRegisterSendTime = SystemClock.elapsedRealtime();
        if (SharedConfig.pushAuthKey == null) {
            SharedConfig.pushAuthKey = new byte[256];
            Utilities.random.nextBytes(SharedConfig.pushAuthKey);
            SharedConfig.saveConfig();
        }
        TLRPC.TL_account_registerDevice req = new TLRPC.TL_account_registerDevice();
        req.token_type = 2;
        req.token = regid;
        req.no_muted = false;
        req.secret = SharedConfig.pushAuthKey;
        for (int a = 0; a < 3; a++) {
            UserConfig userConfig = UserConfig.getInstance(a);
            if (a != this.currentAccount && userConfig.isClientActivated()) {
                int uid = userConfig.getClientUserId();
                req.other_uids.add(Integer.valueOf(uid));
            }
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$registerForPush$212$MessagesController(regid, tLObject, tL_error);
            }
        });
    }

    public void lambda$registerForPush$212$MessagesController(String regid, TLObject response, TLRPC.TL_error error) {
        if (response instanceof TLRPC.TL_boolTrue) {
            getUserConfig().registeredForPush = true;
            SharedConfig.pushString = regid;
            getUserConfig().saveConfig(false);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$211$MessagesController();
            }
        });
    }

    public void lambda$null$211$MessagesController() {
        this.registeringForPush = false;
    }

    public void registerForUPush(final String regid) {
        if (TextUtils.isEmpty(regid) || this.registeringForPush || getUserConfig().getClientUserId() == 0) {
            return;
        }
        if (getUserConfig().registeredForPush && regid.equals(SharedConfig.pushString)) {
            return;
        }
        this.registeringForPush = true;
        this.lastPushRegisterSendTime = SystemClock.elapsedRealtime();
        if (SharedConfig.pushAuthKey == null) {
            SharedConfig.pushAuthKey = new byte[256];
            Utilities.random.nextBytes(SharedConfig.pushAuthKey);
            SharedConfig.saveConfig();
        }
        TLRPC.TL_account_registerDevice req = new TLRPC.TL_account_registerDevice();
        req.token_type = getPushDeviceType();
        req.token = regid;
        req.no_muted = false;
        req.secret = SharedConfig.pushAuthKey;
        for (int a = 0; a < 3; a++) {
            UserConfig userConfig = UserConfig.getInstance(a);
            if (a != this.currentAccount && userConfig.isClientActivated()) {
                int uid = userConfig.getClientUserId();
                req.other_uids.add(Integer.valueOf(uid));
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("add other uid = " + uid + " for account " + this.currentAccount);
                }
            }
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$registerForUPush$214$MessagesController(regid, tLObject, tL_error);
            }
        });
    }

    public void lambda$registerForUPush$214$MessagesController(String regid, TLObject response, TLRPC.TL_error error) {
        if (response instanceof TLRPC.TL_boolTrue) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("account " + this.currentAccount + " registered for push");
            }
            getUserConfig().registeredForPush = true;
            SharedConfig.pushString = regid;
            getUserConfig().saveConfig(false);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$213$MessagesController();
            }
        });
    }

    public void lambda$null$213$MessagesController() {
        this.registeringForPush = false;
    }

    private int getPushDeviceType() {
        if (MryDeviceHelper.isHuawei()) {
            return 5;
        }
        if (MryDeviceHelper.isXiaomi()) {
            return 6;
        }
        if (MryDeviceHelper.isOppo()) {
            return 7;
        }
        return 8;
    }

    public void loadCurrentState() {
        if (this.updatingState) {
            return;
        }
        this.updatingState = true;
        TLRPC.TL_updates_getState req = new TLRPC.TL_updates_getState();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadCurrentState$215$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$loadCurrentState$215$MessagesController(TLObject response, TLRPC.TL_error error) {
        this.updatingState = false;
        if (error == null) {
            TLRPC.TL_updates_state res = (TLRPC.TL_updates_state) response;
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("loadCurrentState ===> response = " + res.toString());
            }
            getMessagesStorage().setLastDateValue(res.date);
            getMessagesStorage().setLastPtsValue(res.pts);
            getMessagesStorage().setLastSeqValue(res.seq);
            getMessagesStorage().setLastQtsValue(res.qts);
            for (int a = 0; a < 3; a++) {
                processUpdatesQueue(a, 2);
            }
            getMessagesStorage().saveDiffParams(getMessagesStorage().getLastSeqValue(), getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue());
        } else if (error.code != 401) {
            loadCurrentState();
        }
    }

    private int getUpdateSeq(TLRPC.Updates updates) {
        if (updates instanceof TLRPC.TL_updatesCombined) {
            return updates.seq_start;
        }
        return updates.seq;
    }

    private void setUpdatesStartTime(int type, long time) {
        if (type == 0) {
            this.updatesStartWaitTimeSeq = time;
        } else if (type == 1) {
            this.updatesStartWaitTimePts = time;
        } else if (type == 2) {
            this.updatesStartWaitTimeQts = time;
        }
    }

    public long getUpdatesStartTime(int type) {
        if (type == 0) {
            return this.updatesStartWaitTimeSeq;
        }
        if (type == 1) {
            return this.updatesStartWaitTimePts;
        }
        if (type == 2) {
            return this.updatesStartWaitTimeQts;
        }
        return 0L;
    }

    private int isValidUpdate(TLRPC.Updates updates, int type) {
        if (type == 0) {
            int seq = getUpdateSeq(updates);
            if (getMessagesStorage().getLastSeqValue() + 1 == seq || getMessagesStorage().getLastSeqValue() == seq) {
                return 0;
            }
            return getMessagesStorage().getLastSeqValue() < seq ? 1 : 2;
        } else if (type == 1) {
            if (updates.pts <= getMessagesStorage().getLastPtsValue()) {
                return 2;
            }
            return getMessagesStorage().getLastPtsValue() + updates.pts_count == updates.pts ? 0 : 1;
        } else if (type != 2) {
            return 0;
        } else {
            if (updates.pts <= getMessagesStorage().getLastQtsValue()) {
                return 2;
            }
            return getMessagesStorage().getLastQtsValue() + updates.updates.size() == updates.pts ? 0 : 1;
        }
    }

    private void processChannelsUpdatesQueue(int channelId, int state) {
        int updateState;
        ArrayList<TLRPC.Updates> updatesQueue = this.updatesQueueChannels.get(channelId);
        if (updatesQueue == null) {
            return;
        }
        int channelPts = this.channelsPts.get(channelId);
        if (!updatesQueue.isEmpty() && channelPts != 0) {
            Collections.sort(updatesQueue, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int compare;
                    compare = AndroidUtilities.compare(((TLRPC.Updates) obj).pts, ((TLRPC.Updates) obj2).pts);
                    return compare;
                }
            });
            boolean anyProceed = false;
            if (state == 2) {
                this.channelsPts.put(channelId, updatesQueue.get(0).pts);
            }
            for (int a = 0; a < updatesQueue.size(); a = (a - 1) + 1) {
                TLRPC.Updates updates = updatesQueue.get(a);
                if (updates.pts <= channelPts) {
                    updateState = 2;
                } else {
                    int updateState2 = updates.pts_count;
                    if (updateState2 + channelPts == updates.pts) {
                        updateState = 0;
                    } else {
                        updateState = 1;
                    }
                }
                if (updateState == 0) {
                    processUpdates(updates, true);
                    anyProceed = true;
                    updatesQueue.remove(a);
                } else if (updateState == 1) {
                    long updatesStartWaitTime = this.updatesStartWaitTimeChannels.get(channelId);
                    if (updatesStartWaitTime != 0 && (anyProceed || Math.abs(System.currentTimeMillis() - updatesStartWaitTime) <= 1500)) {
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("HOLE IN CHANNEL " + channelId + " UPDATES QUEUE - will wait more time");
                        }
                        if (anyProceed) {
                            this.updatesStartWaitTimeChannels.put(channelId, System.currentTimeMillis());
                            return;
                        }
                        return;
                    }
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("HOLE IN CHANNEL " + channelId + " UPDATES QUEUE - getChannelDifference ");
                    }
                    this.updatesStartWaitTimeChannels.delete(channelId);
                    this.updatesQueueChannels.remove(channelId);
                    getChannelDifference(channelId);
                    return;
                } else {
                    updatesQueue.remove(a);
                }
            }
            this.updatesQueueChannels.remove(channelId);
            this.updatesStartWaitTimeChannels.delete(channelId);
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("UPDATES CHANNEL " + channelId + " QUEUE PROCEED - OK");
                return;
            }
            return;
        }
        this.updatesQueueChannels.remove(channelId);
    }

    private void processUpdatesQueue(int type, int state) {
        ArrayList<TLRPC.Updates> updatesQueue = null;
        if (type == 0) {
            updatesQueue = this.updatesQueueSeq;
            Collections.sort(updatesQueue, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    return MessagesController.this.lambda$processUpdatesQueue$217$MessagesController((TLRPC.Updates) obj, (TLRPC.Updates) obj2);
                }
            });
        } else if (type == 1) {
            updatesQueue = this.updatesQueuePts;
            Collections.sort(updatesQueue, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int compare;
                    compare = AndroidUtilities.compare(((TLRPC.Updates) obj).pts, ((TLRPC.Updates) obj2).pts);
                    return compare;
                }
            });
        } else if (type == 2) {
            updatesQueue = this.updatesQueueQts;
            Collections.sort(updatesQueue, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int compare;
                    compare = AndroidUtilities.compare(((TLRPC.Updates) obj).pts, ((TLRPC.Updates) obj2).pts);
                    return compare;
                }
            });
        }
        if (updatesQueue != null && !updatesQueue.isEmpty()) {
            boolean anyProceed = false;
            if (state == 2) {
                TLRPC.Updates updates = updatesQueue.get(0);
                if (type == 0) {
                    getMessagesStorage().setLastSeqValue(getUpdateSeq(updates));
                } else if (type == 1) {
                    getMessagesStorage().setLastPtsValue(updates.pts);
                } else {
                    getMessagesStorage().setLastQtsValue(updates.pts);
                }
            }
            for (int a = 0; a < updatesQueue.size(); a = (a - 1) + 1) {
                TLRPC.Updates updates2 = updatesQueue.get(a);
                int updateState = isValidUpdate(updates2, type);
                if (updateState == 0) {
                    processUpdates(updates2, true);
                    anyProceed = true;
                    updatesQueue.remove(a);
                } else if (updateState == 1) {
                    if (getUpdatesStartTime(type) != 0 && (anyProceed || Math.abs(System.currentTimeMillis() - getUpdatesStartTime(type)) <= 1500)) {
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("HOLE IN UPDATES QUEUE - will wait more time");
                        }
                        if (anyProceed) {
                            setUpdatesStartTime(type, System.currentTimeMillis());
                            return;
                        }
                        return;
                    }
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("HOLE IN UPDATES QUEUE - getDifference");
                    }
                    setUpdatesStartTime(type, 0L);
                    updatesQueue.clear();
                    getDifference();
                    return;
                } else {
                    updatesQueue.remove(a);
                }
            }
            updatesQueue.clear();
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("UPDATES QUEUE PROCEED - OK");
            }
        }
        setUpdatesStartTime(type, 0L);
    }

    public int lambda$processUpdatesQueue$217$MessagesController(TLRPC.Updates updates, TLRPC.Updates updates2) {
        return AndroidUtilities.compare(getUpdateSeq(updates), getUpdateSeq(updates2));
    }

    public void loadUnknownChannel(final TLRPC.Chat channel, long taskId) {
        final long newTaskId;
        if (!(channel instanceof TLRPC.TL_channel) || this.gettingUnknownChannels.indexOfKey(channel.id) >= 0) {
            return;
        }
        if (channel.access_hash == 0) {
            if (taskId != 0) {
                getMessagesStorage().removePendingTask(taskId);
                return;
            }
            return;
        }
        TLRPC.TL_inputPeerChannel inputPeer = new TLRPC.TL_inputPeerChannel();
        inputPeer.channel_id = channel.id;
        inputPeer.access_hash = channel.access_hash;
        this.gettingUnknownChannels.put(channel.id, true);
        TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
        TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
        inputDialogPeer.peer = inputPeer;
        req.peers.add(inputDialogPeer);
        if (taskId == 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(channel.getObjectSize() + 4);
                data.writeInt32(0);
                channel.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        } else {
            newTaskId = taskId;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadUnknownChannel$220$MessagesController(newTaskId, channel, tLObject, tL_error);
            }
        });
    }

    public void lambda$loadUnknownChannel$220$MessagesController(long newTaskId, TLRPC.Chat channel, TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
            if (!res.dialogs.isEmpty() && !res.chats.isEmpty() && !(res.dialogs.get(0) instanceof TLRPC.TL_dialogFolder)) {
                TLRPC.TL_dialog dialog = (TLRPC.TL_dialog) res.dialogs.get(0);
                TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
                dialogs.dialogs.addAll(res.dialogs);
                dialogs.messages.addAll(res.messages);
                dialogs.users.addAll(res.users);
                dialogs.chats.addAll(res.chats);
                processLoadedDialogs(dialogs, null, dialog.folder_id, 0, 1, this.DIALOGS_LOAD_TYPE_CHANNEL, false, false, false);
            }
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        this.gettingUnknownChannels.delete(channel.id);
    }

    public void startShortPoll(final TLRPC.Chat chat, final boolean stop) {
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$startShortPoll$221$MessagesController(stop, chat);
            }
        });
    }

    public void lambda$startShortPoll$221$MessagesController(boolean stop, TLRPC.Chat chat) {
        if (stop) {
            this.needShortPollChannels.delete(chat.id);
            if (chat.megagroup) {
                this.needShortPollOnlines.delete(chat.id);
                return;
            }
            return;
        }
        this.needShortPollChannels.put(chat.id, 0);
        if (this.shortPollChannels.indexOfKey(chat.id) < 0) {
            getChannelDifference(chat.id, 3, 0L, null);
        }
        if (chat.megagroup) {
            this.needShortPollOnlines.put(chat.id, 0);
            if (this.shortPollOnlines.indexOfKey(chat.id) < 0) {
                this.shortPollOnlines.put(chat.id, 0);
            }
        }
    }

    private void getChannelDifference(int channelId) {
        getChannelDifference(channelId, 0, 0L, null);
    }

    public static boolean isSupportUser(TLRPC.User user) {
        return user != null && (user.support || user.id == 777000 || user.id == 333000 || user.id == 4240000 || user.id == 4244000 || user.id == 4245000 || user.id == 4246000 || user.id == 410000 || user.id == 420000 || user.id == 431000 || user.id == 431415000 || user.id == 434000 || user.id == 4243000 || user.id == 439000 || user.id == 449000 || user.id == 450000 || user.id == 452000 || user.id == 454000 || user.id == 4254000 || user.id == 455000 || user.id == 460000 || user.id == 470000 || user.id == 479000 || user.id == 796000 || user.id == 482000 || user.id == 490000 || user.id == 496000 || user.id == 497000 || user.id == 498000 || user.id == 4298000);
    }

    public void getChannelDifference(final int channelId, final int newDialogType, long taskId, TLRPC.InputChannel inputChannel) {
        int limit;
        int channelPts;
        TLRPC.InputChannel inputChannel2;
        long newTaskId;
        boolean gettingDifferenceChannel = this.gettingDifferenceChannels.get(channelId);
        if (gettingDifferenceChannel) {
            return;
        }
        if (newDialogType == 1) {
            if (this.channelsPts.get(channelId) != 0) {
                return;
            }
            limit = 1;
            channelPts = 1;
        } else {
            int channelPts2 = this.channelsPts.get(channelId);
            if (channelPts2 == 0) {
                channelPts2 = getMessagesStorage().getChannelPtsSync(channelId);
                if (channelPts2 != 0) {
                    this.channelsPts.put(channelId, channelPts2);
                }
                if (channelPts2 == 0 && (newDialogType == 2 || newDialogType == 3)) {
                    return;
                }
            }
            if (channelPts2 != 0) {
                limit = 100;
                channelPts = channelPts2;
            } else {
                return;
            }
        }
        if (inputChannel == null) {
            TLRPC.Chat chat = getChat(Integer.valueOf(channelId));
            if (chat == null && (chat = getMessagesStorage().getChatSync(channelId)) != null) {
                putChat(chat, true);
            }
            inputChannel2 = getInputChannel(chat);
        } else {
            inputChannel2 = inputChannel;
        }
        if (inputChannel2 == null || inputChannel2.access_hash == 0) {
            if (taskId != 0) {
                getMessagesStorage().removePendingTask(taskId);
                return;
            }
            return;
        }
        if (taskId == 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(inputChannel2.getObjectSize() + 12);
                data.writeInt32(6);
                data.writeInt32(channelId);
                data.writeInt32(newDialogType);
                inputChannel2.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            long newTaskId2 = getMessagesStorage().createPendingTask(data);
            newTaskId = newTaskId2;
        } else {
            newTaskId = taskId;
        }
        this.gettingDifferenceChannels.put(channelId, true);
        TLRPC.TL_updates_getChannelDifference req = new TLRPC.TL_updates_getChannelDifference();
        req.channel = inputChannel2;
        req.filter = new TLRPC.TL_channelMessagesFilterEmpty();
        req.pts = channelPts;
        req.limit = limit;
        req.force = newDialogType != 3;
        final long j = newTaskId;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$getChannelDifference$230$MessagesController(channelId, newDialogType, j, tLObject, tL_error);
            }
        });
    }

    public void lambda$getChannelDifference$230$MessagesController(final int channelId, final int newDialogType, final long newTaskId, TLObject response, final TLRPC.TL_error error) {
        TLRPC.Chat channel;
        if (response == null) {
            if (error != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$229$MessagesController(error, channelId);
                    }
                });
                this.gettingDifferenceChannels.delete(channelId);
                if (newTaskId != 0) {
                    getMessagesStorage().removePendingTask(newTaskId);
                    return;
                }
                return;
            }
            return;
        }
        final TLRPC.updates_ChannelDifference res = (TLRPC.updates_ChannelDifference) response;
        final SparseArray<TLRPC.User> usersDict = new SparseArray<>();
        for (int a = 0; a < res.users.size(); a++) {
            TLRPC.User user = res.users.get(a);
            usersDict.put(user.id, user);
        }
        int a2 = 0;
        while (true) {
            if (a2 >= res.chats.size()) {
                channel = null;
                break;
            }
            TLRPC.Chat chat = res.chats.get(a2);
            if (chat.id != channelId) {
                a2++;
            } else {
                channel = chat;
                break;
            }
        }
        final TLRPC.Chat channelFinal = channel;
        final ArrayList<TLRPC.TL_updateMessageID> msgUpdates = new ArrayList<>();
        if (!res.other_updates.isEmpty()) {
            int a3 = 0;
            while (a3 < res.other_updates.size()) {
                TLRPC.Update upd = res.other_updates.get(a3);
                if (upd instanceof TLRPC.TL_updateMessageID) {
                    msgUpdates.add((TLRPC.TL_updateMessageID) upd);
                    res.other_updates.remove(a3);
                    a3--;
                }
                a3++;
            }
        }
        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$222$MessagesController(res);
            }
        });
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$228$MessagesController(msgUpdates, channelId, res, channelFinal, usersDict, newDialogType, newTaskId);
            }
        });
    }

    public void lambda$null$222$MessagesController(TLRPC.updates_ChannelDifference res) {
        putUsers(res.users, false);
        putChats(res.chats, false);
    }

    public void lambda$null$228$MessagesController(ArrayList msgUpdates, final int channelId, final TLRPC.updates_ChannelDifference res, final TLRPC.Chat channelFinal, final SparseArray usersDict, final int newDialogType, final long newTaskId) {
        if (!msgUpdates.isEmpty()) {
            final SparseArray<long[]> corrected = new SparseArray<>();
            Iterator it = msgUpdates.iterator();
            while (it.hasNext()) {
                TLRPC.TL_updateMessageID update = (TLRPC.TL_updateMessageID) it.next();
                long[] ids = getMessagesStorage().updateMessageStateAndId(update.random_id, null, update.id, 0, false, channelId, -1);
                if (ids != null) {
                    corrected.put(update.id, ids);
                }
            }
            if (corrected.size() != 0) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$223$MessagesController(corrected);
                    }
                });
            }
        }
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$227$MessagesController(res, channelId, channelFinal, usersDict, newDialogType, newTaskId);
            }
        });
    }

    public void lambda$null$223$MessagesController(SparseArray corrected) {
        for (int a = 0; a < corrected.size(); a++) {
            int newId = corrected.keyAt(a);
            long[] ids = (long[]) corrected.valueAt(a);
            int oldId = (int) ids[1];
            getSendMessagesHelper().processSentMessage(oldId);
            getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, Integer.valueOf(oldId), Integer.valueOf(newId), null, Long.valueOf(ids[0]), 0L, -1, false);
        }
    }

    public void lambda$null$227$MessagesController(final TLRPC.updates_ChannelDifference res, int channelId, TLRPC.Chat channelFinal, SparseArray usersDict, int newDialogType, long newTaskId) {
        Integer inboxValue;
        boolean z;
        MessageObject obj;
        ArrayList<MessageObject> arr;
        boolean z2;
        TLRPC.Chat chat = channelFinal;
        if (!(res instanceof TLRPC.TL_updates_channelDifference) && !(res instanceof TLRPC.TL_updates_channelDifferenceEmpty)) {
            if (res instanceof TLRPC.TL_updates_channelDifferenceTooLong) {
                long dialog_id = -channelId;
                Integer inboxValue2 = this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id));
                if (inboxValue2 == null) {
                    inboxValue2 = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, dialog_id));
                    this.dialogs_read_inbox_max.put(Long.valueOf(dialog_id), inboxValue2);
                }
                Integer outboxValue = this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id));
                if (outboxValue == null) {
                    outboxValue = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, dialog_id));
                    this.dialogs_read_outbox_max.put(Long.valueOf(dialog_id), outboxValue);
                }
                int a = 0;
                while (a < res.messages.size()) {
                    TLRPC.Message message = res.messages.get(a);
                    long dialog_id2 = dialog_id;
                    message.dialog_id = -channelId;
                    if (!(message.action instanceof TLRPC.TL_messageActionChannelCreate) && (chat == null || !chat.left)) {
                        if ((message.out ? outboxValue : inboxValue2).intValue() < message.id) {
                            z2 = true;
                            message.unread = z2;
                            if (chat != null && chat.megagroup) {
                                message.flags |= Integer.MIN_VALUE;
                            }
                            a++;
                            dialog_id = dialog_id2;
                        }
                    }
                    z2 = false;
                    message.unread = z2;
                    if (chat != null) {
                        message.flags |= Integer.MIN_VALUE;
                    }
                    a++;
                    dialog_id = dialog_id2;
                }
                getMessagesStorage().overwriteChannel(channelId, (TLRPC.TL_updates_channelDifferenceTooLong) res, newDialogType);
            }
            this.gettingDifferenceChannels.delete(channelId);
            this.channelsPts.put(channelId, res.pts);
            if ((res.flags & 2) != 0) {
                this.shortPollChannels.put(channelId, ((int) (System.currentTimeMillis() / 1000)) + res.timeout);
            }
            if (!res.isFinal) {
                getChannelDifference(channelId);
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("received channel difference with pts = " + res.pts + " channelId = " + channelId);
            }
            if (newTaskId == 0) {
                getMessagesStorage().removePendingTask(newTaskId);
                return;
            }
            return;
        }
        if (!res.new_messages.isEmpty()) {
            final LongSparseArray<ArrayList<MessageObject>> messages = new LongSparseArray<>();
            ImageLoader.saveMessagesThumbs(res.new_messages);
            final ArrayList<MessageObject> pushMessages = new ArrayList<>();
            long dialog_id3 = -channelId;
            Integer inboxValue3 = this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id3));
            if (inboxValue3 == null) {
                inboxValue3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, dialog_id3));
                this.dialogs_read_inbox_max.put(Long.valueOf(dialog_id3), inboxValue3);
            }
            Integer outboxValue2 = this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id3));
            if (outboxValue2 == null) {
                outboxValue2 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, dialog_id3));
                this.dialogs_read_outbox_max.put(Long.valueOf(dialog_id3), outboxValue2);
            }
            int a2 = 0;
            while (a2 < res.new_messages.size()) {
                TLRPC.Message message2 = res.new_messages.get(a2);
                if (chat == null || !chat.left) {
                    inboxValue = inboxValue3;
                    if ((message2.out ? outboxValue2 : inboxValue3).intValue() < message2.id && !(message2.action instanceof TLRPC.TL_messageActionChannelCreate)) {
                        z = true;
                        message2.unread = z;
                        if (chat == null && chat.megagroup) {
                            message2.flags |= Integer.MIN_VALUE;
                        }
                        obj = new MessageObject(this.currentAccount, message2, usersDict, this.createdDialogIds.contains(Long.valueOf(dialog_id3)));
                        if ((obj.isOut() || obj.messageOwner.from_scheduled) && obj.isUnread()) {
                            pushMessages.add(obj);
                        }
                        long dialog_id4 = dialog_id3;
                        long dialog_id5 = -channelId;
                        arr = messages.get(dialog_id5);
                        if (arr != null) {
                            arr = new ArrayList<>();
                            messages.put(dialog_id5, arr);
                        }
                        arr.add(obj);
                        a2++;
                        chat = channelFinal;
                        inboxValue3 = inboxValue;
                        dialog_id3 = dialog_id4;
                    }
                } else {
                    inboxValue = inboxValue3;
                }
                z = false;
                message2.unread = z;
                if (chat == null) {
                }
                obj = new MessageObject(this.currentAccount, message2, usersDict, this.createdDialogIds.contains(Long.valueOf(dialog_id3)));
                if (obj.isOut()) {
                }
                pushMessages.add(obj);
                long dialog_id42 = dialog_id3;
                long dialog_id52 = -channelId;
                arr = messages.get(dialog_id52);
                if (arr != null) {
                }
                arr.add(obj);
                a2++;
                chat = channelFinal;
                inboxValue3 = inboxValue;
                dialog_id3 = dialog_id42;
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$224$MessagesController(messages);
                }
            });
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$226$MessagesController(pushMessages, res);
                }
            });
        }
        if (!res.other_updates.isEmpty()) {
            processUpdateArray(res.other_updates, res.users, res.chats, true, 0);
        }
        processChannelsUpdatesQueue(channelId, 1);
        getMessagesStorage().saveChannelPts(channelId, res.pts);
        this.gettingDifferenceChannels.delete(channelId);
        this.channelsPts.put(channelId, res.pts);
        if ((res.flags & 2) != 0) {
        }
        if (!res.isFinal) {
        }
        if (BuildVars.LOGS_ENABLED) {
        }
        if (newTaskId == 0) {
        }
    }

    public void lambda$null$224$MessagesController(LongSparseArray messages) {
        for (int a = 0; a < messages.size(); a++) {
            long key = messages.keyAt(a);
            ArrayList<MessageObject> value = (ArrayList) messages.valueAt(a);
            updateInterfaceWithMessages(key, value, false);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public void lambda$null$226$MessagesController(final ArrayList pushMessages, TLRPC.updates_ChannelDifference res) {
        if (!pushMessages.isEmpty()) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$225$MessagesController(pushMessages);
                }
            });
        }
        getMessagesStorage().putMessages(res.new_messages, true, true, false, getDownloadController().getAutodownloadMask(), false);
    }

    public void lambda$null$225$MessagesController(ArrayList pushMessages) {
        getNotificationsController().processNewMessages(pushMessages, true, false, null);
    }

    public void lambda$null$229$MessagesController(TLRPC.TL_error error, int channelId) {
        checkChannelError(error.text, channelId);
    }

    private void checkChannelError(String text, int channelId) {
        char c;
        int hashCode = text.hashCode();
        if (hashCode == -1809401834) {
            if (text.equals("USER_BANNED_IN_CHANNEL")) {
                c = 2;
            }
            c = 65535;
        } else if (hashCode != -795226617) {
            if (hashCode == -471086771 && text.equals("CHANNEL_PUBLIC_GROUP_NA")) {
                c = 1;
            }
            c = 65535;
        } else {
            if (text.equals("CHANNEL_PRIVATE")) {
                c = 0;
            }
            c = 65535;
        }
        if (c == 0) {
            getNotificationCenter().postNotificationName(NotificationCenter.chatInfoCantLoad, Integer.valueOf(channelId), 0);
        } else if (c == 1) {
            getNotificationCenter().postNotificationName(NotificationCenter.chatInfoCantLoad, Integer.valueOf(channelId), 1);
        } else if (c == 2) {
            getNotificationCenter().postNotificationName(NotificationCenter.chatInfoCantLoad, Integer.valueOf(channelId), 2);
        }
    }

    public void getDifference() {
        getDifference(getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue(), false);
    }

    public void getDifference(int pts, final int date, final int qts, boolean slice) {
        registerForPush(SharedConfig.pushString);
        if (getMessagesStorage().getLastPtsValue() == 0) {
            loadCurrentState();
        } else if (!slice && this.gettingDifference) {
        } else {
            this.gettingDifference = true;
            TLRPC.TL_updates_getDifference req = new TLRPC.TL_updates_getDifference();
            req.pts = pts;
            req.date = date;
            req.qts = qts;
            if (this.getDifferenceFirstSync) {
                req.flags |= 1;
                if (ApplicationLoader.isConnectedOrConnectingToWiFi()) {
                    req.pts_total_limit = 5000;
                } else {
                    req.pts_total_limit = 1000;
                }
                this.getDifferenceFirstSync = false;
            }
            if (req.date == 0) {
                req.date = getConnectionsManager().getCurrentTime();
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("getDiff start ===> act=" + this.currentAccount + " ,date=" + date + " ,pts=" + pts + " ,qts=" + qts);
            }
            getConnectionsManager().setIsUpdating(true);
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$getDifference$239$MessagesController(date, qts, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$getDifference$239$MessagesController(final int date, final int qts, TLObject response, TLRPC.TL_error error) {
        if (error != null) {
            this.gettingDifference = false;
            getConnectionsManager().setIsUpdating(false);
            return;
        }
        final TLRPC.updates_Difference res = (TLRPC.updates_Difference) response;
        if (BuildVars.DEBUG_VERSION) {
            FileLog.d("getDiff success ===> act=" + this.currentAccount + " ,date=" + date + " ,res=" + res.toString());
        }
        if (res instanceof TLRPC.TL_updates_differenceTooLong) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$231$MessagesController(res, date, qts);
                }
            });
            return;
        }
        if (res instanceof TLRPC.TL_updates_differenceSlice) {
            getDifference(res.intermediate_state.pts, res.intermediate_state.date, res.intermediate_state.qts, true);
        }
        final SparseArray<TLRPC.User> usersDict = new SparseArray<>();
        final SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>();
        for (int a = 0; a < res.users.size(); a++) {
            TLRPC.User user = res.users.get(a);
            usersDict.put(user.id, user);
        }
        for (int a2 = 0; a2 < res.chats.size(); a2++) {
            TLRPC.Chat chat = res.chats.get(a2);
            chatsDict.put(chat.id, chat);
        }
        final ArrayList<TLRPC.TL_updateMessageID> msgUpdates = new ArrayList<>();
        if (!res.other_updates.isEmpty()) {
            int a3 = 0;
            while (a3 < res.other_updates.size()) {
                TLRPC.Update upd = res.other_updates.get(a3);
                if (upd instanceof TLRPC.TL_updateMessageID) {
                    msgUpdates.add((TLRPC.TL_updateMessageID) upd);
                    res.other_updates.remove(a3);
                    a3--;
                } else if (getUpdateType(upd) == 2) {
                    int channelId = getUpdateChannelId(upd);
                    int channelPts = this.channelsPts.get(channelId);
                    if (channelPts == 0 && (channelPts = getMessagesStorage().getChannelPtsSync(channelId)) != 0) {
                        this.channelsPts.put(channelId, channelPts);
                    }
                    if (channelPts != 0 && getUpdatePts(upd) <= channelPts) {
                        res.other_updates.remove(a3);
                        a3--;
                    }
                }
                a3++;
            }
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$232$MessagesController(res);
            }
        });
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$238$MessagesController(res, msgUpdates, usersDict, chatsDict);
            }
        });
    }

    public void lambda$null$231$MessagesController(TLRPC.updates_Difference res, int date, int qts) {
        this.loadedFullUsers.clear();
        this.loadedFullChats.clear();
        resetDialogs(true, getMessagesStorage().getLastSeqValue(), res.pts, date, qts);
    }

    public void lambda$null$232$MessagesController(TLRPC.updates_Difference res) {
        this.loadedFullUsers.clear();
        this.loadedFullChats.clear();
        putUsers(res.users, false);
        putChats(res.chats, false);
    }

    public void lambda$null$238$MessagesController(final TLRPC.updates_Difference res, ArrayList msgUpdates, final SparseArray usersDict, final SparseArray chatsDict) {
        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, false);
        if (!msgUpdates.isEmpty()) {
            final SparseArray<long[]> corrected = new SparseArray<>();
            for (int a = 0; a < msgUpdates.size(); a++) {
                TLRPC.TL_updateMessageID update = (TLRPC.TL_updateMessageID) msgUpdates.get(a);
                long[] ids = getMessagesStorage().updateMessageStateAndId(update.random_id, null, update.id, 0, false, 0, -1);
                if (ids != null) {
                    corrected.put(update.id, ids);
                }
            }
            int a2 = corrected.size();
            if (a2 != 0) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$233$MessagesController(corrected);
                    }
                });
            }
        }
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$237$MessagesController(res, usersDict, chatsDict);
            }
        });
    }

    public void lambda$null$233$MessagesController(SparseArray corrected) {
        for (int a = 0; a < corrected.size(); a++) {
            int newId = corrected.keyAt(a);
            long[] ids = (long[]) corrected.valueAt(a);
            int oldId = (int) ids[1];
            getSendMessagesHelper().processSentMessage(oldId);
            getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, Integer.valueOf(oldId), Integer.valueOf(newId), null, Long.valueOf(ids[0]), 0L, -1, false);
        }
    }

    public void lambda$null$237$MessagesController(final TLRPC.updates_Difference res, SparseArray usersDict, SparseArray chatsDict) {
        TLRPC.User user;
        if (!res.new_messages.isEmpty() || !res.new_encrypted_messages.isEmpty()) {
            final LongSparseArray<ArrayList<MessageObject>> messages = new LongSparseArray<>();
            for (int b = 0; b < res.new_encrypted_messages.size(); b++) {
                TLRPC.EncryptedMessage encryptedMessage = res.new_encrypted_messages.get(b);
                ArrayList<TLRPC.Message> decryptedMessages = getSecretChatHelper().decryptMessage(encryptedMessage);
                if (decryptedMessages != null && !decryptedMessages.isEmpty()) {
                    res.new_messages.addAll(decryptedMessages);
                }
            }
            ImageLoader.saveMessagesThumbs(res.new_messages);
            final ArrayList<MessageObject> pushMessages = new ArrayList<>();
            int clientUserId = getUserConfig().getClientUserId();
            for (int a = 0; a < res.new_messages.size(); a++) {
                TLRPC.Message message = res.new_messages.get(a);
                if (message.dialog_id == 0) {
                    if (message.to_id.chat_id != 0) {
                        message.dialog_id = -message.to_id.chat_id;
                    } else {
                        if (message.to_id.user_id == getUserConfig().getClientUserId()) {
                            message.to_id.user_id = message.from_id;
                        }
                        message.dialog_id = message.to_id.user_id;
                    }
                }
                if (((int) message.dialog_id) != 0) {
                    if ((message.action instanceof TLRPC.TL_messageActionChatDeleteUser) && (user = (TLRPC.User) usersDict.get(message.action.user_id)) != null && user.bot) {
                        message.reply_markup = new TLRPC.TL_replyKeyboardHide();
                        message.flags |= 64;
                    }
                    if ((message.action instanceof TLRPC.TL_messageActionChatMigrateTo) || (message.action instanceof TLRPC.TL_messageActionChannelCreate)) {
                        message.unread = false;
                        message.media_unread = false;
                    } else {
                        ConcurrentHashMap<Long, Integer> read_max = message.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                        Integer value = read_max.get(Long.valueOf(message.dialog_id));
                        if (value == null) {
                            value = Integer.valueOf(getMessagesStorage().getDialogReadMax(message.out, message.dialog_id));
                            read_max.put(Long.valueOf(message.dialog_id), value);
                        }
                        message.unread = value.intValue() < message.id;
                    }
                }
                if (message.dialog_id == clientUserId) {
                    message.unread = false;
                    message.media_unread = false;
                    message.out = true;
                }
                MessageObject obj = new MessageObject(this.currentAccount, message, usersDict, chatsDict, this.createdDialogIds.contains(Long.valueOf(message.dialog_id)));
                if ((!obj.isOut() || obj.messageOwner.from_scheduled) && obj.isUnread()) {
                    pushMessages.add(obj);
                }
                ArrayList<MessageObject> arr = messages.get(message.dialog_id);
                if (arr == null) {
                    arr = new ArrayList<>();
                    messages.put(message.dialog_id, arr);
                }
                arr.add(obj);
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$234$MessagesController(messages);
                }
            });
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$236$MessagesController(pushMessages, res);
                }
            });
            getSecretChatHelper().processPendingEncMessages();
        }
        if (!res.other_updates.isEmpty()) {
            processUpdateArray(res.other_updates, res.users, res.chats, true, 0);
        }
        if (res instanceof TLRPC.TL_updates_difference) {
            this.gettingDifference = false;
            getMessagesStorage().setLastSeqValue(res.state.seq);
            getMessagesStorage().setLastDateValue(res.state.date);
            getMessagesStorage().setLastPtsValue(res.state.pts);
            getMessagesStorage().setLastQtsValue(res.state.qts);
            getConnectionsManager().setIsUpdating(false);
            for (int a2 = 0; a2 < 3; a2++) {
                processUpdatesQueue(a2, 1);
            }
        } else if (res instanceof TLRPC.TL_updates_differenceSlice) {
            getMessagesStorage().setLastDateValue(res.intermediate_state.date);
            getMessagesStorage().setLastPtsValue(res.intermediate_state.pts);
            getMessagesStorage().setLastQtsValue(res.intermediate_state.qts);
        } else if (res instanceof TLRPC.TL_updates_differenceEmpty) {
            this.gettingDifference = false;
            getMessagesStorage().setLastSeqValue(res.seq);
            getMessagesStorage().setLastDateValue(res.date);
            getConnectionsManager().setIsUpdating(false);
            for (int a3 = 0; a3 < 3; a3++) {
                processUpdatesQueue(a3, 1);
            }
        }
        getMessagesStorage().saveDiffParams(getMessagesStorage().getLastSeqValue(), getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue());
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("getDiff save last diff value ===> act=" + this.currentAccount + " ,date=" + getMessagesStorage().getLastDateValue() + " ,pts=" + getMessagesStorage().getLastPtsValue() + " ,seq=" + getMessagesStorage().getLastSeqValue() + " ,qts=" + getMessagesStorage().getLastQtsValue());
        }
    }

    public void lambda$null$234$MessagesController(LongSparseArray messages) {
        for (int a = 0; a < messages.size(); a++) {
            long key = messages.keyAt(a);
            ArrayList<MessageObject> value = (ArrayList) messages.valueAt(a);
            updateInterfaceWithMessages(key, value, false);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public void lambda$null$236$MessagesController(final ArrayList pushMessages, final TLRPC.updates_Difference res) {
        if (!pushMessages.isEmpty()) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$235$MessagesController(pushMessages, res);
                }
            });
        }
        getMessagesStorage().putMessages(res.new_messages, true, true, false, getDownloadController().getAutodownloadMask(), false);
    }

    public void lambda$null$235$MessagesController(ArrayList pushMessages, TLRPC.updates_Difference res) {
        getNotificationsController().processNewMessages(pushMessages, !(res instanceof TLRPC.TL_updates_differenceSlice), false, null);
    }

    public void markDialogAsUnread(long did, TLRPC.InputPeer peer, long taskId) {
        final long newTaskId;
        TLRPC.Dialog dialog = this.dialogs_dict.get(did);
        if (dialog != null) {
            dialog.unread_mark = true;
            if (dialog.unread_count == 0) {
                this.dialogsUnreadOnly.add(dialog);
                if (!isDialogMuted(did)) {
                    this.unreadUnmutedDialogs++;
                }
            }
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 256);
            getMessagesStorage().setDialogUnread(did, true);
        }
        int lower_id = (int) did;
        if (lower_id != 0) {
            TLRPC.TL_messages_markDialogUnread req = new TLRPC.TL_messages_markDialogUnread();
            req.unread = true;
            if (peer == null) {
                peer = getInputPeer(lower_id);
            }
            if (peer instanceof TLRPC.TL_inputPeerEmpty) {
                return;
            }
            TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
            inputDialogPeer.peer = peer;
            req.peer = inputDialogPeer;
            if (taskId == 0) {
                NativeByteBuffer data = null;
                try {
                    data = new NativeByteBuffer(peer.getObjectSize() + 12);
                    data.writeInt32(9);
                    data.writeInt64(did);
                    peer.serializeToStream(data);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                newTaskId = getMessagesStorage().createPendingTask(data);
            } else {
                newTaskId = taskId;
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$markDialogAsUnread$240$MessagesController(newTaskId, tLObject, tL_error);
                }
            });
        }
    }

    public void lambda$markDialogAsUnread$240$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void loadUnreadDialogs() {
        if (this.loadingUnreadDialogs || getUserConfig().unreadDialogsLoaded) {
            return;
        }
        this.loadingUnreadDialogs = true;
        TLRPC.TL_messages_getDialogUnreadMarks req = new TLRPC.TL_messages_getDialogUnreadMarks();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadUnreadDialogs$242$MessagesController(tLObject, tL_error);
            }
        });
    }

    public void lambda$loadUnreadDialogs$242$MessagesController(final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$241$MessagesController(response);
            }
        });
    }

    public void lambda$null$241$MessagesController(TLObject response) {
        long did;
        if (response != null) {
            TLRPC.Vector vector = (TLRPC.Vector) response;
            int size = vector.objects.size();
            for (int a = 0; a < size; a++) {
                TLRPC.DialogPeer peer = (TLRPC.DialogPeer) vector.objects.get(a);
                if (peer instanceof TLRPC.TL_dialogPeer) {
                    TLRPC.TL_dialogPeer dialogPeer = (TLRPC.TL_dialogPeer) peer;
                    if (dialogPeer.peer.user_id != 0) {
                        if (dialogPeer.peer.user_id != 0) {
                            did = dialogPeer.peer.user_id;
                        } else if (dialogPeer.peer.chat_id != 0) {
                            did = -dialogPeer.peer.chat_id;
                        } else {
                            did = -dialogPeer.peer.channel_id;
                        }
                    } else {
                        did = 0;
                    }
                    getMessagesStorage().setDialogUnread(did, true);
                    TLRPC.Dialog dialog = this.dialogs_dict.get(did);
                    if (dialog != null && !dialog.unread_mark) {
                        dialog.unread_mark = true;
                        if (dialog.unread_count == 0) {
                            this.dialogsUnreadOnly.add(dialog);
                            if (!isDialogMuted(did)) {
                                this.unreadUnmutedDialogs++;
                            }
                        }
                    }
                }
            }
            getUserConfig().unreadDialogsLoaded = true;
            getUserConfig().saveConfig(false);
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 256);
            this.loadingUnreadDialogs = false;
        }
    }

    public void reorderPinnedDialogs(int folderId, ArrayList<TLRPC.InputDialogPeer> order, long taskId) {
        final long newTaskId;
        TLRPC.TL_messages_reorderPinnedDialogs req = new TLRPC.TL_messages_reorderPinnedDialogs();
        req.folder_id = folderId;
        req.force = true;
        if (taskId == 0) {
            ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
            if (dialogs.isEmpty()) {
                return;
            }
            int size = 0;
            int N = dialogs.size();
            for (int a = 0; a < N; a++) {
                TLRPC.Dialog dialog = dialogs.get(a);
                if (!(dialog instanceof TLRPC.TL_dialogFolder)) {
                    if (!dialog.pinned) {
                        break;
                    }
                    getMessagesStorage().setDialogPinned(dialog.id, dialog.pinnedNum);
                    if (((int) dialog.id) != 0) {
                        TLRPC.InputPeer inputPeer = getInputPeer((int) dialogs.get(a).id);
                        TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
                        inputDialogPeer.peer = inputPeer;
                        req.order.add(inputDialogPeer);
                        size += inputDialogPeer.getObjectSize();
                    }
                }
            }
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(size + 12);
                data.writeInt32(16);
                data.writeInt32(folderId);
                data.writeInt32(req.order.size());
                int N2 = req.order.size();
                for (int a2 = 0; a2 < N2; a2++) {
                    req.order.get(a2).serializeToStream(data);
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        } else {
            req.order = order;
            newTaskId = taskId;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$reorderPinnedDialogs$243$MessagesController(newTaskId, tLObject, tL_error);
            }
        });
    }

    public void lambda$reorderPinnedDialogs$243$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public boolean pinDialog(long did, boolean pin, TLRPC.InputPeer peer, long taskId) {
        TLRPC.InputPeer peer2;
        final long newTaskId;
        int lower_id = (int) did;
        TLRPC.Dialog dialog = this.dialogs_dict.get(did);
        if (dialog == null || dialog.pinned == pin) {
            return dialog != null;
        }
        int folderId = dialog.folder_id;
        ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
        dialog.pinned = pin;
        if (pin) {
            int maxPinnedNum = 0;
            for (int a = 0; a < dialogs.size(); a++) {
                TLRPC.Dialog d = dialogs.get(a);
                if (!(d instanceof TLRPC.TL_dialogFolder)) {
                    if (!d.pinned) {
                        break;
                    }
                    maxPinnedNum = Math.max(d.pinnedNum, maxPinnedNum);
                }
            }
            int a2 = maxPinnedNum + 1;
            dialog.pinnedNum = a2;
        } else {
            dialog.pinnedNum = 0;
        }
        sortDialogs(null);
        if (!pin && dialogs.get(dialogs.size() - 1) == dialog && !this.dialogsEndReached.get(folderId)) {
            dialogs.remove(dialogs.size() - 1);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        if (lower_id != 0 && taskId != -1) {
            TLRPC.TL_messages_toggleDialogPin req = new TLRPC.TL_messages_toggleDialogPin();
            req.pinned = pin;
            if (peer != null) {
                peer2 = peer;
            } else {
                peer2 = getInputPeer(lower_id);
            }
            if (peer2 instanceof TLRPC.TL_inputPeerEmpty) {
                return false;
            }
            TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
            inputDialogPeer.peer = peer2;
            req.peer = inputDialogPeer;
            if (taskId == 0) {
                NativeByteBuffer data = null;
                try {
                    data = new NativeByteBuffer(peer2.getObjectSize() + 16);
                    data.writeInt32(4);
                    data.writeInt64(did);
                    data.writeBool(pin);
                    peer2.serializeToStream(data);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                newTaskId = getMessagesStorage().createPendingTask(data);
            } else {
                newTaskId = taskId;
            }
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$pinDialog$244$MessagesController(newTaskId, tLObject, tL_error);
                }
            });
        }
        getMessagesStorage().setDialogPinned(did, dialog.pinnedNum);
        return true;
    }

    public void lambda$pinDialog$244$MessagesController(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void loadPinnedDialogs(final int folderId, long newDialogId, ArrayList<Long> order) {
        if (this.loadingPinnedDialogs.indexOfKey(folderId) >= 0 || getUserConfig().isPinnedDialogsLoaded(folderId)) {
            return;
        }
        this.loadingPinnedDialogs.put(folderId, 1);
        TLRPC.TL_messages_getPinnedDialogs req = new TLRPC.TL_messages_getPinnedDialogs();
        req.folder_id = folderId;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$loadPinnedDialogs$247$MessagesController(folderId, tLObject, tL_error);
            }
        });
    }

    public void lambda$loadPinnedDialogs$247$MessagesController(final int folderId, TLObject response, TLRPC.TL_error error) {
        TLRPC.Chat chat;
        int N;
        Integer value;
        Integer value2;
        MessageObject mess;
        TLRPC.Chat chat2;
        MessagesController messagesController = this;
        if (response != null) {
            final TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
            final ArrayList<TLRPC.Dialog> newPinnedDialogs = new ArrayList<>(res.dialogs);
            messagesController.fetchFolderInLoadedPinnedDialogs(res);
            final TLRPC.TL_messages_dialogs toCache = new TLRPC.TL_messages_dialogs();
            toCache.users.addAll(res.users);
            toCache.chats.addAll(res.chats);
            toCache.dialogs.addAll(res.dialogs);
            toCache.messages.addAll(res.messages);
            final LongSparseArray<MessageObject> new_dialogMessage = new LongSparseArray<>();
            SparseArray<TLRPC.User> usersDict = new SparseArray<>();
            SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>();
            for (int a = 0; a < res.users.size(); a++) {
                TLRPC.User u = res.users.get(a);
                usersDict.put(u.id, u);
            }
            for (int a2 = 0; a2 < res.chats.size(); a2++) {
                TLRPC.Chat c = res.chats.get(a2);
                chatsDict.put(c.id, c);
            }
            for (int a3 = 0; a3 < res.messages.size(); a3++) {
                TLRPC.Message message = res.messages.get(a3);
                if (message.to_id.channel_id != 0) {
                    TLRPC.Chat chat3 = chatsDict.get(message.to_id.channel_id);
                    if (chat3 != null && chat3.left) {
                    }
                    MessageObject messageObject = new MessageObject(messagesController.currentAccount, message, usersDict, chatsDict, false);
                    new_dialogMessage.put(messageObject.getDialogId(), messageObject);
                } else {
                    if (message.to_id.chat_id != 0 && (chat2 = chatsDict.get(message.to_id.chat_id)) != null && chat2.migrated_to != null) {
                    }
                    MessageObject messageObject2 = new MessageObject(messagesController.currentAccount, message, usersDict, chatsDict, false);
                    new_dialogMessage.put(messageObject2.getDialogId(), messageObject2);
                }
            }
            int i = 0;
            boolean z = true;
            final boolean firstIsFolder = !newPinnedDialogs.isEmpty() && (newPinnedDialogs.get(0) instanceof TLRPC.TL_dialogFolder);
            int a4 = 0;
            int N2 = newPinnedDialogs.size();
            while (a4 < N2) {
                TLRPC.Dialog d = newPinnedDialogs.get(a4);
                d.pinned = z;
                DialogObject.initDialog(d);
                if (DialogObject.isChannel(d)) {
                    TLRPC.Chat chat4 = chatsDict.get(-((int) d.id));
                    if (chat4 != null && chat4.left) {
                        N = N2;
                    }
                    if (d.last_message_date == 0 && (mess = new_dialogMessage.get(d.id)) != null) {
                        d.last_message_date = mess.messageOwner.date;
                    }
                    N = N2;
                    value = messagesController.dialogs_read_inbox_max.get(Long.valueOf(d.id));
                    if (value == null) {
                        value = Integer.valueOf(i);
                    }
                    messagesController.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
                    messagesController = this;
                    value2 = messagesController.dialogs_read_outbox_max.get(Long.valueOf(d.id));
                    if (value2 == null) {
                        value2 = Integer.valueOf(i);
                    }
                    messagesController.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
                } else {
                    if (((int) d.id) < 0 && (chat = chatsDict.get(-((int) d.id))) != null && chat.migrated_to != null) {
                        N = N2;
                    }
                    if (d.last_message_date == 0) {
                        d.last_message_date = mess.messageOwner.date;
                    }
                    N = N2;
                    value = messagesController.dialogs_read_inbox_max.get(Long.valueOf(d.id));
                    if (value == null) {
                    }
                    messagesController.dialogs_read_inbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value.intValue(), d.read_inbox_max_id)));
                    messagesController = this;
                    value2 = messagesController.dialogs_read_outbox_max.get(Long.valueOf(d.id));
                    if (value2 == null) {
                    }
                    messagesController.dialogs_read_outbox_max.put(Long.valueOf(d.id), Integer.valueOf(Math.max(value2.intValue(), d.read_outbox_max_id)));
                }
                a4++;
                N2 = N;
                i = 0;
                z = true;
            }
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$246$MessagesController(folderId, newPinnedDialogs, firstIsFolder, res, new_dialogMessage, toCache);
                }
            });
        }
    }

    public void lambda$null$246$MessagesController(final int folderId, final ArrayList newPinnedDialogs, final boolean firstIsFolder, final TLRPC.TL_messages_peerDialogs res, final LongSparseArray new_dialogMessage, final TLRPC.TL_messages_dialogs toCache) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$245$MessagesController(folderId, newPinnedDialogs, firstIsFolder, res, new_dialogMessage, toCache);
            }
        });
    }

    public void lambda$null$245$MessagesController(int folderId, ArrayList newPinnedDialogs, boolean firstIsFolder, TLRPC.TL_messages_peerDialogs res, LongSparseArray new_dialogMessage, TLRPC.TL_messages_dialogs toCache) {
        ArrayList arrayList = newPinnedDialogs;
        this.loadingPinnedDialogs.delete(folderId);
        applyDialogsNotificationsSettings(arrayList);
        boolean changed = false;
        boolean added = false;
        int maxPinnedNum = 0;
        ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
        int pinnedNum = firstIsFolder ? 1 : 0;
        for (int a = 0; a < dialogs.size(); a++) {
            TLRPC.Dialog dialog = dialogs.get(a);
            if (!(dialog instanceof TLRPC.TL_dialogFolder)) {
                if (((int) dialog.id) == 0) {
                    if (pinnedNum < newPinnedDialogs.size()) {
                        arrayList.add(pinnedNum, dialog);
                    } else {
                        arrayList.add(dialog);
                    }
                    pinnedNum++;
                } else if (!dialog.pinned) {
                    break;
                } else {
                    maxPinnedNum = Math.max(dialog.pinnedNum, maxPinnedNum);
                    dialog.pinned = false;
                    dialog.pinnedNum = 0;
                    changed = true;
                    pinnedNum++;
                }
            }
        }
        ArrayList<Long> pinnedDialogs = new ArrayList<>();
        if (!newPinnedDialogs.isEmpty()) {
            putUsers(res.users, false);
            putChats(res.chats, false);
            int a2 = 0;
            int N = newPinnedDialogs.size();
            while (a2 < N) {
                TLRPC.Dialog dialog2 = (TLRPC.Dialog) arrayList.get(a2);
                dialog2.pinnedNum = (N - a2) + maxPinnedNum;
                pinnedDialogs.add(Long.valueOf(dialog2.id));
                TLRPC.Dialog d = this.dialogs_dict.get(dialog2.id);
                if (d != null) {
                    d.pinned = true;
                    d.pinnedNum = dialog2.pinnedNum;
                    getMessagesStorage().setDialogPinned(dialog2.id, dialog2.pinnedNum);
                } else {
                    added = true;
                    this.dialogs_dict.put(dialog2.id, dialog2);
                    MessageObject messageObject = (MessageObject) new_dialogMessage.get(dialog2.id);
                    this.dialogMessage.put(dialog2.id, messageObject);
                    if (messageObject != null && messageObject.messageOwner.to_id.channel_id == 0) {
                        this.dialogMessagesByIds.put(messageObject.getId(), messageObject);
                        if (messageObject.messageOwner.random_id != 0) {
                            this.dialogMessagesByRandomIds.put(messageObject.messageOwner.random_id, messageObject);
                        }
                    }
                }
                changed = true;
                a2++;
                arrayList = newPinnedDialogs;
            }
        }
        if (changed) {
            if (added) {
                this.allDialogs.clear();
                int size = this.dialogs_dict.size();
                for (int a3 = 0; a3 < size; a3++) {
                    this.allDialogs.add(this.dialogs_dict.valueAt(a3));
                }
            }
            sortDialogs(null);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        }
        getMessagesStorage().unpinAllDialogsExceptNew(pinnedDialogs, folderId);
        getMessagesStorage().putDialogs(toCache, 1);
        getUserConfig().setPinnedDialogsLoaded(folderId, true);
        getUserConfig().saveConfig(false);
    }

    public void generateJoinMessage(final int chat_id, boolean ignoreLeft) {
        TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
        if (chat == null || !ChatObject.isChannel(chat_id, this.currentAccount)) {
            return;
        }
        if ((chat.left || chat.kicked) && !ignoreLeft) {
            return;
        }
        TLRPC.TL_messageService message = new TLRPC.TL_messageService();
        message.flags = 256;
        int newMessageId = getUserConfig().getNewMessageId();
        message.id = newMessageId;
        message.local_id = newMessageId;
        message.date = getConnectionsManager().getCurrentTime();
        message.from_id = getUserConfig().getClientUserId();
        message.to_id = new TLRPC.TL_peerChannel();
        message.to_id.channel_id = chat_id;
        message.dialog_id = -chat_id;
        message.post = true;
        message.action = new TLRPC.TL_messageActionChatAddUser();
        message.action.users.add(Integer.valueOf(getUserConfig().getClientUserId()));
        if (chat.megagroup) {
            message.flags |= Integer.MIN_VALUE;
        }
        getUserConfig().saveConfig(false);
        final ArrayList<MessageObject> pushMessages = new ArrayList<>();
        ArrayList<TLRPC.Message> messagesArr = new ArrayList<>();
        messagesArr.add(message);
        MessageObject obj = new MessageObject(this.currentAccount, message, true);
        pushMessages.add(obj);
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$generateJoinMessage$249$MessagesController(pushMessages);
            }
        });
        getMessagesStorage().putMessages(messagesArr, true, true, false, 0, false);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$generateJoinMessage$250$MessagesController(chat_id, pushMessages);
            }
        });
    }

    public void lambda$generateJoinMessage$249$MessagesController(final ArrayList pushMessages) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$248$MessagesController(pushMessages);
            }
        });
    }

    public void lambda$null$248$MessagesController(ArrayList pushMessages) {
        getNotificationsController().processNewMessages(pushMessages, true, false, null);
    }

    public void lambda$generateJoinMessage$250$MessagesController(int chat_id, ArrayList pushMessages) {
        updateInterfaceWithMessages(-chat_id, pushMessages, false);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public void deleteMessagesByPush(final long dialogId, final ArrayList<Integer> ids, final int channelId) {
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$deleteMessagesByPush$252$MessagesController(ids, channelId, dialogId);
            }
        });
    }

    public void lambda$deleteMessagesByPush$252$MessagesController(final ArrayList ids, final int channelId, long dialogId) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$251$MessagesController(ids, channelId);
            }
        });
        getMessagesStorage().deletePushMessages(dialogId, ids);
        ArrayList<Long> dialogIds = getMessagesStorage().markMessagesAsDeleted(ids, false, channelId, true, false);
        getMessagesStorage().updateDialogsWithDeletedMessages(ids, dialogIds, false, channelId);
    }

    public void lambda$null$251$MessagesController(ArrayList ids, int channelId) {
        getNotificationCenter().postNotificationName(NotificationCenter.messagesDeleted, ids, Integer.valueOf(channelId), false);
        if (channelId == 0) {
            int size2 = ids.size();
            for (int b = 0; b < size2; b++) {
                Integer id = (Integer) ids.get(b);
                MessageObject obj = this.dialogMessagesByIds.get(id.intValue());
                if (obj != null) {
                    obj.deleted = true;
                }
            }
            return;
        }
        MessageObject obj2 = this.dialogMessage.get(-channelId);
        if (obj2 != null) {
            int size22 = ids.size();
            for (int b2 = 0; b2 < size22; b2++) {
                if (obj2.getId() == ((Integer) ids.get(b2)).intValue()) {
                    obj2.deleted = true;
                    return;
                }
            }
        }
    }

    public void checkChannelInviter(final int chat_id) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$checkChannelInviter$258$MessagesController(chat_id);
            }
        });
    }

    public void lambda$checkChannelInviter$258$MessagesController(final int chat_id) {
        final TLRPC.Chat chat = getChat(Integer.valueOf(chat_id));
        if (chat == null || !ChatObject.isChannel(chat_id, this.currentAccount) || chat.creator) {
            return;
        }
        TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant();
        req.channel = getInputChannel(chat_id);
        req.user_id = new TLRPC.TL_inputUserSelf();
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$null$257$MessagesController(chat, chat_id, tLObject, tL_error);
            }
        });
    }

    public void lambda$null$257$MessagesController(TLRPC.Chat chat, final int chat_id, TLObject response, TLRPC.TL_error error) {
        final TLRPC.TL_channels_channelParticipant res = (TLRPC.TL_channels_channelParticipant) response;
        if (res != null && (res.participant instanceof TLRPC.TL_channelParticipantSelf) && res.participant.inviter_id != getUserConfig().getClientUserId()) {
            if (!chat.megagroup || !getMessagesStorage().isMigratedChat(chat.id)) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$253$MessagesController(res);
                    }
                });
                getMessagesStorage().putUsersAndChats(res.users, null, true, true);
                TLRPC.TL_messageService message = new TLRPC.TL_messageService();
                message.media_unread = true;
                message.unread = true;
                message.flags = 256;
                message.post = true;
                if (chat.megagroup) {
                    message.flags |= Integer.MIN_VALUE;
                }
                int newMessageId = getUserConfig().getNewMessageId();
                message.id = newMessageId;
                message.local_id = newMessageId;
                message.date = res.participant.date;
                message.action = new TLRPC.TL_messageActionChatAddUser();
                message.from_id = res.participant.inviter_id;
                message.action.users.add(Integer.valueOf(getUserConfig().getClientUserId()));
                message.to_id = new TLRPC.TL_peerChannel();
                message.to_id.channel_id = chat_id;
                message.dialog_id = -chat_id;
                getUserConfig().saveConfig(false);
                final ArrayList<MessageObject> pushMessages = new ArrayList<>();
                ArrayList<TLRPC.Message> messagesArr = new ArrayList<>();
                ConcurrentHashMap<Integer, TLRPC.User> usersDict = new ConcurrentHashMap<>();
                for (int a = 0; a < res.users.size(); a++) {
                    TLRPC.User user = res.users.get(a);
                    usersDict.put(Integer.valueOf(user.id), user);
                }
                messagesArr.add(message);
                MessageObject obj = new MessageObject(this.currentAccount, (TLRPC.Message) message, (AbstractMap<Integer, TLRPC.User>) usersDict, true);
                pushMessages.add(obj);
                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$255$MessagesController(pushMessages);
                    }
                });
                getMessagesStorage().putMessages(messagesArr, true, true, false, 0, false);
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$256$MessagesController(chat_id, pushMessages);
                    }
                });
            }
        }
    }

    public void lambda$null$253$MessagesController(TLRPC.TL_channels_channelParticipant res) {
        putUsers(res.users, false);
    }

    public void lambda$null$254$MessagesController(ArrayList pushMessages) {
        getNotificationsController().processNewMessages(pushMessages, true, false, null);
    }

    public void lambda$null$255$MessagesController(final ArrayList pushMessages) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$254$MessagesController(pushMessages);
            }
        });
    }

    public void lambda$null$256$MessagesController(int chat_id, ArrayList pushMessages) {
        updateInterfaceWithMessages(-chat_id, pushMessages, false);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    private int getUpdateType(TLRPC.Update update) {
        if ((update instanceof TLRPC.TL_updateNewMessage) || (update instanceof TLRPC.TL_updateReadMessagesContents) || (update instanceof TLRPC.TL_updateReadHistoryInbox) || (update instanceof TLRPC.TL_updateReadHistoryOutbox) || (update instanceof TLRPC.TL_updateDeleteMessages) || (update instanceof TLRPC.TL_updateWebPage) || (update instanceof TLRPC.TL_updateEditMessage) || (update instanceof TLRPC.TL_updateFolderPeers)) {
            return 0;
        }
        if (update instanceof TLRPC.TL_updateNewEncryptedMessage) {
            return 1;
        }
        if ((update instanceof TLRPC.TL_updateNewChannelMessage) || (update instanceof TLRPC.TL_updateDeleteChannelMessages) || (update instanceof TLRPC.TL_updateEditChannelMessage) || (update instanceof TLRPC.TL_updateChannelWebPage)) {
            return 2;
        }
        return 3;
    }

    private static int getUpdatePts(TLRPC.Update update) {
        if (update instanceof TLRPC.TL_updateDeleteMessages) {
            return ((TLRPC.TL_updateDeleteMessages) update).pts;
        }
        if (update instanceof TLRPC.TL_updateNewChannelMessage) {
            return ((TLRPC.TL_updateNewChannelMessage) update).pts;
        }
        if (update instanceof TLRPC.TL_updateReadHistoryOutbox) {
            return ((TLRPC.TL_updateReadHistoryOutbox) update).pts;
        }
        if (update instanceof TLRPC.TL_updateNewMessage) {
            return ((TLRPC.TL_updateNewMessage) update).pts;
        }
        if (update instanceof TLRPC.TL_updateEditMessage) {
            return ((TLRPC.TL_updateEditMessage) update).pts;
        }
        if (update instanceof TLRPC.TL_updateWebPage) {
            return ((TLRPC.TL_updateWebPage) update).pts;
        }
        if (update instanceof TLRPC.TL_updateReadHistoryInbox) {
            return ((TLRPC.TL_updateReadHistoryInbox) update).pts;
        }
        if (update instanceof TLRPC.TL_updateChannelWebPage) {
            return ((TLRPC.TL_updateChannelWebPage) update).pts;
        }
        if (update instanceof TLRPC.TL_updateDeleteChannelMessages) {
            return ((TLRPC.TL_updateDeleteChannelMessages) update).pts;
        }
        if (update instanceof TLRPC.TL_updateEditChannelMessage) {
            return ((TLRPC.TL_updateEditChannelMessage) update).pts;
        }
        if (update instanceof TLRPC.TL_updateReadMessagesContents) {
            return ((TLRPC.TL_updateReadMessagesContents) update).pts;
        }
        if (update instanceof TLRPC.TL_updateChannelTooLong) {
            return ((TLRPC.TL_updateChannelTooLong) update).pts;
        }
        if (update instanceof TLRPC.TL_updateFolderPeers) {
            return ((TLRPC.TL_updateFolderPeers) update).pts;
        }
        return 0;
    }

    private static int getUpdatePtsCount(TLRPC.Update update) {
        if (update instanceof TLRPC.TL_updateDeleteMessages) {
            return ((TLRPC.TL_updateDeleteMessages) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateNewChannelMessage) {
            return ((TLRPC.TL_updateNewChannelMessage) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateReadHistoryOutbox) {
            return ((TLRPC.TL_updateReadHistoryOutbox) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateNewMessage) {
            return ((TLRPC.TL_updateNewMessage) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateEditMessage) {
            return ((TLRPC.TL_updateEditMessage) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateWebPage) {
            return ((TLRPC.TL_updateWebPage) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateReadHistoryInbox) {
            return ((TLRPC.TL_updateReadHistoryInbox) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateChannelWebPage) {
            return ((TLRPC.TL_updateChannelWebPage) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateDeleteChannelMessages) {
            return ((TLRPC.TL_updateDeleteChannelMessages) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateEditChannelMessage) {
            return ((TLRPC.TL_updateEditChannelMessage) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateReadMessagesContents) {
            return ((TLRPC.TL_updateReadMessagesContents) update).pts_count;
        }
        if (update instanceof TLRPC.TL_updateFolderPeers) {
            return ((TLRPC.TL_updateFolderPeers) update).pts_count;
        }
        return 0;
    }

    private static int getUpdateQts(TLRPC.Update update) {
        if (update instanceof TLRPC.TL_updateNewEncryptedMessage) {
            return ((TLRPC.TL_updateNewEncryptedMessage) update).qts;
        }
        return 0;
    }

    private static int getUpdateChannelId(TLRPC.Update update) {
        if (update instanceof TLRPC.TL_updateNewChannelMessage) {
            return ((TLRPC.TL_updateNewChannelMessage) update).message.to_id.channel_id;
        }
        if (update instanceof TLRPC.TL_updateEditChannelMessage) {
            return ((TLRPC.TL_updateEditChannelMessage) update).message.to_id.channel_id;
        }
        if (update instanceof TLRPC.TL_updateReadChannelOutbox) {
            return ((TLRPC.TL_updateReadChannelOutbox) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannelMessageViews) {
            return ((TLRPC.TL_updateChannelMessageViews) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannelTooLong) {
            return ((TLRPC.TL_updateChannelTooLong) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannelPinnedMessage) {
            return ((TLRPC.TL_updateChannelPinnedMessage) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannelReadMessagesContents) {
            return ((TLRPC.TL_updateChannelReadMessagesContents) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannelAvailableMessages) {
            return ((TLRPC.TL_updateChannelAvailableMessages) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannel) {
            return ((TLRPC.TL_updateChannel) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateChannelWebPage) {
            return ((TLRPC.TL_updateChannelWebPage) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateDeleteChannelMessages) {
            return ((TLRPC.TL_updateDeleteChannelMessages) update).channel_id;
        }
        if (update instanceof TLRPC.TL_updateReadChannelInbox) {
            return ((TLRPC.TL_updateReadChannelInbox) update).channel_id;
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("trying to get unknown update channel_id for " + update);
            return 0;
        }
        return 0;
    }

    public void processUpdates(final TLRPC.Updates updates, boolean fromQueue) {
        boolean needReceivedQueue;
        boolean updateStatus;
        boolean missingData;
        boolean needReceivedQueue2;
        boolean updateStatus2;
        boolean updateStatus3;
        ArrayList<Integer> needGetChannelsDiff;
        boolean needGetDiff;
        boolean z;
        final boolean printUpdate;
        TLRPC.User user2;
        TLRPC.User user3;
        boolean updateStatus4;
        boolean needGetDiff2;
        boolean needReceivedQueue3;
        boolean processUpdate;
        SparseArray<TLRPC.Chat> minChannels;
        boolean skipUpdate;
        int channelPts;
        boolean needGetDiff3;
        boolean needGetDiff4;
        ArrayList<Integer> needGetChannelsDiff2 = null;
        boolean needGetDiff5 = false;
        boolean needReceivedQueue4 = false;
        boolean updateStatus5 = false;
        if (updates instanceof TLRPC.TL_updateShort) {
            ArrayList<TLRPC.Update> arr = new ArrayList<>();
            arr.add(updates.update);
            processUpdateArray(arr, null, null, false, updates.date);
        } else {
            if (updates instanceof TLRPC.TL_updateShortChatMessage) {
                needReceivedQueue = false;
                updateStatus = false;
            } else if (updates instanceof TLRPC.TL_updateShortMessage) {
                needReceivedQueue = false;
                updateStatus = false;
            } else if ((updates instanceof TLRPC.TL_updatesCombined) || (updates instanceof TLRPC.TL_updates)) {
                SparseArray<TLRPC.Chat> minChannels2 = null;
                for (int a = 0; a < updates.chats.size(); a++) {
                    TLRPC.Chat chat = updates.chats.get(a);
                    if ((chat instanceof TLRPC.TL_channel) && chat.min) {
                        TLRPC.Chat existChat = getChat(Integer.valueOf(chat.id));
                        if (existChat == null || existChat.min) {
                            TLRPC.Chat cacheChat = getMessagesStorage().getChatSync(updates.chat_id);
                            putChat(cacheChat, true);
                            existChat = cacheChat;
                        }
                        if (existChat == null || existChat.min) {
                            if (minChannels2 == null) {
                                minChannels2 = new SparseArray<>();
                            }
                            minChannels2.put(chat.id, chat);
                        }
                    }
                }
                if (minChannels2 != null) {
                    int a2 = 0;
                    while (true) {
                        if (a2 >= updates.updates.size()) {
                            break;
                        }
                        TLRPC.Update update = updates.updates.get(a2);
                        if (update instanceof TLRPC.TL_updateNewChannelMessage) {
                            int channelId = ((TLRPC.TL_updateNewChannelMessage) update).message.to_id.channel_id;
                            if (minChannels2.indexOfKey(channelId) >= 0) {
                                if (BuildVars.LOGS_ENABLED) {
                                    FileLog.d("need get diff because of min channel=" + channelId + " ,act=" + this.currentAccount);
                                }
                                needGetDiff5 = true;
                            }
                        }
                        a2++;
                    }
                }
                if (needGetDiff5) {
                    updateStatus4 = false;
                } else {
                    getMessagesStorage().putUsersAndChats(updates.users, updates.chats, true, true);
                    Collections.sort(updates.updates, this.updatesComparator);
                    boolean needReceivedQueue5 = false;
                    boolean needGetDiff6 = needGetDiff5;
                    ArrayList<Integer> needGetChannelsDiff3 = null;
                    int a3 = 0;
                    while (true) {
                        if (a3 >= updates.updates.size()) {
                            needGetDiff2 = needGetDiff6;
                            updateStatus4 = updateStatus5;
                            needReceivedQueue3 = needReceivedQueue5;
                            break;
                        }
                        TLRPC.Update update2 = updates.updates.get(a3);
                        if (getUpdateType(update2) != 0) {
                            minChannels = minChannels2;
                            needGetDiff2 = needGetDiff6;
                            updateStatus4 = updateStatus5;
                            if (getUpdateType(update2) != 1) {
                                if (getUpdateType(update2) != 2) {
                                    needReceivedQueue3 = needReceivedQueue5;
                                    break;
                                }
                                int channelId2 = getUpdateChannelId(update2);
                                boolean skipUpdate2 = false;
                                int channelPts2 = this.channelsPts.get(channelId2);
                                if (channelPts2 != 0) {
                                    skipUpdate = false;
                                    channelPts = channelPts2;
                                } else {
                                    int channelPts3 = getMessagesStorage().getChannelPtsSync(channelId2);
                                    if (channelPts3 == 0) {
                                        int c = 0;
                                        while (true) {
                                            if (c >= updates.chats.size()) {
                                                break;
                                            }
                                            TLRPC.Chat chat2 = updates.chats.get(c);
                                            if (chat2.id != channelId2) {
                                                c++;
                                            } else {
                                                loadUnknownChannel(chat2, 0L);
                                                skipUpdate2 = true;
                                                break;
                                            }
                                        }
                                        skipUpdate = skipUpdate2;
                                        channelPts = channelPts3;
                                    } else {
                                        this.channelsPts.put(channelId2, channelPts3);
                                        skipUpdate = false;
                                        channelPts = channelPts3;
                                    }
                                }
                                TLRPC.TL_updates updatesNew = new TLRPC.TL_updates();
                                updatesNew.updates.add(update2);
                                updatesNew.pts = getUpdatePts(update2);
                                updatesNew.pts_count = getUpdatePtsCount(update2);
                                for (int b = a3 + 1; b < updates.updates.size(); b = (b - 1) + 1) {
                                    TLRPC.Update update22 = updates.updates.get(b);
                                    int pts2 = getUpdatePts(update22);
                                    int count2 = getUpdatePtsCount(update22);
                                    if (getUpdateType(update22) != 2 || channelId2 != getUpdateChannelId(update22) || updatesNew.pts + count2 != pts2) {
                                        break;
                                    }
                                    updatesNew.updates.add(update22);
                                    updatesNew.pts = pts2;
                                    updatesNew.pts_count += count2;
                                    updates.updates.remove(b);
                                }
                                boolean needReceivedQueue6 = needReceivedQueue5;
                                if (BuildVars.LOGS_ENABLED) {
                                    FileLog.d("need load unknown channel = " + channelId2);
                                }
                                needReceivedQueue5 = needReceivedQueue6;
                                needGetDiff6 = needGetDiff2;
                            } else {
                                TLRPC.TL_updates updatesNew2 = new TLRPC.TL_updates();
                                updatesNew2.updates.add(update2);
                                updatesNew2.pts = getUpdateQts(update2);
                                for (int b2 = a3 + 1; b2 < updates.updates.size(); b2 = (b2 - 1) + 1) {
                                    TLRPC.Update update23 = updates.updates.get(b2);
                                    int qts2 = getUpdateQts(update23);
                                    if (getUpdateType(update23) != 1 || updatesNew2.pts + 1 != qts2) {
                                        break;
                                    }
                                    updatesNew2.updates.add(update23);
                                    updatesNew2.pts = qts2;
                                    updates.updates.remove(b2);
                                }
                                if (getMessagesStorage().getLastQtsValue() == 0 || getMessagesStorage().getLastQtsValue() + updatesNew2.updates.size() == updatesNew2.pts) {
                                    processUpdateArray(updatesNew2.updates, updates.users, updates.chats, false, updates.date);
                                    getMessagesStorage().setLastQtsValue(updatesNew2.pts);
                                    needReceivedQueue5 = true;
                                } else if (getMessagesStorage().getLastPtsValue() != updatesNew2.pts) {
                                    if (!this.gettingDifference) {
                                        long j = this.updatesStartWaitTimeQts;
                                        if (j != 0 && (j == 0 || Math.abs(System.currentTimeMillis() - this.updatesStartWaitTimeQts) > 1500)) {
                                            needGetDiff2 = true;
                                        }
                                    }
                                    if (this.updatesStartWaitTimeQts == 0) {
                                        this.updatesStartWaitTimeQts = System.currentTimeMillis();
                                    }
                                    if (BuildVars.LOGS_ENABLED) {
                                        FileLog.d("add to queue");
                                    }
                                    this.updatesQueueQts.add(updatesNew2);
                                }
                                needGetDiff6 = needGetDiff2;
                            }
                        } else {
                            TLRPC.TL_updates updatesNew3 = new TLRPC.TL_updates();
                            updatesNew3.updates.add(update2);
                            updatesNew3.pts = getUpdatePts(update2);
                            updatesNew3.pts_count = getUpdatePtsCount(update2);
                            for (int b3 = a3 + 1; b3 < updates.updates.size(); b3 = (b3 - 1) + 1) {
                                TLRPC.Update update24 = updates.updates.get(b3);
                                int pts22 = getUpdatePts(update24);
                                int count22 = getUpdatePtsCount(update24);
                                if (getUpdateType(update24) != 0 || updatesNew3.pts + count22 != pts22) {
                                    break;
                                }
                                updatesNew3.updates.add(update24);
                                updatesNew3.pts = pts22;
                                updatesNew3.pts_count += count22;
                                updates.updates.remove(b3);
                            }
                            if (getMessagesStorage().getLastPtsValue() + updatesNew3.pts_count == updatesNew3.pts) {
                                minChannels = minChannels2;
                                needGetDiff3 = needGetDiff6;
                                updateStatus4 = updateStatus5;
                                if (!processUpdateArray(updatesNew3.updates, updates.users, updates.chats, false, updates.date)) {
                                    needGetDiff4 = true;
                                    needGetDiff6 = needGetDiff4;
                                } else {
                                    getMessagesStorage().setLastPtsValue(updatesNew3.pts);
                                    needGetDiff4 = needGetDiff3;
                                    needGetDiff6 = needGetDiff4;
                                }
                            } else {
                                minChannels = minChannels2;
                                needGetDiff3 = needGetDiff6;
                                updateStatus4 = updateStatus5;
                                if (getMessagesStorage().getLastPtsValue() != updatesNew3.pts) {
                                    if (!this.gettingDifference) {
                                        long j2 = this.updatesStartWaitTimePts;
                                        if (j2 != 0 && (j2 == 0 || Math.abs(System.currentTimeMillis() - this.updatesStartWaitTimePts) > 1500)) {
                                            needGetDiff4 = true;
                                            needGetDiff6 = needGetDiff4;
                                        }
                                    }
                                    if (this.updatesStartWaitTimePts == 0) {
                                        this.updatesStartWaitTimePts = System.currentTimeMillis();
                                    }
                                    if (BuildVars.LOGS_ENABLED) {
                                        FileLog.d("add to queue");
                                    }
                                    this.updatesQueuePts.add(updatesNew3);
                                }
                                needGetDiff4 = needGetDiff3;
                                needGetDiff6 = needGetDiff4;
                            }
                        }
                        updates.updates.remove(a3);
                        a3 = (a3 - 1) + 1;
                        minChannels2 = minChannels;
                        updateStatus5 = updateStatus4;
                    }
                    if (updates instanceof TLRPC.TL_updatesCombined) {
                        processUpdate = getMessagesStorage().getLastSeqValue() + 1 == updates.seq_start || getMessagesStorage().getLastSeqValue() == updates.seq_start;
                    } else {
                        processUpdate = getMessagesStorage().getLastSeqValue() + 1 == updates.seq || updates.seq == 0 || updates.seq == getMessagesStorage().getLastSeqValue();
                    }
                    if (processUpdate) {
                        processUpdateArray(updates.updates, updates.users, updates.chats, false, updates.date);
                        if (updates.seq != 0) {
                            if (updates.date != 0) {
                                getMessagesStorage().setLastDateValue(updates.date);
                            }
                            getMessagesStorage().setLastSeqValue(updates.seq);
                        }
                    } else {
                        if (BuildVars.LOGS_ENABLED) {
                            if (updates instanceof TLRPC.TL_updatesCombined) {
                                FileLog.d("need get diff TL_updatesCombined, seq=" + getMessagesStorage().getLastSeqValue() + " ,up.seq_start=" + updates.seq_start);
                            } else {
                                FileLog.d("need get diff TL_updates, seq=" + getMessagesStorage().getLastSeqValue() + " ,up.seq_start=" + updates.seq);
                            }
                        }
                        if (this.gettingDifference || this.updatesStartWaitTimeSeq == 0 || Math.abs(System.currentTimeMillis() - this.updatesStartWaitTimeSeq) <= 1500) {
                            if (this.updatesStartWaitTimeSeq == 0) {
                                this.updatesStartWaitTimeSeq = System.currentTimeMillis();
                            }
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("add TL_updates/Combined to queue");
                            }
                            this.updatesQueueSeq.add(updates);
                        } else {
                            needGetChannelsDiff2 = needGetChannelsDiff3;
                            needReceivedQueue4 = needReceivedQueue3;
                            needGetDiff5 = true;
                        }
                    }
                    needGetChannelsDiff2 = needGetChannelsDiff3;
                    needReceivedQueue4 = needReceivedQueue3;
                    needGetDiff5 = needGetDiff2;
                }
                updateStatus5 = updateStatus4;
            } else if (updates instanceof TLRPC.TL_updatesTooLong) {
                needGetDiff5 = true;
            } else if (updates instanceof UserActionUpdatesSeq) {
                getMessagesStorage().setLastSeqValue(updates.seq);
            } else if (updates instanceof UserActionUpdatesPts) {
                if (updates.chat_id != 0) {
                    this.channelsPts.put(updates.chat_id, updates.pts);
                    getMessagesStorage().saveChannelPts(updates.chat_id, updates.pts);
                } else {
                    getMessagesStorage().setLastPtsValue(updates.pts);
                }
            }
            final int user_id = updates instanceof TLRPC.TL_updateShortChatMessage ? updates.from_id : updates.user_id;
            TLRPC.User user = getUser(Integer.valueOf(user_id));
            TLRPC.User user22 = null;
            TLRPC.User user32 = null;
            TLRPC.Chat channel = null;
            if (user == null || user.min) {
                user = getMessagesStorage().getUserSync(user_id);
                if (user != null && user.min) {
                    user = null;
                }
                putUser(user, true);
            }
            boolean needFwdUser = false;
            if (updates.fwd_from != null) {
                if (updates.fwd_from.from_id != 0) {
                    user22 = getUser(Integer.valueOf(updates.fwd_from.from_id));
                    if (user22 == null) {
                        user22 = getMessagesStorage().getUserSync(updates.fwd_from.from_id);
                        putUser(user22, true);
                    }
                    needFwdUser = true;
                }
                if (updates.fwd_from.channel_id != 0) {
                    channel = getChat(Integer.valueOf(updates.fwd_from.channel_id));
                    if (channel == null) {
                        channel = getMessagesStorage().getChatSync(updates.fwd_from.channel_id);
                        putChat(channel, true);
                    }
                    needFwdUser = true;
                }
            }
            boolean needBotUser = false;
            if (updates.via_bot_id != 0) {
                user32 = getUser(Integer.valueOf(updates.via_bot_id));
                if (user32 == null) {
                    user32 = getMessagesStorage().getUserSync(updates.via_bot_id);
                    putUser(user32, true);
                }
                needBotUser = true;
            }
            if (!(updates instanceof TLRPC.TL_updateShortMessage)) {
                TLRPC.Chat chat3 = getChat(Integer.valueOf(updates.chat_id));
                if (chat3 == null) {
                    chat3 = getMessagesStorage().getChatSync(updates.chat_id);
                    putChat(chat3, true);
                }
                missingData = chat3 == null || user == null || (needFwdUser && user22 == null && channel == null) || (needBotUser && user32 == null);
            } else {
                missingData = user == null || (needFwdUser && user22 == null && channel == null) || (needBotUser && user32 == null);
            }
            if (missingData || updates.entities.isEmpty()) {
                needReceivedQueue2 = needReceivedQueue;
            } else {
                int a4 = 0;
                while (true) {
                    if (a4 >= updates.entities.size()) {
                        needReceivedQueue2 = needReceivedQueue;
                        break;
                    }
                    TLRPC.MessageEntity entity = updates.entities.get(a4);
                    needReceivedQueue2 = needReceivedQueue;
                    if (!(entity instanceof TLRPC.TL_messageEntityMentionName)) {
                        user2 = user22;
                        user3 = user32;
                    } else {
                        int uid = ((TLRPC.TL_messageEntityMentionName) entity).user_id;
                        user2 = user22;
                        TLRPC.User entityUser = getUser(Integer.valueOf(uid));
                        if (entityUser != null) {
                            user3 = user32;
                            if (!entityUser.min) {
                                continue;
                            }
                        } else {
                            user3 = user32;
                        }
                        TLRPC.User entityUser2 = getMessagesStorage().getUserSync(uid);
                        if (entityUser2 != null && entityUser2.min) {
                            entityUser2 = null;
                        }
                        if (entityUser2 != null) {
                            putUser(user, true);
                        } else {
                            missingData = true;
                            break;
                        }
                    }
                    a4++;
                    needReceivedQueue = needReceivedQueue2;
                    user22 = user2;
                    user32 = user3;
                }
            }
            if (!updates.out && user != null && user.status != null && user.status.expires <= 0 && Math.abs(getConnectionsManager().getCurrentTime() - updates.date) < 30) {
                this.onlinePrivacy.put(Integer.valueOf(user.id), Integer.valueOf(updates.date));
                updateStatus2 = true;
            } else {
                updateStatus2 = updateStatus;
            }
            if (missingData) {
                updateStatus3 = updateStatus2;
                needGetDiff5 = true;
                needGetChannelsDiff = null;
            } else {
                if (getMessagesStorage().getLastPtsValue() + updates.pts_count == updates.pts) {
                    TLRPC.TL_message message = new TLRPC.TL_message();
                    message.id = updates.id;
                    int clientUserId = getUserConfig().getClientUserId();
                    if (updates instanceof TLRPC.TL_updateShortMessage) {
                        if (updates.out) {
                            message.from_id = clientUserId;
                        } else {
                            message.from_id = user_id;
                        }
                        message.to_id = new TLRPC.TL_peerUser();
                        message.to_id.user_id = user_id;
                        message.dialog_id = user_id;
                    } else {
                        message.from_id = user_id;
                        message.to_id = new TLRPC.TL_peerChat();
                        message.to_id.chat_id = updates.chat_id;
                        message.dialog_id = -updates.chat_id;
                    }
                    message.fwd_from = updates.fwd_from;
                    message.silent = updates.silent;
                    message.out = updates.out;
                    message.mentioned = updates.mentioned;
                    message.media_unread = updates.media_unread;
                    message.entities = updates.entities;
                    message.message = updates.message;
                    message.date = updates.date;
                    message.via_bot_id = updates.via_bot_id;
                    message.flags = updates.flags | 256;
                    message.reply_to_msg_id = updates.reply_to_msg_id;
                    message.media = new TLRPC.TL_messageMediaEmpty();
                    ConcurrentHashMap<Long, Integer> read_max = message.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                    Integer value = read_max.get(Long.valueOf(message.dialog_id));
                    if (value == null) {
                        updateStatus3 = updateStatus2;
                        needGetChannelsDiff = null;
                        needGetDiff = false;
                        value = Integer.valueOf(getMessagesStorage().getDialogReadMax(message.out, message.dialog_id));
                        read_max.put(Long.valueOf(message.dialog_id), value);
                    } else {
                        updateStatus3 = updateStatus2;
                        needGetChannelsDiff = null;
                        needGetDiff = false;
                    }
                    message.unread = value.intValue() < message.id;
                    if (message.dialog_id == clientUserId) {
                        message.unread = false;
                        message.media_unread = false;
                        message.out = true;
                    }
                    getMessagesStorage().setLastPtsValue(updates.pts);
                    MessageObject obj = new MessageObject(this.currentAccount, message, this.createdDialogIds.contains(Long.valueOf(message.dialog_id)));
                    final ArrayList<MessageObject> objArr = new ArrayList<>();
                    objArr.add(obj);
                    ArrayList<TLRPC.Message> arr2 = new ArrayList<>();
                    arr2.add(message);
                    if (!(updates instanceof TLRPC.TL_updateShortMessage)) {
                        final boolean printUpdate2 = updatePrintingUsersWithNewMessages(-updates.chat_id, objArr);
                        if (printUpdate2) {
                            updatePrintingStrings();
                        }
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                MessagesController.this.lambda$processUpdates$260$MessagesController(printUpdate2, updates, objArr);
                            }
                        });
                    } else {
                        if (!updates.out && updatePrintingUsersWithNewMessages(updates.user_id, objArr)) {
                            z = true;
                            printUpdate = z;
                            if (printUpdate) {
                                updatePrintingStrings();
                            }
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public final void run() {
                                    MessagesController.this.lambda$processUpdates$259$MessagesController(printUpdate, user_id, objArr);
                                }
                            });
                        }
                        z = false;
                        printUpdate = z;
                        if (printUpdate) {
                        }
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                MessagesController.this.lambda$processUpdates$259$MessagesController(printUpdate, user_id, objArr);
                            }
                        });
                    }
                    if (!obj.isOut()) {
                        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                            @Override
                            public final void run() {
                                MessagesController.this.lambda$processUpdates$262$MessagesController(objArr);
                            }
                        });
                    }
                    getMessagesStorage().putMessages(arr2, false, true, false, 0, false);
                } else {
                    updateStatus3 = updateStatus2;
                    needGetChannelsDiff = null;
                    needGetDiff = false;
                    if (getMessagesStorage().getLastPtsValue() != updates.pts) {
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("need get diff short message, act=" + this.currentAccount + " ,pts: " + getMessagesStorage().getLastPtsValue() + " ,up.pts=" + updates.pts + " ,count=" + updates.pts_count);
                        }
                        if (this.gettingDifference || this.updatesStartWaitTimePts == 0 || Math.abs(System.currentTimeMillis() - this.updatesStartWaitTimePts) <= 1500) {
                            if (this.updatesStartWaitTimePts == 0) {
                                this.updatesStartWaitTimePts = System.currentTimeMillis();
                            }
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("add to queue");
                            }
                            this.updatesQueuePts.add(updates);
                        } else {
                            needGetDiff5 = true;
                        }
                    }
                }
                needGetDiff5 = needGetDiff;
            }
            needReceivedQueue4 = needReceivedQueue2;
            updateStatus5 = updateStatus3;
            needGetChannelsDiff2 = needGetChannelsDiff;
        }
        getSecretChatHelper().processPendingEncMessages();
        if (!fromQueue) {
            for (int a5 = 0; a5 < this.updatesQueueChannels.size(); a5++) {
                int key = this.updatesQueueChannels.keyAt(a5);
                if (needGetChannelsDiff2 == null || !needGetChannelsDiff2.contains(Integer.valueOf(key))) {
                    processChannelsUpdatesQueue(key, 0);
                } else {
                    getChannelDifference(key);
                }
            }
            if (needGetDiff5) {
                getDifference();
            } else {
                for (int a6 = 0; a6 < 3; a6++) {
                    processUpdatesQueue(a6, 0);
                }
            }
        }
        if (needReceivedQueue4) {
            TLRPC.TL_messages_receivedQueue req = new TLRPC.TL_messages_receivedQueue();
            req.max_qts = getMessagesStorage().getLastQtsValue();
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.lambda$processUpdates$263(tLObject, tL_error);
                }
            });
        }
        if (updateStatus5) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$processUpdates$264$MessagesController();
                }
            });
        }
        getMessagesStorage().saveDiffParams(getMessagesStorage().getLastSeqValue(), getMessagesStorage().getLastPtsValue(), getMessagesStorage().getLastDateValue(), getMessagesStorage().getLastQtsValue());
    }

    public void lambda$processUpdates$259$MessagesController(boolean printUpdate, int user_id, ArrayList objArr) {
        if (printUpdate) {
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 64);
        }
        updateInterfaceWithMessages(user_id, objArr, false);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public void lambda$processUpdates$260$MessagesController(boolean printUpdate, TLRPC.Updates updates, ArrayList objArr) {
        if (printUpdate) {
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 64);
        }
        updateInterfaceWithMessages(-updates.chat_id, objArr, false);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
    }

    public void lambda$null$261$MessagesController(ArrayList objArr) {
        getNotificationsController().processNewMessages(objArr, true, false, null);
    }

    public void lambda$processUpdates$262$MessagesController(final ArrayList objArr) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$261$MessagesController(objArr);
            }
        });
    }

    public static void lambda$processUpdates$263(TLObject response, TLRPC.TL_error error) {
    }

    public void lambda$processUpdates$264$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 4);
    }

    public void ensureMessagesLoaded(final long dialog_id, boolean isChannel, int messageId, final Runnable callback) {
        int messageId2;
        SharedPreferences sharedPreferences = getNotificationsSettings(this.currentAccount);
        if (messageId == 0) {
            messageId2 = sharedPreferences.getInt("diditem" + dialog_id, 0);
        } else {
            messageId2 = messageId;
        }
        int finalMessageId = messageId2;
        final int classGuid = ConnectionsManager.generateClassGuid();
        getNotificationCenter().addObserver(new NotificationCenter.NotificationCenterDelegate() {
            {
                MessagesController.this = this;
            }

            @Override
            public void didReceivedNotification(int id, int account, Object... args) {
                if (id == NotificationCenter.messagesDidLoad && ((Integer) args[10]).intValue() == classGuid) {
                    ArrayList<MessageObject> messArr = (ArrayList) args[2];
                    boolean isCache = ((Boolean) args[3]).booleanValue();
                    if (!messArr.isEmpty() || !isCache) {
                        MessagesController.this.getNotificationCenter().removeObserver(this, NotificationCenter.didReceiveNewMessages);
                        callback.run();
                        return;
                    }
                    MessagesController.this.loadMessages(dialog_id, 20, 3, 0, false, 0, classGuid, 3, 0, false, false, 0);
                }
            }
        }, NotificationCenter.messagesDidLoad);
        loadMessages(dialog_id, 1, finalMessageId, 0, true, 0, classGuid, 3, 0, false, false, 0);
    }

    public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, final ArrayList<TLRPC.User> usersArr, final ArrayList<TLRPC.Chat> chatsArr, boolean fromGetDifference, int date) {
        boolean printChanged;
        LongSparseArray<ArrayList<MessageObject>> messages;
        LongSparseArray<ArrayList<MessageObject>> scheduledMessages;
        ConcurrentHashMap<Integer, TLRPC.User> usersDict;
        LongSparseArray<TLRPC.WebPage> webPages;
        ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict;
        int interfaceUpdateMask;
        ArrayList<Integer> contactsIds;
        long currentTime;
        ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict2;
        LongSparseArray<ArrayList<MessageObject>> messages2;
        final LongSparseArray<ArrayList<MessageObject>> editingMessages;
        SparseIntArray markAsReadEncrypted;
        SparseLongArray markAsReadMessagesOutbox;
        ArrayList<Long> markAsReadMessages;
        boolean z;
        SparseArray<SparseIntArray> sparseArray;
        SparseArray<ArrayList<Integer>> scheduledDeletedMessages;
        SparseIntArray clearHistoryMessages;
        ConcurrentHashMap<Integer, TLRPC.User> usersDict2;
        int c;
        ArrayList<Long> markAsReadMessages2;
        SparseArray<ArrayList<Integer>> scheduledDeletedMessages2;
        ArrayList<Integer> contactsIds2;
        ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict3;
        int interfaceUpdateMask2;
        long currentTime2;
        Map<String, String> mapVCallId;
        SparseLongArray markAsReadMessagesOutbox2;
        long currentTime3;
        TLRPC.Message message;
        SparseArray<SparseIntArray> sparseArray2;
        ArrayList<TLRPC.Message> messagesArr;
        ArrayList<MessageObject> pushMessages;
        boolean z2;
        ArrayList<TLRPC.Message> scheduledMessagesArr;
        LongSparseArray<ArrayList<MessageObject>> scheduledMessages2;
        int chat_id;
        long currentTime4;
        SparseArray<ArrayList<Integer>> scheduledDeletedMessages3;
        long currentTime5;
        ArrayList<Integer> contactsIds3;
        int interfaceUpdateMask3;
        SparseLongArray markAsReadMessagesOutbox3;
        int chat_id2;
        int chat_id3;
        TLRPC.SendMessageAction action;
        long uid;
        SparseLongArray markAsReadMessagesOutbox4;
        ArrayList<Integer> contactsIds4;
        int interfaceUpdateMask4;
        Map<String, String> mapVCallId2;
        final TLRPC.Message message2;
        int interfaceUpdateMask5;
        SparseLongArray markAsReadMessagesOutbox5;
        LongSparseArray<ArrayList<MessageObject>> editingMessages2;
        int count;
        Map<String, String> mapVCallId3;
        Map<String, String> mapVCallId4;
        boolean blnEqualUser;
        ArrayList<Integer> arrayList;
        ArrayList<Integer> arrayList2;
        long dialogId;
        ArrayList<Integer> arrayList3;
        ArrayList<Integer> arrayList4;
        ArrayList<Integer> arrayList5;
        ArrayList<Integer> arrayList6;
        ArrayList<Integer> arrayList7;
        ArrayList<Integer> arrayList8;
        ArrayList<Integer> arrayList9;
        ArrayList<Integer> arrayList10;
        ArrayList<Integer> arrayList11;
        ArrayList<Integer> arrayList12;
        ArrayList<Integer> arrayList13;
        ArrayList<Integer> arrayList14;
        int chatId;
        ArrayList<Integer> arrayList15;
        SparseArray<SparseIntArray> channelViews;
        ArrayList<Integer> arrayList16;
        LongSparseArray<TLRPC.WebPage> webPages2;
        LongSparseArray<TLRPC.WebPage> webPages3;
        ArrayList<Integer> arrayList17;
        ArrayList<Integer> arrayList18;
        ArrayList<Integer> arrayList19;
        ArrayList<Integer> arrayList20;
        ArrayList<TLRPC.Message> messagesArr2;
        ArrayList<MessageObject> pushMessages2;
        ArrayList<Integer> arrayList21;
        SparseIntArray markAsReadEncrypted2;
        TLRPC.TL_updateEncryptedChatTyping update;
        long currentTime6;
        SparseArray<ArrayList<Integer>> scheduledDeletedMessages4;
        int size;
        ArrayList<TLRPC.Message> messagesArr3;
        ArrayList<MessageObject> pushMessages3;
        ArrayList<Integer> arrayList22;
        ArrayList<Integer> arrayList23;
        ArrayList<Integer> arrayList24;
        ArrayList<Integer> arrayList25;
        ArrayList<Integer> arrayList26;
        ArrayList<TLRPC.TL_updateEncryptedMessagesRead> arrayList27;
        int id;
        ArrayList<Integer> arrayList28;
        long dialog_id;
        long dialog_id2;
        ArrayList<MessageObject> pushMessages4;
        ArrayList<TLRPC.Update> arrayList29 = updates;
        if (updates.isEmpty()) {
            if (usersArr != null || chatsArr != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$processUpdateArray$265$MessagesController(usersArr, chatsArr);
                    }
                });
            }
            return true;
        }
        long currentTime7 = System.currentTimeMillis();
        LongSparseArray<ArrayList<MessageObject>> messages3 = null;
        LongSparseArray<ArrayList<MessageObject>> scheduledMessages3 = null;
        LongSparseArray<TLRPC.WebPage> webPages4 = null;
        ArrayList<MessageObject> pushMessages5 = null;
        boolean checkForUsers = true;
        if (usersArr != null) {
            ConcurrentHashMap<Integer, TLRPC.User> usersDict3 = new ConcurrentHashMap<>();
            int size2 = usersArr.size();
            printChanged = false;
            int a = 0;
            while (a < size2) {
                int size3 = size2;
                TLRPC.User user = usersArr.get(a);
                usersDict3.put(Integer.valueOf(user.id), user);
                a++;
                messages3 = messages3;
                size2 = size3;
                scheduledMessages3 = scheduledMessages3;
            }
            messages = messages3;
            scheduledMessages = scheduledMessages3;
            usersDict = usersDict3;
        } else {
            printChanged = false;
            messages = null;
            scheduledMessages = null;
            checkForUsers = false;
            usersDict = this.users;
        }
        if (chatsArr != null) {
            ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict4 = new ConcurrentHashMap<>();
            int a2 = 0;
            int size4 = chatsArr.size();
            while (a2 < size4) {
                int size5 = size4;
                TLRPC.Chat chat = chatsArr.get(a2);
                chatsDict4.put(Integer.valueOf(chat.id), chat);
                a2++;
                webPages4 = webPages4;
                size4 = size5;
            }
            webPages = webPages4;
            chatsDict = chatsDict4;
        } else {
            webPages = null;
            checkForUsers = false;
            chatsDict = this.chats;
        }
        if (fromGetDifference) {
            checkForUsers = false;
        }
        if (usersArr != null || chatsArr != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$processUpdateArray$266$MessagesController(usersArr, chatsArr);
                }
            });
        }
        int interfaceUpdateMask6 = 0;
        Map<String, String> hashMap = new HashMap<>();
        int i = 0;
        while (true) {
            interfaceUpdateMask = interfaceUpdateMask6;
            int interfaceUpdateMask7 = updates.size();
            if (i >= interfaceUpdateMask7) {
                break;
            }
            TLRPC.Update baseUpdate = arrayList29.get(i);
            if (!(baseUpdate instanceof TLRPCCall.TL_UpdateMeetCallRequested)) {
                pushMessages4 = pushMessages5;
            } else {
                pushMessages4 = pushMessages5;
                hashMap.put(((TLRPCCall.TL_UpdateMeetCallRequested) baseUpdate).id, "1");
            }
            if (baseUpdate instanceof TLRPCCall.TL_UpdateMeetCallDiscarded) {
                TLRPCCall.TL_UpdateMeetCallDiscarded discarded = (TLRPCCall.TL_UpdateMeetCallDiscarded) baseUpdate;
                if (hashMap.get(discarded.id) != null) {
                    hashMap.remove(discarded.id);
                }
            }
            i++;
            interfaceUpdateMask6 = interfaceUpdateMask;
            pushMessages5 = pushMessages4;
        }
        ArrayList<MessageObject> pushMessages6 = pushMessages5;
        int size32 = updates.size();
        int c2 = 0;
        final SparseLongArray markAsReadMessagesInbox = null;
        SparseIntArray clearHistoryMessages2 = null;
        ArrayList<TLRPC.TL_updateEncryptedMessagesRead> tasks = null;
        LongSparseArray<ArrayList<MessageObject>> messages4 = messages;
        ArrayList<MessageObject> pushMessages7 = pushMessages6;
        LongSparseArray<ArrayList<MessageObject>> editingMessages3 = null;
        SparseArray<ArrayList<Integer>> scheduledDeletedMessages5 = null;
        ArrayList<TLRPC.TL_updateEncryptedMessagesRead> tasks2 = null;
        ArrayList<TLRPC.Message> messagesArr4 = null;
        int interfaceUpdateMask8 = interfaceUpdateMask;
        Map<String, String> map = hashMap;
        ArrayList<Long> markAsReadMessages3 = null;
        SparseArray<SparseIntArray> channelViews2 = null;
        SparseArray<SparseIntArray> channelViews3 = null;
        SparseIntArray markAsReadEncrypted3 = null;
        LongSparseArray<TLRPC.WebPage> webPages5 = webPages;
        long currentTime8 = currentTime7;
        ArrayList<Integer> contactsIds5 = null;
        ArrayList<Integer> contactsIds6 = null;
        ArrayList<TLRPC.Message> scheduledMessagesArr2 = null;
        SparseLongArray markAsReadMessagesOutbox6 = null;
        while (c2 < size32) {
            final TLRPC.Update baseUpdate2 = arrayList29.get(c2);
            int size33 = size32;
            if ((baseUpdate2 instanceof TLRPC.TL_updateNewMessage) || (baseUpdate2 instanceof TLRPC.TL_updateNewChannelMessage)) {
                usersDict2 = usersDict;
                c = c2;
                markAsReadMessages2 = markAsReadMessages3;
                scheduledDeletedMessages2 = scheduledDeletedMessages5;
                contactsIds2 = contactsIds5;
                chatsDict3 = chatsDict;
                interfaceUpdateMask2 = interfaceUpdateMask8;
                currentTime2 = currentTime8;
                mapVCallId = map;
                markAsReadMessagesOutbox2 = markAsReadMessagesOutbox6;
            } else if (baseUpdate2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                usersDict2 = usersDict;
                c = c2;
                markAsReadMessages2 = markAsReadMessages3;
                scheduledDeletedMessages2 = scheduledDeletedMessages5;
                contactsIds2 = contactsIds5;
                chatsDict3 = chatsDict;
                interfaceUpdateMask2 = interfaceUpdateMask8;
                currentTime2 = currentTime8;
                mapVCallId = map;
                markAsReadMessagesOutbox2 = markAsReadMessagesOutbox6;
            } else {
                if (baseUpdate2 instanceof TLRPC.TL_updateReadMessagesContents) {
                    TLRPC.TL_updateReadMessagesContents update2 = (TLRPC.TL_updateReadMessagesContents) baseUpdate2;
                    if (markAsReadMessages3 == null) {
                        markAsReadMessages3 = new ArrayList<>();
                    }
                    int size6 = update2.messages.size();
                    int a3 = 0;
                    while (a3 < size6) {
                        int size7 = size6;
                        long id2 = update2.messages.get(a3).intValue();
                        markAsReadMessages3.add(Long.valueOf(id2));
                        a3++;
                        size6 = size7;
                        update2 = update2;
                        c2 = c2;
                    }
                    c = c2;
                    usersDict2 = usersDict;
                    markAsReadMessages2 = markAsReadMessages3;
                    currentTime3 = currentTime8;
                    chatsDict3 = chatsDict;
                    mapVCallId = map;
                } else {
                    c = c2;
                    if (baseUpdate2 instanceof TLRPC.TL_updateChannelReadMessagesContents) {
                        TLRPC.TL_updateChannelReadMessagesContents update3 = (TLRPC.TL_updateChannelReadMessagesContents) baseUpdate2;
                        if (markAsReadMessages3 == null) {
                            markAsReadMessages3 = new ArrayList<>();
                        }
                        int a4 = 0;
                        int size8 = update3.messages.size();
                        while (a4 < size8) {
                            long id3 = update3.messages.get(a4).intValue();
                            int size9 = size8;
                            int size10 = update3.channel_id;
                            markAsReadMessages3.add(Long.valueOf((size10 << 32) | id3));
                            a4++;
                            size8 = size9;
                            update3 = update3;
                            chatsDict = chatsDict;
                            usersDict = usersDict;
                        }
                        markAsReadMessages2 = markAsReadMessages3;
                        currentTime3 = currentTime8;
                        chatsDict3 = chatsDict;
                        usersDict2 = usersDict;
                        mapVCallId = map;
                    } else {
                        ConcurrentHashMap<Integer, TLRPC.User> usersDict4 = usersDict;
                        ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict5 = chatsDict;
                        if (baseUpdate2 instanceof TLRPC.TL_updateReadHistoryInbox) {
                            TLRPC.TL_updateReadHistoryInbox update4 = (TLRPC.TL_updateReadHistoryInbox) baseUpdate2;
                            if (markAsReadMessagesInbox == null) {
                                markAsReadMessagesInbox = new SparseLongArray();
                            }
                            if (update4.peer.chat_id != 0) {
                                markAsReadMessagesInbox.put(-update4.peer.chat_id, update4.max_id);
                                dialog_id2 = -update4.peer.chat_id;
                            } else {
                                markAsReadMessagesInbox.put(update4.peer.user_id, update4.max_id);
                                dialog_id2 = update4.peer.user_id;
                            }
                            Integer value = this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id2));
                            if (value == null) {
                                value = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, dialog_id2));
                            }
                            this.dialogs_read_inbox_max.put(Long.valueOf(dialog_id2), Integer.valueOf(Math.max(value.intValue(), update4.max_id)));
                            markAsReadMessages2 = markAsReadMessages3;
                            currentTime3 = currentTime8;
                            chatsDict3 = chatsDict5;
                            usersDict2 = usersDict4;
                            mapVCallId = map;
                        } else if (baseUpdate2 instanceof TLRPC.TL_updateReadHistoryOutbox) {
                            TLRPC.TL_updateReadHistoryOutbox update5 = (TLRPC.TL_updateReadHistoryOutbox) baseUpdate2;
                            if (markAsReadMessagesOutbox6 == null) {
                                markAsReadMessagesOutbox6 = new SparseLongArray();
                            }
                            if (update5.peer.chat_id != 0) {
                                markAsReadMessagesOutbox6.put(-update5.peer.chat_id, update5.max_id);
                                dialog_id = -update5.peer.chat_id;
                            } else {
                                markAsReadMessagesOutbox6.put(update5.peer.user_id, update5.max_id);
                                dialog_id = update5.peer.user_id;
                            }
                            Integer value2 = this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id));
                            if (value2 == null) {
                                value2 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, dialog_id));
                            }
                            this.dialogs_read_outbox_max.put(Long.valueOf(dialog_id), Integer.valueOf(Math.max(value2.intValue(), update5.max_id)));
                            markAsReadMessages2 = markAsReadMessages3;
                            currentTime3 = currentTime8;
                            chatsDict3 = chatsDict5;
                            usersDict2 = usersDict4;
                            mapVCallId = map;
                        } else if (baseUpdate2 instanceof TLRPC.TL_updateDeleteMessages) {
                            TLRPC.TL_updateDeleteMessages update6 = (TLRPC.TL_updateDeleteMessages) baseUpdate2;
                            if (channelViews3 == null) {
                                channelViews3 = new SparseArray<>();
                            }
                            ArrayList arrayList30 = (ArrayList) channelViews3.get(0);
                            if (arrayList30 == null) {
                                arrayList30 = new ArrayList();
                                channelViews3.put(0, arrayList30);
                            }
                            arrayList30.addAll(update6.messages);
                            markAsReadMessages2 = markAsReadMessages3;
                            currentTime3 = currentTime8;
                            chatsDict3 = chatsDict5;
                            usersDict2 = usersDict4;
                            mapVCallId = map;
                        } else if (baseUpdate2 instanceof TLRPC.TL_updateDeleteScheduledMessages) {
                            TLRPC.TL_updateDeleteScheduledMessages update7 = (TLRPC.TL_updateDeleteScheduledMessages) baseUpdate2;
                            if (scheduledDeletedMessages5 == null) {
                                scheduledDeletedMessages5 = new SparseArray<>();
                            }
                            if (update7.peer instanceof TLRPC.TL_peerChannel) {
                                int i2 = update7.peer.channel_id;
                                id = i2;
                                arrayList28 = scheduledDeletedMessages5.get(i2);
                            } else {
                                id = 0;
                                arrayList28 = scheduledDeletedMessages5.get(0);
                            }
                            if (arrayList28 == null) {
                                arrayList28 = new ArrayList<>();
                                scheduledDeletedMessages5.put(id, arrayList28);
                            }
                            arrayList28.addAll(update7.messages);
                            markAsReadMessages2 = markAsReadMessages3;
                            currentTime3 = currentTime8;
                            chatsDict3 = chatsDict5;
                            usersDict2 = usersDict4;
                            mapVCallId = map;
                        } else {
                            if (baseUpdate2 instanceof TLRPC.TL_updateUserTyping) {
                                markAsReadMessages2 = markAsReadMessages3;
                                scheduledDeletedMessages3 = scheduledDeletedMessages5;
                                currentTime5 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                contactsIds3 = contactsIds5;
                                mapVCallId = map;
                                interfaceUpdateMask3 = interfaceUpdateMask8;
                                markAsReadMessagesOutbox3 = markAsReadMessagesOutbox6;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChatUserTyping) {
                                markAsReadMessages2 = markAsReadMessages3;
                                scheduledDeletedMessages3 = scheduledDeletedMessages5;
                                currentTime5 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                contactsIds3 = contactsIds5;
                                mapVCallId = map;
                                interfaceUpdateMask3 = interfaceUpdateMask8;
                                markAsReadMessagesOutbox3 = markAsReadMessagesOutbox6;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChatParticipants) {
                                TLRPC.TL_updateChatParticipants update8 = (TLRPC.TL_updateChatParticipants) baseUpdate2;
                                int interfaceUpdateMask9 = interfaceUpdateMask8 | 32;
                                if (tasks2 != null) {
                                    arrayList27 = tasks2;
                                } else {
                                    arrayList27 = new ArrayList<>();
                                }
                                arrayList27.add(update8.participants);
                                interfaceUpdateMask8 = interfaceUpdateMask9;
                                tasks2 = arrayList27;
                                markAsReadMessages2 = markAsReadMessages3;
                                currentTime3 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                mapVCallId = map;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updateUserStatus) {
                                int interfaceUpdateMask10 = interfaceUpdateMask8 | 4;
                                if (contactsIds6 != null) {
                                    arrayList26 = contactsIds6;
                                } else {
                                    arrayList26 = new ArrayList<>();
                                }
                                arrayList26.add(baseUpdate2);
                                interfaceUpdateMask8 = interfaceUpdateMask10;
                                contactsIds6 = arrayList26;
                                markAsReadMessages2 = markAsReadMessages3;
                                currentTime3 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                mapVCallId = map;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updateUserName) {
                                int interfaceUpdateMask11 = interfaceUpdateMask8 | 1;
                                if (contactsIds6 != null) {
                                    arrayList25 = contactsIds6;
                                } else {
                                    arrayList25 = new ArrayList<>();
                                }
                                arrayList25.add(baseUpdate2);
                                interfaceUpdateMask8 = interfaceUpdateMask11;
                                contactsIds6 = arrayList25;
                                markAsReadMessages2 = markAsReadMessages3;
                                currentTime3 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                mapVCallId = map;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updateUserPhoto) {
                                int interfaceUpdateMask12 = interfaceUpdateMask8 | 2;
                                getMessagesStorage().clearUserPhotos(((TLRPC.TL_updateUserPhoto) baseUpdate2).user_id);
                                if (contactsIds6 != null) {
                                    arrayList24 = contactsIds6;
                                } else {
                                    arrayList24 = new ArrayList<>();
                                }
                                arrayList24.add(baseUpdate2);
                                interfaceUpdateMask8 = interfaceUpdateMask12;
                                contactsIds6 = arrayList24;
                                markAsReadMessages2 = markAsReadMessages3;
                                currentTime3 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                mapVCallId = map;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updateUserPhone) {
                                int interfaceUpdateMask13 = interfaceUpdateMask8 | 1024;
                                if (contactsIds6 != null) {
                                    arrayList23 = contactsIds6;
                                } else {
                                    arrayList23 = new ArrayList<>();
                                }
                                arrayList23.add(baseUpdate2);
                                interfaceUpdateMask8 = interfaceUpdateMask13;
                                contactsIds6 = arrayList23;
                                markAsReadMessages2 = markAsReadMessages3;
                                currentTime3 = currentTime8;
                                chatsDict3 = chatsDict5;
                                usersDict2 = usersDict4;
                                mapVCallId = map;
                            } else if (baseUpdate2 instanceof TLRPC.TL_updatePeerSettings) {
                                TLRPC.TL_updatePeerSettings update9 = (TLRPC.TL_updatePeerSettings) baseUpdate2;
                                if (contactsIds5 == null) {
                                    contactsIds5 = new ArrayList<>();
                                }
                                if (!(update9.peer instanceof TLRPC.TL_peerUser)) {
                                    usersDict2 = usersDict4;
                                } else {
                                    usersDict2 = usersDict4;
                                    TLRPC.User user2 = usersDict2.get(Integer.valueOf(update9.peer.user_id));
                                    if (user2 != null) {
                                        if (user2.contact) {
                                            int idx = contactsIds5.indexOf(Integer.valueOf(-update9.peer.user_id));
                                            if (idx != -1) {
                                                contactsIds5.remove(idx);
                                            }
                                            if (!contactsIds5.contains(Integer.valueOf(update9.peer.user_id))) {
                                                contactsIds5.add(Integer.valueOf(update9.peer.user_id));
                                            }
                                        } else {
                                            int idx2 = contactsIds5.indexOf(Integer.valueOf(update9.peer.user_id));
                                            if (idx2 != -1) {
                                                contactsIds5.remove(idx2);
                                            }
                                            if (!contactsIds5.contains(Integer.valueOf(update9.peer.user_id))) {
                                                contactsIds5.add(Integer.valueOf(-update9.peer.user_id));
                                            }
                                        }
                                    }
                                }
                                if (contactsIds6 != null) {
                                    arrayList22 = contactsIds6;
                                } else {
                                    arrayList22 = new ArrayList<>();
                                }
                                arrayList22.add(baseUpdate2);
                                contactsIds6 = arrayList22;
                                markAsReadMessages2 = markAsReadMessages3;
                                currentTime3 = currentTime8;
                                chatsDict3 = chatsDict5;
                                mapVCallId = map;
                            } else {
                                usersDict2 = usersDict4;
                                if (baseUpdate2 instanceof TLRPC.TL_updateNewEncryptedMessage) {
                                    ArrayList<TLRPC.Message> decryptedMessages = getSecretChatHelper().decryptMessage(((TLRPC.TL_updateNewEncryptedMessage) baseUpdate2).message);
                                    if (decryptedMessages == null || decryptedMessages.isEmpty()) {
                                        markAsReadMessages2 = markAsReadMessages3;
                                        scheduledDeletedMessages4 = scheduledDeletedMessages5;
                                    } else {
                                        int cid = ((TLRPC.TL_updateNewEncryptedMessage) baseUpdate2).message.chat_id;
                                        long uid2 = cid << 32;
                                        if (messages4 == null) {
                                            messages4 = new LongSparseArray<>();
                                        }
                                        ArrayList<MessageObject> arr = messages4.get(uid2);
                                        if (arr == null) {
                                            arr = new ArrayList<>();
                                            messages4.put(uid2, arr);
                                        }
                                        int size11 = decryptedMessages.size();
                                        markAsReadMessages2 = markAsReadMessages3;
                                        int a5 = 0;
                                        while (a5 < size11) {
                                            ArrayList<TLRPC.Message> decryptedMessages2 = decryptedMessages;
                                            TLRPC.Message message3 = decryptedMessages.get(a5);
                                            ImageLoader.saveMessageThumbs(message3);
                                            if (messagesArr4 != null) {
                                                size = size11;
                                                messagesArr3 = messagesArr4;
                                            } else {
                                                size = size11;
                                                messagesArr3 = new ArrayList<>();
                                            }
                                            messagesArr3.add(message3);
                                            ArrayList<TLRPC.Message> messagesArr5 = messagesArr3;
                                            LongSparseArray<ArrayList<MessageObject>> messages5 = messages4;
                                            SparseArray<ArrayList<Integer>> scheduledDeletedMessages6 = scheduledDeletedMessages5;
                                            MessageObject obj = new MessageObject(this.currentAccount, message3, usersDict2, chatsDict5, this.createdDialogIds.contains(Long.valueOf(uid2)));
                                            arr.add(obj);
                                            if (pushMessages7 != null) {
                                                pushMessages3 = pushMessages7;
                                            } else {
                                                pushMessages3 = new ArrayList<>();
                                            }
                                            pushMessages3.add(obj);
                                            a5++;
                                            pushMessages7 = pushMessages3;
                                            size11 = size;
                                            decryptedMessages = decryptedMessages2;
                                            messagesArr4 = messagesArr5;
                                            messages4 = messages5;
                                            scheduledDeletedMessages5 = scheduledDeletedMessages6;
                                        }
                                        scheduledDeletedMessages4 = scheduledDeletedMessages5;
                                    }
                                    currentTime3 = currentTime8;
                                    chatsDict3 = chatsDict5;
                                    scheduledDeletedMessages5 = scheduledDeletedMessages4;
                                    mapVCallId = map;
                                } else {
                                    markAsReadMessages2 = markAsReadMessages3;
                                    SparseArray<ArrayList<Integer>> scheduledDeletedMessages7 = scheduledDeletedMessages5;
                                    if (baseUpdate2 instanceof TLRPC.TL_updateEncryptedChatTyping) {
                                        TLRPC.EncryptedChat encryptedChat = getEncryptedChatDB(((TLRPC.TL_updateEncryptedChatTyping) baseUpdate2).chat_id, true);
                                        if (encryptedChat != null) {
                                            long currentTime9 = update.chat_id << 32;
                                            ArrayList<PrintingUser> arr2 = this.printingUsers.get(Long.valueOf(currentTime9));
                                            if (arr2 == null) {
                                                arr2 = new ArrayList<>();
                                                this.printingUsers.put(Long.valueOf(currentTime9), arr2);
                                            }
                                            boolean exist = false;
                                            int a6 = 0;
                                            int size12 = arr2.size();
                                            while (true) {
                                                if (a6 >= size12) {
                                                    currentTime6 = currentTime8;
                                                    break;
                                                }
                                                int size13 = size12;
                                                PrintingUser u = arr2.get(a6);
                                                long uid3 = currentTime9;
                                                if (u.userId != encryptedChat.user_id) {
                                                    a6++;
                                                    size12 = size13;
                                                    currentTime9 = uid3;
                                                } else {
                                                    currentTime6 = currentTime8;
                                                    u.lastTime = currentTime6;
                                                    u.action = new TLRPC.TL_sendMessageTypingAction();
                                                    exist = true;
                                                    break;
                                                }
                                            }
                                            if (!exist) {
                                                PrintingUser newUser = new PrintingUser();
                                                newUser.userId = encryptedChat.user_id;
                                                newUser.lastTime = currentTime6;
                                                newUser.action = new TLRPC.TL_sendMessageTypingAction();
                                                arr2.add(newUser);
                                                printChanged = true;
                                            }
                                            if (Math.abs(getConnectionsManager().getCurrentTime() - date) < 30) {
                                                this.onlinePrivacy.put(Integer.valueOf(encryptedChat.user_id), Integer.valueOf(date));
                                            }
                                        } else {
                                            currentTime6 = currentTime8;
                                        }
                                        currentTime3 = currentTime6;
                                        mapVCallId = map;
                                        chatsDict3 = chatsDict5;
                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                    } else {
                                        currentTime3 = currentTime8;
                                        if (!(baseUpdate2 instanceof TLRPC.TL_updateEncryptedMessagesRead)) {
                                            ArrayList<TLRPC.TL_updateEncryptedMessagesRead> tasks3 = tasks;
                                            if (baseUpdate2 instanceof TLRPC.TL_updateChatParticipantAdd) {
                                                TLRPC.TL_updateChatParticipantAdd update10 = (TLRPC.TL_updateChatParticipantAdd) baseUpdate2;
                                                getMessagesStorage().updateChatInfo(update10.chat_id, update10.user_id, 0, update10.inviter_id, update10.version);
                                                tasks = tasks3;
                                                mapVCallId = map;
                                                chatsDict3 = chatsDict5;
                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                contactsIds4 = contactsIds5;
                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChatParticipantDelete) {
                                                TLRPC.TL_updateChatParticipantDelete update11 = (TLRPC.TL_updateChatParticipantDelete) baseUpdate2;
                                                getMessagesStorage().updateChatInfo(update11.chat_id, update11.user_id, 1, 0, update11.version);
                                                tasks = tasks3;
                                                mapVCallId = map;
                                                chatsDict3 = chatsDict5;
                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                contactsIds4 = contactsIds5;
                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                            } else {
                                                if (baseUpdate2 instanceof TLRPC.TL_updateDcOptions) {
                                                    tasks = tasks3;
                                                    mapVCallId = map;
                                                    chatsDict3 = chatsDict5;
                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                    contactsIds4 = contactsIds5;
                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateConfig) {
                                                    tasks = tasks3;
                                                    mapVCallId = map;
                                                    chatsDict3 = chatsDict5;
                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                    contactsIds4 = contactsIds5;
                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateEncryption) {
                                                    getSecretChatHelper().processUpdateEncryption((TLRPC.TL_updateEncryption) baseUpdate2, usersDict2);
                                                    tasks = tasks3;
                                                    mapVCallId = map;
                                                    chatsDict3 = chatsDict5;
                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                    contactsIds4 = contactsIds5;
                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateUserBlocked) {
                                                    final TLRPC.TL_updateUserBlocked finalUpdate = (TLRPC.TL_updateUserBlocked) baseUpdate2;
                                                    getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                                        @Override
                                                        public final void run() {
                                                            MessagesController.this.lambda$processUpdateArray$268$MessagesController(finalUpdate);
                                                        }
                                                    });
                                                    tasks = tasks3;
                                                    mapVCallId = map;
                                                    chatsDict3 = chatsDict5;
                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                    contactsIds4 = contactsIds5;
                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateNotifySettings) {
                                                    if (contactsIds6 != null) {
                                                        arrayList21 = contactsIds6;
                                                    } else {
                                                        arrayList21 = new ArrayList<>();
                                                    }
                                                    arrayList21.add(baseUpdate2);
                                                    contactsIds6 = arrayList21;
                                                    tasks = tasks3;
                                                    mapVCallId = map;
                                                    chatsDict3 = chatsDict5;
                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateServiceNotification) {
                                                    final TLRPC.TL_updateServiceNotification update12 = (TLRPC.TL_updateServiceNotification) baseUpdate2;
                                                    if (update12.popup && update12.message != null && update12.message.length() > 0) {
                                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                                            @Override
                                                            public final void run() {
                                                                MessagesController.this.lambda$processUpdateArray$269$MessagesController(update12);
                                                            }
                                                        });
                                                    }
                                                    if ((update12.flags & 2) == 0 || update12.message.equals("ErrorSendMessageTooFreq")) {
                                                        tasks = tasks3;
                                                    } else {
                                                        TLRPC.TL_message newMessage = new TLRPC.TL_message();
                                                        int newMessageId = getUserConfig().getNewMessageId();
                                                        newMessage.id = newMessageId;
                                                        newMessage.local_id = newMessageId;
                                                        getUserConfig().saveConfig(false);
                                                        newMessage.unread = true;
                                                        newMessage.flags = 256;
                                                        if (update12.inbox_date != 0) {
                                                            newMessage.date = update12.inbox_date;
                                                        } else {
                                                            newMessage.date = (int) (System.currentTimeMillis() / 1000);
                                                        }
                                                        newMessage.from_id = 777000;
                                                        newMessage.to_id = new TLRPC.TL_peerUser();
                                                        newMessage.to_id.user_id = getUserConfig().getClientUserId();
                                                        newMessage.dialog_id = 777000L;
                                                        if (update12.media != null) {
                                                            newMessage.media = update12.media;
                                                            newMessage.flags |= 512;
                                                        }
                                                        newMessage.message = update12.message;
                                                        if (update12.entities != null) {
                                                            newMessage.entities = update12.entities;
                                                            newMessage.flags |= 128;
                                                        }
                                                        if (messagesArr4 != null) {
                                                            messagesArr2 = messagesArr4;
                                                        } else {
                                                            messagesArr2 = new ArrayList<>();
                                                        }
                                                        messagesArr2.add(newMessage);
                                                        tasks = tasks3;
                                                        MessageObject obj2 = new MessageObject(this.currentAccount, newMessage, usersDict2, chatsDict5, this.createdDialogIds.contains(Long.valueOf(newMessage.dialog_id)));
                                                        if (messages4 == null) {
                                                            messages4 = new LongSparseArray<>();
                                                        }
                                                        ArrayList<MessageObject> arr3 = messages4.get(newMessage.dialog_id);
                                                        if (arr3 == null) {
                                                            arr3 = new ArrayList<>();
                                                            messages4.put(newMessage.dialog_id, arr3);
                                                        }
                                                        arr3.add(obj2);
                                                        if (pushMessages7 != null) {
                                                            pushMessages2 = pushMessages7;
                                                        } else {
                                                            pushMessages2 = new ArrayList<>();
                                                        }
                                                        pushMessages2.add(obj2);
                                                        messagesArr4 = messagesArr2;
                                                        pushMessages7 = pushMessages2;
                                                    }
                                                    mapVCallId = map;
                                                    chatsDict3 = chatsDict5;
                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                } else {
                                                    tasks = tasks3;
                                                    if (baseUpdate2 instanceof TLRPC.TL_updateDialogPinned) {
                                                        if (contactsIds6 != null) {
                                                            arrayList20 = contactsIds6;
                                                        } else {
                                                            arrayList20 = new ArrayList<>();
                                                        }
                                                        arrayList20.add(baseUpdate2);
                                                        contactsIds6 = arrayList20;
                                                        mapVCallId = map;
                                                        chatsDict3 = chatsDict5;
                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updatePinnedDialogs) {
                                                        if (contactsIds6 != null) {
                                                            arrayList19 = contactsIds6;
                                                        } else {
                                                            arrayList19 = new ArrayList<>();
                                                        }
                                                        arrayList19.add(baseUpdate2);
                                                        contactsIds6 = arrayList19;
                                                        mapVCallId = map;
                                                        chatsDict3 = chatsDict5;
                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updateFolderPeers) {
                                                        if (contactsIds6 != null) {
                                                            arrayList18 = contactsIds6;
                                                        } else {
                                                            arrayList18 = new ArrayList<>();
                                                        }
                                                        arrayList18.add(baseUpdate2);
                                                        getMessagesStorage().setDialogsFolderId(((TLRPC.TL_updateFolderPeers) baseUpdate2).folder_peers, null, 0L, 0);
                                                        contactsIds6 = arrayList18;
                                                        mapVCallId = map;
                                                        chatsDict3 = chatsDict5;
                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updatePrivacy) {
                                                        if (contactsIds6 != null) {
                                                            arrayList17 = contactsIds6;
                                                        } else {
                                                            arrayList17 = new ArrayList<>();
                                                        }
                                                        arrayList17.add(baseUpdate2);
                                                        contactsIds6 = arrayList17;
                                                        mapVCallId = map;
                                                        chatsDict3 = chatsDict5;
                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updateWebPage) {
                                                        TLRPC.TL_updateWebPage update13 = (TLRPC.TL_updateWebPage) baseUpdate2;
                                                        if (webPages5 != null) {
                                                            webPages3 = webPages5;
                                                        } else {
                                                            webPages3 = new LongSparseArray<>();
                                                        }
                                                        webPages3.put(update13.webpage.id, update13.webpage);
                                                        webPages5 = webPages3;
                                                        mapVCallId = map;
                                                        chatsDict3 = chatsDict5;
                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updateChannelWebPage) {
                                                        TLRPC.TL_updateChannelWebPage update14 = (TLRPC.TL_updateChannelWebPage) baseUpdate2;
                                                        if (webPages5 != null) {
                                                            webPages2 = webPages5;
                                                        } else {
                                                            webPages2 = new LongSparseArray<>();
                                                        }
                                                        webPages2.put(update14.webpage.id, update14.webpage);
                                                        webPages5 = webPages2;
                                                        mapVCallId = map;
                                                        chatsDict3 = chatsDict5;
                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updateChannelTooLong) {
                                                        TLRPC.TL_updateChannelTooLong update15 = (TLRPC.TL_updateChannelTooLong) baseUpdate2;
                                                        if (BuildVars.LOGS_ENABLED) {
                                                            FileLog.d(baseUpdate2 + " channelId = " + update15.channel_id);
                                                        }
                                                        int channelPts = this.channelsPts.get(update15.channel_id);
                                                        if (channelPts != 0) {
                                                            chatsDict3 = chatsDict5;
                                                        } else {
                                                            channelPts = getMessagesStorage().getChannelPtsSync(update15.channel_id);
                                                            if (channelPts == 0) {
                                                                chatsDict3 = chatsDict5;
                                                                TLRPC.Chat chat2 = chatsDict3.get(Integer.valueOf(update15.channel_id));
                                                                if (chat2 == null || chat2.min) {
                                                                    chat2 = getChat(Integer.valueOf(update15.channel_id));
                                                                }
                                                                if (chat2 == null || chat2.min) {
                                                                    chat2 = getMessagesStorage().getChatSync(update15.channel_id);
                                                                    putChat(chat2, true);
                                                                }
                                                                if (chat2 != null && !chat2.min) {
                                                                    loadUnknownChannel(chat2, 0L);
                                                                }
                                                            } else {
                                                                chatsDict3 = chatsDict5;
                                                                this.channelsPts.put(update15.channel_id, channelPts);
                                                            }
                                                        }
                                                        if (channelPts != 0) {
                                                            if ((update15.flags & 1) == 0) {
                                                                getChannelDifference(update15.channel_id);
                                                            } else if (update15.pts > channelPts) {
                                                                getChannelDifference(update15.channel_id);
                                                            }
                                                        }
                                                        contactsIds4 = contactsIds5;
                                                        mapVCallId = map;
                                                        interfaceUpdateMask4 = interfaceUpdateMask8;
                                                        markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                    } else {
                                                        chatsDict3 = chatsDict5;
                                                        if (baseUpdate2 instanceof TLRPC.TL_updateReadChannelInbox) {
                                                            TLRPC.TL_updateReadChannelInbox update16 = (TLRPC.TL_updateReadChannelInbox) baseUpdate2;
                                                            long message_id = update16.max_id;
                                                            ArrayList<Integer> contactsIds7 = contactsIds5;
                                                            long message_id2 = message_id | (update16.channel_id << 32);
                                                            long dialog_id3 = -update16.channel_id;
                                                            if (markAsReadMessagesInbox == null) {
                                                                markAsReadMessagesInbox = new SparseLongArray();
                                                            }
                                                            markAsReadMessagesInbox.put(-update16.channel_id, message_id2);
                                                            Integer value3 = this.dialogs_read_inbox_max.get(Long.valueOf(dialog_id3));
                                                            if (value3 == null) {
                                                                value3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, dialog_id3));
                                                            }
                                                            this.dialogs_read_inbox_max.put(Long.valueOf(dialog_id3), Integer.valueOf(Math.max(value3.intValue(), update16.max_id)));
                                                            mapVCallId = map;
                                                            contactsIds5 = contactsIds7;
                                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                        } else {
                                                            contactsIds4 = contactsIds5;
                                                            if (baseUpdate2 instanceof TLRPC.TL_updateReadChannelOutbox) {
                                                                TLRPC.TL_updateReadChannelOutbox update17 = (TLRPC.TL_updateReadChannelOutbox) baseUpdate2;
                                                                long message_id3 = update17.max_id;
                                                                long message_id4 = message_id3 | (update17.channel_id << 32);
                                                                long dialog_id4 = -update17.channel_id;
                                                                if (markAsReadMessagesOutbox6 == null) {
                                                                    markAsReadMessagesOutbox6 = new SparseLongArray();
                                                                }
                                                                markAsReadMessagesOutbox6.put(-update17.channel_id, message_id4);
                                                                Integer value4 = this.dialogs_read_outbox_max.get(Long.valueOf(dialog_id4));
                                                                if (value4 == null) {
                                                                    value4 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, dialog_id4));
                                                                }
                                                                this.dialogs_read_outbox_max.put(Long.valueOf(dialog_id4), Integer.valueOf(Math.max(value4.intValue(), update17.max_id)));
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateDeleteChannelMessages) {
                                                                TLRPC.TL_updateDeleteChannelMessages update18 = (TLRPC.TL_updateDeleteChannelMessages) baseUpdate2;
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                    FileLog.d(baseUpdate2 + " channelId = " + update18.channel_id);
                                                                }
                                                                if (channelViews3 == null) {
                                                                    channelViews3 = new SparseArray<>();
                                                                }
                                                                ArrayList arrayList31 = (ArrayList) channelViews3.get(update18.channel_id);
                                                                if (arrayList31 == null) {
                                                                    arrayList31 = new ArrayList();
                                                                    channelViews3.put(update18.channel_id, arrayList31);
                                                                }
                                                                arrayList31.addAll(update18.messages);
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChannel) {
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                    FileLog.d(baseUpdate2 + " channelId = " + ((TLRPC.TL_updateChannel) baseUpdate2).channel_id);
                                                                }
                                                                if (contactsIds6 != null) {
                                                                    arrayList16 = contactsIds6;
                                                                } else {
                                                                    arrayList16 = new ArrayList<>();
                                                                }
                                                                arrayList16.add(baseUpdate2);
                                                                contactsIds6 = arrayList16;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChannelMessageViews) {
                                                                TLRPC.TL_updateChannelMessageViews update19 = (TLRPC.TL_updateChannelMessageViews) baseUpdate2;
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                    FileLog.d(baseUpdate2 + " channelId = " + update19.channel_id);
                                                                }
                                                                if (channelViews2 != null) {
                                                                    channelViews = channelViews2;
                                                                } else {
                                                                    channelViews = new SparseArray<>();
                                                                }
                                                                SparseIntArray array = channelViews.get(update19.channel_id);
                                                                if (array == null) {
                                                                    array = new SparseIntArray();
                                                                    channelViews.put(update19.channel_id, array);
                                                                }
                                                                array.put(update19.id, update19.views);
                                                                channelViews2 = channelViews;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChatParticipantAdmin) {
                                                                TLRPC.TL_updateChatParticipantAdmin update20 = (TLRPC.TL_updateChatParticipantAdmin) baseUpdate2;
                                                                getMessagesStorage().updateChatInfo(update20.chat_id, update20.user_id, 2, update20.is_admin ? 1 : 0, update20.version);
                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                mapVCallId = map;
                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateChatDefaultBannedRights) {
                                                                TLRPC.TL_updateChatDefaultBannedRights update21 = (TLRPC.TL_updateChatDefaultBannedRights) baseUpdate2;
                                                                if (update21.peer.channel_id != 0) {
                                                                    chatId = update21.peer.channel_id;
                                                                } else {
                                                                    chatId = update21.peer.chat_id;
                                                                }
                                                                getMessagesStorage().updateChatDefaultBannedRights(chatId, update21.default_banned_rights, update21.version);
                                                                if (contactsIds6 != null) {
                                                                    arrayList15 = contactsIds6;
                                                                } else {
                                                                    arrayList15 = new ArrayList<>();
                                                                }
                                                                arrayList15.add(baseUpdate2);
                                                                contactsIds6 = arrayList15;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateStickerSets) {
                                                                if (contactsIds6 != null) {
                                                                    arrayList14 = contactsIds6;
                                                                } else {
                                                                    arrayList14 = new ArrayList<>();
                                                                }
                                                                arrayList14.add(baseUpdate2);
                                                                contactsIds6 = arrayList14;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateStickerSetsOrder) {
                                                                if (contactsIds6 != null) {
                                                                    arrayList13 = contactsIds6;
                                                                } else {
                                                                    arrayList13 = new ArrayList<>();
                                                                }
                                                                arrayList13.add(baseUpdate2);
                                                                contactsIds6 = arrayList13;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateNewStickerSet) {
                                                                if (contactsIds6 != null) {
                                                                    arrayList12 = contactsIds6;
                                                                } else {
                                                                    arrayList12 = new ArrayList<>();
                                                                }
                                                                arrayList12.add(baseUpdate2);
                                                                contactsIds6 = arrayList12;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateDraftMessage) {
                                                                if (contactsIds6 != null) {
                                                                    arrayList11 = contactsIds6;
                                                                } else {
                                                                    arrayList11 = new ArrayList<>();
                                                                }
                                                                arrayList11.add(baseUpdate2);
                                                                contactsIds6 = arrayList11;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else if (baseUpdate2 instanceof TLRPC.TL_updateSavedGifs) {
                                                                if (contactsIds6 != null) {
                                                                    arrayList10 = contactsIds6;
                                                                } else {
                                                                    arrayList10 = new ArrayList<>();
                                                                }
                                                                arrayList10.add(baseUpdate2);
                                                                contactsIds6 = arrayList10;
                                                                mapVCallId = map;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            } else {
                                                                if (baseUpdate2 instanceof TLRPC.TL_updateEditChannelMessage) {
                                                                    mapVCallId2 = map;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateEditMessage) {
                                                                    mapVCallId2 = map;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateChannelPinnedMessage) {
                                                                    TLRPC.TL_updateChannelPinnedMessage update22 = (TLRPC.TL_updateChannelPinnedMessage) baseUpdate2;
                                                                    if (BuildVars.LOGS_ENABLED) {
                                                                        FileLog.d(baseUpdate2 + " channelId = " + update22.channel_id);
                                                                    }
                                                                    getMessagesStorage().updateChatPinnedMessage(update22.channel_id, update22.id);
                                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                    mapVCallId = map;
                                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateChatPinnedMessage) {
                                                                    TLRPC.TL_updateChatPinnedMessage update23 = (TLRPC.TL_updateChatPinnedMessage) baseUpdate2;
                                                                    getMessagesStorage().updateChatPinnedMessage(update23.chat_id, update23.id);
                                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                    mapVCallId = map;
                                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateUserPinnedMessage) {
                                                                    TLRPC.TL_updateUserPinnedMessage update24 = (TLRPC.TL_updateUserPinnedMessage) baseUpdate2;
                                                                    getMessagesStorage().updateUserPinnedMessage(update24.user_id, update24.id);
                                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                    mapVCallId = map;
                                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateReadFeaturedStickers) {
                                                                    if (contactsIds6 != null) {
                                                                        arrayList9 = contactsIds6;
                                                                    } else {
                                                                        arrayList9 = new ArrayList<>();
                                                                    }
                                                                    arrayList9.add(baseUpdate2);
                                                                    contactsIds6 = arrayList9;
                                                                    mapVCallId = map;
                                                                    contactsIds5 = contactsIds4;
                                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updatePhoneCall) {
                                                                    if (contactsIds6 != null) {
                                                                        arrayList8 = contactsIds6;
                                                                    } else {
                                                                        arrayList8 = new ArrayList<>();
                                                                    }
                                                                    arrayList8.add(baseUpdate2);
                                                                    contactsIds6 = arrayList8;
                                                                    mapVCallId = map;
                                                                    contactsIds5 = contactsIds4;
                                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateLangPack) {
                                                                    final TLRPC.TL_updateLangPack update25 = (TLRPC.TL_updateLangPack) baseUpdate2;
                                                                    AndroidUtilities.runOnUIThread(new Runnable() {
                                                                        @Override
                                                                        public final void run() {
                                                                            MessagesController.this.lambda$processUpdateArray$271$MessagesController(update25);
                                                                        }
                                                                    });
                                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                    mapVCallId = map;
                                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateLangPackTooLong) {
                                                                    LocaleController.getInstance().reloadCurrentRemoteLocale(this.currentAccount, ((TLRPC.TL_updateLangPackTooLong) baseUpdate2).lang_code);
                                                                    interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                    mapVCallId = map;
                                                                    markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateFavedStickers) {
                                                                    if (contactsIds6 != null) {
                                                                        arrayList7 = contactsIds6;
                                                                    } else {
                                                                        arrayList7 = new ArrayList<>();
                                                                    }
                                                                    arrayList7.add(baseUpdate2);
                                                                    contactsIds6 = arrayList7;
                                                                    mapVCallId = map;
                                                                    contactsIds5 = contactsIds4;
                                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateContactsReset) {
                                                                    if (contactsIds6 != null) {
                                                                        arrayList6 = contactsIds6;
                                                                    } else {
                                                                        arrayList6 = new ArrayList<>();
                                                                    }
                                                                    arrayList6.add(baseUpdate2);
                                                                    contactsIds6 = arrayList6;
                                                                    mapVCallId = map;
                                                                    contactsIds5 = contactsIds4;
                                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                } else if (baseUpdate2 instanceof TLRPC.TL_updateChannelAvailableMessages) {
                                                                    TLRPC.TL_updateChannelAvailableMessages update26 = (TLRPC.TL_updateChannelAvailableMessages) baseUpdate2;
                                                                    SparseIntArray clearHistoryMessages3 = clearHistoryMessages2;
                                                                    if (clearHistoryMessages3 == null) {
                                                                        clearHistoryMessages3 = new SparseIntArray();
                                                                    }
                                                                    int currentValue = clearHistoryMessages3.get(update26.channel_id);
                                                                    if (currentValue == 0 || currentValue < update26.available_min_id) {
                                                                        clearHistoryMessages3.put(update26.channel_id, update26.available_min_id);
                                                                    }
                                                                    clearHistoryMessages2 = clearHistoryMessages3;
                                                                    mapVCallId = map;
                                                                    contactsIds5 = contactsIds4;
                                                                    scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                } else {
                                                                    SparseIntArray clearHistoryMessages4 = clearHistoryMessages2;
                                                                    if (baseUpdate2 instanceof TLRPC.TL_updateDialogUnreadMark) {
                                                                        if (contactsIds6 != null) {
                                                                            arrayList5 = contactsIds6;
                                                                        } else {
                                                                            arrayList5 = new ArrayList<>();
                                                                        }
                                                                        arrayList5.add(baseUpdate2);
                                                                        contactsIds6 = arrayList5;
                                                                        clearHistoryMessages2 = clearHistoryMessages4;
                                                                        mapVCallId = map;
                                                                        contactsIds5 = contactsIds4;
                                                                        scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                    } else if (baseUpdate2 instanceof TLRPC.TL_updateMessagePoll) {
                                                                        TLRPC.TL_updateMessagePoll update27 = (TLRPC.TL_updateMessagePoll) baseUpdate2;
                                                                        long time = getSendMessagesHelper().getVoteSendTime(update27.poll_id);
                                                                        if (Math.abs(SystemClock.uptimeMillis() - time) < 600) {
                                                                            clearHistoryMessages2 = clearHistoryMessages4;
                                                                            interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                            mapVCallId = map;
                                                                            markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                        } else {
                                                                            clearHistoryMessages2 = clearHistoryMessages4;
                                                                            getMessagesStorage().updateMessagePollResults(update27.poll_id, update27.poll, update27.results);
                                                                            if (contactsIds6 != null) {
                                                                                arrayList4 = contactsIds6;
                                                                            } else {
                                                                                arrayList4 = new ArrayList<>();
                                                                            }
                                                                            arrayList4.add(baseUpdate2);
                                                                            contactsIds6 = arrayList4;
                                                                            mapVCallId = map;
                                                                            contactsIds5 = contactsIds4;
                                                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                        }
                                                                    } else {
                                                                        clearHistoryMessages2 = clearHistoryMessages4;
                                                                        if (baseUpdate2 instanceof TLRPC.TL_updateMessageReactions) {
                                                                            TLRPC.TL_updateMessageReactions update28 = (TLRPC.TL_updateMessageReactions) baseUpdate2;
                                                                            if (update28.peer.chat_id != 0) {
                                                                                dialogId = -update28.peer.chat_id;
                                                                            } else if (update28.peer.channel_id != 0) {
                                                                                dialogId = -update28.peer.channel_id;
                                                                            } else {
                                                                                dialogId = update28.peer.user_id;
                                                                            }
                                                                            getMessagesStorage().updateMessageReactions(dialogId, update28.msg_id, update28.peer.channel_id, update28.reactions);
                                                                            if (contactsIds6 != null) {
                                                                                arrayList3 = contactsIds6;
                                                                            } else {
                                                                                arrayList3 = new ArrayList<>();
                                                                            }
                                                                            arrayList3.add(baseUpdate2);
                                                                            contactsIds6 = arrayList3;
                                                                            mapVCallId = map;
                                                                            contactsIds5 = contactsIds4;
                                                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                        } else if (baseUpdate2 instanceof TLRPC.TL_updatePeerLocated) {
                                                                            if (contactsIds6 != null) {
                                                                                arrayList2 = contactsIds6;
                                                                            } else {
                                                                                arrayList2 = new ArrayList<>();
                                                                            }
                                                                            arrayList2.add(baseUpdate2);
                                                                            contactsIds6 = arrayList2;
                                                                            mapVCallId = map;
                                                                            contactsIds5 = contactsIds4;
                                                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                        } else if (baseUpdate2 instanceof TLRPC.TL_updateTheme) {
                                                                            if (contactsIds6 != null) {
                                                                                arrayList = contactsIds6;
                                                                            } else {
                                                                                arrayList = new ArrayList<>();
                                                                            }
                                                                            arrayList.add(baseUpdate2);
                                                                            contactsIds6 = arrayList;
                                                                            mapVCallId = map;
                                                                            contactsIds5 = contactsIds4;
                                                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                                        } else if (baseUpdate2 instanceof TLRPCContacts.UpdateContactApplyRequested) {
                                                                            interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                            mapVCallId = map;
                                                                            markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                        } else if (baseUpdate2 instanceof TLRPC.TL_updateUserMomentStateV1) {
                                                                            final TLRPC.TL_updateUserMomentStateV1 userMomentStateV1 = (TLRPC.TL_updateUserMomentStateV1) baseUpdate2;
                                                                            if (userMomentStateV1 != null && userMomentStateV1.user_id != 0 && userMomentStateV1.type != 0) {
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        MessagesController.this.lambda$processUpdateArray$272$MessagesController(userMomentStateV1);
                                                                                    }
                                                                                });
                                                                            }
                                                                            interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                            mapVCallId = map;
                                                                            markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                        } else if (baseUpdate2 instanceof TLRPCCall.TL_UpdateMeetCallRequested) {
                                                                            TLRPCCall.TL_UpdateMeetCallRequested requested = (TLRPCCall.TL_UpdateMeetCallRequested) baseUpdate2;
                                                                            if (requested == null || requested.admin_id == getUserConfig().getClientUserId() || (System.currentTimeMillis() / 1000) - requested.date >= 35) {
                                                                                mapVCallId4 = map;
                                                                            } else {
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> receive video call , id = " + requested.id);
                                                                                }
                                                                                if (requested.participant_id != null) {
                                                                                    Iterator<TLRPC.InputPeer> it = requested.participant_id.iterator();
                                                                                    while (it.hasNext()) {
                                                                                        TLRPC.InputPeer peer = it.next();
                                                                                        if (peer.user_id == AccountInstance.getInstance(UserConfig.selectedAccount).getUserConfig().getCurrentUser().id) {
                                                                                            blnEqualUser = true;
                                                                                            break;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                blnEqualUser = false;
                                                                                mapVCallId4 = map;
                                                                                if (mapVCallId4.get(requested.id) != null && blnEqualUser) {
                                                                                    boolean blnVideo = (requested.flags & 32) != 0;
                                                                                    Intent intent = new Intent(ApplicationLoader.applicationContext, VisualCallReceiveService.class);
                                                                                    intent.putExtra(MimeTypes.BASE_TYPE_VIDEO, blnVideo);
                                                                                    intent.putExtra(TtmlNode.ATTR_ID, requested.id);
                                                                                    intent.putExtra("admin_id", requested.admin_id);
                                                                                    intent.putExtra("app_id", requested.appid);
                                                                                    intent.putExtra("token", requested.token);
                                                                                    intent.putStringArrayListExtra("gslb", requested.gslb);
                                                                                    intent.putExtra("json", requested.data.data);
                                                                                    try {
                                                                                        if (Build.VERSION.SDK_INT >= 26) {
                                                                                            ApplicationLoader.applicationContext.startForegroundService(intent);
                                                                                        } else {
                                                                                            ApplicationLoader.applicationContext.startService(intent);
                                                                                        }
                                                                                    } catch (Throwable e) {
                                                                                        FileLog.e(e);
                                                                                    }
                                                                                }
                                                                            }
                                                                            mapVCallId = mapVCallId4;
                                                                            interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                            markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                        } else {
                                                                            Map<String, String> mapVCallId5 = map;
                                                                            if (baseUpdate2 instanceof TLRPCCall.TL_UpdateMeetCallAccepted) {
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> 对方已接受请求");
                                                                                }
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.receivedAVideoCallAccept, TLRPC.Update.this);
                                                                                    }
                                                                                });
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCCall.TL_UpdateMeetCallDiscarded) {
                                                                                TLRPCCall.TL_UpdateMeetCallDiscarded discarded2 = (TLRPCCall.TL_UpdateMeetCallDiscarded) baseUpdate2;
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> 收到挂断反馈 , d.id = " + discarded2.id + " d.duration = " + discarded2.duration);
                                                                                }
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.reecivedAVideoDiscarded, TLRPC.Update.this);
                                                                                    }
                                                                                });
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCCall.TL_UpdateMeetCall) {
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> 准备进入视频通道");
                                                                                }
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.receivedAVideoCallReady, TLRPC.Update.this);
                                                                                    }
                                                                                });
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCContacts.UpdateResetContactsApplyUnread) {
                                                                                handleUpdatesContactsApply(0);
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        MessagesController.this.lambda$processUpdateArray$276$MessagesController();
                                                                                    }
                                                                                });
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCContacts.UpdateRegetContactsApplies) {
                                                                                getContactsApplyDifferenceV2(true, false);
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCCall.TL_UpdateMeetCallWaiting) {
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.receivedAVideoCallBusy, TLRPC.Update.this);
                                                                                    }
                                                                                }, AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS);
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCCall.TL_UpdateMeetChangeCall) {
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> 对方切换到语音");
                                                                                }
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.receivedAVideoCallChangeVoice, TLRPC.Update.this);
                                                                                    }
                                                                                });
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCContacts.CL_user_updateUserFull) {
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else if (baseUpdate2 instanceof TLRPCContacts.TL_updateContactGroups) {
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        MessagesController.this.lambda$processUpdateArray$279$MessagesController();
                                                                                    }
                                                                                });
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            } else {
                                                                                mapVCallId = mapVCallId5;
                                                                                interfaceUpdateMask4 = interfaceUpdateMask8;
                                                                                markAsReadMessagesOutbox4 = markAsReadMessagesOutbox6;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                int clientUserId = getUserConfig().getClientUserId();
                                                                if (baseUpdate2 instanceof TLRPC.TL_updateEditChannelMessage) {
                                                                    message2 = ((TLRPC.TL_updateEditChannelMessage) baseUpdate2).message;
                                                                    if (message2.media instanceof TLRPC.TL_messageMediaShare) {
                                                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                                                            @Override
                                                                            public final void run() {
                                                                                MessagesController.this.lambda$processUpdateArray$270$MessagesController(message2);
                                                                            }
                                                                        });
                                                                    }
                                                                    TLRPC.Chat chat3 = chatsDict3.get(Integer.valueOf(message2.to_id.channel_id));
                                                                    if (chat3 == null) {
                                                                        chat3 = getChat(Integer.valueOf(message2.to_id.channel_id));
                                                                    }
                                                                    if (chat3 == null) {
                                                                        chat3 = getMessagesStorage().getChatSync(message2.to_id.channel_id);
                                                                        putChat(chat3, true);
                                                                    }
                                                                    if (chat3 != null && chat3.megagroup) {
                                                                        message2.flags |= Integer.MIN_VALUE;
                                                                    }
                                                                } else {
                                                                    message2 = ((TLRPC.TL_updateEditMessage) baseUpdate2).message;
                                                                    if (message2.dialog_id == clientUserId) {
                                                                        message2.unread = false;
                                                                        message2.media_unread = false;
                                                                        message2.out = true;
                                                                    }
                                                                }
                                                                if (!message2.out && message2.from_id == getUserConfig().getClientUserId()) {
                                                                    message2.out = true;
                                                                }
                                                                if (fromGetDifference) {
                                                                    mapVCallId = mapVCallId2;
                                                                } else {
                                                                    int a7 = 0;
                                                                    int count2 = message2.entities.size();
                                                                    while (a7 < count2) {
                                                                        TLRPC.MessageEntity entity = message2.entities.get(a7);
                                                                        if (!(entity instanceof TLRPC.TL_messageEntityMentionName)) {
                                                                            count = count2;
                                                                            mapVCallId3 = mapVCallId2;
                                                                        } else {
                                                                            int user_id = ((TLRPC.TL_messageEntityMentionName) entity).user_id;
                                                                            count = count2;
                                                                            TLRPC.User user3 = usersDict2.get(Integer.valueOf(user_id));
                                                                            if (user3 != null) {
                                                                                mapVCallId3 = mapVCallId2;
                                                                            } else {
                                                                                mapVCallId3 = mapVCallId2;
                                                                            }
                                                                            user3 = getUser(Integer.valueOf(user_id));
                                                                            if (user3 == null || user3.min) {
                                                                                user3 = getMessagesStorage().getUserSync(user_id);
                                                                                if (user3 != null && user3.min) {
                                                                                    user3 = null;
                                                                                }
                                                                                putUser(user3, true);
                                                                            }
                                                                            if (user3 == null) {
                                                                                return false;
                                                                            }
                                                                        }
                                                                        a7++;
                                                                        count2 = count;
                                                                        mapVCallId2 = mapVCallId3;
                                                                    }
                                                                    mapVCallId = mapVCallId2;
                                                                }
                                                                if (message2.to_id.chat_id != 0) {
                                                                    message2.dialog_id = -message2.to_id.chat_id;
                                                                } else if (message2.to_id.channel_id != 0) {
                                                                    message2.dialog_id = -message2.to_id.channel_id;
                                                                } else {
                                                                    if (message2.to_id.user_id == getUserConfig().getClientUserId()) {
                                                                        message2.to_id.user_id = message2.from_id;
                                                                    }
                                                                    message2.dialog_id = message2.to_id.user_id;
                                                                }
                                                                ConcurrentHashMap<Long, Integer> read_max = message2.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                                                                Integer value5 = read_max.get(Long.valueOf(message2.dialog_id));
                                                                if (value5 != null) {
                                                                    interfaceUpdateMask5 = interfaceUpdateMask8;
                                                                    markAsReadMessagesOutbox5 = markAsReadMessagesOutbox6;
                                                                } else {
                                                                    interfaceUpdateMask5 = interfaceUpdateMask8;
                                                                    markAsReadMessagesOutbox5 = markAsReadMessagesOutbox6;
                                                                    value5 = Integer.valueOf(getMessagesStorage().getDialogReadMax(message2.out, message2.dialog_id));
                                                                    read_max.put(Long.valueOf(message2.dialog_id), value5);
                                                                }
                                                                message2.unread = value5.intValue() < message2.id;
                                                                if (message2.dialog_id == clientUserId) {
                                                                    message2.out = true;
                                                                    message2.unread = false;
                                                                    message2.media_unread = false;
                                                                }
                                                                if (message2.out && message2.message == null) {
                                                                    message2.message = "";
                                                                    message2.attachPath = "";
                                                                }
                                                                ImageLoader.saveMessageThumbs(message2);
                                                                MessageObject obj3 = new MessageObject(this.currentAccount, message2, usersDict2, chatsDict3, this.createdDialogIds.contains(Long.valueOf(message2.dialog_id)));
                                                                if (editingMessages3 != null) {
                                                                    editingMessages2 = editingMessages3;
                                                                } else {
                                                                    editingMessages2 = new LongSparseArray<>();
                                                                }
                                                                LongSparseArray<ArrayList<MessageObject>> array2 = editingMessages2;
                                                                LongSparseArray<ArrayList<MessageObject>> editingMessages4 = editingMessages2;
                                                                ArrayList<MessageObject> arr4 = array2.get(message2.dialog_id);
                                                                if (arr4 != null) {
                                                                    editingMessages3 = editingMessages4;
                                                                } else {
                                                                    arr4 = new ArrayList<>();
                                                                    editingMessages3 = editingMessages4;
                                                                    array2.put(message2.dialog_id, arr4);
                                                                }
                                                                arr4.add(obj3);
                                                                interfaceUpdateMask8 = interfaceUpdateMask5;
                                                                markAsReadMessagesOutbox6 = markAsReadMessagesOutbox5;
                                                                contactsIds5 = contactsIds4;
                                                                scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                                            }
                                                        }
                                                    }
                                                }
                                                getConnectionsManager().updateDcSettings();
                                            }
                                            interfaceUpdateMask8 = interfaceUpdateMask4;
                                            markAsReadMessagesOutbox6 = markAsReadMessagesOutbox4;
                                            contactsIds5 = contactsIds4;
                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                        } else {
                                            TLRPC.TL_updateEncryptedMessagesRead update29 = (TLRPC.TL_updateEncryptedMessagesRead) baseUpdate2;
                                            if (markAsReadEncrypted3 != null) {
                                                markAsReadEncrypted2 = markAsReadEncrypted3;
                                            } else {
                                                markAsReadEncrypted2 = new SparseIntArray();
                                            }
                                            markAsReadEncrypted2.put(update29.chat_id, update29.max_date);
                                            ArrayList<TLRPC.TL_updateEncryptedMessagesRead> tasks4 = tasks;
                                            if (tasks4 == null) {
                                                tasks4 = new ArrayList<>();
                                            }
                                            tasks4.add((TLRPC.TL_updateEncryptedMessagesRead) baseUpdate2);
                                            tasks = tasks4;
                                            markAsReadEncrypted3 = markAsReadEncrypted2;
                                            mapVCallId = map;
                                            chatsDict3 = chatsDict5;
                                            scheduledDeletedMessages5 = scheduledDeletedMessages7;
                                        }
                                    }
                                }
                            }
                            if (baseUpdate2 instanceof TLRPC.TL_updateUserTyping) {
                                TLRPC.TL_updateUserTyping update30 = (TLRPC.TL_updateUserTyping) baseUpdate2;
                                chat_id3 = update30.user_id;
                                action = update30.action;
                                chat_id2 = 0;
                            } else {
                                TLRPC.TL_updateChatUserTyping update31 = (TLRPC.TL_updateChatUserTyping) baseUpdate2;
                                int chat_id4 = update31.chat_id;
                                int user_id2 = update31.user_id;
                                TLRPC.SendMessageAction sendMessageAction = update31.action;
                                chat_id2 = chat_id4;
                                chat_id3 = user_id2;
                                action = sendMessageAction;
                            }
                            if (chat_id3 != getUserConfig().getClientUserId()) {
                                long uid4 = -chat_id2;
                                if (uid4 == 0) {
                                    uid4 = chat_id3;
                                }
                                ArrayList<PrintingUser> arr5 = this.printingUsers.get(Long.valueOf(uid4));
                                if (action instanceof TLRPC.TL_sendMessageCancelAction) {
                                    if (arr5 != null) {
                                        int a8 = 0;
                                        int size14 = arr5.size();
                                        while (true) {
                                            if (a8 >= size14) {
                                                break;
                                            }
                                            int chat_id5 = chat_id2;
                                            PrintingUser pu = arr5.get(a8);
                                            int size15 = size14;
                                            int size16 = pu.userId;
                                            if (size16 != chat_id3) {
                                                a8++;
                                                size14 = size15;
                                                chat_id2 = chat_id5;
                                            } else {
                                                arr5.remove(a8);
                                                printChanged = true;
                                                break;
                                            }
                                        }
                                        if (arr5.isEmpty()) {
                                            this.printingUsers.remove(Long.valueOf(uid4));
                                        }
                                        uid = currentTime5;
                                    } else {
                                        uid = currentTime5;
                                    }
                                } else {
                                    if (arr5 == null) {
                                        arr5 = new ArrayList<>();
                                        this.printingUsers.put(Long.valueOf(uid4), arr5);
                                    }
                                    boolean exist2 = false;
                                    Iterator<PrintingUser> it2 = arr5.iterator();
                                    while (true) {
                                        if (!it2.hasNext()) {
                                            uid = currentTime5;
                                            break;
                                        }
                                        PrintingUser u2 = it2.next();
                                        boolean exist3 = exist2;
                                        if (u2.userId == chat_id3) {
                                            uid = currentTime5;
                                            u2.lastTime = uid;
                                            if (u2.action.getClass() != action.getClass()) {
                                                printChanged = true;
                                            }
                                            u2.action = action;
                                            exist2 = true;
                                        } else {
                                            exist2 = exist3;
                                            uid4 = uid4;
                                        }
                                    }
                                    if (!exist2) {
                                        PrintingUser newUser2 = new PrintingUser();
                                        newUser2.userId = chat_id3;
                                        newUser2.lastTime = uid;
                                        newUser2.action = action;
                                        arr5.add(newUser2);
                                        printChanged = true;
                                    }
                                }
                                if (Math.abs(getConnectionsManager().getCurrentTime() - date) < 30) {
                                    this.onlinePrivacy.put(Integer.valueOf(chat_id3), Integer.valueOf(date));
                                }
                            } else {
                                uid = currentTime5;
                            }
                            currentTime3 = uid;
                            interfaceUpdateMask8 = interfaceUpdateMask3;
                            markAsReadMessagesOutbox6 = markAsReadMessagesOutbox3;
                            contactsIds5 = contactsIds3;
                            scheduledDeletedMessages5 = scheduledDeletedMessages3;
                        }
                    }
                }
                c2 = c + 1;
                chatsDict = chatsDict3;
                usersDict = usersDict2;
                map = mapVCallId;
                size32 = size33;
                markAsReadMessages3 = markAsReadMessages2;
                currentTime8 = currentTime3;
                arrayList29 = updates;
            }
            if (baseUpdate2 instanceof TLRPC.TL_updateNewMessage) {
                message = ((TLRPC.TL_updateNewMessage) baseUpdate2).message;
            } else if (baseUpdate2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                message = ((TLRPC.TL_updateNewScheduledMessage) baseUpdate2).message;
            } else {
                message = ((TLRPC.TL_updateNewChannelMessage) baseUpdate2).message;
                if (!message.out && message.from_id == getUserConfig().getClientUserId()) {
                    message.out = true;
                }
            }
            TLRPC.Chat chat4 = null;
            int chat_id6 = 0;
            int user_id3 = 0;
            if (message.to_id.channel_id != 0) {
                chat_id6 = message.to_id.channel_id;
            } else if (message.to_id.chat_id != 0) {
                chat_id6 = message.to_id.chat_id;
            } else if (message.to_id.user_id != 0) {
                user_id3 = message.to_id.user_id;
            }
            if (chat_id6 != 0) {
                TLRPC.Chat chat5 = chatsDict3.get(Integer.valueOf(chat_id6));
                chat4 = chat5;
                if (chat4 == null) {
                    chat4 = getChat(Integer.valueOf(chat_id6));
                }
                if (chat4 == null) {
                    chat4 = getMessagesStorage().getChatSync(chat_id6);
                    putChat(chat4, true);
                }
            }
            if (!checkForUsers) {
                currentTime3 = currentTime2;
            } else if (chat_id6 != 0 && chat4 == null) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("not found chat " + chat_id6);
                    return false;
                }
                return false;
            } else {
                int count3 = message.entities.size() + 3;
                int a9 = 0;
                while (a9 < count3) {
                    boolean allowMin = false;
                    if (a9 == 0) {
                        chat_id = chat_id6;
                        currentTime4 = currentTime2;
                    } else {
                        chat_id = chat_id6;
                        if (a9 == 1) {
                            user_id3 = message.from_id;
                            if (!message.post) {
                                currentTime4 = currentTime2;
                            } else {
                                allowMin = true;
                                currentTime4 = currentTime2;
                            }
                        } else if (a9 == 2) {
                            user_id3 = message.fwd_from != null ? message.fwd_from.from_id : 0;
                            currentTime4 = currentTime2;
                        } else {
                            currentTime4 = currentTime2;
                            TLRPC.MessageEntity entity2 = message.entities.get(a9 - 3);
                            user_id3 = entity2 instanceof TLRPC.TL_messageEntityMentionName ? ((TLRPC.TL_messageEntityMentionName) entity2).user_id : 0;
                        }
                    }
                    if (user_id3 > 0) {
                        TLRPC.User user4 = usersDict2.get(Integer.valueOf(user_id3));
                        if (user4 == null || (!allowMin && user4.min)) {
                            user4 = getUser(Integer.valueOf(user_id3));
                        }
                        if (user4 == null || (!allowMin && user4.min)) {
                            user4 = getMessagesStorage().getUserSync(user_id3);
                            if (user4 != null && !allowMin && user4.min) {
                                user4 = null;
                            }
                            putUser(user4, true);
                        }
                        if (user4 == null) {
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("not found user " + user_id3);
                                return false;
                            }
                            return false;
                        } else if (!message.out && a9 == 1 && user4.status != null && user4.status.expires <= 0 && Math.abs(getConnectionsManager().getCurrentTime() - message.date) < 30) {
                            this.onlinePrivacy.put(Integer.valueOf(user_id3), Integer.valueOf(message.date));
                            interfaceUpdateMask2 |= 4;
                        }
                    }
                    a9++;
                    chat_id6 = chat_id;
                    currentTime2 = currentTime4;
                }
                currentTime3 = currentTime2;
            }
            if (chat4 != null && chat4.megagroup) {
                message.flags |= Integer.MIN_VALUE;
            }
            if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                TLRPC.User user5 = usersDict2.get(Integer.valueOf(message.action.user_id));
                if (user5 != null && user5.bot) {
                    message.reply_markup = new TLRPC.TL_replyKeyboardHide();
                    message.flags |= 64;
                } else if (message.from_id == getUserConfig().getClientUserId() && message.action.user_id == getUserConfig().getClientUserId()) {
                    interfaceUpdateMask8 = interfaceUpdateMask2;
                    markAsReadMessagesOutbox6 = markAsReadMessagesOutbox2;
                    contactsIds5 = contactsIds2;
                    scheduledDeletedMessages5 = scheduledDeletedMessages2;
                    c2 = c + 1;
                    chatsDict = chatsDict3;
                    usersDict = usersDict2;
                    map = mapVCallId;
                    size32 = size33;
                    markAsReadMessages3 = markAsReadMessages2;
                    currentTime8 = currentTime3;
                    arrayList29 = updates;
                }
            }
            ImageLoader.saveMessageThumbs(message);
            int clientUserId2 = getUserConfig().getClientUserId();
            if (message.to_id.chat_id != 0) {
                message.dialog_id = -message.to_id.chat_id;
            } else if (message.to_id.channel_id != 0) {
                message.dialog_id = -message.to_id.channel_id;
            } else {
                if (message.to_id.user_id == clientUserId2) {
                    message.to_id.user_id = message.from_id;
                }
                if (clientUserId2 == 0) {
                    message.dialog_id = message.from_id;
                } else {
                    message.dialog_id = message.to_id.user_id;
                }
            }
            if (baseUpdate2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                if (scheduledMessagesArr2 != null) {
                    scheduledMessagesArr = scheduledMessagesArr2;
                } else {
                    scheduledMessagesArr = new ArrayList<>();
                }
                scheduledMessagesArr.add(message);
                sparseArray2 = channelViews3;
                MessageObject obj4 = new MessageObject(this.currentAccount, message, usersDict2, chatsDict3, this.createdScheduledDialogIds.contains(Long.valueOf(message.dialog_id)));
                obj4.scheduled = true;
                if (scheduledMessages != null) {
                    scheduledMessages2 = scheduledMessages;
                } else {
                    scheduledMessages2 = new LongSparseArray<>();
                }
                ArrayList<MessageObject> arr6 = scheduledMessages2.get(message.dialog_id);
                if (arr6 == null) {
                    arr6 = new ArrayList<>();
                    scheduledMessages2.put(message.dialog_id, arr6);
                }
                arr6.add(obj4);
                scheduledMessagesArr2 = scheduledMessagesArr;
                scheduledMessages = scheduledMessages2;
            } else {
                sparseArray2 = channelViews3;
                if (messagesArr4 != null) {
                    messagesArr = messagesArr4;
                } else {
                    messagesArr = new ArrayList<>();
                }
                messagesArr.add(message);
                ConcurrentHashMap<Long, Integer> read_max2 = message.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                Integer value6 = read_max2.get(Long.valueOf(message.dialog_id));
                if (value6 == null) {
                    value6 = Integer.valueOf(getMessagesStorage().getDialogReadMax(message.out, message.dialog_id));
                    read_max2.put(Long.valueOf(message.dialog_id), value6);
                }
                message.unread = value6.intValue() < message.id && !((chat4 != null && ChatObject.isNotInChat(chat4)) || (message.action instanceof TLRPC.TL_messageActionChatMigrateTo) || (message.action instanceof TLRPC.TL_messageActionChannelCreate));
                ArrayList<TLRPC.Message> messagesArr6 = messagesArr;
                if (message.dialog_id == clientUserId2) {
                    if (message.from_scheduled) {
                        z2 = false;
                    } else {
                        z2 = false;
                        message.unread = false;
                    }
                    message.media_unread = z2;
                    message.out = true;
                }
                MessageObject obj5 = new MessageObject(this.currentAccount, message, usersDict2, chatsDict3, this.createdDialogIds.contains(Long.valueOf(message.dialog_id)));
                if (obj5.type == 11) {
                    interfaceUpdateMask2 |= 8;
                } else if (obj5.type == 10) {
                    interfaceUpdateMask2 |= 16;
                }
                if (messages4 == null) {
                    messages4 = new LongSparseArray<>();
                }
                ArrayList<MessageObject> arr7 = messages4.get(message.dialog_id);
                if (arr7 == null) {
                    arr7 = new ArrayList<>();
                    messages4.put(message.dialog_id, arr7);
                }
                arr7.add(obj5);
                if ((!obj5.isOut() || obj5.messageOwner.from_scheduled) && obj5.isUnread()) {
                    if (pushMessages7 != null) {
                        pushMessages = pushMessages7;
                    } else {
                        pushMessages = new ArrayList<>();
                    }
                    pushMessages.add(obj5);
                    pushMessages7 = pushMessages;
                    messagesArr4 = messagesArr6;
                } else {
                    messagesArr4 = messagesArr6;
                }
            }
            interfaceUpdateMask8 = interfaceUpdateMask2;
            markAsReadMessagesOutbox6 = markAsReadMessagesOutbox2;
            channelViews3 = sparseArray2;
            contactsIds5 = contactsIds2;
            scheduledDeletedMessages5 = scheduledDeletedMessages2;
            c2 = c + 1;
            chatsDict = chatsDict3;
            usersDict = usersDict2;
            map = mapVCallId;
            size32 = size33;
            markAsReadMessages3 = markAsReadMessages2;
            currentTime8 = currentTime3;
            arrayList29 = updates;
        }
        ConcurrentHashMap<Integer, TLRPC.User> usersDict5 = usersDict;
        final ArrayList<Long> markAsReadMessages4 = markAsReadMessages3;
        final SparseArray<ArrayList<Integer>> scheduledDeletedMessages8 = scheduledDeletedMessages5;
        ArrayList<Integer> contactsIds8 = contactsIds5;
        long currentTime10 = currentTime8;
        ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict6 = chatsDict;
        final int interfaceUpdateMask14 = interfaceUpdateMask8;
        final SparseArray<SparseIntArray> sparseArray3 = channelViews3;
        final SparseLongArray markAsReadMessagesOutbox7 = markAsReadMessagesOutbox6;
        if (messages4 != null) {
            int size17 = messages4.size();
            for (int a10 = 0; a10 < size17; a10++) {
                long key = messages4.keyAt(a10);
                if (updatePrintingUsersWithNewMessages(key, messages4.valueAt(a10))) {
                    printChanged = true;
                }
            }
        }
        if (printChanged) {
            updatePrintingStrings();
        }
        final SparseArray<SparseIntArray> channelViews4 = channelViews2;
        final SparseIntArray markAsReadEncrypted4 = markAsReadEncrypted3;
        final boolean printChangedArg = printChanged;
        if (contactsIds8 == null) {
            contactsIds = contactsIds8;
        } else {
            contactsIds = contactsIds8;
            getContactsController().processContactsUpdates(contactsIds, usersDict5);
        }
        if (pushMessages7 == null) {
            currentTime = currentTime10;
        } else {
            final ArrayList<MessageObject> pushMessagesFinal = pushMessages7;
            currentTime = currentTime10;
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$processUpdateArray$281$MessagesController(pushMessagesFinal);
                }
            });
        }
        if (scheduledMessagesArr2 != null) {
            getMessagesStorage().putMessages(scheduledMessagesArr2, true, true, false, getDownloadController().getAutodownloadMask(), true);
        }
        if (messagesArr4 != null) {
            getStatsController().incrementReceivedItemsCount(ApplicationLoader.getCurrentNetworkType(), 1, messagesArr4.size());
            getMessagesStorage().putMessages(messagesArr4, true, true, false, getDownloadController().getAutodownloadMask(), false);
        }
        if (editingMessages3 == null) {
            chatsDict2 = chatsDict6;
            messages2 = messages4;
            editingMessages = editingMessages3;
        } else {
            int b = 0;
            int size18 = editingMessages3.size();
            while (b < size18) {
                TLRPC.TL_messages_messages messagesRes = new TLRPC.TL_messages_messages();
                LongSparseArray<ArrayList<MessageObject>> editingMessages5 = editingMessages3;
                int size19 = size18;
                ArrayList<MessageObject> messageObjects = editingMessages5.valueAt(b);
                ConcurrentHashMap<Integer, TLRPC.Chat> chatsDict7 = chatsDict6;
                int size22 = messageObjects.size();
                LongSparseArray<ArrayList<MessageObject>> messages6 = messages4;
                int a11 = 0;
                while (a11 < size22) {
                    messagesRes.messages.add(messageObjects.get(a11).messageOwner);
                    a11++;
                    size22 = size22;
                    messageObjects = messageObjects;
                }
                getMessagesStorage().putMessages((TLRPC.messages_Messages) messagesRes, editingMessages5.keyAt(b), -2, 0, false, false);
                b++;
                editingMessages3 = editingMessages5;
                size18 = size19;
                messages4 = messages6;
                chatsDict6 = chatsDict7;
            }
            chatsDict2 = chatsDict6;
            messages2 = messages4;
            editingMessages = editingMessages3;
        }
        if (channelViews4 != null) {
            getMessagesStorage().putChannelViews(channelViews4, true);
        }
        final ArrayList<Integer> contactsIds9 = contactsIds;
        final LongSparseArray<TLRPC.WebPage> webPages6 = webPages5;
        final LongSparseArray<ArrayList<MessageObject>> messagesFinal = messages2;
        final LongSparseArray<ArrayList<MessageObject>> scheduledMessagesFinal = scheduledMessages;
        final ArrayList<TLRPC.TL_updateEncryptedMessagesRead> arrayList32 = tasks2;
        final ArrayList<Integer> arrayList33 = contactsIds6;
        ArrayList<TLRPC.TL_updateEncryptedMessagesRead> tasks5 = tasks;
        final SparseIntArray clearHistoryMessages5 = clearHistoryMessages2;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processUpdateArray$286$MessagesController(interfaceUpdateMask14, arrayList33, webPages6, messagesFinal, scheduledMessagesFinal, editingMessages, printChangedArg, contactsIds9, arrayList32, channelViews4);
            }
        });
        SparseLongArray markAsReadMessagesInbox2 = markAsReadMessagesInbox;
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processUpdateArray$288$MessagesController(markAsReadMessagesInbox, markAsReadMessagesOutbox7, markAsReadEncrypted4, markAsReadMessages4, sparseArray3, scheduledDeletedMessages8, clearHistoryMessages5);
            }
        });
        if (webPages6 != null) {
            getMessagesStorage().putWebPages(webPages6);
        }
        if (markAsReadMessagesInbox2 == null) {
            markAsReadMessagesOutbox = markAsReadMessagesOutbox7;
            if (markAsReadMessagesOutbox == null) {
                markAsReadEncrypted = markAsReadEncrypted4;
                if (markAsReadEncrypted == null) {
                    markAsReadMessages = markAsReadMessages4;
                    if (markAsReadMessages == null) {
                        if (markAsReadMessages != null) {
                            getMessagesStorage().markMessagesContentAsRead(markAsReadMessages, getConnectionsManager().getCurrentTime());
                        }
                        sparseArray = sparseArray3;
                        if (sparseArray == null) {
                            int size20 = sparseArray.size();
                            int a12 = 0;
                            while (a12 < size20) {
                                int size21 = size20;
                                final int key2 = sparseArray.keyAt(a12);
                                ArrayList<Long> markAsReadMessages5 = markAsReadMessages;
                                final ArrayList<Integer> arrayList34 = (ArrayList) sparseArray.valueAt(a12);
                                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                    @Override
                                    public final void run() {
                                        MessagesController.this.lambda$processUpdateArray$289$MessagesController(arrayList34, key2);
                                    }
                                });
                                a12++;
                                size20 = size21;
                                messagesFinal = messagesFinal;
                                markAsReadMessages = markAsReadMessages5;
                                sparseArray = sparseArray;
                            }
                        }
                        scheduledDeletedMessages = scheduledDeletedMessages8;
                        if (scheduledDeletedMessages == null) {
                            int a13 = 0;
                            int size23 = scheduledDeletedMessages.size();
                            while (a13 < size23) {
                                int key3 = scheduledDeletedMessages.keyAt(a13);
                                ArrayList<Integer> arrayList35 = scheduledDeletedMessages.valueAt(a13);
                                MessagesStorage.getInstance(this.currentAccount).markMessagesAsDeleted(arrayList35, true, key3, false, true);
                                a13++;
                                scheduledDeletedMessages = scheduledDeletedMessages;
                            }
                        }
                        clearHistoryMessages = clearHistoryMessages5;
                        if (clearHistoryMessages == null) {
                            int a14 = 0;
                            int size24 = clearHistoryMessages.size();
                            while (a14 < size24) {
                                final int key4 = clearHistoryMessages.keyAt(a14);
                                final int id4 = clearHistoryMessages.valueAt(a14);
                                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                    @Override
                                    public final void run() {
                                        MessagesController.this.lambda$processUpdateArray$290$MessagesController(key4, id4);
                                    }
                                });
                                a14++;
                                size24 = size24;
                                clearHistoryMessages = clearHistoryMessages;
                            }
                        }
                        if (tasks5 == null) {
                            int a15 = 0;
                            int size25 = tasks5.size();
                            while (a15 < size25) {
                                TLRPC.TL_updateEncryptedMessagesRead update32 = tasks5.get(a15);
                                MessagesStorage messagesStorage = getMessagesStorage();
                                int i3 = update32.chat_id;
                                int i4 = update32.max_date;
                                int size26 = size25;
                                int size27 = update32.date;
                                messagesStorage.createTaskForSecretChat(i3, i4, size27, 1, null);
                                a15++;
                                size25 = size26;
                            }
                            return true;
                        }
                        return true;
                    }
                } else {
                    markAsReadMessages = markAsReadMessages4;
                }
            } else {
                markAsReadEncrypted = markAsReadEncrypted4;
                markAsReadMessages = markAsReadMessages4;
            }
        } else {
            markAsReadEncrypted = markAsReadEncrypted4;
            markAsReadMessagesOutbox = markAsReadMessagesOutbox7;
            markAsReadMessages = markAsReadMessages4;
        }
        if (markAsReadMessagesInbox2 == null && markAsReadMessages == null) {
            z = true;
        } else {
            z = true;
            getMessagesStorage().updateDialogsWithReadMessages(markAsReadMessagesInbox2, markAsReadMessagesOutbox, markAsReadMessages, true);
        }
        getMessagesStorage().markMessagesAsRead(markAsReadMessagesInbox2, markAsReadMessagesOutbox, markAsReadEncrypted, z);
        if (markAsReadMessages != null) {
        }
        sparseArray = sparseArray3;
        if (sparseArray == null) {
        }
        scheduledDeletedMessages = scheduledDeletedMessages8;
        if (scheduledDeletedMessages == null) {
        }
        clearHistoryMessages = clearHistoryMessages5;
        if (clearHistoryMessages == null) {
        }
        if (tasks5 == null) {
        }
    }

    public void lambda$processUpdateArray$265$MessagesController(ArrayList usersArr, ArrayList chatsArr) {
        putUsers(usersArr, false);
        putChats(chatsArr, false);
    }

    public void lambda$processUpdateArray$266$MessagesController(ArrayList usersArr, ArrayList chatsArr) {
        putUsers(usersArr, false);
        putChats(chatsArr, false);
    }

    public void lambda$processUpdateArray$268$MessagesController(final TLRPC.TL_updateUserBlocked finalUpdate) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$267$MessagesController(finalUpdate);
            }
        });
    }

    public void lambda$null$267$MessagesController(TLRPC.TL_updateUserBlocked finalUpdate) {
        if (finalUpdate.blocked) {
            if (this.blockedUsers.indexOfKey(finalUpdate.user_id) < 0) {
                this.blockedUsers.put(finalUpdate.user_id, 1);
            }
        } else {
            this.blockedUsers.delete(finalUpdate.user_id);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad, new Object[0]);
    }

    public void lambda$processUpdateArray$269$MessagesController(TLRPC.TL_updateServiceNotification update) {
        getNotificationCenter().postNotificationName(NotificationCenter.needShowAlert, 2, update.message, update.type);
    }

    public void lambda$processUpdateArray$270$MessagesController(TLRPC.Message message) {
        getNotificationCenter().postNotificationName(NotificationCenter.livestatechange, message.media);
    }

    public void lambda$processUpdateArray$271$MessagesController(TLRPC.TL_updateLangPack update) {
        LocaleController.getInstance().saveRemoteLocaleStringsForCurrentLocale(update.difference, this.currentAccount);
    }

    public void lambda$processUpdateArray$272$MessagesController(TLRPC.TL_updateUserMomentStateV1 userMomentStateV1) {
        NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.userFriendsCircleUpdate, userMomentStateV1);
    }

    public void lambda$processUpdateArray$276$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.contactApplyUpdateCount, 0);
    }

    public void lambda$processUpdateArray$279$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.groupingChanged, new Object[0]);
    }

    public void lambda$null$280$MessagesController(ArrayList pushMessagesFinal) {
        getNotificationsController().processNewMessages(pushMessagesFinal, true, false, null);
    }

    public void lambda$processUpdateArray$281$MessagesController(final ArrayList pushMessagesFinal) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$280$MessagesController(pushMessagesFinal);
            }
        });
    }

    public void lambda$processUpdateArray$286$MessagesController(int interfaceUpdateMaskFinal, ArrayList updatesOnMainThreadFinal, LongSparseArray webPagesFinal, LongSparseArray messagesFinal, LongSparseArray scheduledMessagesFinal, LongSparseArray editingMessagesFinal, boolean printChangedArg, ArrayList contactsIdsFinal, ArrayList chatInfoToUpdateFinal, SparseArray channelViewsFinal) {
        ?? r2;
        int i;
        Object obj;
        int i2;
        boolean forceDialogsUpdate;
        boolean updateDialogs;
        HashMap<String, ArrayList<MessageObject>> map;
        LongSparseArray<ArrayList<MessageObject>> array;
        boolean z;
        ArrayList<TLRPC.User> dbUsersStatus;
        int size;
        ArrayList<TLRPC.User> dbUsersStatus2;
        int updateMask;
        long dialogId;
        long dialogId2;
        long did;
        long did2;
        int chatId;
        TLRPC.Dialog dialog;
        SharedPreferences.Editor editor;
        long dialog_id;
        int i3;
        ArrayList<Long> order;
        long did3;
        long did4;
        ArrayList arrayList = updatesOnMainThreadFinal;
        int updateMask2 = interfaceUpdateMaskFinal;
        boolean forceDialogsUpdate2 = false;
        int i4 = 0;
        if (arrayList == null) {
            r2 = 0;
            i = 1;
        } else {
            ArrayList<TLRPC.User> dbUsers = new ArrayList<>();
            ArrayList<TLRPC.User> dbUsers2 = new ArrayList<>();
            int size2 = updatesOnMainThreadFinal.size();
            int a = 0;
            SharedPreferences.Editor editor2 = null;
            boolean forceDialogsUpdate3 = false;
            int updateMask3 = updateMask2;
            while (a < size2) {
                int size3 = size2;
                TLRPC.Update baseUpdate = (TLRPC.Update) arrayList.get(a);
                if (baseUpdate instanceof TLRPC.TL_updatePrivacy) {
                    TLRPC.TL_updatePrivacy update = (TLRPC.TL_updatePrivacy) baseUpdate;
                    if (update.key instanceof TLRPC.TL_privacyKeyStatusTimestamp) {
                        getContactsController().setPrivacyRules(update.rules, i4);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyChatInvite) {
                        getContactsController().setPrivacyRules(update.rules, 1);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyMoment) {
                        getContactsController().setPrivacyRules(update.rules, 8);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyPhoneCall) {
                        getContactsController().setPrivacyRules(update.rules, 2);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyPhoneP2P) {
                        getContactsController().setPrivacyRules(update.rules, 3);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyProfilePhoto) {
                        getContactsController().setPrivacyRules(update.rules, 4);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyForwards) {
                        getContactsController().setPrivacyRules(update.rules, 5);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyPhoneNumber) {
                        getContactsController().setPrivacyRules(update.rules, 6);
                    } else if (update.key instanceof TLRPC.TL_privacyKeyAddedByPhone) {
                        getContactsController().setPrivacyRules(update.rules, 7);
                    }
                    updateMask = updateMask3;
                    dbUsersStatus = dbUsers2;
                    size = size3;
                    dbUsersStatus2 = dbUsers;
                } else if (baseUpdate instanceof TLRPC.TL_updateUserStatus) {
                    TLRPC.TL_updateUserStatus update2 = (TLRPC.TL_updateUserStatus) baseUpdate;
                    TLRPC.User currentUser = getUser(Integer.valueOf(update2.user_id));
                    if (update2.status instanceof TLRPC.TL_userStatusRecently) {
                        update2.status.expires = -100;
                    } else if (update2.status instanceof TLRPC.TL_userStatusLastWeek) {
                        update2.status.expires = -101;
                    } else if (update2.status instanceof TLRPC.TL_userStatusLastMonth) {
                        update2.status.expires = -102;
                    }
                    if (currentUser != null) {
                        currentUser.id = update2.user_id;
                        currentUser.status = update2.status;
                    }
                    TLRPC.User toDbUser = new TLRPC.TL_user();
                    toDbUser.id = update2.user_id;
                    toDbUser.status = update2.status;
                    dbUsers2.add(toDbUser);
                    int updateMask4 = updateMask3;
                    if (update2.user_id == getUserConfig().getClientUserId()) {
                        getNotificationsController().setLastOnlineFromOtherDevice(update2.status.expires);
                    }
                    dbUsersStatus = dbUsers2;
                    size = size3;
                    updateMask = updateMask4;
                    dbUsersStatus2 = dbUsers;
                } else {
                    int updateMask5 = updateMask3;
                    if (baseUpdate instanceof TLRPC.TL_updateUserName) {
                        TLRPC.TL_updateUserName update3 = (TLRPC.TL_updateUserName) baseUpdate;
                        TLRPC.User currentUser2 = getUser(Integer.valueOf(update3.user_id));
                        if (currentUser2 != null) {
                            if (!UserObject.isContact(currentUser2)) {
                                currentUser2.first_name = update3.first_name;
                                currentUser2.last_name = update3.last_name;
                            }
                            if (!TextUtils.isEmpty(currentUser2.username)) {
                                this.objectsByUsernames.remove(currentUser2.username);
                            }
                            if (TextUtils.isEmpty(update3.username)) {
                                this.objectsByUsernames.put(update3.username, currentUser2);
                            }
                            currentUser2.username = update3.username;
                        }
                        TLRPC.User toDbUser2 = new TLRPC.TL_user();
                        toDbUser2.id = update3.user_id;
                        toDbUser2.first_name = update3.first_name;
                        toDbUser2.last_name = update3.last_name;
                        toDbUser2.username = update3.username;
                        dbUsers.add(toDbUser2);
                        dbUsersStatus = dbUsers2;
                        size = size3;
                        updateMask = updateMask5;
                        dbUsersStatus2 = dbUsers;
                    } else if (baseUpdate instanceof TLRPC.TL_updateDialogPinned) {
                        TLRPC.TL_updateDialogPinned update4 = (TLRPC.TL_updateDialogPinned) baseUpdate;
                        if (update4.peer instanceof TLRPC.TL_dialogPeer) {
                            did4 = DialogObject.getPeerDialogId(((TLRPC.TL_dialogPeer) update4.peer).peer);
                        } else {
                            did4 = 0;
                        }
                        ArrayList<TLRPC.User> dbUsers3 = dbUsers;
                        dbUsersStatus = dbUsers2;
                        long did5 = did4;
                        size = size3;
                        if (!pinDialog(did4, update4.pinned, null, -1L)) {
                            getUserConfig().setPinnedDialogsLoaded(update4.folder_id, false);
                            getUserConfig().saveConfig(false);
                            loadPinnedDialogs(update4.folder_id, did5, null);
                        }
                        updateMask = updateMask5;
                        dbUsersStatus2 = dbUsers3;
                    } else {
                        ArrayList<TLRPC.User> dbUsers4 = dbUsers;
                        dbUsersStatus = dbUsers2;
                        size = size3;
                        if (baseUpdate instanceof TLRPC.TL_updatePinnedDialogs) {
                            TLRPC.TL_updatePinnedDialogs update5 = (TLRPC.TL_updatePinnedDialogs) baseUpdate;
                            getUserConfig().setPinnedDialogsLoaded(update5.folder_id, false);
                            getUserConfig().saveConfig(false);
                            if ((update5.flags & 1) != 0) {
                                order = new ArrayList<>();
                                ArrayList<TLRPC.DialogPeer> peers = update5.order;
                                int size22 = peers.size();
                                for (int b = 0; b < size22; b++) {
                                    TLRPC.DialogPeer dialogPeer = peers.get(b);
                                    if (dialogPeer instanceof TLRPC.TL_dialogPeer) {
                                        TLRPC.Peer peer = ((TLRPC.TL_dialogPeer) dialogPeer).peer;
                                        if (peer.user_id != 0) {
                                            did3 = peer.user_id;
                                        } else if (peer.chat_id != 0) {
                                            did3 = -peer.chat_id;
                                        } else {
                                            did3 = -peer.channel_id;
                                        }
                                    } else {
                                        did3 = 0;
                                    }
                                    order.add(Long.valueOf(did3));
                                }
                            } else {
                                order = null;
                            }
                            loadPinnedDialogs(update5.folder_id, 0L, order);
                            updateMask = updateMask5;
                            dbUsersStatus2 = dbUsers4;
                        } else {
                            if (baseUpdate instanceof TLRPC.TL_updateFolderPeers) {
                                TLRPC.TL_updateFolderPeers update6 = (TLRPC.TL_updateFolderPeers) baseUpdate;
                                int size23 = update6.folder_peers.size();
                                for (int b2 = 0; b2 < size23; b2++) {
                                    TLRPC.TL_folderPeer folderPeer = update6.folder_peers.get(b2);
                                    long dialogId3 = DialogObject.getPeerDialogId(folderPeer.peer);
                                    TLRPC.Dialog dialog2 = this.dialogs_dict.get(dialogId3);
                                    if (dialog2 != null && dialog2.folder_id != folderPeer.folder_id) {
                                        dialog2.pinned = false;
                                        dialog2.pinnedNum = 0;
                                        dialog2.folder_id = folderPeer.folder_id;
                                        ensureFolderDialogExists(folderPeer.folder_id, null);
                                    }
                                }
                                forceDialogsUpdate3 = true;
                                updateMask3 = updateMask5;
                                dbUsersStatus2 = dbUsers4;
                            } else if (baseUpdate instanceof TLRPC.TL_updateUserPhoto) {
                                TLRPC.TL_updateUserPhoto update7 = (TLRPC.TL_updateUserPhoto) baseUpdate;
                                TLRPC.User currentUser3 = getUser(Integer.valueOf(update7.user_id));
                                if (currentUser3 != null) {
                                    currentUser3.photo = update7.photo;
                                }
                                TLRPC.User toDbUser3 = new TLRPC.TL_user();
                                toDbUser3.id = update7.user_id;
                                toDbUser3.photo = update7.photo;
                                dbUsersStatus2 = dbUsers4;
                                dbUsersStatus2.add(toDbUser3);
                                updateMask = updateMask5;
                            } else {
                                dbUsersStatus2 = dbUsers4;
                                if (baseUpdate instanceof TLRPC.TL_updateUserPhone) {
                                    TLRPC.TL_updateUserPhone update8 = (TLRPC.TL_updateUserPhone) baseUpdate;
                                    final TLRPC.User currentUser4 = getUser(Integer.valueOf(update8.user_id));
                                    if (currentUser4 != null) {
                                        currentUser4.phone = update8.phone;
                                        Utilities.phoneBookQueue.postRunnable(new Runnable() {
                                            @Override
                                            public final void run() {
                                                MessagesController.this.lambda$null$282$MessagesController(currentUser4);
                                            }
                                        });
                                        if (UserObject.isUserSelf(currentUser4)) {
                                            getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
                                        }
                                    }
                                    TLRPC.User toDbUser4 = new TLRPC.TL_user();
                                    toDbUser4.id = update8.user_id;
                                    toDbUser4.phone = update8.phone;
                                    dbUsersStatus2.add(toDbUser4);
                                    updateMask = updateMask5;
                                } else if (baseUpdate instanceof TLRPC.TL_updateNotifySettings) {
                                    TLRPC.TL_updateNotifySettings update9 = (TLRPC.TL_updateNotifySettings) baseUpdate;
                                    if (update9.notify_settings instanceof TLRPC.TL_peerNotifySettings) {
                                        if (editor2 != null) {
                                            editor = editor2;
                                        } else {
                                            SharedPreferences.Editor editor3 = this.notificationsPreferences.edit();
                                            editor = editor3;
                                        }
                                        int currentTime1 = getConnectionsManager().getCurrentTime();
                                        if (update9.peer instanceof TLRPC.TL_notifyPeer) {
                                            TLRPC.TL_notifyPeer notifyPeer = (TLRPC.TL_notifyPeer) update9.peer;
                                            if (notifyPeer.peer.user_id != 0) {
                                                dialog_id = notifyPeer.peer.user_id;
                                            } else if (notifyPeer.peer.chat_id != 0) {
                                                dialog_id = -notifyPeer.peer.chat_id;
                                            } else {
                                                dialog_id = -notifyPeer.peer.channel_id;
                                            }
                                            TLRPC.Dialog dialog3 = this.dialogs_dict.get(dialog_id);
                                            if (dialog3 != null) {
                                                dialog3.notify_settings = update9.notify_settings;
                                            }
                                            if ((update9.notify_settings.flags & 2) != 0) {
                                                editor.putBoolean("silent_" + dialog_id, update9.notify_settings.silent);
                                            } else {
                                                editor.remove("silent_" + dialog_id);
                                            }
                                            if ((update9.notify_settings.flags & 4) != 0) {
                                                if (update9.notify_settings.mute_until > currentTime1) {
                                                    int until = 0;
                                                    if (update9.notify_settings.mute_until > currentTime1 + 31536000) {
                                                        editor.putInt("notify2_" + dialog_id, 2);
                                                        if (dialog3 != null) {
                                                            update9.notify_settings.mute_until = Integer.MAX_VALUE;
                                                        }
                                                    } else {
                                                        until = update9.notify_settings.mute_until;
                                                        editor.putInt("notify2_" + dialog_id, 3);
                                                        editor.putInt("notifyuntil_" + dialog_id, update9.notify_settings.mute_until);
                                                        if (dialog3 != null) {
                                                            update9.notify_settings.mute_until = until;
                                                        }
                                                    }
                                                    getMessagesStorage().setDialogFlags(dialog_id, (until << 32) | 1);
                                                    getNotificationsController().removeNotificationsForDialog(dialog_id);
                                                } else {
                                                    if (dialog3 == null) {
                                                        i3 = 0;
                                                    } else {
                                                        i3 = 0;
                                                        update9.notify_settings.mute_until = 0;
                                                    }
                                                    editor.putInt("notify2_" + dialog_id, i3);
                                                    getMessagesStorage().setDialogFlags(dialog_id, 0L);
                                                }
                                            } else {
                                                if (dialog3 != null) {
                                                    update9.notify_settings.mute_until = 0;
                                                }
                                                editor.remove("notify2_" + dialog_id);
                                                getMessagesStorage().setDialogFlags(dialog_id, 0L);
                                            }
                                        } else if (update9.peer instanceof TLRPC.TL_notifyChats) {
                                            if ((update9.notify_settings.flags & 1) != 0) {
                                                editor.putBoolean("EnablePreviewGroup", update9.notify_settings.show_previews);
                                            }
                                            int i5 = update9.notify_settings.flags;
                                            if ((update9.notify_settings.flags & 4) != 0) {
                                                editor.putInt("EnableGroup2", update9.notify_settings.mute_until);
                                            }
                                        } else if (update9.peer instanceof TLRPC.TL_notifyUsers) {
                                            if ((update9.notify_settings.flags & 1) != 0) {
                                                editor.putBoolean("EnablePreviewAll", update9.notify_settings.show_previews);
                                            }
                                            int i6 = update9.notify_settings.flags;
                                            if ((update9.notify_settings.flags & 4) != 0) {
                                                editor.putInt("EnableAll2", update9.notify_settings.mute_until);
                                            }
                                        } else if (update9.peer instanceof TLRPC.TL_notifyBroadcasts) {
                                            if ((update9.notify_settings.flags & 1) != 0) {
                                                editor.putBoolean("EnablePreviewChannel", update9.notify_settings.show_previews);
                                            }
                                            int i7 = update9.notify_settings.flags;
                                            if ((update9.notify_settings.flags & 4) != 0) {
                                                editor.putInt("EnableChannel2", update9.notify_settings.mute_until);
                                            }
                                        }
                                        editor2 = editor;
                                    }
                                    updateMask3 = updateMask5;
                                } else if (baseUpdate instanceof TLRPC.TL_updateChannel) {
                                    final TLRPC.TL_updateChannel update10 = (TLRPC.TL_updateChannel) baseUpdate;
                                    TLRPC.Dialog dialog4 = this.dialogs_dict.get(-update10.channel_id);
                                    TLRPC.Chat chat = getChat(Integer.valueOf(update10.channel_id));
                                    if (chat != null) {
                                        if (dialog4 == null && (chat instanceof TLRPC.TL_channel) && !chat.left) {
                                            Utilities.stageQueue.postRunnable(new Runnable() {
                                                @Override
                                                public final void run() {
                                                    MessagesController.this.lambda$null$283$MessagesController(update10);
                                                }
                                            });
                                        } else if (chat.left && dialog4 != null && ((dialog = this.proxyDialog) == null || dialog.id != dialog4.id)) {
                                            deleteDialog(dialog4.id, 0);
                                        }
                                    }
                                    loadFullChat(update10.channel_id, 0, true);
                                    updateMask3 = updateMask5 | 8192;
                                } else {
                                    updateMask = updateMask5;
                                    if (baseUpdate instanceof TLRPC.TL_updateChatDefaultBannedRights) {
                                        TLRPC.TL_updateChatDefaultBannedRights update11 = (TLRPC.TL_updateChatDefaultBannedRights) baseUpdate;
                                        if (update11.peer.channel_id != 0) {
                                            chatId = update11.peer.channel_id;
                                        } else {
                                            chatId = update11.peer.chat_id;
                                        }
                                        final TLRPC.Chat chat2 = getChat(Integer.valueOf(chatId));
                                        if (chat2 != null) {
                                            chat2.default_banned_rights = update11.default_banned_rights;
                                            AndroidUtilities.runOnUIThread(new Runnable() {
                                                @Override
                                                public final void run() {
                                                    MessagesController.this.lambda$null$284$MessagesController(chat2);
                                                }
                                            });
                                        }
                                    } else if (baseUpdate instanceof TLRPC.TL_updateStickerSets) {
                                        TLRPC.TL_updateStickerSets tL_updateStickerSets = (TLRPC.TL_updateStickerSets) baseUpdate;
                                        getMediaDataController().loadStickers(0, false, true);
                                    } else if (baseUpdate instanceof TLRPC.TL_updateStickerSetsOrder) {
                                        getMediaDataController().reorderStickers(((TLRPC.TL_updateStickerSetsOrder) baseUpdate).masks ? 1 : 0, ((TLRPC.TL_updateStickerSetsOrder) baseUpdate).order);
                                    } else if (baseUpdate instanceof TLRPC.TL_updateFavedStickers) {
                                        getMediaDataController().loadRecents(2, false, false, true);
                                    } else if (baseUpdate instanceof TLRPC.TL_updateContactsReset) {
                                        getContactsController().forceImportContacts();
                                    } else if (baseUpdate instanceof TLRPC.TL_updateNewStickerSet) {
                                        getMediaDataController().addNewStickerSet(((TLRPC.TL_updateNewStickerSet) baseUpdate).stickerset);
                                    } else if (baseUpdate instanceof TLRPC.TL_updateSavedGifs) {
                                        SharedPreferences.Editor editor22 = this.emojiPreferences.edit();
                                        editor22.putLong("lastGifLoadTime", 0L).commit();
                                    } else if (baseUpdate instanceof TLRPC.TL_updateRecentStickers) {
                                        SharedPreferences.Editor editor23 = this.emojiPreferences.edit();
                                        editor23.putLong("lastStickersLoadTime", 0L).commit();
                                    } else if (baseUpdate instanceof TLRPC.TL_updateDraftMessage) {
                                        TLRPC.TL_updateDraftMessage update12 = (TLRPC.TL_updateDraftMessage) baseUpdate;
                                        forceDialogsUpdate3 = true;
                                        TLRPC.Peer peer2 = ((TLRPC.TL_updateDraftMessage) baseUpdate).peer;
                                        if (peer2.user_id != 0) {
                                            did2 = peer2.user_id;
                                        } else if (peer2.channel_id != 0) {
                                            did2 = -peer2.channel_id;
                                        } else {
                                            did2 = -peer2.chat_id;
                                        }
                                        getMediaDataController().saveDraft(did2, update12.draft, null, true);
                                        updateMask3 = updateMask;
                                    } else if (baseUpdate instanceof TLRPC.TL_updateReadFeaturedStickers) {
                                        getMediaDataController().markFaturedStickersAsRead(false);
                                    } else if (baseUpdate instanceof TLRPC.TL_updatePhoneCall) {
                                        TLRPC.TL_updatePhoneCall upd = (TLRPC.TL_updatePhoneCall) baseUpdate;
                                        TLRPC.PhoneCall call = upd.phone_call;
                                        VoIPService svc = VoIPService.getSharedInstance();
                                        if (BuildVars.LOGS_ENABLED) {
                                            FileLog.d("Received call in update: " + call);
                                            FileLog.d("call id " + call.id);
                                        }
                                        if (call instanceof TLRPC.TL_phoneCallRequested) {
                                            if (call.date + (this.callRingTimeout / 1000) < getConnectionsManager().getCurrentTime()) {
                                                if (BuildVars.LOGS_ENABLED) {
                                                    FileLog.d("ignoring too old call");
                                                }
                                            } else if (Build.VERSION.SDK_INT >= 21 && !NotificationManagerCompat.from(ApplicationLoader.applicationContext).areNotificationsEnabled()) {
                                                if (BuildVars.LOGS_ENABLED) {
                                                    FileLog.d("Ignoring incoming call because notifications are disabled in system");
                                                }
                                            } else {
                                                TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService("phone");
                                                if (svc != null || VoIPService.callIShouldHavePutIntoIntent != null || tm.getCallState() != 0) {
                                                    if (BuildVars.LOGS_ENABLED) {
                                                        FileLog.d("Auto-declining call " + call.id + " because there's already active one");
                                                    }
                                                    TLRPC.TL_phone_discardCall req = new TLRPC.TL_phone_discardCall();
                                                    req.peer = new TLRPC.TL_inputPhoneCall();
                                                    req.peer.access_hash = call.access_hash;
                                                    req.peer.id = call.id;
                                                    req.reason = new TLRPC.TL_phoneCallDiscardReasonBusy();
                                                    getConnectionsManager().sendRequest(req, new RequestDelegate() {
                                                        @Override
                                                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                                            MessagesController.this.lambda$null$285$MessagesController(tLObject, tL_error);
                                                        }
                                                    });
                                                } else {
                                                    if (BuildVars.LOGS_ENABLED) {
                                                        FileLog.d("Starting service for call " + call.id);
                                                    }
                                                    VoIPService.callIShouldHavePutIntoIntent = call;
                                                    Intent intent = new Intent(ApplicationLoader.applicationContext, VoIPService.class);
                                                    intent.putExtra("is_outgoing", false);
                                                    intent.putExtra("user_id", call.participant_id == getUserConfig().getClientUserId() ? call.admin_id : call.participant_id);
                                                    intent.putExtra("account", this.currentAccount);
                                                    try {
                                                        if (Build.VERSION.SDK_INT >= 26) {
                                                            ApplicationLoader.applicationContext.startForegroundService(intent);
                                                        } else {
                                                            ApplicationLoader.applicationContext.startService(intent);
                                                        }
                                                    } catch (Throwable e) {
                                                        FileLog.e(e);
                                                    }
                                                }
                                            }
                                        } else if (svc != null && call != null) {
                                            svc.onCallUpdated(call);
                                        } else if (VoIPService.callIShouldHavePutIntoIntent != null) {
                                            if (BuildVars.LOGS_ENABLED) {
                                                FileLog.d("Updated the call while the service is starting");
                                            }
                                            if (call.id == VoIPService.callIShouldHavePutIntoIntent.id) {
                                                VoIPService.callIShouldHavePutIntoIntent = call;
                                            }
                                        }
                                    } else if (baseUpdate instanceof TLRPC.TL_updateDialogUnreadMark) {
                                        TLRPC.TL_updateDialogUnreadMark update13 = (TLRPC.TL_updateDialogUnreadMark) baseUpdate;
                                        if (update13.peer instanceof TLRPC.TL_dialogPeer) {
                                            TLRPC.TL_dialogPeer dialogPeer2 = (TLRPC.TL_dialogPeer) update13.peer;
                                            if (dialogPeer2.peer.user_id != 0) {
                                                did = dialogPeer2.peer.user_id;
                                            } else if (dialogPeer2.peer.chat_id != 0) {
                                                did = -dialogPeer2.peer.chat_id;
                                            } else {
                                                did = -dialogPeer2.peer.channel_id;
                                            }
                                        } else {
                                            did = 0;
                                        }
                                        getMessagesStorage().setDialogUnread(did, update13.unread);
                                        TLRPC.Dialog dialog5 = this.dialogs_dict.get(did);
                                        if (dialog5 != null && dialog5.unread_mark != update13.unread) {
                                            dialog5.unread_mark = update13.unread;
                                            if (dialog5.unread_count == 0 && !isDialogMuted(did)) {
                                                if (dialog5.unread_mark) {
                                                    this.unreadUnmutedDialogs++;
                                                } else {
                                                    this.unreadUnmutedDialogs--;
                                                }
                                            }
                                            if (dialog5.unread_count == 0 && dialog5.unread_mark) {
                                                this.dialogsUnreadOnly.add(dialog5);
                                            }
                                            updateMask3 = updateMask | 256;
                                        } else {
                                            updateMask3 = updateMask;
                                        }
                                    } else if (baseUpdate instanceof TLRPC.TL_updateMessagePoll) {
                                        TLRPC.TL_updateMessagePoll update14 = (TLRPC.TL_updateMessagePoll) baseUpdate;
                                        getNotificationCenter().postNotificationName(NotificationCenter.didUpdatePollResults, Long.valueOf(update14.poll_id), update14.poll, update14.results);
                                    } else if (baseUpdate instanceof TLRPC.TL_updatePeerSettings) {
                                        TLRPC.TL_updatePeerSettings update15 = (TLRPC.TL_updatePeerSettings) baseUpdate;
                                        if (update15.peer instanceof TLRPC.TL_peerUser) {
                                            dialogId2 = update15.peer.user_id;
                                        } else if (update15.peer instanceof TLRPC.TL_peerChat) {
                                            dialogId2 = -update15.peer.chat_id;
                                        } else {
                                            dialogId2 = -update15.peer.channel_id;
                                        }
                                        savePeerSettings(dialogId2, update15.settings, true);
                                    } else if (baseUpdate instanceof TLRPC.TL_updatePeerLocated) {
                                        getNotificationCenter().postNotificationName(NotificationCenter.newPeopleNearbyAvailable, baseUpdate);
                                    } else if (baseUpdate instanceof TLRPC.TL_updateMessageReactions) {
                                        TLRPC.TL_updateMessageReactions update16 = (TLRPC.TL_updateMessageReactions) baseUpdate;
                                        if (update16.peer.chat_id != 0) {
                                            dialogId = -update16.peer.chat_id;
                                        } else if (update16.peer.channel_id != 0) {
                                            dialogId = -update16.peer.channel_id;
                                        } else {
                                            dialogId = update16.peer.user_id;
                                        }
                                        getNotificationCenter().postNotificationName(NotificationCenter.didUpdateReactions, Long.valueOf(dialogId), Integer.valueOf(update16.msg_id), update16.reactions);
                                    } else if (baseUpdate instanceof TLRPC.TL_updateTheme) {
                                        TLRPC.TL_theme theme = (TLRPC.TL_theme) ((TLRPC.TL_updateTheme) baseUpdate).theme;
                                        Theme.setThemeUploadInfo(null, theme, true);
                                    }
                                }
                            }
                            a++;
                            arrayList = updatesOnMainThreadFinal;
                            dbUsers = dbUsersStatus2;
                            size2 = size;
                            dbUsers2 = dbUsersStatus;
                            i4 = 0;
                        }
                    }
                }
                updateMask3 = updateMask;
                a++;
                arrayList = updatesOnMainThreadFinal;
                dbUsers = dbUsersStatus2;
                size2 = size;
                dbUsers2 = dbUsersStatus;
                i4 = 0;
            }
            int updateMask6 = updateMask3;
            ArrayList<TLRPC.User> dbUsersStatus3 = dbUsers2;
            ArrayList<TLRPC.User> dbUsersStatus4 = dbUsers;
            if (editor2 == null) {
                z = false;
            } else {
                editor2.commit();
                z = false;
                getNotificationCenter().postNotificationName(NotificationCenter.notificationsSettingsUpdated, new Object[0]);
            }
            i = 1;
            getMessagesStorage().updateUsers(dbUsersStatus3, true, true, true);
            getMessagesStorage().updateUsers(dbUsersStatus4, z, true, true);
            updateMask2 = updateMask6;
            forceDialogsUpdate2 = forceDialogsUpdate3;
            r2 = z;
        }
        if (webPagesFinal != null) {
            NotificationCenter notificationCenter = getNotificationCenter();
            int i8 = NotificationCenter.didReceivedWebpagesInUpdates;
            Object[] objArr = new Object[i];
            objArr[r2] = webPagesFinal;
            notificationCenter.postNotificationName(i8, objArr);
            int i9 = 0;
            while (i9 < 2) {
                HashMap<String, ArrayList<MessageObject>> map2 = i9 == i ? this.reloadingScheduledWebpages : this.reloadingWebpages;
                LongSparseArray<ArrayList<MessageObject>> array2 = i9 == i ? this.reloadingScheduledWebpagesPending : this.reloadingWebpagesPending;
                int b3 = 0;
                int size4 = webPagesFinal.size();
                while (b3 < size4) {
                    long key = webPagesFinal.keyAt(b3);
                    ArrayList<MessageObject> arrayList2 = array2.get(key);
                    array2.remove(key);
                    if (arrayList2 == null) {
                        map = map2;
                        array = array2;
                    } else {
                        TLRPC.WebPage webpage = (TLRPC.WebPage) webPagesFinal.valueAt(b3);
                        ArrayList<TLRPC.Message> arr = new ArrayList<>();
                        long dialog_id2 = 0;
                        map = map2;
                        if (!(webpage instanceof TLRPC.TL_webPage) && !(webpage instanceof TLRPC.TL_webPageEmpty)) {
                            long key2 = webpage.id;
                            array2.put(key2, arrayList2);
                            if (!arr.isEmpty()) {
                                array = array2;
                            } else {
                                getMessagesStorage().putMessages(arr, true, true, false, getDownloadController().getAutodownloadMask(), i9 == 1);
                                array = array2;
                                getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(dialog_id2), arrayList2);
                            }
                        }
                        int size24 = arrayList2.size();
                        for (int a2 = 0; a2 < size24; a2++) {
                            arrayList2.get(a2).messageOwner.media.webpage = webpage;
                            if (a2 == 0) {
                                dialog_id2 = arrayList2.get(a2).getDialogId();
                                ImageLoader.saveMessageThumbs(arrayList2.get(a2).messageOwner);
                            }
                            arr.add(arrayList2.get(a2).messageOwner);
                        }
                        if (!arr.isEmpty()) {
                        }
                    }
                    b3++;
                    map2 = map;
                    array2 = array;
                }
                i9++;
                i = 1;
            }
        }
        boolean updateDialogs2 = false;
        if (messagesFinal != null) {
            int size5 = messagesFinal.size();
            for (int a3 = 0; a3 < size5; a3++) {
                long key3 = messagesFinal.keyAt(a3);
                ArrayList<MessageObject> value = (ArrayList) messagesFinal.valueAt(a3);
                updateInterfaceWithMessages(key3, value, false);
            }
            updateDialogs2 = true;
            obj = null;
        } else if (!forceDialogsUpdate2) {
            obj = null;
        } else {
            obj = null;
            sortDialogs(null);
            updateDialogs2 = true;
        }
        Object obj2 = obj;
        if (scheduledMessagesFinal != null) {
            int size6 = scheduledMessagesFinal.size();
            for (int a4 = 0; a4 < size6; a4++) {
                long key4 = scheduledMessagesFinal.keyAt(a4);
                ArrayList<MessageObject> value2 = (ArrayList) scheduledMessagesFinal.valueAt(a4);
                updateInterfaceWithMessages(key4, value2, true);
            }
        }
        if (editingMessagesFinal != null) {
            int b4 = 0;
            int size7 = editingMessagesFinal.size();
            while (b4 < size7) {
                long dialog_id3 = editingMessagesFinal.keyAt(b4);
                ArrayList<MessageObject> arrayList3 = (ArrayList) editingMessagesFinal.valueAt(b4);
                MessageObject oldObject = this.dialogMessage.get(dialog_id3);
                if (oldObject == null) {
                    forceDialogsUpdate = forceDialogsUpdate2;
                    updateDialogs = updateDialogs2;
                } else {
                    int a5 = 0;
                    int size25 = arrayList3.size();
                    while (true) {
                        if (a5 >= size25) {
                            forceDialogsUpdate = forceDialogsUpdate2;
                            updateDialogs = updateDialogs2;
                            break;
                        }
                        forceDialogsUpdate = forceDialogsUpdate2;
                        MessageObject newMessage = arrayList3.get(a5);
                        boolean updateDialogs3 = updateDialogs2;
                        if (oldObject.getId() == newMessage.getId()) {
                            this.dialogMessage.put(dialog_id3, newMessage);
                            if (newMessage.messageOwner.to_id != null && newMessage.messageOwner.to_id.channel_id == 0) {
                                this.dialogMessagesByIds.put(newMessage.getId(), newMessage);
                            }
                            updateDialogs = true;
                        } else if (oldObject.getDialogId() != newMessage.getDialogId() || !(oldObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) || oldObject.replyMessageObject == null || oldObject.replyMessageObject.getId() != newMessage.getId()) {
                            a5++;
                            updateDialogs2 = updateDialogs3;
                            forceDialogsUpdate2 = forceDialogsUpdate;
                        } else {
                            oldObject.replyMessageObject = newMessage;
                            oldObject.generatePinMessageText(null, null);
                            updateDialogs = true;
                            break;
                        }
                    }
                }
                getMediaDataController().loadReplyMessagesForMessages(arrayList3, dialog_id3, false);
                getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(dialog_id3), arrayList3, false);
                b4++;
                updateDialogs2 = updateDialogs;
                forceDialogsUpdate2 = forceDialogsUpdate;
                obj2 = null;
            }
        }
        if (updateDialogs2) {
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        }
        if (printChangedArg) {
            updateMask2 |= 64;
        }
        if (contactsIdsFinal != null) {
            updateMask2 = updateMask2 | 1 | 128;
        }
        if (chatInfoToUpdateFinal != null) {
            int size8 = chatInfoToUpdateFinal.size();
            for (int a6 = 0; a6 < size8; a6++) {
                TLRPC.ChatParticipants info = (TLRPC.ChatParticipants) chatInfoToUpdateFinal.get(a6);
                getMessagesStorage().updateChatParticipants(info);
            }
        }
        if (channelViewsFinal == null) {
            i2 = 1;
        } else {
            i2 = 1;
            getNotificationCenter().postNotificationName(NotificationCenter.didUpdatedMessagesViews, channelViewsFinal);
        }
        if (updateMask2 != 0) {
            NotificationCenter notificationCenter2 = getNotificationCenter();
            int i10 = NotificationCenter.updateInterfaces;
            Object[] objArr2 = new Object[i2];
            objArr2[0] = Integer.valueOf(updateMask2);
            notificationCenter2.postNotificationName(i10, objArr2);
        }
    }

    public void lambda$null$282$MessagesController(TLRPC.User currentUser) {
        getContactsController().addContactToPhoneBook(currentUser, true);
    }

    public void lambda$null$283$MessagesController(TLRPC.TL_updateChannel update) {
        getChannelDifference(update.channel_id, 1, 0L, null);
    }

    public void lambda$null$284$MessagesController(TLRPC.Chat chat) {
        getNotificationCenter().postNotificationName(NotificationCenter.channelRightsUpdated, chat);
    }

    public void lambda$null$285$MessagesController(TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            TLRPC.Updates updates1 = (TLRPC.Updates) response;
            processUpdates(updates1, false);
        }
    }

    public void lambda$processUpdateArray$288$MessagesController(final SparseLongArray markAsReadMessagesInboxFinal, final SparseLongArray markAsReadMessagesOutboxFinal, final SparseIntArray markAsReadEncryptedFinal, final ArrayList markAsReadMessagesFinal, final SparseArray deletedMessagesFinal, final SparseArray scheduledDeletedMessagesFinal, final SparseIntArray clearHistoryMessagesFinal) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$287$MessagesController(markAsReadMessagesInboxFinal, markAsReadMessagesOutboxFinal, markAsReadEncryptedFinal, markAsReadMessagesFinal, deletedMessagesFinal, scheduledDeletedMessagesFinal, clearHistoryMessagesFinal);
            }
        });
    }

    public void lambda$null$287$MessagesController(SparseLongArray markAsReadMessagesInboxFinal, SparseLongArray markAsReadMessagesOutboxFinal, SparseIntArray markAsReadEncryptedFinal, ArrayList markAsReadMessagesFinal, SparseArray deletedMessagesFinal, SparseArray scheduledDeletedMessagesFinal, SparseIntArray clearHistoryMessagesFinal) {
        MessageObject obj;
        MessageObject obj2;
        int i;
        MessageObject message;
        SparseLongArray sparseLongArray = markAsReadMessagesInboxFinal;
        int updateMask = 0;
        char c = 2;
        if (sparseLongArray != null || markAsReadMessagesOutboxFinal != null) {
            getNotificationCenter().postNotificationName(NotificationCenter.messagesRead, sparseLongArray, markAsReadMessagesOutboxFinal);
            if (sparseLongArray != null) {
                getNotificationsController().processReadMessages(markAsReadMessagesInboxFinal, 0L, 0, 0, false);
                SharedPreferences.Editor editor = this.notificationsPreferences.edit();
                int b = 0;
                int size = markAsReadMessagesInboxFinal.size();
                while (b < size) {
                    int key = sparseLongArray.keyAt(b);
                    int messageId = (int) sparseLongArray.valueAt(b);
                    TLRPC.Dialog dialog = this.dialogs_dict.get(key);
                    if (dialog != null && dialog.top_message > 0 && dialog.top_message <= messageId && (obj2 = this.dialogMessage.get(dialog.id)) != null && !obj2.isOut()) {
                        obj2.setIsRead();
                        updateMask |= 256;
                    }
                    if (key != getUserConfig().getClientUserId()) {
                        editor.remove("diditem" + key);
                        editor.remove("diditemo" + key);
                    }
                    b++;
                    sparseLongArray = markAsReadMessagesInboxFinal;
                }
                editor.commit();
            }
            if (markAsReadMessagesOutboxFinal != null) {
                int size2 = markAsReadMessagesOutboxFinal.size();
                for (int b2 = 0; b2 < size2; b2++) {
                    int key2 = markAsReadMessagesOutboxFinal.keyAt(b2);
                    int messageId2 = (int) markAsReadMessagesOutboxFinal.valueAt(b2);
                    TLRPC.Dialog dialog2 = this.dialogs_dict.get(key2);
                    if (dialog2 != null && dialog2.top_message > 0 && dialog2.top_message <= messageId2 && (obj = this.dialogMessage.get(dialog2.id)) != null && obj.isOut()) {
                        obj.setIsRead();
                        updateMask |= 256;
                    }
                }
            }
        }
        if (markAsReadEncryptedFinal == null) {
            i = 1;
        } else {
            int size3 = markAsReadEncryptedFinal.size();
            for (int a = 0; a < size3; a++) {
                int key3 = markAsReadEncryptedFinal.keyAt(a);
                int value = markAsReadEncryptedFinal.valueAt(a);
                getNotificationCenter().postNotificationName(NotificationCenter.messagesReadEncrypted, Integer.valueOf(key3), Integer.valueOf(value));
                long dialog_id = key3 << 32;
                if (this.dialogs_dict.get(dialog_id) != null && (message = this.dialogMessage.get(dialog_id)) != null && message.messageOwner.date <= value) {
                    message.setIsRead();
                    updateMask |= 256;
                }
            }
            i = 1;
        }
        if (markAsReadMessagesFinal != null) {
            NotificationCenter notificationCenter = getNotificationCenter();
            int i2 = NotificationCenter.messagesReadContent;
            Object[] objArr = new Object[i];
            objArr[0] = markAsReadMessagesFinal;
            notificationCenter.postNotificationName(i2, objArr);
        }
        if (deletedMessagesFinal != null) {
            int a2 = 0;
            int size4 = deletedMessagesFinal.size();
            while (a2 < size4) {
                int key4 = deletedMessagesFinal.keyAt(a2);
                ArrayList<Integer> arrayList = (ArrayList) deletedMessagesFinal.valueAt(a2);
                if (arrayList != null) {
                    NotificationCenter notificationCenter2 = getNotificationCenter();
                    int i3 = NotificationCenter.messagesDeleted;
                    Object[] objArr2 = new Object[3];
                    objArr2[0] = arrayList;
                    objArr2[i] = Integer.valueOf(key4);
                    objArr2[c] = false;
                    notificationCenter2.postNotificationName(i3, objArr2);
                    if (key4 == 0) {
                        int size22 = arrayList.size();
                        for (int b3 = 0; b3 < size22; b3++) {
                            MessageObject obj3 = this.dialogMessagesByIds.get(arrayList.get(b3).intValue());
                            if (obj3 != null) {
                                obj3.deleted = i;
                            }
                        }
                    } else {
                        MessageObject obj4 = this.dialogMessage.get(-key4);
                        if (obj4 != null) {
                            int b4 = 0;
                            int size23 = arrayList.size();
                            while (true) {
                                if (b4 < size23) {
                                    if (obj4.getId() != arrayList.get(b4).intValue()) {
                                        b4++;
                                    } else {
                                        obj4.deleted = i;
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                }
                a2++;
                c = 2;
            }
            getNotificationsController().removeDeletedMessagesFromNotifications(deletedMessagesFinal);
        }
        if (scheduledDeletedMessagesFinal != null) {
            int size5 = scheduledDeletedMessagesFinal.size();
            for (int a3 = 0; a3 < size5; a3++) {
                int key5 = scheduledDeletedMessagesFinal.keyAt(a3);
                ArrayList<Integer> arrayList2 = (ArrayList) scheduledDeletedMessagesFinal.valueAt(a3);
                if (arrayList2 != null) {
                    NotificationCenter notificationCenter3 = NotificationCenter.getInstance(this.currentAccount);
                    int i4 = NotificationCenter.messagesDeleted;
                    Object[] objArr3 = new Object[3];
                    objArr3[0] = arrayList2;
                    objArr3[i] = Integer.valueOf(key5);
                    objArr3[2] = Boolean.valueOf((boolean) i);
                    notificationCenter3.postNotificationName(i4, objArr3);
                }
            }
        }
        if (clearHistoryMessagesFinal != null) {
            int a4 = 0;
            int size6 = clearHistoryMessagesFinal.size();
            while (true) {
                if (a4 >= size6) {
                    break;
                }
                int key6 = clearHistoryMessagesFinal.keyAt(a4);
                int id = clearHistoryMessagesFinal.valueAt(a4);
                long did = -key6;
                getNotificationCenter().postNotificationName(NotificationCenter.historyCleared, Long.valueOf(did), Integer.valueOf(id));
                MessageObject obj5 = this.dialogMessage.get(did);
                if (obj5 == null || obj5.getId() > id) {
                    a4++;
                } else {
                    obj5.deleted = true;
                    break;
                }
            }
            getNotificationsController().removeDeletedHisoryFromNotifications(clearHistoryMessagesFinal);
        }
        if (updateMask != 0) {
            getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, Integer.valueOf(updateMask));
        }
    }

    public void lambda$processUpdateArray$289$MessagesController(ArrayList arrayList, int key) {
        ArrayList<Long> dialogIds = getMessagesStorage().markMessagesAsDeleted(arrayList, false, key, true, false);
        getMessagesStorage().updateDialogsWithDeletedMessages(arrayList, dialogIds, false, key);
    }

    public void lambda$processUpdateArray$290$MessagesController(int key, int id) {
        ArrayList<Long> dialogIds = getMessagesStorage().markMessagesAsDeleted(key, id, false, true);
        getMessagesStorage().updateDialogsWithDeletedMessages(new ArrayList<>(), dialogIds, false, key);
    }

    public boolean isDialogMuted(long dialog_id) {
        SharedPreferences sharedPreferences = this.notificationsPreferences;
        int mute_type = sharedPreferences.getInt("notify2_" + dialog_id, -1);
        if (mute_type == -1) {
            return true ^ getNotificationsController().isGlobalNotificationsEnabled(dialog_id);
        }
        if (mute_type == 2) {
            return true;
        }
        if (mute_type == 3) {
            SharedPreferences sharedPreferences2 = this.notificationsPreferences;
            int mute_until = sharedPreferences2.getInt("notifyuntil_" + dialog_id, 0);
            if (mute_until >= getConnectionsManager().getCurrentTime()) {
                return true;
            }
        }
        return false;
    }

    private boolean updatePrintingUsersWithNewMessages(long uid, ArrayList<MessageObject> messages) {
        if (uid > 0) {
            if (this.printingUsers.get(Long.valueOf(uid)) != null) {
                this.printingUsers.remove(Long.valueOf(uid));
                return true;
            }
            return false;
        } else if (uid < 0) {
            ArrayList<Integer> messagesUsers = new ArrayList<>();
            Iterator<MessageObject> it = messages.iterator();
            while (it.hasNext()) {
                MessageObject message = it.next();
                if (!messagesUsers.contains(Integer.valueOf(message.messageOwner.from_id))) {
                    messagesUsers.add(Integer.valueOf(message.messageOwner.from_id));
                }
            }
            ArrayList<PrintingUser> arr = this.printingUsers.get(Long.valueOf(uid));
            boolean changed = false;
            if (arr != null) {
                int a = 0;
                while (a < arr.size()) {
                    PrintingUser user = arr.get(a);
                    if (messagesUsers.contains(Integer.valueOf(user.userId))) {
                        arr.remove(a);
                        a--;
                        if (arr.isEmpty()) {
                            this.printingUsers.remove(Long.valueOf(uid));
                        }
                        changed = true;
                    }
                    a++;
                }
            }
            return changed;
        } else {
            return false;
        }
    }

    public void updateInterfaceWithMessages(final long uid, ArrayList<MessageObject> messages, boolean scheduled) {
        if (messages == null || messages.isEmpty()) {
            return;
        }
        boolean isEncryptedChat = ((int) uid) == 0;
        MessageObject lastMessage = null;
        int channelId = 0;
        boolean updateRating = false;
        boolean hasNotOutMessage = false;
        if (!scheduled) {
            for (int a = 0; a < messages.size(); a++) {
                MessageObject message = messages.get(a);
                if (lastMessage == null || ((!isEncryptedChat && message.getId() > lastMessage.getId()) || (((isEncryptedChat || (message.getId() < 0 && lastMessage.getId() < 0)) && message.getId() < lastMessage.getId()) || message.messageOwner.date > lastMessage.messageOwner.date))) {
                    lastMessage = message;
                    if (message.messageOwner.to_id.channel_id != 0) {
                        channelId = message.messageOwner.to_id.channel_id;
                    }
                }
                if (!hasNotOutMessage && !message.isOut()) {
                    hasNotOutMessage = true;
                }
                if (message.isOut() && !message.isSending() && !message.isForwarded()) {
                    if (message.isNewGif()) {
                        getMediaDataController().addRecentGif(message.messageOwner.media.document, message.messageOwner.date);
                    } else if (!message.isAnimatedEmoji() && (message.isSticker() || message.isAnimatedSticker())) {
                        getMediaDataController().addRecentSticker(0, message, message.messageOwner.media.document, message.messageOwner.date, false);
                    }
                }
                if (message.isOut() && message.isSent()) {
                    updateRating = true;
                }
            }
        }
        getMediaDataController().loadReplyMessagesForMessages(messages, uid, scheduled);
        getNotificationCenter().postNotificationName(NotificationCenter.didReceiveNewMessages, Long.valueOf(uid), messages, Boolean.valueOf(scheduled));
        if (lastMessage == null || scheduled) {
            return;
        }
        TLRPC.TL_dialog dialog = (TLRPC.TL_dialog) this.dialogs_dict.get(uid);
        if (lastMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
            if (dialog != null) {
                this.allDialogs.remove(dialog);
                this.dialogsServerOnly.remove(dialog);
                this.dialogsCanAddUsers.remove(dialog);
                this.dialogsChannelsOnly.remove(dialog);
                this.dialogsGroupsOnly.remove(dialog);
                this.dialogsUnreadOnly.remove(dialog);
                this.dialogsUsersOnly.remove(dialog);
                this.dialogsForward.remove(dialog);
                this.dialogs_dict.remove(dialog.id);
                this.dialogs_read_inbox_max.remove(Long.valueOf(dialog.id));
                this.dialogs_read_outbox_max.remove(Long.valueOf(dialog.id));
                int offset = this.nextDialogsCacheOffset.get(dialog.folder_id, 0);
                if (offset > 0) {
                    this.nextDialogsCacheOffset.put(dialog.folder_id, offset - 1);
                }
                this.dialogMessage.remove(dialog.id);
                ArrayList<TLRPC.Dialog> dialogs = this.dialogsByFolder.get(dialog.folder_id);
                if (dialogs != null) {
                    dialogs.remove(dialog);
                }
                MessageObject object = this.dialogMessagesByIds.get(dialog.top_message);
                this.dialogMessagesByIds.remove(dialog.top_message);
                if (object != null && object.messageOwner.random_id != 0) {
                    this.dialogMessagesByRandomIds.remove(object.messageOwner.random_id);
                }
                dialog.top_message = 0;
                getNotificationsController().removeNotificationsForDialog(dialog.id);
                getNotificationCenter().postNotificationName(NotificationCenter.needReloadRecentDialogsSearch, new Object[0]);
                return;
            }
            return;
        }
        boolean changed = false;
        if (dialog == null) {
            TLRPC.Chat chat = getChat(Integer.valueOf(channelId));
            if (channelId != 0 && chat == null) {
                return;
            }
            if (chat != null && ChatObject.isNotInChat(chat)) {
                return;
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("not found dialog with id " + uid + " dictCount = " + this.dialogs_dict.size() + " allCount = " + this.allDialogs.size());
            }
            final TLRPC.TL_dialog dialog2 = new TLRPC.TL_dialog();
            dialog2.id = uid;
            dialog2.unread_count = 0;
            dialog2.top_message = lastMessage.getId();
            dialog2.last_message_date = lastMessage.messageOwner.date;
            dialog2.flags = ChatObject.isChannel(chat) ? 1 : 0;
            this.dialogs_dict.put(uid, dialog2);
            this.allDialogs.add(dialog2);
            this.dialogMessage.put(uid, lastMessage);
            if (lastMessage.messageOwner.to_id.channel_id == 0) {
                this.dialogMessagesByIds.put(lastMessage.getId(), lastMessage);
                if (lastMessage.messageOwner.random_id != 0) {
                    this.dialogMessagesByRandomIds.put(lastMessage.messageOwner.random_id, lastMessage);
                }
            }
            changed = true;
            getMessagesStorage().getDialogFolderId(uid, new MessagesStorage.IntCallback() {
                @Override
                public final void run(int i) {
                    MessagesController.this.lambda$updateInterfaceWithMessages$291$MessagesController(dialog2, uid, i);
                }
            });
        } else {
            if (hasNotOutMessage && dialog.folder_id == 1 && !isDialogMuted(dialog.id)) {
                dialog.folder_id = 0;
                dialog.pinned = false;
                dialog.pinnedNum = 0;
                getMessagesStorage().setDialogsFolderId(null, null, dialog.id, 0);
                changed = true;
            }
            if ((dialog.top_message > 0 && lastMessage.getId() > 0 && lastMessage.getId() > dialog.top_message) || ((dialog.top_message < 0 && lastMessage.getId() < 0 && lastMessage.getId() < dialog.top_message) || this.dialogMessage.indexOfKey(uid) < 0 || dialog.top_message < 0 || dialog.last_message_date <= lastMessage.messageOwner.date)) {
                MessageObject object2 = this.dialogMessagesByIds.get(dialog.top_message);
                this.dialogMessagesByIds.remove(dialog.top_message);
                if (object2 != null && object2.messageOwner.random_id != 0) {
                    this.dialogMessagesByRandomIds.remove(object2.messageOwner.random_id);
                }
                dialog.top_message = lastMessage.getId();
                dialog.last_message_date = lastMessage.messageOwner.date;
                changed = true;
                this.dialogMessage.put(uid, lastMessage);
                if (lastMessage.messageOwner.to_id.channel_id == 0) {
                    this.dialogMessagesByIds.put(lastMessage.getId(), lastMessage);
                    if (lastMessage.messageOwner.random_id != 0) {
                        this.dialogMessagesByRandomIds.put(lastMessage.messageOwner.random_id, lastMessage);
                    }
                }
            }
        }
        if (changed) {
            sortDialogs(null);
        }
        if (updateRating) {
            getMediaDataController().increasePeerRaiting(uid);
        }
    }

    public void lambda$updateInterfaceWithMessages$291$MessagesController(TLRPC.Dialog dialogFinal, long uid, int param) {
        if (param != -1) {
            if (param != 0) {
                dialogFinal.folder_id = param;
                sortDialogs(null);
                getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
                return;
            }
            return;
        }
        int lowerId = (int) uid;
        if (lowerId != 0) {
            loadUnknownDialog(getInputPeer(lowerId), 0L);
        }
    }

    public void addDialogAction(long did, boolean clean) {
        TLRPC.Dialog dialog = this.dialogs_dict.get(did);
        if (dialog == null) {
            return;
        }
        if (clean) {
            this.clearingHistoryDialogs.put(did, dialog);
        } else {
            this.deletingDialogs.put(did, dialog);
            this.allDialogs.remove(dialog);
            sortDialogs(null);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
    }

    public void removeDialogAction(long did, boolean clean, boolean apply) {
        TLRPC.Dialog dialog = this.dialogs_dict.get(did);
        if (dialog == null) {
            return;
        }
        if (clean) {
            this.clearingHistoryDialogs.remove(did);
        } else {
            this.deletingDialogs.remove(did);
            if (!apply) {
                this.allDialogs.add(dialog);
                sortDialogs(null);
            }
        }
        if (!apply) {
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
        }
    }

    public boolean isClearingDialog(long did) {
        return this.clearingHistoryDialogs.get(did) != null;
    }

    public void sortDialogs(SparseArray<TLRPC.Chat> chatsDict) {
        TLRPC.User user;
        TLRPC.Chat chat;
        TLRPC.Chat chat2;
        this.dialogsServerOnly.clear();
        this.dialogsCanAddUsers.clear();
        this.dialogsChannelsOnly.clear();
        this.dialogsGroupsOnly.clear();
        this.dialogsUnreadOnly.clear();
        this.dialogsUsersOnly.clear();
        this.dialogsForward.clear();
        for (int a = 0; a < this.dialogsByFolder.size(); a++) {
            ArrayList<TLRPC.Dialog> arrayList = this.dialogsByFolder.valueAt(a);
            if (arrayList != null) {
                arrayList.clear();
            }
        }
        this.unreadUnmutedDialogs = 0;
        boolean selfAdded = false;
        int selfId = getUserConfig().getClientUserId();
        Collections.sort(this.allDialogs, this.dialogComparator);
        this.isLeftProxyChannel = true;
        TLRPC.Dialog dialog = this.proxyDialog;
        if (dialog != null && dialog.id < 0 && (chat2 = getChat(Integer.valueOf(-((int) this.proxyDialog.id)))) != null && !chat2.left) {
            this.isLeftProxyChannel = false;
        }
        boolean countMessages = getNotificationsController().showBadgeMessages;
        int a2 = 0;
        int N = this.allDialogs.size();
        while (a2 < N) {
            TLRPC.Dialog d = this.allDialogs.get(a2);
            int high_id = (int) (d.id >> 32);
            int lower_id = (int) d.id;
            if (d instanceof TLRPC.TL_dialog) {
                boolean canAddToForward = true;
                if (lower_id != 0 && high_id != 1) {
                    this.dialogsServerOnly.add(d);
                    if (DialogObject.isChannel(d)) {
                        TLRPC.Chat chat3 = getChat(Integer.valueOf(-lower_id));
                        if (chat3 != null && ((chat3.megagroup && chat3.admin_rights != null && (chat3.admin_rights.post_messages || chat3.admin_rights.add_admins)) || chat3.creator)) {
                            this.dialogsCanAddUsers.add(d);
                        }
                        if (chat3 != null && chat3.megagroup) {
                            this.dialogsGroupsOnly.add(d);
                        } else {
                            this.dialogsChannelsOnly.add(d);
                            canAddToForward = ChatObject.hasAdminRights(chat3) && ChatObject.canPost(chat3);
                        }
                    } else if (lower_id < 0) {
                        if (chatsDict != null && (chat = chatsDict.get(-lower_id)) != null && chat.migrated_to != null) {
                            this.allDialogs.remove(a2);
                            a2--;
                            N--;
                            a2++;
                        } else {
                            this.dialogsCanAddUsers.add(d);
                            this.dialogsGroupsOnly.add(d);
                        }
                    } else if (lower_id > 0 && lower_id != selfId) {
                        this.dialogsUsersOnly.add(d);
                    }
                }
                if (d.unread_count != 0 || d.unread_mentions_count != 0) {
                    this.dialogsUnreadOnly.add(d);
                }
                if (canAddToForward && d.folder_id == 0) {
                    if (lower_id == selfId) {
                        this.dialogsForward.add(0, d);
                        selfAdded = true;
                    } else {
                        this.dialogsForward.add(d);
                    }
                }
            }
            if ((d.unread_count != 0 || d.unread_mark) && !isDialogMuted(d.id)) {
                this.unreadUnmutedDialogs++;
            }
            if (this.proxyDialog == null || d.id != this.proxyDialog.id || !this.isLeftProxyChannel) {
                addDialogToItsFolder(-1, d, countMessages);
            } else {
                this.allDialogs.remove(a2);
                a2--;
                N--;
            }
            a2++;
        }
        TLRPC.Dialog dialog2 = this.proxyDialog;
        if (dialog2 != null && this.isLeftProxyChannel) {
            this.allDialogs.add(0, dialog2);
            addDialogToItsFolder(-2, this.proxyDialog, countMessages);
        }
        if (!selfAdded && (user = getUserConfig().getCurrentUser()) != null) {
            TLRPC.Dialog dialog3 = new TLRPC.TL_dialog();
            dialog3.id = user.id;
            dialog3.notify_settings = new TLRPC.TL_peerNotifySettings();
            dialog3.peer = new TLRPC.TL_peerUser();
            dialog3.peer.user_id = user.id;
            this.dialogsForward.add(0, dialog3);
        }
        for (int a3 = 0; a3 < this.dialogsByFolder.size(); a3++) {
            int folderId = this.dialogsByFolder.keyAt(a3);
            ArrayList<TLRPC.Dialog> dialogs = this.dialogsByFolder.valueAt(a3);
            if (dialogs.isEmpty()) {
                this.dialogsByFolder.remove(folderId);
            }
        }
    }

    private void addDialogToItsFolder(int index, TLRPC.Dialog dialog, boolean countMessages) {
        int folderId;
        TLRPC.Dialog folder;
        if (dialog instanceof TLRPC.TL_dialogFolder) {
            folderId = 0;
            dialog.unread_count = 0;
            dialog.unread_mentions_count = 0;
        } else {
            folderId = dialog.folder_id;
        }
        ArrayList<TLRPC.Dialog> dialogs = this.dialogsByFolder.get(folderId);
        if (dialogs == null) {
            dialogs = new ArrayList<>();
            this.dialogsByFolder.put(folderId, dialogs);
        }
        if (folderId != 0 && dialog.unread_count != 0 && (folder = this.dialogs_dict.get(DialogObject.makeFolderDialogId(folderId))) != null) {
            if (countMessages) {
                if (isDialogMuted(dialog.id)) {
                    folder.unread_count += dialog.unread_count;
                } else {
                    folder.unread_mentions_count += dialog.unread_count;
                }
            } else if (isDialogMuted(dialog.id)) {
                folder.unread_count++;
            } else {
                folder.unread_mentions_count++;
            }
        }
        if (index == -1) {
            dialogs.add(dialog);
        } else if (index == -2) {
            if (dialogs.isEmpty() || !(dialogs.get(0) instanceof TLRPC.TL_dialogFolder)) {
                dialogs.add(0, dialog);
            } else {
                dialogs.add(1, dialog);
            }
        } else {
            dialogs.add(index, dialog);
        }
    }

    public static String getRestrictionReason(ArrayList<TLRPC.TL_restrictionReason> reasons) {
        if (reasons.isEmpty()) {
            return null;
        }
        int N = reasons.size();
        for (int a = 0; a < N; a++) {
            TLRPC.TL_restrictionReason reason = reasons.get(a);
            if ("all".equals(reason.platform) || "android".equals(reason.platform)) {
                return reason.text;
            }
        }
        return null;
    }

    public static void showCantOpenAlert(BaseFragment fragment, String reason) {
        if (fragment == null || fragment.getParentActivity() == null) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setMessage(reason);
        fragment.showDialog(builder.create());
    }

    public static void showCantOpenAlert2(final BaseFragment fragment, String reason) {
        if (fragment == null || fragment.getParentActivity() == null) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                fragment.finishFragment();
            }
        });
        builder.setMessage(reason);
        fragment.showDialog(builder.create());
    }

    public boolean checkCanOpenChat(Bundle bundle, BaseFragment fragment) {
        return checkCanOpenChat(bundle, fragment, null);
    }

    public boolean checkCanOpenChat2(Bundle bundle, BaseFragment fragment) {
        return checkCanOpenChat2(bundle, fragment, null);
    }

    public boolean checkCanOpenChat(final Bundle bundle, final BaseFragment fragment, MessageObject originalMessage) {
        int did;
        TLObject req;
        if (bundle == null || fragment == null) {
            return true;
        }
        TLRPC.User user = null;
        TLRPC.Chat chat = null;
        int user_id = bundle.getInt("user_id", 0);
        int chat_id = bundle.getInt("chat_id", 0);
        int messageId = bundle.getInt("message_id", 0);
        if (user_id != 0) {
            user = getUser(Integer.valueOf(user_id));
        } else if (chat_id != 0) {
            chat = getChat(Integer.valueOf(chat_id));
        }
        if (user == null && chat == null) {
            return true;
        }
        String reason = null;
        if (chat != null) {
            reason = getRestrictionReason(chat.restriction_reason);
        } else if (user != null) {
            reason = getRestrictionReason(user.restriction_reason);
        }
        if (reason != null) {
            showCantOpenAlert(fragment, reason);
            return false;
        } else if (messageId == 0 || originalMessage == null || chat == null || chat.access_hash != 0 || (did = (int) originalMessage.getDialogId()) == 0) {
            return true;
        } else {
            final AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
            if (did < 0) {
                chat = getChat(Integer.valueOf(-did));
            }
            if (did <= 0 && ChatObject.isChannel(chat)) {
                TLRPC.Chat chat2 = getChat(Integer.valueOf(-did));
                TLRPC.TL_channels_getMessages request = new TLRPC.TL_channels_getMessages();
                request.channel = getInputChannel(chat2);
                request.id.add(Integer.valueOf(originalMessage.getId()));
                req = request;
            } else {
                TLRPC.TL_messages_getMessages request2 = new TLRPC.TL_messages_getMessages();
                request2.id.add(Integer.valueOf(originalMessage.getId()));
                req = request2;
            }
            final int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$checkCanOpenChat$293$MessagesController(progressDialog, fragment, bundle, tLObject, tL_error);
                }
            });
            progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public final void onCancel(DialogInterface dialogInterface) {
                    MessagesController.this.lambda$checkCanOpenChat$294$MessagesController(reqId, fragment, dialogInterface);
                }
            });
            fragment.setVisibleDialog(progressDialog);
            progressDialog.show();
            return false;
        }
    }

    public void lambda$checkCanOpenChat$293$MessagesController(final AlertDialog progressDialog, final BaseFragment fragment, final Bundle bundle, final TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$292$MessagesController(progressDialog, response, fragment, bundle);
                }
            });
        }
    }

    public void lambda$null$292$MessagesController(AlertDialog progressDialog, TLObject response, BaseFragment fragment, Bundle bundle) {
        try {
            progressDialog.dismiss();
        } catch (Exception e) {
            FileLog.e(e);
        }
        TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
        putUsers(res.users, false);
        putChats(res.chats, false);
        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
        fragment.presentFragment(new ChatActivity(bundle), true);
    }

    public void lambda$checkCanOpenChat$294$MessagesController(int reqId, BaseFragment fragment, DialogInterface dialog) {
        getConnectionsManager().cancelRequest(reqId, true);
        if (fragment != null) {
            fragment.setVisibleDialog(null);
        }
    }

    public boolean checkCanOpenChat2(final Bundle bundle, final BaseFragment fragment, MessageObject originalMessage) {
        int did;
        TLObject req;
        if (bundle == null || fragment == null) {
            return true;
        }
        TLRPC.User user = null;
        TLRPC.Chat chat = null;
        int user_id = bundle.getInt("user_id", 0);
        int chat_id = bundle.getInt("chat_id", 0);
        int messageId = bundle.getInt("message_id", 0);
        if (user_id != 0) {
            user = getUser(Integer.valueOf(user_id));
        } else if (chat_id != 0) {
            chat = getChat(Integer.valueOf(chat_id));
        }
        if (user == null && chat == null) {
            return true;
        }
        String reason = null;
        if (chat != null) {
            reason = getRestrictionReason(chat.restriction_reason);
        } else if (user != null) {
            reason = getRestrictionReason(user.restriction_reason);
        }
        if (reason != null) {
            showCantOpenAlert2(fragment, reason);
            return false;
        } else if (messageId == 0 || originalMessage == null || chat == null || chat.access_hash != 0 || (did = (int) originalMessage.getDialogId()) == 0) {
            return true;
        } else {
            final AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
            if (did < 0) {
                chat = getChat(Integer.valueOf(-did));
            }
            if (did <= 0 && ChatObject.isChannel(chat)) {
                TLRPC.Chat chat2 = getChat(Integer.valueOf(-did));
                TLRPC.TL_channels_getMessages request = new TLRPC.TL_channels_getMessages();
                request.channel = getInputChannel(chat2);
                request.id.add(Integer.valueOf(originalMessage.getId()));
                req = request;
            } else {
                TLRPC.TL_messages_getMessages request2 = new TLRPC.TL_messages_getMessages();
                request2.id.add(Integer.valueOf(originalMessage.getId()));
                req = request2;
            }
            final int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    MessagesController.this.lambda$checkCanOpenChat2$296$MessagesController(progressDialog, fragment, bundle, tLObject, tL_error);
                }
            });
            progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public final void onCancel(DialogInterface dialogInterface) {
                    MessagesController.this.lambda$checkCanOpenChat2$297$MessagesController(reqId, fragment, dialogInterface);
                }
            });
            fragment.setVisibleDialog(progressDialog);
            progressDialog.show();
            return false;
        }
    }

    public void lambda$checkCanOpenChat2$296$MessagesController(final AlertDialog progressDialog, final BaseFragment fragment, final Bundle bundle, final TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$null$295$MessagesController(progressDialog, response, fragment, bundle);
                }
            });
        }
    }

    public void lambda$null$295$MessagesController(AlertDialog progressDialog, TLObject response, BaseFragment fragment, Bundle bundle) {
        try {
            progressDialog.dismiss();
        } catch (Exception e) {
            FileLog.e(e);
        }
        TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
        putUsers(res.users, false);
        putChats(res.chats, false);
        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
        fragment.presentFragment(new ChatActivity(bundle), true);
    }

    public void lambda$checkCanOpenChat2$297$MessagesController(int reqId, BaseFragment fragment, DialogInterface dialog) {
        getConnectionsManager().cancelRequest(reqId, true);
        if (fragment != null) {
            fragment.setVisibleDialog(null);
        }
    }

    public static void openChatOrProfileWith(TLRPC.User user, TLRPC.Chat chat, BaseFragment fragment, int type, boolean closeLast) {
        if ((user == null && chat == null) || fragment == null) {
            return;
        }
        String reason = null;
        if (chat != null) {
            reason = getRestrictionReason(chat.restriction_reason);
        } else if (user != null) {
            reason = getRestrictionReason(user.restriction_reason);
            if (user.bot) {
                type = 1;
                closeLast = true;
            }
        }
        if (reason != null) {
            showCantOpenAlert(fragment, reason);
            return;
        }
        Bundle args = new Bundle();
        if (chat != null) {
            args.putInt("chat_id", chat.id);
        } else {
            args.putInt("user_id", user.id);
        }
        if (type == 0) {
            fragment.presentFragment(new ProfileActivity(args));
        } else if (type == 2) {
            fragment.presentFragment(new ChatActivity(args), true, true);
        } else {
            fragment.presentFragment(new ChatActivity(args), closeLast);
        }
    }

    public void openByUserName(String username, BaseFragment fragment, int type) {
        openByUserName(username, fragment, type, false);
    }

    public void openByUserName(String username, final BaseFragment fragment, final int type, final boolean closeLast) {
        TLRPC.User user;
        TLRPC.Chat chat;
        if (username != null && fragment != null) {
            TLObject object = getUserOrChat(username);
            if (object instanceof TLRPC.User) {
                TLRPC.User user2 = (TLRPC.User) object;
                if (!user2.min) {
                    user = user2;
                    chat = null;
                } else {
                    user = null;
                    chat = null;
                }
            } else if (!(object instanceof TLRPC.Chat)) {
                user = null;
                chat = null;
            } else {
                TLRPC.Chat chat2 = (TLRPC.Chat) object;
                if (chat2.min) {
                    user = null;
                    chat = null;
                } else {
                    user = null;
                    chat = chat2;
                }
            }
            if (user != null) {
                openChatOrProfileWith(user, null, fragment, type, closeLast);
            } else if (chat != null) {
                openChatOrProfileWith(null, chat, fragment, 1, closeLast);
            } else if (fragment.getParentActivity() == null) {
            } else {
                final AlertDialog[] progressDialog = {new AlertDialog(fragment.getParentActivity(), 3)};
                TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
                req.username = username;
                final int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$openByUserName$299$MessagesController(progressDialog, fragment, closeLast, type, tLObject, tL_error);
                    }
                });
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$openByUserName$301$MessagesController(progressDialog, reqId, fragment);
                    }
                }, 500L);
            }
        }
    }

    public void lambda$openByUserName$299$MessagesController(final AlertDialog[] progressDialog, final BaseFragment fragment, final boolean closeLast, final int type, final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$298$MessagesController(progressDialog, fragment, error, response, closeLast, type);
            }
        });
    }

    public void lambda$null$298$MessagesController(AlertDialog[] progressDialog, BaseFragment fragment, TLRPC.TL_error error, TLObject response, boolean closeLast, int type) {
        try {
            progressDialog[0].dismiss();
        } catch (Exception e) {
        }
        progressDialog[0] = null;
        fragment.setVisibleDialog(null);
        if (error == null) {
            TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
            putUsers(res.users, false);
            putChats(res.chats, false);
            getMessagesStorage().putUsersAndChats(res.users, res.chats, false, true);
            if (!res.chats.isEmpty()) {
                openChatOrProfileWith(null, res.chats.get(0), fragment, 1, closeLast);
            } else if (!res.users.isEmpty()) {
                if (res.users.get(0).contact) {
                    openChatOrProfileWith(res.users.get(0), null, fragment, type, closeLast);
                } else {
                    fragment.presentFragment(new AddContactsInfoActivity(null, res.users.get(0)));
                }
            }
        } else if (fragment != null && fragment.getParentActivity() != null) {
            if (type == 0) {
                ToastUtils.show((int) R.string.NoUsernameFound);
            } else {
                AlertsCreator.createSimpleAlert(fragment.getParentActivity(), LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist)).show();
            }
        }
    }

    public void lambda$openByUserName$301$MessagesController(AlertDialog[] progressDialog, final int reqId, BaseFragment fragment) {
        if (progressDialog[0] == null) {
            return;
        }
        progressDialog[0].setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public final void onCancel(DialogInterface dialogInterface) {
                MessagesController.this.lambda$null$300$MessagesController(reqId, dialogInterface);
            }
        });
        fragment.showDialog(progressDialog[0]);
    }

    public void lambda$null$300$MessagesController(int reqId, DialogInterface dialog) {
        getConnectionsManager().cancelRequest(reqId, true);
    }

    public void openByUserName(String username, final BaseFragment fragment, final TLRPC.Chat currentChat, final boolean closeLast) {
        TLRPC.User user;
        TLRPC.Chat chat;
        if (username != null && fragment != null) {
            if (!ChatObject.canSendEmbed(currentChat)) {
                ToastUtils.show((int) R.string.ForbidViewUserAndGroupInfoTips);
                return;
            }
            TLObject object = getUserOrChat(username);
            if (object instanceof TLRPC.User) {
                TLRPC.User user2 = (TLRPC.User) object;
                if (!user2.min) {
                    user = user2;
                    chat = null;
                } else {
                    user = null;
                    chat = null;
                }
            } else if (!(object instanceof TLRPC.Chat)) {
                user = null;
                chat = null;
            } else {
                TLRPC.Chat chat2 = (TLRPC.Chat) object;
                if (chat2.min) {
                    user = null;
                    chat = null;
                } else {
                    user = null;
                    chat = chat2;
                }
            }
            boolean z = false;
            if (user != null) {
                if (!user.self && currentChat != null && !ChatObject.hasAdminRights(currentChat) && currentChat.megagroup && (currentChat.flags & ConnectionsManager.FileTypeVideo) != 0 && !user.mutual_contact) {
                    ToastUtils.show((int) R.string.ForbidViewUserInfoTips);
                } else if (user.contact) {
                    Bundle args = new Bundle();
                    args.putInt("user_id", user.id);
                    if (currentChat != null) {
                        if (currentChat.megagroup && (33554432 & currentChat.flags) != 0) {
                            z = true;
                        }
                        args.putBoolean("forbid_add_contact", z);
                        args.putBoolean("has_admin_right", ChatObject.hasAdminRights(currentChat));
                    }
                    fragment.presentFragment(new NewProfileActivity(args));
                } else {
                    Bundle args2 = new Bundle();
                    args2.putInt("user_id", user.id);
                    if (currentChat != null) {
                        if (currentChat.megagroup && (33554432 & currentChat.flags) != 0) {
                            z = true;
                        }
                        args2.putBoolean("forbid_add_contact", z);
                        args2.putBoolean("has_admin_right", ChatObject.hasAdminRights(currentChat));
                    }
                    args2.putInt("from_type", 2);
                    fragment.presentFragment(new NewProfileActivity(args2));
                }
            } else if (chat != null) {
                openChatOrProfileWith(null, chat, fragment, 1, closeLast);
            } else if (fragment.getParentActivity() == null) {
            } else {
                final AlertDialog[] progressDialog = {new AlertDialog(fragment.getParentActivity(), 3)};
                TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
                req.username = username;
                final int reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        MessagesController.this.lambda$openByUserName$303$MessagesController(progressDialog, fragment, closeLast, currentChat, tLObject, tL_error);
                    }
                });
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$openByUserName$305$MessagesController(progressDialog, reqId, fragment);
                    }
                }, 500L);
            }
        }
    }

    public void lambda$openByUserName$303$MessagesController(final AlertDialog[] progressDialog, final BaseFragment fragment, final boolean closeLast, final TLRPC.Chat currentChat, final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$null$302$MessagesController(progressDialog, fragment, error, response, closeLast, currentChat);
            }
        });
    }

    public void lambda$null$302$MessagesController(AlertDialog[] progressDialog, BaseFragment fragment, TLRPC.TL_error error, TLObject response, boolean closeLast, TLRPC.Chat currentChat) {
        boolean z = false;
        try {
            progressDialog[0].dismiss();
        } catch (Exception e) {
        }
        progressDialog[0] = null;
        fragment.setVisibleDialog(null);
        if (error == null) {
            TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
            putUsers(res.users, false);
            putChats(res.chats, false);
            getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
            if (!res.chats.isEmpty()) {
                openChatOrProfileWith(null, res.chats.get(0), fragment, 1, closeLast);
            } else if (!res.users.isEmpty()) {
                TLRPC.User user1 = res.users.get(0);
                if (!user1.self && currentChat != null && !ChatObject.hasAdminRights(currentChat) && currentChat.megagroup && (currentChat.flags & ConnectionsManager.FileTypeVideo) != 0 && !user1.mutual_contact) {
                    ToastUtils.show((int) R.string.ForbidViewUserInfoTips);
                    return;
                }
                Bundle args = new Bundle();
                args.putInt("user_id", user1.id);
                if (currentChat != null) {
                    if (currentChat.megagroup && (33554432 & currentChat.flags) != 0) {
                        z = true;
                    }
                    args.putBoolean("forbid_add_contact", z);
                    args.putBoolean("has_admin_right", ChatObject.hasAdminRights(currentChat));
                }
                args.putInt("from_type", 2);
                fragment.presentFragment(new NewProfileActivity(args));
            }
        } else if (fragment != null && fragment.getParentActivity() != null) {
            try {
                ToastUtils.show((int) R.string.NoUsernameFound);
            } catch (Exception e2) {
                FileLog.e(e2);
            }
        }
    }

    public void lambda$openByUserName$305$MessagesController(AlertDialog[] progressDialog, final int reqId, BaseFragment fragment) {
        if (progressDialog[0] == null) {
            return;
        }
        progressDialog[0].setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public final void onCancel(DialogInterface dialogInterface) {
                MessagesController.this.lambda$null$304$MessagesController(reqId, dialogInterface);
            }
        });
        fragment.showDialog(progressDialog[0]);
    }

    public void lambda$null$304$MessagesController(int reqId, DialogInterface dialog) {
        getConnectionsManager().cancelRequest(reqId, true);
    }

    public void saveContactsAppliesId(int applyId) {
        this.mainPreferences.edit().putInt("contacts_apply_id", applyId).apply();
    }

    public void saveContactsAppliesDate(int date) {
        this.mainPreferences.edit().putInt("last_contacts_get_diff", date).apply();
    }

    public void saveContactsAppliesHash(long hash) {
        this.mainPreferences.edit().putLong("contacts_apply_hash", hash).apply();
    }

    public void handleUpdatesContactsApply(int count) {
        if (count <= 0) {
            this.mainPreferences.edit().putInt("contacts_apply_count", 0).apply();
        } else {
            this.mainPreferences.edit().putInt("contacts_apply_count", count).apply();
        }
    }

    public void getContactsApplyDifferenceV2(boolean reget, boolean slice) {
        getContactsApplyDifferenceV2(reget, false, slice);
    }

    public void getContactsApplyDifferenceV2(final boolean reget, boolean reset, boolean slice) {
        if (this.contactsGetDiff) {
            return;
        }
        this.contactsGetDiff = true;
        int applyId = this.mainPreferences.getInt("contacts_apply_id", -1);
        int needTime = this.mainPreferences.getInt("last_contacts_get_diff", 0);
        long applyHash = this.mainPreferences.getLong("contacts_apply_hash", 0L);
        TLRPCContacts.GetContactAppliesDifferenceV2 req = new TLRPCContacts.GetContactAppliesDifferenceV2();
        req.apply_id = reget ? -1 : applyId;
        req.total_limit = 100;
        req.date = needTime;
        req.hash = reset ? 0L : applyHash;
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$getContactsApplyDifferenceV2$309$MessagesController(reget, tLObject, tL_error);
            }
        });
    }

    public void lambda$getContactsApplyDifferenceV2$309$MessagesController(boolean reget, TLObject response, TLRPC.TL_error error) {
        this.contactsGetDiff = false;
        if (error == null) {
            final TLRPCContacts.ContactsAppiesDifferenceV2 res = (TLRPCContacts.ContactsAppiesDifferenceV2) response;
            if (res instanceof TLRPCContacts.HC_contacts_apply_notModified) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$null$306$MessagesController();
                    }
                });
            } else if (res instanceof TLRPCContacts.HC_contacts_apply_differenceSlice_v2) {
                getMessagesController().putUsers(res.users, false);
                ArrayList<TLRPCContacts.ContactApplyInfo> infos = new ArrayList<>();
                for (int i = 0; i < res.otherUpdates.size(); i++) {
                    TLRPC.Update update = res.otherUpdates.get(i);
                    if (update instanceof TLRPCContacts.UpdateContactApplyRequested) {
                        TLRPCContacts.UpdateContactApplyRequested obj = (TLRPCContacts.UpdateContactApplyRequested) update;
                        if (obj.apply_info.from_peer.user_id != getUserConfig().clientUserId) {
                            infos.add(obj.apply_info);
                        }
                    }
                }
                getContactsApplyDifferenceV2(false, true);
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.e("------------> slice response");
                }
                if (infos.size() > 0 && BuildVars.LOGS_ENABLED) {
                    FileLog.e("------------> infos.size() :" + infos.size());
                }
            } else {
                final ArrayList<TLRPCContacts.ContactApplyInfo> infos2 = new ArrayList<>();
                getMessagesController().putUsers(res.users, false);
                for (int i2 = 0; i2 < res.otherUpdates.size(); i2++) {
                    TLRPC.Update update2 = res.otherUpdates.get(i2);
                    if (update2 instanceof TLRPCContacts.UpdateContactApplyRequested) {
                        TLRPCContacts.UpdateContactApplyRequested obj2 = (TLRPCContacts.UpdateContactApplyRequested) update2;
                        if (obj2.apply_info.from_peer.user_id != getUserConfig().clientUserId) {
                            infos2.add(obj2.apply_info);
                        }
                    }
                }
                if (infos2.size() > 0) {
                    handleUpdatesContactsApply(res.state.unread_count);
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            MessagesController.this.lambda$null$307$MessagesController(res, infos2);
                        }
                    });
                } else {
                    handleUpdatesContactsApply(res.state.unread_count);
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            MessagesController.this.lambda$null$308$MessagesController(res);
                        }
                    });
                }
                saveContactsAppliesId(res.state.apply_id);
                saveContactsAppliesHash(res.hash);
            }
        }
    }

    public void lambda$null$306$MessagesController() {
        getNotificationCenter().postNotificationName(NotificationCenter.contactApplyUpdateCount, 0);
    }

    public void lambda$null$307$MessagesController(TLRPCContacts.ContactsAppiesDifferenceV2 res, ArrayList infos) {
        getNotificationCenter().postNotificationName(NotificationCenter.contactApplyUpdateCount, Integer.valueOf(res.state.unread_count));
        getNotificationCenter().postNotificationName(NotificationCenter.contactApplieReceived, infos, res.users);
    }

    public void lambda$null$308$MessagesController(TLRPCContacts.ContactsAppiesDifferenceV2 res) {
        getNotificationCenter().postNotificationName(NotificationCenter.contactApplyUpdateCount, Integer.valueOf(res.state.unread_count));
    }
}