APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:国中资本
版本号:1.0.0
包名称:com.byhhd.oxojy

MD5 校验值:1036132062d4d223cd1a714f5bbea98b

反编译源代码说明

MessagesController.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package im.skmzhmurqt.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.skmzhmurqt.javaBean.fc.FollowedFcListBean;
import im.skmzhmurqt.javaBean.fc.HomeFcListBean;
import im.skmzhmurqt.javaBean.fc.RecommendFcListBean;
import im.skmzhmurqt.messenger.MessagesStorage;
import im.skmzhmurqt.messenger.NotificationCenter;
import im.skmzhmurqt.messenger.support.SparseLongArray;
import im.skmzhmurqt.messenger.voip.VoIPService;
import im.skmzhmurqt.sqlite.SQLiteCursor;
import im.skmzhmurqt.tgnet.ConnectionsManager;
import im.skmzhmurqt.tgnet.NativeByteBuffer;
import im.skmzhmurqt.tgnet.RequestDelegate;
import im.skmzhmurqt.tgnet.TLObject;
import im.skmzhmurqt.tgnet.TLRPC;
import im.skmzhmurqt.tgnet.TLRPCCall;
import im.skmzhmurqt.tgnet.TLRPCChats;
import im.skmzhmurqt.tgnet.TLRPCContacts;
import im.skmzhmurqt.ui.ChatActivity;
import im.skmzhmurqt.ui.DialogsActivity;
import im.skmzhmurqt.ui.ProfileActivity;
import im.skmzhmurqt.ui.actionbar.AlertDialog;
import im.skmzhmurqt.ui.actionbar.BaseFragment;
import im.skmzhmurqt.ui.actionbar.Theme;
import im.skmzhmurqt.ui.components.AlertsCreator;
import im.skmzhmurqt.ui.components.toast.ToastUtils;
import im.skmzhmurqt.ui.hui.chats.NewProfileActivity;
import im.skmzhmurqt.ui.hui.contacts.AddContactsInfoActivity;
import im.skmzhmurqt.ui.hui.friendscircle_v1.helper.FcDBHelper;
import im.skmzhmurqt.ui.hui.visualcall.VisualCallReceiveService;
import im.skmzhmurqt.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() {
        }

        UserActionUpdatesSeq(AnonymousClass1 x0) {
            this();
        }
    }

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

        UserActionUpdatesPts(AnonymousClass1 x0) {
            this();
        }
    }

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

        private ReadTask() {
        }

        ReadTask(MessagesController x0, AnonymousClass1 x1) {
            this();
        }
    }

    public int lambda$new$1$MessagesController(TLRPC.Dialog dialog1, TLRPC.Dialog dialog2) {
        if ((dialog1 instanceof TLRPC.TL_dialogFolder) && !(dialog2 instanceof TLRPC.TL_dialogFolder)) {
            return -1;
        }
        if (!(dialog1 instanceof TLRPC.TL_dialogFolder) && (dialog2 instanceof TLRPC.TL_dialogFolder)) {
            return 1;
        }
        if (!dialog1.pinned && dialog2.pinned) {
            return 1;
        }
        if (dialog1.pinned && !dialog2.pinned) {
            return -1;
        }
        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;
    }

    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 {
            this.notificationsPreferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications" + this.currentAccount, 0);
            this.mainPreferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig" + this.currentAccount, 0);
            this.emojiPreferences = ApplicationLoader.applicationContext.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 = "Pxxx";
        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 = "Pxxx";
        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);
                return;
            }
            return;
        }
        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;
                return;
            }
            return;
        }
        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);
                    return;
                }
                return;
            }
            return;
        }
        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);
        } else {
            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;
                } else {
                    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);
            return;
        }
        if (oldChat == null) {
            this.chats.put(Integer.valueOf(chat.id), chat);
            return;
        }
        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, null);
    }

    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) {
            if (this.notificationsPreferences.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);
            return;
        }
        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());
                return;
            }
            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);
            return;
        }
        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);
            return;
        }
        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);
        } else {
            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);
        } else {
            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);
        } else {
            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(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(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);
            return;
        }
        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);
                }
            });
            return;
        }
        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);
                }
            });
            return;
        }
        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$OXc9yNP7oK9LyTVN9JvBs_9MT4(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$OXc9yNP7oK9LyTVN9JvBs_9MT4(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);
                return;
            }
            return;
        }
        if (action != 0) {
            return;
        }
        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;
            }
            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;
            }
            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;
        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) + r4.id) % 2147483648L) * 20261) + 2147483648L) + r4.edit_date) % 2147483648L)) + 2147483648L) + r4.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 message = messages_messages.messages.get(a6);
                if (isMegagroup) {
                    message.flags |= Integer.MIN_VALUE;
                }
                if (!scheduled) {
                    if ((message.action instanceof TLRPC.TL_messageActionChatDeleteUser) && (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 {
                        message.unread = (message.out ? outboxValue : inboxValue).intValue() < message.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 message2 = messages_messages.messages.get(a7);
            message2.dialog_id = j;
            int a8 = a7;
            HashMap<String, ArrayList<MessageObject>> webpagesToReload2 = webpagesToReload;
            MessageObject messageObject = new MessageObject(messagesController.currentAccount, message2, usersDict, chatsDict, true);
            messageObject.scheduled = z;
            objects.add(messageObject);
            if (isCache) {
                if (message2.legacy && message2.layer < 105) {
                    messagesToReload.add(Integer.valueOf(message2.id));
                } else if (message2.media instanceof TLRPC.TL_messageMediaUnsupported) {
                    if (message2.media.bytes != null) {
                        if (message2.media.bytes.length != 0) {
                            if (message2.media.bytes.length == 1) {
                            }
                        }
                        messagesToReload.add(Integer.valueOf(message2.id));
                    }
                }
                if (message2.media instanceof TLRPC.TL_messageMediaWebPage) {
                    if ((message2.media.webpage instanceof TLRPC.TL_webPagePending) && message2.media.webpage.date <= getConnectionsManager().getCurrentTime()) {
                        messagesToReload.add(Integer.valueOf(message2.id));
                    } else if (message2.media.webpage instanceof TLRPC.TL_webPageUrlPending) {
                        ArrayList<MessageObject> arrayList = webpagesToReload2.get(message2.media.webpage.url);
                        if (arrayList == null) {
                            arrayList = new ArrayList<>();
                            webpagesToReload2.put(message2.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);
                }
            });
            return;
        }
        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);
                }
            });
        } else {
            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);
            return;
        }
        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);
                }
            });
            return;
        }
        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 readTask) {
        TLRPC.TL_messages_readHistory tL_messages_readHistory;
        int i = (int) readTask.dialogId;
        int i2 = (int) (readTask.dialogId >> 32);
        if (i != 0) {
            TLRPC.InputPeer inputPeer = getInputPeer(i);
            if (inputPeer instanceof TLRPC.TL_inputPeerChannel) {
                TLRPC.TL_channels_readHistory tL_channels_readHistory = new TLRPC.TL_channels_readHistory();
                tL_channels_readHistory.channel = getInputChannel(-i);
                tL_channels_readHistory.max_id = readTask.maxId;
                tL_messages_readHistory = tL_channels_readHistory;
            } else {
                TLRPC.TL_messages_readHistory tL_messages_readHistory2 = new TLRPC.TL_messages_readHistory();
                tL_messages_readHistory2.peer = inputPeer;
                tL_messages_readHistory2.max_id = readTask.maxId;
                tL_messages_readHistory = tL_messages_readHistory2;
            }
            getConnectionsManager().sendRequest(tL_messages_readHistory, 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 encryptedChat = getEncryptedChat(Integer.valueOf(i2));
        if (encryptedChat.auth_key != null && encryptedChat.auth_key.length > 1 && (encryptedChat instanceof TLRPC.TL_encryptedChat)) {
            TLRPC.TL_messages_readEncryptedHistory tL_messages_readEncryptedHistory = new TLRPC.TL_messages_readEncryptedHistory();
            tL_messages_readEncryptedHistory.peer = new TLRPC.TL_inputEncryptedChat();
            tL_messages_readEncryptedHistory.peer.chat_id = encryptedChat.id;
            tL_messages_readEncryptedHistory.peer.access_hash = encryptedChat.access_hash;
            tL_messages_readEncryptedHistory.max_date = readTask.maxDate;
            getConnectionsManager().sendRequest(tL_messages_readEncryptedHistory, 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, null);
    }

    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);
                }
            });
            return;
        }
        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, null);
            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 i, TLRPC.User user, TLRPC.ChatFull chatFull, boolean z, boolean z2) {
        TLRPC.TL_messages_deleteChatUser tL_messages_deleteChatUser;
        if (user == null) {
            return;
        }
        if (i <= 0) {
            if (chatFull instanceof TLRPC.TL_chatFull) {
                TLRPC.Chat chat = getChat(Integer.valueOf(i));
                chat.participants_count--;
                ArrayList<TLRPC.Chat> arrayList = new ArrayList<>();
                arrayList.add(chat);
                getMessagesStorage().putUsersAndChats(null, arrayList, true, true);
                boolean z3 = false;
                int i2 = 0;
                while (true) {
                    if (i2 >= chatFull.participants.participants.size()) {
                        break;
                    }
                    if (chatFull.participants.participants.get(i2).user_id != user.id) {
                        i2++;
                    } else {
                        chatFull.participants.participants.remove(i2);
                        z3 = true;
                        break;
                    }
                }
                if (z3) {
                    getMessagesStorage().updateChatInfo(chatFull, true);
                    getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, chatFull, 0, false, null);
                }
                getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 32);
                return;
            }
            return;
        }
        final TLRPC.InputUser inputUser = getInputUser(user);
        TLRPC.Chat chat2 = getChat(Integer.valueOf(i));
        final boolean isChannel = ChatObject.isChannel(chat2);
        if (isChannel) {
            if (inputUser instanceof TLRPC.TL_inputUserSelf) {
                if (chat2.creator && z) {
                    TLRPC.TL_channels_deleteChannel tL_channels_deleteChannel = new TLRPC.TL_channels_deleteChannel();
                    tL_channels_deleteChannel.channel = getInputChannel(chat2);
                    tL_messages_deleteChatUser = tL_channels_deleteChannel;
                } else {
                    TLRPC.TL_channels_leaveChannel tL_channels_leaveChannel = new TLRPC.TL_channels_leaveChannel();
                    tL_channels_leaveChannel.channel = getInputChannel(chat2);
                    tL_messages_deleteChatUser = tL_channels_leaveChannel;
                }
            } else {
                TLRPC.TL_channels_editBanned tL_channels_editBanned = new TLRPC.TL_channels_editBanned();
                tL_channels_editBanned.channel = getInputChannel(chat2);
                tL_channels_editBanned.user_id = inputUser;
                tL_channels_editBanned.banned_rights = new TLRPC.TL_chatBannedRights();
                tL_channels_editBanned.banned_rights.view_messages = true;
                tL_channels_editBanned.banned_rights.send_media = true;
                tL_channels_editBanned.banned_rights.send_messages = true;
                tL_channels_editBanned.banned_rights.send_stickers = true;
                tL_channels_editBanned.banned_rights.send_gifs = true;
                tL_channels_editBanned.banned_rights.send_games = true;
                tL_channels_editBanned.banned_rights.send_inline = true;
                tL_channels_editBanned.banned_rights.embed_links = true;
                tL_channels_editBanned.banned_rights.pin_messages = true;
                tL_channels_editBanned.banned_rights.send_polls = true;
                tL_channels_editBanned.banned_rights.invite_users = true;
                tL_channels_editBanned.banned_rights.change_info = true;
                tL_messages_deleteChatUser = tL_channels_editBanned;
            }
        } else {
            TLRPC.TL_messages_deleteChatUser tL_messages_deleteChatUser2 = new TLRPC.TL_messages_deleteChatUser();
            tL_messages_deleteChatUser2.chat_id = i;
            tL_messages_deleteChatUser2.user_id = getInputUser(user);
            tL_messages_deleteChatUser = tL_messages_deleteChatUser2;
        }
        if (user.id == getUserConfig().getClientUserId()) {
            deleteDialog(-i, 0, z2);
        }
        getConnectionsManager().sendRequest(tL_messages_deleteChatUser, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$deleteUserFromChat$204$MessagesController(isChannel, inputUser, i, 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 i, String str) {
        TLRPC.TL_messages_editChatTitle tL_messages_editChatTitle;
        if (i > 0) {
            if (ChatObject.isChannel(i, this.currentAccount)) {
                TLRPC.TL_channels_editTitle tL_channels_editTitle = new TLRPC.TL_channels_editTitle();
                tL_channels_editTitle.channel = getInputChannel(i);
                tL_channels_editTitle.title = str;
                tL_messages_editChatTitle = tL_channels_editTitle;
            } else {
                TLRPC.TL_messages_editChatTitle tL_messages_editChatTitle2 = new TLRPC.TL_messages_editChatTitle();
                tL_messages_editChatTitle2.chat_id = i;
                tL_messages_editChatTitle2.title = str;
                tL_messages_editChatTitle = tL_messages_editChatTitle2;
            }
            getConnectionsManager().sendRequest(tL_messages_editChatTitle, 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(i));
        chat.title = str;
        ArrayList<TLRPC.Chat> arrayList = new ArrayList<>();
        arrayList.add(chat);
        getMessagesStorage().putUsersAndChats(null, arrayList, 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 i, TLRPC.InputFile inputFile, final TLRPC.FileLocation fileLocation, final TLRPC.FileLocation fileLocation2) {
        TLRPC.TL_messages_editChatPhoto tL_messages_editChatPhoto;
        if (ChatObject.isChannel(i, this.currentAccount)) {
            TLRPC.TL_channels_editPhoto tL_channels_editPhoto = new TLRPC.TL_channels_editPhoto();
            tL_channels_editPhoto.channel = getInputChannel(i);
            if (inputFile != null) {
                tL_channels_editPhoto.photo = new TLRPC.TL_inputChatUploadedPhoto();
                tL_channels_editPhoto.photo.file = inputFile;
                tL_messages_editChatPhoto = tL_channels_editPhoto;
            } else {
                tL_channels_editPhoto.photo = new TLRPC.TL_inputChatPhotoEmpty();
                tL_messages_editChatPhoto = tL_channels_editPhoto;
            }
        } else {
            TLRPC.TL_messages_editChatPhoto tL_messages_editChatPhoto2 = new TLRPC.TL_messages_editChatPhoto();
            tL_messages_editChatPhoto2.chat_id = i;
            if (inputFile != null) {
                tL_messages_editChatPhoto2.photo = new TLRPC.TL_inputChatUploadedPhoto();
                tL_messages_editChatPhoto2.photo.file = inputFile;
            } else {
                tL_messages_editChatPhoto2.photo = new TLRPC.TL_inputChatPhotoEmpty();
            }
            tL_messages_editChatPhoto = tL_messages_editChatPhoto2;
        }
        getConnectionsManager().sendRequest(tL_messages_editChatPhoto, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                MessagesController.this.lambda$changeChatAvatar$206$MessagesController(fileLocation, fileLocation2, 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());
            return;
        }
        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;
        }
        if (type == 1) {
            if (updates.pts <= getMessagesStorage().getLastPtsValue()) {
                return 2;
            }
            return getMessagesStorage().getLastPtsValue() + updates.pts_count == updates.pts ? 0 : 1;
        }
        if (type != 2) {
            return 0;
        }
        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;
                    }
                    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;
                    }
                    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, (SparseArray<TLRPC.User>) 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, (SparseArray<TLRPC.User>) 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();
            return;
        }
        if (!slice && this.gettingDifference) {
            return;
        }
        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, (SparseArray<TLRPC.User>) usersDict, (SparseArray<TLRPC.Chat>) 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 i, ArrayList arrayList, boolean z, TLRPC.TL_messages_peerDialogs tL_messages_peerDialogs, LongSparseArray longSparseArray, TLRPC.TL_messages_dialogs tL_messages_dialogs) {
        ArrayList arrayList2 = arrayList;
        this.loadingPinnedDialogs.delete(i);
        applyDialogsNotificationsSettings(arrayList2);
        boolean z2 = false;
        boolean z3 = false;
        int i2 = 0;
        ArrayList<TLRPC.Dialog> dialogs = getDialogs(i);
        int i3 = z ? 1 : 0;
        for (int i4 = 0; i4 < dialogs.size(); i4++) {
            TLRPC.Dialog dialog = dialogs.get(i4);
            if (!(dialog instanceof TLRPC.TL_dialogFolder)) {
                if (((int) dialog.id) == 0) {
                    if (i3 < arrayList.size()) {
                        arrayList2.add(i3, dialog);
                    } else {
                        arrayList2.add(dialog);
                    }
                    i3++;
                } else {
                    if (!dialog.pinned) {
                        break;
                    }
                    i2 = Math.max(dialog.pinnedNum, i2);
                    dialog.pinned = false;
                    dialog.pinnedNum = 0;
                    z2 = true;
                    i3++;
                }
            }
        }
        ArrayList<Long> arrayList3 = new ArrayList<>();
        if (!arrayList.isEmpty()) {
            putUsers(tL_messages_peerDialogs.users, false);
            putChats(tL_messages_peerDialogs.chats, false);
            int i5 = 0;
            int size = arrayList.size();
            while (i5 < size) {
                TLRPC.Dialog dialog2 = (TLRPC.Dialog) arrayList2.get(i5);
                dialog2.pinnedNum = (size - i5) + i2;
                arrayList3.add(Long.valueOf(dialog2.id));
                TLRPC.Dialog dialog3 = this.dialogs_dict.get(dialog2.id);
                if (dialog3 != null) {
                    dialog3.pinned = true;
                    dialog3.pinnedNum = dialog2.pinnedNum;
                    getMessagesStorage().setDialogPinned(dialog2.id, dialog2.pinnedNum);
                } else {
                    z3 = true;
                    this.dialogs_dict.put(dialog2.id, dialog2);
                    MessageObject messageObject = (MessageObject) longSparseArray.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);
                        }
                    }
                }
                z2 = true;
                i5++;
                arrayList2 = arrayList;
            }
        }
        if (z2) {
            if (z3) {
                this.allDialogs.clear();
                int size2 = this.dialogs_dict.size();
                for (int i6 = 0; i6 < size2; i6++) {
                    this.allDialogs.add(this.dialogs_dict.valueAt(i6));
                }
            }
            sortDialogs(null);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        }
        getMessagesStorage().unpinAllDialogsExceptNew(arrayList3, i);
        getMessagesStorage().putDialogs(tL_messages_dialogs, 1);
        getUserConfig().setPinnedDialogsLoaded(i, 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(long dialog_id, boolean isChannel, int messageId, 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;
        int classGuid = ConnectionsManager.generateClassGuid();
        getNotificationCenter().addObserver(new NotificationCenter.NotificationCenterDelegate() {
            final Runnable val$callback;
            final int val$classGuid;
            final long val$dialog_id;

            AnonymousClass1(int classGuid2, long dialog_id2, Runnable callback2) {
                r2 = classGuid2;
                r3 = dialog_id2;
                r5 = callback2;
            }

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

    public class AnonymousClass1 implements NotificationCenter.NotificationCenterDelegate {
        final Runnable val$callback;
        final int val$classGuid;
        final long val$dialog_id;

        AnonymousClass1(int classGuid2, long dialog_id2, Runnable callback2) {
            r2 = classGuid2;
            r3 = dialog_id2;
            r5 = callback2;
        }

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

    public boolean processUpdateArray(ArrayList<TLRPC.Update> arrayList, final ArrayList<TLRPC.User> arrayList2, final ArrayList<TLRPC.Chat> arrayList3, boolean z, int i) {
        boolean z2;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray2;
        ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap;
        LongSparseArray<TLRPC.WebPage> longSparseArray3;
        ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap2;
        int i2;
        ArrayList<Integer> arrayList4;
        long j;
        ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap3;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray4;
        final LongSparseArray longSparseArray5;
        SparseIntArray sparseIntArray;
        SparseLongArray sparseLongArray;
        ArrayList<Long> arrayList5;
        boolean z3;
        SparseArray sparseArray;
        SparseArray sparseArray2;
        SparseIntArray sparseIntArray2;
        ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap4;
        int i3;
        ArrayList<Long> arrayList6;
        SparseArray sparseArray3;
        ArrayList<Integer> arrayList7;
        ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap5;
        int i4;
        long j2;
        HashMap hashMap;
        SparseLongArray sparseLongArray2;
        long j3;
        TLRPC.Message message;
        SparseArray sparseArray4;
        ArrayList<TLRPC.Message> arrayList8;
        ArrayList<MessageObject> arrayList9;
        boolean z4;
        ArrayList<TLRPC.Message> arrayList10;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray6;
        int i5;
        long j4;
        SparseArray sparseArray5;
        long j5;
        ArrayList<Integer> arrayList11;
        int i6;
        SparseLongArray sparseLongArray3;
        int i7;
        int i8;
        TLRPC.SendMessageAction sendMessageAction;
        long j6;
        SparseLongArray sparseLongArray4;
        ArrayList<Integer> arrayList12;
        int i9;
        HashMap hashMap2;
        final TLRPC.Message message2;
        int i10;
        SparseLongArray sparseLongArray5;
        LongSparseArray longSparseArray7;
        int i11;
        HashMap hashMap3;
        HashMap hashMap4;
        boolean z5;
        ArrayList arrayList13;
        ArrayList arrayList14;
        long j7;
        ArrayList arrayList15;
        ArrayList arrayList16;
        ArrayList arrayList17;
        ArrayList arrayList18;
        ArrayList arrayList19;
        ArrayList arrayList20;
        ArrayList arrayList21;
        ArrayList arrayList22;
        ArrayList arrayList23;
        ArrayList arrayList24;
        ArrayList arrayList25;
        ArrayList arrayList26;
        int i12;
        ArrayList arrayList27;
        SparseArray<SparseIntArray> sparseArray6;
        ArrayList arrayList28;
        LongSparseArray<TLRPC.WebPage> longSparseArray8;
        LongSparseArray<TLRPC.WebPage> longSparseArray9;
        ArrayList arrayList29;
        ArrayList arrayList30;
        ArrayList arrayList31;
        ArrayList arrayList32;
        ?? r2;
        ArrayList<MessageObject> arrayList33;
        ArrayList arrayList34;
        SparseIntArray sparseIntArray3;
        long j8;
        SparseArray sparseArray7;
        int i13;
        ArrayList<TLRPC.Message> arrayList35;
        ArrayList<MessageObject> arrayList36;
        ArrayList arrayList37;
        ArrayList arrayList38;
        ArrayList arrayList39;
        ArrayList arrayList40;
        ArrayList arrayList41;
        ArrayList arrayList42;
        int i14;
        ArrayList arrayList43;
        long j9;
        long j10;
        ArrayList<MessageObject> arrayList44;
        ArrayList<TLRPC.Update> arrayList45 = arrayList;
        if (arrayList.isEmpty()) {
            if (arrayList2 != null || arrayList3 != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        MessagesController.this.lambda$processUpdateArray$265$MessagesController(arrayList2, arrayList3);
                    }
                });
            }
            return true;
        }
        long currentTimeMillis = System.currentTimeMillis();
        LongSparseArray<ArrayList<MessageObject>> longSparseArray10 = null;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray11 = null;
        LongSparseArray<TLRPC.WebPage> longSparseArray12 = null;
        ArrayList<MessageObject> arrayList46 = null;
        boolean z6 = true;
        if (arrayList2 != null) {
            ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap6 = new ConcurrentHashMap<>();
            int size = arrayList2.size();
            z2 = false;
            int i15 = 0;
            while (i15 < size) {
                int i16 = size;
                TLRPC.User user = arrayList2.get(i15);
                concurrentHashMap6.put(Integer.valueOf(user.id), user);
                i15++;
                longSparseArray10 = longSparseArray10;
                size = i16;
                longSparseArray11 = longSparseArray11;
            }
            longSparseArray = longSparseArray10;
            longSparseArray2 = longSparseArray11;
            concurrentHashMap = concurrentHashMap6;
        } else {
            z2 = false;
            longSparseArray = null;
            longSparseArray2 = null;
            z6 = false;
            concurrentHashMap = this.users;
        }
        if (arrayList3 != null) {
            ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap7 = new ConcurrentHashMap<>();
            int i17 = 0;
            int size2 = arrayList3.size();
            while (i17 < size2) {
                int i18 = size2;
                TLRPC.Chat chat = arrayList3.get(i17);
                concurrentHashMap7.put(Integer.valueOf(chat.id), chat);
                i17++;
                longSparseArray12 = longSparseArray12;
                size2 = i18;
            }
            longSparseArray3 = longSparseArray12;
            concurrentHashMap2 = concurrentHashMap7;
        } else {
            longSparseArray3 = null;
            z6 = false;
            concurrentHashMap2 = this.chats;
        }
        if (z) {
            z6 = false;
        }
        if (arrayList2 != null || arrayList3 != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$processUpdateArray$266$MessagesController(arrayList2, arrayList3);
                }
            });
        }
        int i19 = 0;
        HashMap hashMap5 = new HashMap();
        int i20 = 0;
        while (true) {
            i2 = i19;
            if (i20 >= arrayList.size()) {
                break;
            }
            TLRPC.Update update = arrayList45.get(i20);
            if (!(update instanceof TLRPCCall.TL_UpdateMeetCallRequested)) {
                arrayList44 = arrayList46;
            } else {
                arrayList44 = arrayList46;
                hashMap5.put(((TLRPCCall.TL_UpdateMeetCallRequested) update).id, "1");
            }
            if (update instanceof TLRPCCall.TL_UpdateMeetCallDiscarded) {
                TLRPCCall.TL_UpdateMeetCallDiscarded tL_UpdateMeetCallDiscarded = (TLRPCCall.TL_UpdateMeetCallDiscarded) update;
                if (hashMap5.get(tL_UpdateMeetCallDiscarded.id) != null) {
                    hashMap5.remove(tL_UpdateMeetCallDiscarded.id);
                }
            }
            i20++;
            i19 = i2;
            arrayList46 = arrayList44;
        }
        ArrayList<MessageObject> arrayList47 = arrayList46;
        int size3 = arrayList.size();
        int i21 = 0;
        final SparseLongArray sparseLongArray6 = null;
        SparseIntArray sparseIntArray4 = null;
        ArrayList arrayList48 = null;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray13 = longSparseArray;
        ArrayList<MessageObject> arrayList49 = arrayList47;
        LongSparseArray longSparseArray14 = null;
        SparseArray sparseArray8 = null;
        ArrayList arrayList50 = null;
        ArrayList<TLRPC.Message> arrayList51 = null;
        int i22 = i2;
        HashMap hashMap6 = hashMap5;
        ArrayList<Long> arrayList52 = null;
        SparseArray<SparseIntArray> sparseArray9 = null;
        SparseArray sparseArray10 = null;
        SparseIntArray sparseIntArray5 = null;
        LongSparseArray<TLRPC.WebPage> longSparseArray15 = longSparseArray3;
        long j11 = currentTimeMillis;
        ArrayList<Integer> arrayList53 = null;
        ArrayList arrayList54 = null;
        ArrayList<TLRPC.Message> arrayList55 = null;
        SparseLongArray sparseLongArray7 = null;
        while (i21 < size3) {
            final TLRPC.Update update2 = arrayList45.get(i21);
            int i23 = size3;
            if ((update2 instanceof TLRPC.TL_updateNewMessage) || (update2 instanceof TLRPC.TL_updateNewChannelMessage)) {
                concurrentHashMap4 = concurrentHashMap;
                i3 = i21;
                arrayList6 = arrayList52;
                sparseArray3 = sparseArray8;
                arrayList7 = arrayList53;
                concurrentHashMap5 = concurrentHashMap2;
                i4 = i22;
                j2 = j11;
                hashMap = hashMap6;
                sparseLongArray2 = sparseLongArray7;
            } else if (update2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                concurrentHashMap4 = concurrentHashMap;
                i3 = i21;
                arrayList6 = arrayList52;
                sparseArray3 = sparseArray8;
                arrayList7 = arrayList53;
                concurrentHashMap5 = concurrentHashMap2;
                i4 = i22;
                j2 = j11;
                hashMap = hashMap6;
                sparseLongArray2 = sparseLongArray7;
            } else {
                if (update2 instanceof TLRPC.TL_updateReadMessagesContents) {
                    TLRPC.TL_updateReadMessagesContents tL_updateReadMessagesContents = (TLRPC.TL_updateReadMessagesContents) update2;
                    if (arrayList52 == null) {
                        arrayList52 = new ArrayList<>();
                    }
                    int size4 = tL_updateReadMessagesContents.messages.size();
                    int i24 = 0;
                    while (i24 < size4) {
                        arrayList52.add(Long.valueOf(tL_updateReadMessagesContents.messages.get(i24).intValue()));
                        i24++;
                        size4 = size4;
                        tL_updateReadMessagesContents = tL_updateReadMessagesContents;
                        i21 = i21;
                    }
                    i3 = i21;
                    concurrentHashMap4 = concurrentHashMap;
                    arrayList6 = arrayList52;
                    j3 = j11;
                    concurrentHashMap5 = concurrentHashMap2;
                    hashMap = hashMap6;
                } else {
                    i3 = i21;
                    if (update2 instanceof TLRPC.TL_updateChannelReadMessagesContents) {
                        TLRPC.TL_updateChannelReadMessagesContents tL_updateChannelReadMessagesContents = (TLRPC.TL_updateChannelReadMessagesContents) update2;
                        if (arrayList52 == null) {
                            arrayList52 = new ArrayList<>();
                        }
                        int i25 = 0;
                        int size5 = tL_updateChannelReadMessagesContents.messages.size();
                        while (i25 < size5) {
                            arrayList52.add(Long.valueOf((tL_updateChannelReadMessagesContents.channel_id << 32) | tL_updateChannelReadMessagesContents.messages.get(i25).intValue()));
                            i25++;
                            size5 = size5;
                            tL_updateChannelReadMessagesContents = tL_updateChannelReadMessagesContents;
                            concurrentHashMap2 = concurrentHashMap2;
                            concurrentHashMap = concurrentHashMap;
                        }
                        arrayList6 = arrayList52;
                        j3 = j11;
                        concurrentHashMap5 = concurrentHashMap2;
                        concurrentHashMap4 = concurrentHashMap;
                        hashMap = hashMap6;
                    } else {
                        ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap8 = concurrentHashMap;
                        ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap9 = concurrentHashMap2;
                        if (update2 instanceof TLRPC.TL_updateReadHistoryInbox) {
                            TLRPC.TL_updateReadHistoryInbox tL_updateReadHistoryInbox = (TLRPC.TL_updateReadHistoryInbox) update2;
                            if (sparseLongArray6 == null) {
                                sparseLongArray6 = new SparseLongArray();
                            }
                            if (tL_updateReadHistoryInbox.peer.chat_id != 0) {
                                sparseLongArray6.put(-tL_updateReadHistoryInbox.peer.chat_id, tL_updateReadHistoryInbox.max_id);
                                j10 = -tL_updateReadHistoryInbox.peer.chat_id;
                            } else {
                                sparseLongArray6.put(tL_updateReadHistoryInbox.peer.user_id, tL_updateReadHistoryInbox.max_id);
                                j10 = tL_updateReadHistoryInbox.peer.user_id;
                            }
                            Integer num = this.dialogs_read_inbox_max.get(Long.valueOf(j10));
                            if (num == null) {
                                num = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, j10));
                            }
                            this.dialogs_read_inbox_max.put(Long.valueOf(j10), Integer.valueOf(Math.max(num.intValue(), tL_updateReadHistoryInbox.max_id)));
                            arrayList6 = arrayList52;
                            j3 = j11;
                            concurrentHashMap5 = concurrentHashMap9;
                            concurrentHashMap4 = concurrentHashMap8;
                            hashMap = hashMap6;
                        } else if (update2 instanceof TLRPC.TL_updateReadHistoryOutbox) {
                            TLRPC.TL_updateReadHistoryOutbox tL_updateReadHistoryOutbox = (TLRPC.TL_updateReadHistoryOutbox) update2;
                            if (sparseLongArray7 == null) {
                                sparseLongArray7 = new SparseLongArray();
                            }
                            if (tL_updateReadHistoryOutbox.peer.chat_id != 0) {
                                sparseLongArray7.put(-tL_updateReadHistoryOutbox.peer.chat_id, tL_updateReadHistoryOutbox.max_id);
                                j9 = -tL_updateReadHistoryOutbox.peer.chat_id;
                            } else {
                                sparseLongArray7.put(tL_updateReadHistoryOutbox.peer.user_id, tL_updateReadHistoryOutbox.max_id);
                                j9 = tL_updateReadHistoryOutbox.peer.user_id;
                            }
                            Integer num2 = this.dialogs_read_outbox_max.get(Long.valueOf(j9));
                            if (num2 == null) {
                                num2 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, j9));
                            }
                            this.dialogs_read_outbox_max.put(Long.valueOf(j9), Integer.valueOf(Math.max(num2.intValue(), tL_updateReadHistoryOutbox.max_id)));
                            arrayList6 = arrayList52;
                            j3 = j11;
                            concurrentHashMap5 = concurrentHashMap9;
                            concurrentHashMap4 = concurrentHashMap8;
                            hashMap = hashMap6;
                        } else if (update2 instanceof TLRPC.TL_updateDeleteMessages) {
                            TLRPC.TL_updateDeleteMessages tL_updateDeleteMessages = (TLRPC.TL_updateDeleteMessages) update2;
                            if (sparseArray10 == null) {
                                sparseArray10 = new SparseArray();
                            }
                            ArrayList arrayList56 = (ArrayList) sparseArray10.get(0);
                            if (arrayList56 == null) {
                                arrayList56 = new ArrayList();
                                sparseArray10.put(0, arrayList56);
                            }
                            arrayList56.addAll(tL_updateDeleteMessages.messages);
                            arrayList6 = arrayList52;
                            j3 = j11;
                            concurrentHashMap5 = concurrentHashMap9;
                            concurrentHashMap4 = concurrentHashMap8;
                            hashMap = hashMap6;
                        } else if (update2 instanceof TLRPC.TL_updateDeleteScheduledMessages) {
                            TLRPC.TL_updateDeleteScheduledMessages tL_updateDeleteScheduledMessages = (TLRPC.TL_updateDeleteScheduledMessages) update2;
                            if (sparseArray8 == null) {
                                sparseArray8 = new SparseArray();
                            }
                            if (tL_updateDeleteScheduledMessages.peer instanceof TLRPC.TL_peerChannel) {
                                int i26 = tL_updateDeleteScheduledMessages.peer.channel_id;
                                i14 = i26;
                                arrayList43 = (ArrayList) sparseArray8.get(i26);
                            } else {
                                i14 = 0;
                                arrayList43 = (ArrayList) sparseArray8.get(0);
                            }
                            if (arrayList43 == null) {
                                arrayList43 = new ArrayList();
                                sparseArray8.put(i14, arrayList43);
                            }
                            arrayList43.addAll(tL_updateDeleteScheduledMessages.messages);
                            arrayList6 = arrayList52;
                            j3 = j11;
                            concurrentHashMap5 = concurrentHashMap9;
                            concurrentHashMap4 = concurrentHashMap8;
                            hashMap = hashMap6;
                        } else {
                            if (update2 instanceof TLRPC.TL_updateUserTyping) {
                                arrayList6 = arrayList52;
                                sparseArray5 = sparseArray8;
                                j5 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                arrayList11 = arrayList53;
                                hashMap = hashMap6;
                                i6 = i22;
                                sparseLongArray3 = sparseLongArray7;
                            } else if (update2 instanceof TLRPC.TL_updateChatUserTyping) {
                                arrayList6 = arrayList52;
                                sparseArray5 = sparseArray8;
                                j5 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                arrayList11 = arrayList53;
                                hashMap = hashMap6;
                                i6 = i22;
                                sparseLongArray3 = sparseLongArray7;
                            } else if (update2 instanceof TLRPC.TL_updateChatParticipants) {
                                TLRPC.TL_updateChatParticipants tL_updateChatParticipants = (TLRPC.TL_updateChatParticipants) update2;
                                int i27 = i22 | 32;
                                if (arrayList50 != null) {
                                    arrayList42 = arrayList50;
                                } else {
                                    arrayList42 = new ArrayList();
                                }
                                arrayList42.add(tL_updateChatParticipants.participants);
                                i22 = i27;
                                arrayList50 = arrayList42;
                                arrayList6 = arrayList52;
                                j3 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                hashMap = hashMap6;
                            } else if (update2 instanceof TLRPC.TL_updateUserStatus) {
                                int i28 = i22 | 4;
                                if (arrayList54 != null) {
                                    arrayList41 = arrayList54;
                                } else {
                                    arrayList41 = new ArrayList();
                                }
                                arrayList41.add(update2);
                                i22 = i28;
                                arrayList54 = arrayList41;
                                arrayList6 = arrayList52;
                                j3 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                hashMap = hashMap6;
                            } else if (update2 instanceof TLRPC.TL_updateUserName) {
                                int i29 = i22 | 1;
                                if (arrayList54 != null) {
                                    arrayList40 = arrayList54;
                                } else {
                                    arrayList40 = new ArrayList();
                                }
                                arrayList40.add(update2);
                                i22 = i29;
                                arrayList54 = arrayList40;
                                arrayList6 = arrayList52;
                                j3 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                hashMap = hashMap6;
                            } else if (update2 instanceof TLRPC.TL_updateUserPhoto) {
                                int i30 = i22 | 2;
                                getMessagesStorage().clearUserPhotos(((TLRPC.TL_updateUserPhoto) update2).user_id);
                                if (arrayList54 != null) {
                                    arrayList39 = arrayList54;
                                } else {
                                    arrayList39 = new ArrayList();
                                }
                                arrayList39.add(update2);
                                i22 = i30;
                                arrayList54 = arrayList39;
                                arrayList6 = arrayList52;
                                j3 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                hashMap = hashMap6;
                            } else if (update2 instanceof TLRPC.TL_updateUserPhone) {
                                int i31 = i22 | 1024;
                                if (arrayList54 != null) {
                                    arrayList38 = arrayList54;
                                } else {
                                    arrayList38 = new ArrayList();
                                }
                                arrayList38.add(update2);
                                i22 = i31;
                                arrayList54 = arrayList38;
                                arrayList6 = arrayList52;
                                j3 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                concurrentHashMap4 = concurrentHashMap8;
                                hashMap = hashMap6;
                            } else if (update2 instanceof TLRPC.TL_updatePeerSettings) {
                                TLRPC.TL_updatePeerSettings tL_updatePeerSettings = (TLRPC.TL_updatePeerSettings) update2;
                                if (arrayList53 == null) {
                                    arrayList53 = new ArrayList<>();
                                }
                                if (!(tL_updatePeerSettings.peer instanceof TLRPC.TL_peerUser)) {
                                    concurrentHashMap4 = concurrentHashMap8;
                                } else {
                                    concurrentHashMap4 = concurrentHashMap8;
                                    TLRPC.User user2 = concurrentHashMap4.get(Integer.valueOf(tL_updatePeerSettings.peer.user_id));
                                    if (user2 != null) {
                                        if (user2.contact) {
                                            int indexOf = arrayList53.indexOf(Integer.valueOf(-tL_updatePeerSettings.peer.user_id));
                                            if (indexOf != -1) {
                                                arrayList53.remove(indexOf);
                                            }
                                            if (!arrayList53.contains(Integer.valueOf(tL_updatePeerSettings.peer.user_id))) {
                                                arrayList53.add(Integer.valueOf(tL_updatePeerSettings.peer.user_id));
                                            }
                                        } else {
                                            int indexOf2 = arrayList53.indexOf(Integer.valueOf(tL_updatePeerSettings.peer.user_id));
                                            if (indexOf2 != -1) {
                                                arrayList53.remove(indexOf2);
                                            }
                                            if (!arrayList53.contains(Integer.valueOf(tL_updatePeerSettings.peer.user_id))) {
                                                arrayList53.add(Integer.valueOf(-tL_updatePeerSettings.peer.user_id));
                                            }
                                        }
                                    }
                                }
                                if (arrayList54 != null) {
                                    arrayList37 = arrayList54;
                                } else {
                                    arrayList37 = new ArrayList();
                                }
                                arrayList37.add(update2);
                                arrayList54 = arrayList37;
                                arrayList6 = arrayList52;
                                j3 = j11;
                                concurrentHashMap5 = concurrentHashMap9;
                                hashMap = hashMap6;
                            } else {
                                concurrentHashMap4 = concurrentHashMap8;
                                if (update2 instanceof TLRPC.TL_updateNewEncryptedMessage) {
                                    ArrayList<TLRPC.Message> decryptMessage = getSecretChatHelper().decryptMessage(((TLRPC.TL_updateNewEncryptedMessage) update2).message);
                                    if (decryptMessage == null || decryptMessage.isEmpty()) {
                                        arrayList6 = arrayList52;
                                        sparseArray7 = sparseArray8;
                                    } else {
                                        long j12 = ((TLRPC.TL_updateNewEncryptedMessage) update2).message.chat_id << 32;
                                        if (longSparseArray13 == null) {
                                            longSparseArray13 = new LongSparseArray<>();
                                        }
                                        ArrayList<MessageObject> arrayList57 = longSparseArray13.get(j12);
                                        if (arrayList57 == null) {
                                            arrayList57 = new ArrayList<>();
                                            longSparseArray13.put(j12, arrayList57);
                                        }
                                        int size6 = decryptMessage.size();
                                        arrayList6 = arrayList52;
                                        int i32 = 0;
                                        while (i32 < size6) {
                                            ArrayList<TLRPC.Message> arrayList58 = decryptMessage;
                                            TLRPC.Message message3 = decryptMessage.get(i32);
                                            ImageLoader.saveMessageThumbs(message3);
                                            if (arrayList51 != null) {
                                                i13 = size6;
                                                arrayList35 = arrayList51;
                                            } else {
                                                i13 = size6;
                                                arrayList35 = new ArrayList<>();
                                            }
                                            arrayList35.add(message3);
                                            ArrayList<TLRPC.Message> arrayList59 = arrayList35;
                                            LongSparseArray<ArrayList<MessageObject>> longSparseArray16 = longSparseArray13;
                                            SparseArray sparseArray11 = sparseArray8;
                                            MessageObject messageObject = new MessageObject(this.currentAccount, message3, concurrentHashMap4, concurrentHashMap9, this.createdDialogIds.contains(Long.valueOf(j12)));
                                            arrayList57.add(messageObject);
                                            if (arrayList49 != null) {
                                                arrayList36 = arrayList49;
                                            } else {
                                                arrayList36 = new ArrayList<>();
                                            }
                                            arrayList36.add(messageObject);
                                            i32++;
                                            arrayList49 = arrayList36;
                                            size6 = i13;
                                            decryptMessage = arrayList58;
                                            arrayList51 = arrayList59;
                                            longSparseArray13 = longSparseArray16;
                                            sparseArray8 = sparseArray11;
                                        }
                                        sparseArray7 = sparseArray8;
                                    }
                                    j3 = j11;
                                    concurrentHashMap5 = concurrentHashMap9;
                                    sparseArray8 = sparseArray7;
                                    hashMap = hashMap6;
                                } else {
                                    arrayList6 = arrayList52;
                                    SparseArray sparseArray12 = sparseArray8;
                                    if (update2 instanceof TLRPC.TL_updateEncryptedChatTyping) {
                                        TLRPC.EncryptedChat encryptedChatDB = getEncryptedChatDB(((TLRPC.TL_updateEncryptedChatTyping) update2).chat_id, true);
                                        if (encryptedChatDB != null) {
                                            long j13 = r0.chat_id << 32;
                                            ArrayList<PrintingUser> arrayList60 = this.printingUsers.get(Long.valueOf(j13));
                                            if (arrayList60 == null) {
                                                arrayList60 = new ArrayList<>();
                                                this.printingUsers.put(Long.valueOf(j13), arrayList60);
                                            }
                                            boolean z7 = false;
                                            int i33 = 0;
                                            int size7 = arrayList60.size();
                                            while (true) {
                                                if (i33 >= size7) {
                                                    j8 = j11;
                                                    break;
                                                }
                                                int i34 = size7;
                                                PrintingUser printingUser = arrayList60.get(i33);
                                                long j14 = j13;
                                                if (printingUser.userId != encryptedChatDB.user_id) {
                                                    i33++;
                                                    size7 = i34;
                                                    j13 = j14;
                                                } else {
                                                    j8 = j11;
                                                    printingUser.lastTime = j8;
                                                    printingUser.action = new TLRPC.TL_sendMessageTypingAction();
                                                    z7 = true;
                                                    break;
                                                }
                                            }
                                            if (!z7) {
                                                PrintingUser printingUser2 = new PrintingUser();
                                                printingUser2.userId = encryptedChatDB.user_id;
                                                printingUser2.lastTime = j8;
                                                printingUser2.action = new TLRPC.TL_sendMessageTypingAction();
                                                arrayList60.add(printingUser2);
                                                z2 = true;
                                            }
                                            if (Math.abs(getConnectionsManager().getCurrentTime() - i) < 30) {
                                                this.onlinePrivacy.put(Integer.valueOf(encryptedChatDB.user_id), Integer.valueOf(i));
                                            }
                                        } else {
                                            j8 = j11;
                                        }
                                        j3 = j8;
                                        hashMap = hashMap6;
                                        concurrentHashMap5 = concurrentHashMap9;
                                        sparseArray8 = sparseArray12;
                                    } else {
                                        j3 = j11;
                                        if (!(update2 instanceof TLRPC.TL_updateEncryptedMessagesRead)) {
                                            ArrayList arrayList61 = arrayList48;
                                            if (update2 instanceof TLRPC.TL_updateChatParticipantAdd) {
                                                TLRPC.TL_updateChatParticipantAdd tL_updateChatParticipantAdd = (TLRPC.TL_updateChatParticipantAdd) update2;
                                                getMessagesStorage().updateChatInfo(tL_updateChatParticipantAdd.chat_id, tL_updateChatParticipantAdd.user_id, 0, tL_updateChatParticipantAdd.inviter_id, tL_updateChatParticipantAdd.version);
                                                arrayList48 = arrayList61;
                                                hashMap = hashMap6;
                                                concurrentHashMap5 = concurrentHashMap9;
                                                sparseLongArray4 = sparseLongArray7;
                                                arrayList12 = arrayList53;
                                                i9 = i22;
                                            } else if (update2 instanceof TLRPC.TL_updateChatParticipantDelete) {
                                                TLRPC.TL_updateChatParticipantDelete tL_updateChatParticipantDelete = (TLRPC.TL_updateChatParticipantDelete) update2;
                                                getMessagesStorage().updateChatInfo(tL_updateChatParticipantDelete.chat_id, tL_updateChatParticipantDelete.user_id, 1, 0, tL_updateChatParticipantDelete.version);
                                                arrayList48 = arrayList61;
                                                hashMap = hashMap6;
                                                concurrentHashMap5 = concurrentHashMap9;
                                                sparseLongArray4 = sparseLongArray7;
                                                arrayList12 = arrayList53;
                                                i9 = i22;
                                            } else {
                                                if (update2 instanceof TLRPC.TL_updateDcOptions) {
                                                    arrayList48 = arrayList61;
                                                    hashMap = hashMap6;
                                                    concurrentHashMap5 = concurrentHashMap9;
                                                    sparseLongArray4 = sparseLongArray7;
                                                    arrayList12 = arrayList53;
                                                    i9 = i22;
                                                } else if (update2 instanceof TLRPC.TL_updateConfig) {
                                                    arrayList48 = arrayList61;
                                                    hashMap = hashMap6;
                                                    concurrentHashMap5 = concurrentHashMap9;
                                                    sparseLongArray4 = sparseLongArray7;
                                                    arrayList12 = arrayList53;
                                                    i9 = i22;
                                                } else if (update2 instanceof TLRPC.TL_updateEncryption) {
                                                    getSecretChatHelper().processUpdateEncryption((TLRPC.TL_updateEncryption) update2, concurrentHashMap4);
                                                    arrayList48 = arrayList61;
                                                    hashMap = hashMap6;
                                                    concurrentHashMap5 = concurrentHashMap9;
                                                    sparseLongArray4 = sparseLongArray7;
                                                    arrayList12 = arrayList53;
                                                    i9 = i22;
                                                } else if (update2 instanceof TLRPC.TL_updateUserBlocked) {
                                                    final TLRPC.TL_updateUserBlocked tL_updateUserBlocked = (TLRPC.TL_updateUserBlocked) update2;
                                                    getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                                        @Override
                                                        public final void run() {
                                                            MessagesController.this.lambda$processUpdateArray$268$MessagesController(tL_updateUserBlocked);
                                                        }
                                                    });
                                                    arrayList48 = arrayList61;
                                                    hashMap = hashMap6;
                                                    concurrentHashMap5 = concurrentHashMap9;
                                                    sparseLongArray4 = sparseLongArray7;
                                                    arrayList12 = arrayList53;
                                                    i9 = i22;
                                                } else if (update2 instanceof TLRPC.TL_updateNotifySettings) {
                                                    if (arrayList54 != null) {
                                                        arrayList34 = arrayList54;
                                                    } else {
                                                        arrayList34 = new ArrayList();
                                                    }
                                                    arrayList34.add(update2);
                                                    arrayList54 = arrayList34;
                                                    arrayList48 = arrayList61;
                                                    hashMap = hashMap6;
                                                    concurrentHashMap5 = concurrentHashMap9;
                                                    sparseArray8 = sparseArray12;
                                                } else if (update2 instanceof TLRPC.TL_updateServiceNotification) {
                                                    final TLRPC.TL_updateServiceNotification tL_updateServiceNotification = (TLRPC.TL_updateServiceNotification) update2;
                                                    if (tL_updateServiceNotification.popup && tL_updateServiceNotification.message != null && tL_updateServiceNotification.message.length() > 0) {
                                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                                            @Override
                                                            public final void run() {
                                                                MessagesController.this.lambda$processUpdateArray$269$MessagesController(tL_updateServiceNotification);
                                                            }
                                                        });
                                                    }
                                                    if ((tL_updateServiceNotification.flags & 2) == 0 || tL_updateServiceNotification.message.equals("ErrorSendMessageTooFreq")) {
                                                        arrayList48 = arrayList61;
                                                    } else {
                                                        TLRPC.TL_message tL_message = new TLRPC.TL_message();
                                                        int newMessageId = getUserConfig().getNewMessageId();
                                                        tL_message.id = newMessageId;
                                                        tL_message.local_id = newMessageId;
                                                        getUserConfig().saveConfig(false);
                                                        tL_message.unread = true;
                                                        tL_message.flags = 256;
                                                        if (tL_updateServiceNotification.inbox_date != 0) {
                                                            tL_message.date = tL_updateServiceNotification.inbox_date;
                                                        } else {
                                                            tL_message.date = (int) (System.currentTimeMillis() / 1000);
                                                        }
                                                        tL_message.from_id = 777000;
                                                        tL_message.to_id = new TLRPC.TL_peerUser();
                                                        tL_message.to_id.user_id = getUserConfig().getClientUserId();
                                                        tL_message.dialog_id = 777000L;
                                                        if (tL_updateServiceNotification.media != null) {
                                                            tL_message.media = tL_updateServiceNotification.media;
                                                            tL_message.flags |= 512;
                                                        }
                                                        tL_message.message = tL_updateServiceNotification.message;
                                                        if (tL_updateServiceNotification.entities != null) {
                                                            tL_message.entities = tL_updateServiceNotification.entities;
                                                            tL_message.flags |= 128;
                                                        }
                                                        if (arrayList51 != null) {
                                                            r2 = arrayList51;
                                                        } else {
                                                            r2 = new ArrayList();
                                                        }
                                                        r2.add(tL_message);
                                                        arrayList48 = arrayList61;
                                                        MessageObject messageObject2 = new MessageObject(this.currentAccount, tL_message, concurrentHashMap4, concurrentHashMap9, this.createdDialogIds.contains(Long.valueOf(tL_message.dialog_id)));
                                                        if (longSparseArray13 == null) {
                                                            longSparseArray13 = new LongSparseArray<>();
                                                        }
                                                        ArrayList<MessageObject> arrayList62 = longSparseArray13.get(tL_message.dialog_id);
                                                        if (arrayList62 == null) {
                                                            arrayList62 = new ArrayList<>();
                                                            longSparseArray13.put(tL_message.dialog_id, arrayList62);
                                                        }
                                                        arrayList62.add(messageObject2);
                                                        if (arrayList49 != null) {
                                                            arrayList33 = arrayList49;
                                                        } else {
                                                            arrayList33 = new ArrayList<>();
                                                        }
                                                        arrayList33.add(messageObject2);
                                                        arrayList51 = r2;
                                                        arrayList49 = arrayList33;
                                                    }
                                                    hashMap = hashMap6;
                                                    concurrentHashMap5 = concurrentHashMap9;
                                                    sparseArray8 = sparseArray12;
                                                } else {
                                                    arrayList48 = arrayList61;
                                                    if (update2 instanceof TLRPC.TL_updateDialogPinned) {
                                                        if (arrayList54 != null) {
                                                            arrayList32 = arrayList54;
                                                        } else {
                                                            arrayList32 = new ArrayList();
                                                        }
                                                        arrayList32.add(update2);
                                                        arrayList54 = arrayList32;
                                                        hashMap = hashMap6;
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        sparseArray8 = sparseArray12;
                                                    } else if (update2 instanceof TLRPC.TL_updatePinnedDialogs) {
                                                        if (arrayList54 != null) {
                                                            arrayList31 = arrayList54;
                                                        } else {
                                                            arrayList31 = new ArrayList();
                                                        }
                                                        arrayList31.add(update2);
                                                        arrayList54 = arrayList31;
                                                        hashMap = hashMap6;
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        sparseArray8 = sparseArray12;
                                                    } else if (update2 instanceof TLRPC.TL_updateFolderPeers) {
                                                        if (arrayList54 != null) {
                                                            arrayList30 = arrayList54;
                                                        } else {
                                                            arrayList30 = new ArrayList();
                                                        }
                                                        arrayList30.add(update2);
                                                        getMessagesStorage().setDialogsFolderId(((TLRPC.TL_updateFolderPeers) update2).folder_peers, null, 0L, 0);
                                                        arrayList54 = arrayList30;
                                                        hashMap = hashMap6;
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        sparseArray8 = sparseArray12;
                                                    } else if (update2 instanceof TLRPC.TL_updatePrivacy) {
                                                        if (arrayList54 != null) {
                                                            arrayList29 = arrayList54;
                                                        } else {
                                                            arrayList29 = new ArrayList();
                                                        }
                                                        arrayList29.add(update2);
                                                        arrayList54 = arrayList29;
                                                        hashMap = hashMap6;
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        sparseArray8 = sparseArray12;
                                                    } else if (update2 instanceof TLRPC.TL_updateWebPage) {
                                                        TLRPC.TL_updateWebPage tL_updateWebPage = (TLRPC.TL_updateWebPage) update2;
                                                        if (longSparseArray15 != null) {
                                                            longSparseArray9 = longSparseArray15;
                                                        } else {
                                                            longSparseArray9 = new LongSparseArray<>();
                                                        }
                                                        longSparseArray9.put(tL_updateWebPage.webpage.id, tL_updateWebPage.webpage);
                                                        longSparseArray15 = longSparseArray9;
                                                        hashMap = hashMap6;
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        sparseArray8 = sparseArray12;
                                                    } else if (update2 instanceof TLRPC.TL_updateChannelWebPage) {
                                                        TLRPC.TL_updateChannelWebPage tL_updateChannelWebPage = (TLRPC.TL_updateChannelWebPage) update2;
                                                        if (longSparseArray15 != null) {
                                                            longSparseArray8 = longSparseArray15;
                                                        } else {
                                                            longSparseArray8 = new LongSparseArray<>();
                                                        }
                                                        longSparseArray8.put(tL_updateChannelWebPage.webpage.id, tL_updateChannelWebPage.webpage);
                                                        longSparseArray15 = longSparseArray8;
                                                        hashMap = hashMap6;
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        sparseArray8 = sparseArray12;
                                                    } else if (update2 instanceof TLRPC.TL_updateChannelTooLong) {
                                                        TLRPC.TL_updateChannelTooLong tL_updateChannelTooLong = (TLRPC.TL_updateChannelTooLong) update2;
                                                        if (BuildVars.LOGS_ENABLED) {
                                                            FileLog.d(update2 + " channelId = " + tL_updateChannelTooLong.channel_id);
                                                        }
                                                        int i35 = this.channelsPts.get(tL_updateChannelTooLong.channel_id);
                                                        if (i35 != 0) {
                                                            concurrentHashMap5 = concurrentHashMap9;
                                                        } else {
                                                            i35 = getMessagesStorage().getChannelPtsSync(tL_updateChannelTooLong.channel_id);
                                                            if (i35 == 0) {
                                                                concurrentHashMap5 = concurrentHashMap9;
                                                                TLRPC.Chat chat2 = concurrentHashMap5.get(Integer.valueOf(tL_updateChannelTooLong.channel_id));
                                                                if (chat2 == null || chat2.min) {
                                                                    chat2 = getChat(Integer.valueOf(tL_updateChannelTooLong.channel_id));
                                                                }
                                                                if (chat2 == null || chat2.min) {
                                                                    chat2 = getMessagesStorage().getChatSync(tL_updateChannelTooLong.channel_id);
                                                                    putChat(chat2, true);
                                                                }
                                                                if (chat2 != null && !chat2.min) {
                                                                    loadUnknownChannel(chat2, 0L);
                                                                }
                                                            } else {
                                                                concurrentHashMap5 = concurrentHashMap9;
                                                                this.channelsPts.put(tL_updateChannelTooLong.channel_id, i35);
                                                            }
                                                        }
                                                        if (i35 != 0) {
                                                            if ((tL_updateChannelTooLong.flags & 1) == 0) {
                                                                getChannelDifference(tL_updateChannelTooLong.channel_id);
                                                            } else if (tL_updateChannelTooLong.pts > i35) {
                                                                getChannelDifference(tL_updateChannelTooLong.channel_id);
                                                            }
                                                        }
                                                        arrayList12 = arrayList53;
                                                        hashMap = hashMap6;
                                                        i9 = i22;
                                                        sparseLongArray4 = sparseLongArray7;
                                                    } else {
                                                        concurrentHashMap5 = concurrentHashMap9;
                                                        if (update2 instanceof TLRPC.TL_updateReadChannelInbox) {
                                                            TLRPC.TL_updateReadChannelInbox tL_updateReadChannelInbox = (TLRPC.TL_updateReadChannelInbox) update2;
                                                            ArrayList<Integer> arrayList63 = arrayList53;
                                                            long j15 = tL_updateReadChannelInbox.max_id | (tL_updateReadChannelInbox.channel_id << 32);
                                                            long j16 = -tL_updateReadChannelInbox.channel_id;
                                                            if (sparseLongArray6 == null) {
                                                                sparseLongArray6 = new SparseLongArray();
                                                            }
                                                            sparseLongArray6.put(-tL_updateReadChannelInbox.channel_id, j15);
                                                            Integer num3 = this.dialogs_read_inbox_max.get(Long.valueOf(j16));
                                                            if (num3 == null) {
                                                                num3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(false, j16));
                                                            }
                                                            this.dialogs_read_inbox_max.put(Long.valueOf(j16), Integer.valueOf(Math.max(num3.intValue(), tL_updateReadChannelInbox.max_id)));
                                                            hashMap = hashMap6;
                                                            arrayList53 = arrayList63;
                                                            sparseArray8 = sparseArray12;
                                                        } else {
                                                            arrayList12 = arrayList53;
                                                            if (update2 instanceof TLRPC.TL_updateReadChannelOutbox) {
                                                                TLRPC.TL_updateReadChannelOutbox tL_updateReadChannelOutbox = (TLRPC.TL_updateReadChannelOutbox) update2;
                                                                long j17 = tL_updateReadChannelOutbox.max_id | (tL_updateReadChannelOutbox.channel_id << 32);
                                                                long j18 = -tL_updateReadChannelOutbox.channel_id;
                                                                if (sparseLongArray7 == null) {
                                                                    sparseLongArray7 = new SparseLongArray();
                                                                }
                                                                sparseLongArray7.put(-tL_updateReadChannelOutbox.channel_id, j17);
                                                                Integer num4 = this.dialogs_read_outbox_max.get(Long.valueOf(j18));
                                                                if (num4 == null) {
                                                                    num4 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, j18));
                                                                }
                                                                this.dialogs_read_outbox_max.put(Long.valueOf(j18), Integer.valueOf(Math.max(num4.intValue(), tL_updateReadChannelOutbox.max_id)));
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateDeleteChannelMessages) {
                                                                TLRPC.TL_updateDeleteChannelMessages tL_updateDeleteChannelMessages = (TLRPC.TL_updateDeleteChannelMessages) update2;
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                    FileLog.d(update2 + " channelId = " + tL_updateDeleteChannelMessages.channel_id);
                                                                }
                                                                if (sparseArray10 == null) {
                                                                    sparseArray10 = new SparseArray();
                                                                }
                                                                ArrayList arrayList64 = (ArrayList) sparseArray10.get(tL_updateDeleteChannelMessages.channel_id);
                                                                if (arrayList64 == null) {
                                                                    arrayList64 = new ArrayList();
                                                                    sparseArray10.put(tL_updateDeleteChannelMessages.channel_id, arrayList64);
                                                                }
                                                                arrayList64.addAll(tL_updateDeleteChannelMessages.messages);
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateChannel) {
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                    FileLog.d(update2 + " channelId = " + ((TLRPC.TL_updateChannel) update2).channel_id);
                                                                }
                                                                if (arrayList54 != null) {
                                                                    arrayList28 = arrayList54;
                                                                } else {
                                                                    arrayList28 = new ArrayList();
                                                                }
                                                                arrayList28.add(update2);
                                                                arrayList54 = arrayList28;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateChannelMessageViews) {
                                                                TLRPC.TL_updateChannelMessageViews tL_updateChannelMessageViews = (TLRPC.TL_updateChannelMessageViews) update2;
                                                                if (BuildVars.LOGS_ENABLED) {
                                                                    FileLog.d(update2 + " channelId = " + tL_updateChannelMessageViews.channel_id);
                                                                }
                                                                if (sparseArray9 != null) {
                                                                    sparseArray6 = sparseArray9;
                                                                } else {
                                                                    sparseArray6 = new SparseArray<>();
                                                                }
                                                                SparseIntArray sparseIntArray6 = sparseArray6.get(tL_updateChannelMessageViews.channel_id);
                                                                if (sparseIntArray6 == null) {
                                                                    sparseIntArray6 = new SparseIntArray();
                                                                    sparseArray6.put(tL_updateChannelMessageViews.channel_id, sparseIntArray6);
                                                                }
                                                                sparseIntArray6.put(tL_updateChannelMessageViews.id, tL_updateChannelMessageViews.views);
                                                                sparseArray9 = sparseArray6;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateChatParticipantAdmin) {
                                                                TLRPC.TL_updateChatParticipantAdmin tL_updateChatParticipantAdmin = (TLRPC.TL_updateChatParticipantAdmin) update2;
                                                                getMessagesStorage().updateChatInfo(tL_updateChatParticipantAdmin.chat_id, tL_updateChatParticipantAdmin.user_id, 2, tL_updateChatParticipantAdmin.is_admin ? 1 : 0, tL_updateChatParticipantAdmin.version);
                                                                i9 = i22;
                                                                hashMap = hashMap6;
                                                                sparseLongArray4 = sparseLongArray7;
                                                            } else if (update2 instanceof TLRPC.TL_updateChatDefaultBannedRights) {
                                                                TLRPC.TL_updateChatDefaultBannedRights tL_updateChatDefaultBannedRights = (TLRPC.TL_updateChatDefaultBannedRights) update2;
                                                                if (tL_updateChatDefaultBannedRights.peer.channel_id != 0) {
                                                                    i12 = tL_updateChatDefaultBannedRights.peer.channel_id;
                                                                } else {
                                                                    i12 = tL_updateChatDefaultBannedRights.peer.chat_id;
                                                                }
                                                                getMessagesStorage().updateChatDefaultBannedRights(i12, tL_updateChatDefaultBannedRights.default_banned_rights, tL_updateChatDefaultBannedRights.version);
                                                                if (arrayList54 != null) {
                                                                    arrayList27 = arrayList54;
                                                                } else {
                                                                    arrayList27 = new ArrayList();
                                                                }
                                                                arrayList27.add(update2);
                                                                arrayList54 = arrayList27;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateStickerSets) {
                                                                if (arrayList54 != null) {
                                                                    arrayList26 = arrayList54;
                                                                } else {
                                                                    arrayList26 = new ArrayList();
                                                                }
                                                                arrayList26.add(update2);
                                                                arrayList54 = arrayList26;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateStickerSetsOrder) {
                                                                if (arrayList54 != null) {
                                                                    arrayList25 = arrayList54;
                                                                } else {
                                                                    arrayList25 = new ArrayList();
                                                                }
                                                                arrayList25.add(update2);
                                                                arrayList54 = arrayList25;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateNewStickerSet) {
                                                                if (arrayList54 != null) {
                                                                    arrayList24 = arrayList54;
                                                                } else {
                                                                    arrayList24 = new ArrayList();
                                                                }
                                                                arrayList24.add(update2);
                                                                arrayList54 = arrayList24;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateDraftMessage) {
                                                                if (arrayList54 != null) {
                                                                    arrayList23 = arrayList54;
                                                                } else {
                                                                    arrayList23 = new ArrayList();
                                                                }
                                                                arrayList23.add(update2);
                                                                arrayList54 = arrayList23;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else if (update2 instanceof TLRPC.TL_updateSavedGifs) {
                                                                if (arrayList54 != null) {
                                                                    arrayList22 = arrayList54;
                                                                } else {
                                                                    arrayList22 = new ArrayList();
                                                                }
                                                                arrayList22.add(update2);
                                                                arrayList54 = arrayList22;
                                                                hashMap = hashMap6;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            } else {
                                                                if (update2 instanceof TLRPC.TL_updateEditChannelMessage) {
                                                                    hashMap2 = hashMap6;
                                                                } else if (update2 instanceof TLRPC.TL_updateEditMessage) {
                                                                    hashMap2 = hashMap6;
                                                                } else if (update2 instanceof TLRPC.TL_updateChannelPinnedMessage) {
                                                                    TLRPC.TL_updateChannelPinnedMessage tL_updateChannelPinnedMessage = (TLRPC.TL_updateChannelPinnedMessage) update2;
                                                                    if (BuildVars.LOGS_ENABLED) {
                                                                        FileLog.d(update2 + " channelId = " + tL_updateChannelPinnedMessage.channel_id);
                                                                    }
                                                                    getMessagesStorage().updateChatPinnedMessage(tL_updateChannelPinnedMessage.channel_id, tL_updateChannelPinnedMessage.id);
                                                                    i9 = i22;
                                                                    hashMap = hashMap6;
                                                                    sparseLongArray4 = sparseLongArray7;
                                                                } else if (update2 instanceof TLRPC.TL_updateChatPinnedMessage) {
                                                                    TLRPC.TL_updateChatPinnedMessage tL_updateChatPinnedMessage = (TLRPC.TL_updateChatPinnedMessage) update2;
                                                                    getMessagesStorage().updateChatPinnedMessage(tL_updateChatPinnedMessage.chat_id, tL_updateChatPinnedMessage.id);
                                                                    i9 = i22;
                                                                    hashMap = hashMap6;
                                                                    sparseLongArray4 = sparseLongArray7;
                                                                } else if (update2 instanceof TLRPC.TL_updateUserPinnedMessage) {
                                                                    TLRPC.TL_updateUserPinnedMessage tL_updateUserPinnedMessage = (TLRPC.TL_updateUserPinnedMessage) update2;
                                                                    getMessagesStorage().updateUserPinnedMessage(tL_updateUserPinnedMessage.user_id, tL_updateUserPinnedMessage.id);
                                                                    i9 = i22;
                                                                    hashMap = hashMap6;
                                                                    sparseLongArray4 = sparseLongArray7;
                                                                } else if (update2 instanceof TLRPC.TL_updateReadFeaturedStickers) {
                                                                    if (arrayList54 != null) {
                                                                        arrayList21 = arrayList54;
                                                                    } else {
                                                                        arrayList21 = new ArrayList();
                                                                    }
                                                                    arrayList21.add(update2);
                                                                    arrayList54 = arrayList21;
                                                                    hashMap = hashMap6;
                                                                    arrayList53 = arrayList12;
                                                                    sparseArray8 = sparseArray12;
                                                                } else if (update2 instanceof TLRPC.TL_updatePhoneCall) {
                                                                    if (arrayList54 != null) {
                                                                        arrayList20 = arrayList54;
                                                                    } else {
                                                                        arrayList20 = new ArrayList();
                                                                    }
                                                                    arrayList20.add(update2);
                                                                    arrayList54 = arrayList20;
                                                                    hashMap = hashMap6;
                                                                    arrayList53 = arrayList12;
                                                                    sparseArray8 = sparseArray12;
                                                                } else if (update2 instanceof TLRPC.TL_updateLangPack) {
                                                                    final TLRPC.TL_updateLangPack tL_updateLangPack = (TLRPC.TL_updateLangPack) update2;
                                                                    AndroidUtilities.runOnUIThread(new Runnable() {
                                                                        @Override
                                                                        public final void run() {
                                                                            MessagesController.this.lambda$processUpdateArray$271$MessagesController(tL_updateLangPack);
                                                                        }
                                                                    });
                                                                    i9 = i22;
                                                                    hashMap = hashMap6;
                                                                    sparseLongArray4 = sparseLongArray7;
                                                                } else if (update2 instanceof TLRPC.TL_updateLangPackTooLong) {
                                                                    LocaleController.getInstance().reloadCurrentRemoteLocale(this.currentAccount, ((TLRPC.TL_updateLangPackTooLong) update2).lang_code);
                                                                    i9 = i22;
                                                                    hashMap = hashMap6;
                                                                    sparseLongArray4 = sparseLongArray7;
                                                                } else if (update2 instanceof TLRPC.TL_updateFavedStickers) {
                                                                    if (arrayList54 != null) {
                                                                        arrayList19 = arrayList54;
                                                                    } else {
                                                                        arrayList19 = new ArrayList();
                                                                    }
                                                                    arrayList19.add(update2);
                                                                    arrayList54 = arrayList19;
                                                                    hashMap = hashMap6;
                                                                    arrayList53 = arrayList12;
                                                                    sparseArray8 = sparseArray12;
                                                                } else if (update2 instanceof TLRPC.TL_updateContactsReset) {
                                                                    if (arrayList54 != null) {
                                                                        arrayList18 = arrayList54;
                                                                    } else {
                                                                        arrayList18 = new ArrayList();
                                                                    }
                                                                    arrayList18.add(update2);
                                                                    arrayList54 = arrayList18;
                                                                    hashMap = hashMap6;
                                                                    arrayList53 = arrayList12;
                                                                    sparseArray8 = sparseArray12;
                                                                } else if (update2 instanceof TLRPC.TL_updateChannelAvailableMessages) {
                                                                    TLRPC.TL_updateChannelAvailableMessages tL_updateChannelAvailableMessages = (TLRPC.TL_updateChannelAvailableMessages) update2;
                                                                    SparseIntArray sparseIntArray7 = sparseIntArray4;
                                                                    if (sparseIntArray7 == null) {
                                                                        sparseIntArray7 = new SparseIntArray();
                                                                    }
                                                                    int i36 = sparseIntArray7.get(tL_updateChannelAvailableMessages.channel_id);
                                                                    if (i36 == 0 || i36 < tL_updateChannelAvailableMessages.available_min_id) {
                                                                        sparseIntArray7.put(tL_updateChannelAvailableMessages.channel_id, tL_updateChannelAvailableMessages.available_min_id);
                                                                    }
                                                                    sparseIntArray4 = sparseIntArray7;
                                                                    hashMap = hashMap6;
                                                                    arrayList53 = arrayList12;
                                                                    sparseArray8 = sparseArray12;
                                                                } else {
                                                                    SparseIntArray sparseIntArray8 = sparseIntArray4;
                                                                    if (update2 instanceof TLRPC.TL_updateDialogUnreadMark) {
                                                                        if (arrayList54 != null) {
                                                                            arrayList17 = arrayList54;
                                                                        } else {
                                                                            arrayList17 = new ArrayList();
                                                                        }
                                                                        arrayList17.add(update2);
                                                                        arrayList54 = arrayList17;
                                                                        sparseIntArray4 = sparseIntArray8;
                                                                        hashMap = hashMap6;
                                                                        arrayList53 = arrayList12;
                                                                        sparseArray8 = sparseArray12;
                                                                    } else if (update2 instanceof TLRPC.TL_updateMessagePoll) {
                                                                        TLRPC.TL_updateMessagePoll tL_updateMessagePoll = (TLRPC.TL_updateMessagePoll) update2;
                                                                        if (Math.abs(SystemClock.uptimeMillis() - getSendMessagesHelper().getVoteSendTime(tL_updateMessagePoll.poll_id)) < 600) {
                                                                            sparseIntArray4 = sparseIntArray8;
                                                                            i9 = i22;
                                                                            hashMap = hashMap6;
                                                                            sparseLongArray4 = sparseLongArray7;
                                                                        } else {
                                                                            sparseIntArray4 = sparseIntArray8;
                                                                            getMessagesStorage().updateMessagePollResults(tL_updateMessagePoll.poll_id, tL_updateMessagePoll.poll, tL_updateMessagePoll.results);
                                                                            if (arrayList54 != null) {
                                                                                arrayList16 = arrayList54;
                                                                            } else {
                                                                                arrayList16 = new ArrayList();
                                                                            }
                                                                            arrayList16.add(update2);
                                                                            arrayList54 = arrayList16;
                                                                            hashMap = hashMap6;
                                                                            arrayList53 = arrayList12;
                                                                            sparseArray8 = sparseArray12;
                                                                        }
                                                                    } else {
                                                                        sparseIntArray4 = sparseIntArray8;
                                                                        if (update2 instanceof TLRPC.TL_updateMessageReactions) {
                                                                            TLRPC.TL_updateMessageReactions tL_updateMessageReactions = (TLRPC.TL_updateMessageReactions) update2;
                                                                            if (tL_updateMessageReactions.peer.chat_id != 0) {
                                                                                j7 = -tL_updateMessageReactions.peer.chat_id;
                                                                            } else if (tL_updateMessageReactions.peer.channel_id != 0) {
                                                                                j7 = -tL_updateMessageReactions.peer.channel_id;
                                                                            } else {
                                                                                j7 = tL_updateMessageReactions.peer.user_id;
                                                                            }
                                                                            getMessagesStorage().updateMessageReactions(j7, tL_updateMessageReactions.msg_id, tL_updateMessageReactions.peer.channel_id, tL_updateMessageReactions.reactions);
                                                                            if (arrayList54 != null) {
                                                                                arrayList15 = arrayList54;
                                                                            } else {
                                                                                arrayList15 = new ArrayList();
                                                                            }
                                                                            arrayList15.add(update2);
                                                                            arrayList54 = arrayList15;
                                                                            hashMap = hashMap6;
                                                                            arrayList53 = arrayList12;
                                                                            sparseArray8 = sparseArray12;
                                                                        } else if (update2 instanceof TLRPC.TL_updatePeerLocated) {
                                                                            if (arrayList54 != null) {
                                                                                arrayList14 = arrayList54;
                                                                            } else {
                                                                                arrayList14 = new ArrayList();
                                                                            }
                                                                            arrayList14.add(update2);
                                                                            arrayList54 = arrayList14;
                                                                            hashMap = hashMap6;
                                                                            arrayList53 = arrayList12;
                                                                            sparseArray8 = sparseArray12;
                                                                        } else if (update2 instanceof TLRPC.TL_updateTheme) {
                                                                            if (arrayList54 != null) {
                                                                                arrayList13 = arrayList54;
                                                                            } else {
                                                                                arrayList13 = new ArrayList();
                                                                            }
                                                                            arrayList13.add(update2);
                                                                            arrayList54 = arrayList13;
                                                                            hashMap = hashMap6;
                                                                            arrayList53 = arrayList12;
                                                                            sparseArray8 = sparseArray12;
                                                                        } else if (update2 instanceof TLRPCContacts.UpdateContactApplyRequested) {
                                                                            i9 = i22;
                                                                            hashMap = hashMap6;
                                                                            sparseLongArray4 = sparseLongArray7;
                                                                        } else if (update2 instanceof TLRPC.TL_updateUserMomentStateV1) {
                                                                            final TLRPC.TL_updateUserMomentStateV1 tL_updateUserMomentStateV1 = (TLRPC.TL_updateUserMomentStateV1) update2;
                                                                            if (tL_updateUserMomentStateV1 != null && tL_updateUserMomentStateV1.user_id != 0 && tL_updateUserMomentStateV1.type != 0) {
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        MessagesController.this.lambda$processUpdateArray$272$MessagesController(tL_updateUserMomentStateV1);
                                                                                    }
                                                                                });
                                                                            }
                                                                            i9 = i22;
                                                                            hashMap = hashMap6;
                                                                            sparseLongArray4 = sparseLongArray7;
                                                                        } else if (update2 instanceof TLRPCCall.TL_UpdateMeetCallRequested) {
                                                                            TLRPCCall.TL_UpdateMeetCallRequested tL_UpdateMeetCallRequested = (TLRPCCall.TL_UpdateMeetCallRequested) update2;
                                                                            if (tL_UpdateMeetCallRequested == null || tL_UpdateMeetCallRequested.admin_id == getUserConfig().getClientUserId() || (System.currentTimeMillis() / 1000) - tL_UpdateMeetCallRequested.date >= 35) {
                                                                                hashMap4 = hashMap6;
                                                                            } else {
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> receive video call , id = " + tL_UpdateMeetCallRequested.id);
                                                                                }
                                                                                if (tL_UpdateMeetCallRequested.participant_id != null) {
                                                                                    Iterator<TLRPC.InputPeer> it = tL_UpdateMeetCallRequested.participant_id.iterator();
                                                                                    while (it.hasNext()) {
                                                                                        if (it.next().user_id == AccountInstance.getInstance(UserConfig.selectedAccount).getUserConfig().getCurrentUser().id) {
                                                                                            z5 = true;
                                                                                            break;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                z5 = false;
                                                                                hashMap4 = hashMap6;
                                                                                if (hashMap4.get(tL_UpdateMeetCallRequested.id) != null && z5) {
                                                                                    boolean z8 = (tL_UpdateMeetCallRequested.flags & 32) != 0;
                                                                                    Intent intent = new Intent(ApplicationLoader.applicationContext, (Class<?>) VisualCallReceiveService.class);
                                                                                    intent.putExtra(MimeTypes.BASE_TYPE_VIDEO, z8);
                                                                                    intent.putExtra(TtmlNode.ATTR_ID, tL_UpdateMeetCallRequested.id);
                                                                                    intent.putExtra("admin_id", tL_UpdateMeetCallRequested.admin_id);
                                                                                    intent.putExtra("app_id", tL_UpdateMeetCallRequested.appid);
                                                                                    intent.putExtra("token", tL_UpdateMeetCallRequested.token);
                                                                                    intent.putStringArrayListExtra("gslb", tL_UpdateMeetCallRequested.gslb);
                                                                                    intent.putExtra("json", tL_UpdateMeetCallRequested.data.data);
                                                                                    try {
                                                                                        if (Build.VERSION.SDK_INT >= 26) {
                                                                                            ApplicationLoader.applicationContext.startForegroundService(intent);
                                                                                        } else {
                                                                                            ApplicationLoader.applicationContext.startService(intent);
                                                                                        }
                                                                                    } catch (Throwable th) {
                                                                                        FileLog.e(th);
                                                                                    }
                                                                                }
                                                                            }
                                                                            hashMap = hashMap4;
                                                                            i9 = i22;
                                                                            sparseLongArray4 = sparseLongArray7;
                                                                        } else {
                                                                            HashMap hashMap7 = hashMap6;
                                                                            if (update2 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);
                                                                                    }
                                                                                });
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 instanceof TLRPCCall.TL_UpdateMeetCallDiscarded) {
                                                                                TLRPCCall.TL_UpdateMeetCallDiscarded tL_UpdateMeetCallDiscarded2 = (TLRPCCall.TL_UpdateMeetCallDiscarded) update2;
                                                                                if (BuildVars.LOGS_ENABLED) {
                                                                                    FileLog.d("MessagesController call ===> 收到挂断反馈 , d.id = " + tL_UpdateMeetCallDiscarded2.id + " d.duration = " + tL_UpdateMeetCallDiscarded2.duration);
                                                                                }
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.reecivedAVideoDiscarded, TLRPC.Update.this);
                                                                                    }
                                                                                });
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 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);
                                                                                    }
                                                                                });
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 instanceof TLRPCContacts.UpdateResetContactsApplyUnread) {
                                                                                handleUpdatesContactsApply(0);
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        MessagesController.this.lambda$processUpdateArray$276$MessagesController();
                                                                                    }
                                                                                });
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 instanceof TLRPCContacts.UpdateRegetContactsApplies) {
                                                                                getContactsApplyDifferenceV2(true, false);
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 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);
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 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);
                                                                                    }
                                                                                });
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 instanceof TLRPCContacts.CL_user_updateUserFull) {
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else if (update2 instanceof TLRPCContacts.TL_updateContactGroups) {
                                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                    @Override
                                                                                    public final void run() {
                                                                                        MessagesController.this.lambda$processUpdateArray$279$MessagesController();
                                                                                    }
                                                                                });
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            } else {
                                                                                hashMap = hashMap7;
                                                                                i9 = i22;
                                                                                sparseLongArray4 = sparseLongArray7;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                int clientUserId = getUserConfig().getClientUserId();
                                                                if (update2 instanceof TLRPC.TL_updateEditChannelMessage) {
                                                                    message2 = ((TLRPC.TL_updateEditChannelMessage) update2).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 = concurrentHashMap5.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) update2).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 (z) {
                                                                    hashMap = hashMap2;
                                                                } else {
                                                                    int i37 = 0;
                                                                    int size8 = message2.entities.size();
                                                                    while (i37 < size8) {
                                                                        TLRPC.MessageEntity messageEntity = message2.entities.get(i37);
                                                                        if (!(messageEntity instanceof TLRPC.TL_messageEntityMentionName)) {
                                                                            i11 = size8;
                                                                            hashMap3 = hashMap2;
                                                                        } else {
                                                                            int i38 = ((TLRPC.TL_messageEntityMentionName) messageEntity).user_id;
                                                                            i11 = size8;
                                                                            TLRPC.User user3 = concurrentHashMap4.get(Integer.valueOf(i38));
                                                                            if (user3 != null) {
                                                                                hashMap3 = hashMap2;
                                                                            } else {
                                                                                hashMap3 = hashMap2;
                                                                            }
                                                                            user3 = getUser(Integer.valueOf(i38));
                                                                            if (user3 == null || user3.min) {
                                                                                user3 = getMessagesStorage().getUserSync(i38);
                                                                                if (user3 != null && user3.min) {
                                                                                    user3 = null;
                                                                                }
                                                                                putUser(user3, true);
                                                                            }
                                                                            if (user3 == null) {
                                                                                return false;
                                                                            }
                                                                        }
                                                                        i37++;
                                                                        size8 = i11;
                                                                        hashMap2 = hashMap3;
                                                                    }
                                                                    hashMap = hashMap2;
                                                                }
                                                                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> concurrentHashMap10 = message2.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                                                                Integer num5 = concurrentHashMap10.get(Long.valueOf(message2.dialog_id));
                                                                if (num5 != null) {
                                                                    i10 = i22;
                                                                    sparseLongArray5 = sparseLongArray7;
                                                                } else {
                                                                    i10 = i22;
                                                                    sparseLongArray5 = sparseLongArray7;
                                                                    num5 = Integer.valueOf(getMessagesStorage().getDialogReadMax(message2.out, message2.dialog_id));
                                                                    concurrentHashMap10.put(Long.valueOf(message2.dialog_id), num5);
                                                                }
                                                                message2.unread = num5.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 messageObject3 = new MessageObject(this.currentAccount, message2, concurrentHashMap4, concurrentHashMap5, this.createdDialogIds.contains(Long.valueOf(message2.dialog_id)));
                                                                if (longSparseArray14 != null) {
                                                                    longSparseArray7 = longSparseArray14;
                                                                } else {
                                                                    longSparseArray7 = new LongSparseArray();
                                                                }
                                                                LongSparseArray longSparseArray17 = longSparseArray7;
                                                                LongSparseArray longSparseArray18 = longSparseArray7;
                                                                ArrayList arrayList65 = (ArrayList) longSparseArray17.get(message2.dialog_id);
                                                                if (arrayList65 != null) {
                                                                    longSparseArray14 = longSparseArray18;
                                                                } else {
                                                                    arrayList65 = new ArrayList();
                                                                    longSparseArray14 = longSparseArray18;
                                                                    longSparseArray17.put(message2.dialog_id, arrayList65);
                                                                }
                                                                arrayList65.add(messageObject3);
                                                                i22 = i10;
                                                                sparseLongArray7 = sparseLongArray5;
                                                                arrayList53 = arrayList12;
                                                                sparseArray8 = sparseArray12;
                                                            }
                                                        }
                                                    }
                                                }
                                                getConnectionsManager().updateDcSettings();
                                            }
                                            i22 = i9;
                                            sparseLongArray7 = sparseLongArray4;
                                            arrayList53 = arrayList12;
                                            sparseArray8 = sparseArray12;
                                        } else {
                                            TLRPC.TL_updateEncryptedMessagesRead tL_updateEncryptedMessagesRead = (TLRPC.TL_updateEncryptedMessagesRead) update2;
                                            if (sparseIntArray5 != null) {
                                                sparseIntArray3 = sparseIntArray5;
                                            } else {
                                                sparseIntArray3 = new SparseIntArray();
                                            }
                                            sparseIntArray3.put(tL_updateEncryptedMessagesRead.chat_id, tL_updateEncryptedMessagesRead.max_date);
                                            ArrayList arrayList66 = arrayList48;
                                            if (arrayList66 == null) {
                                                arrayList66 = new ArrayList();
                                            }
                                            arrayList66.add((TLRPC.TL_updateEncryptedMessagesRead) update2);
                                            arrayList48 = arrayList66;
                                            sparseIntArray5 = sparseIntArray3;
                                            hashMap = hashMap6;
                                            concurrentHashMap5 = concurrentHashMap9;
                                            sparseArray8 = sparseArray12;
                                        }
                                    }
                                }
                            }
                            if (update2 instanceof TLRPC.TL_updateUserTyping) {
                                TLRPC.TL_updateUserTyping tL_updateUserTyping = (TLRPC.TL_updateUserTyping) update2;
                                i8 = tL_updateUserTyping.user_id;
                                sendMessageAction = tL_updateUserTyping.action;
                                i7 = 0;
                            } else {
                                TLRPC.TL_updateChatUserTyping tL_updateChatUserTyping = (TLRPC.TL_updateChatUserTyping) update2;
                                int i39 = tL_updateChatUserTyping.chat_id;
                                int i40 = tL_updateChatUserTyping.user_id;
                                TLRPC.SendMessageAction sendMessageAction2 = tL_updateChatUserTyping.action;
                                i7 = i39;
                                i8 = i40;
                                sendMessageAction = sendMessageAction2;
                            }
                            if (i8 != getUserConfig().getClientUserId()) {
                                long j19 = -i7;
                                if (j19 == 0) {
                                    j19 = i8;
                                }
                                ArrayList<PrintingUser> arrayList67 = this.printingUsers.get(Long.valueOf(j19));
                                if (sendMessageAction instanceof TLRPC.TL_sendMessageCancelAction) {
                                    if (arrayList67 != null) {
                                        int i41 = 0;
                                        int size9 = arrayList67.size();
                                        while (true) {
                                            if (i41 >= size9) {
                                                break;
                                            }
                                            int i42 = i7;
                                            int i43 = size9;
                                            if (arrayList67.get(i41).userId != i8) {
                                                i41++;
                                                size9 = i43;
                                                i7 = i42;
                                            } else {
                                                arrayList67.remove(i41);
                                                z2 = true;
                                                break;
                                            }
                                        }
                                        if (arrayList67.isEmpty()) {
                                            this.printingUsers.remove(Long.valueOf(j19));
                                        }
                                        j6 = j5;
                                    } else {
                                        j6 = j5;
                                    }
                                } else {
                                    if (arrayList67 == null) {
                                        arrayList67 = new ArrayList<>();
                                        this.printingUsers.put(Long.valueOf(j19), arrayList67);
                                    }
                                    boolean z9 = false;
                                    Iterator<PrintingUser> it2 = arrayList67.iterator();
                                    while (true) {
                                        if (!it2.hasNext()) {
                                            j6 = j5;
                                            break;
                                        }
                                        PrintingUser next = it2.next();
                                        boolean z10 = z9;
                                        if (next.userId == i8) {
                                            j6 = j5;
                                            next.lastTime = j6;
                                            if (next.action.getClass() != sendMessageAction.getClass()) {
                                                z2 = true;
                                            }
                                            next.action = sendMessageAction;
                                            z9 = true;
                                        } else {
                                            z9 = z10;
                                            j19 = j19;
                                        }
                                    }
                                    if (!z9) {
                                        PrintingUser printingUser3 = new PrintingUser();
                                        printingUser3.userId = i8;
                                        printingUser3.lastTime = j6;
                                        printingUser3.action = sendMessageAction;
                                        arrayList67.add(printingUser3);
                                        z2 = true;
                                    }
                                }
                                if (Math.abs(getConnectionsManager().getCurrentTime() - i) < 30) {
                                    this.onlinePrivacy.put(Integer.valueOf(i8), Integer.valueOf(i));
                                }
                            } else {
                                j6 = j5;
                            }
                            j3 = j6;
                            i22 = i6;
                            sparseLongArray7 = sparseLongArray3;
                            arrayList53 = arrayList11;
                            sparseArray8 = sparseArray5;
                        }
                    }
                }
                i21 = i3 + 1;
                concurrentHashMap2 = concurrentHashMap5;
                concurrentHashMap = concurrentHashMap4;
                hashMap6 = hashMap;
                size3 = i23;
                arrayList52 = arrayList6;
                j11 = j3;
                arrayList45 = arrayList;
            }
            if (update2 instanceof TLRPC.TL_updateNewMessage) {
                message = ((TLRPC.TL_updateNewMessage) update2).message;
            } else if (update2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                message = ((TLRPC.TL_updateNewScheduledMessage) update2).message;
            } else {
                message = ((TLRPC.TL_updateNewChannelMessage) update2).message;
                if (!message.out && message.from_id == getUserConfig().getClientUserId()) {
                    message.out = true;
                }
            }
            TLRPC.Chat chat4 = null;
            int i44 = 0;
            int i45 = 0;
            if (message.to_id.channel_id != 0) {
                i44 = message.to_id.channel_id;
            } else if (message.to_id.chat_id != 0) {
                i44 = message.to_id.chat_id;
            } else if (message.to_id.user_id != 0) {
                i45 = message.to_id.user_id;
            }
            if (i44 != 0) {
                chat4 = concurrentHashMap5.get(Integer.valueOf(i44));
                if (chat4 == null) {
                    chat4 = getChat(Integer.valueOf(i44));
                }
                if (chat4 == null) {
                    chat4 = getMessagesStorage().getChatSync(i44);
                    putChat(chat4, true);
                }
            }
            if (!z6) {
                j3 = j2;
            } else {
                if (i44 != 0 && chat4 == null) {
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("not found chat " + i44);
                        return false;
                    }
                    return false;
                }
                int size10 = message.entities.size() + 3;
                int i46 = 0;
                while (i46 < size10) {
                    boolean z11 = false;
                    if (i46 == 0) {
                        i5 = i44;
                        j4 = j2;
                    } else {
                        i5 = i44;
                        if (i46 == 1) {
                            i45 = message.from_id;
                            if (!message.post) {
                                j4 = j2;
                            } else {
                                z11 = true;
                                j4 = j2;
                            }
                        } else if (i46 == 2) {
                            i45 = message.fwd_from != null ? message.fwd_from.from_id : 0;
                            j4 = j2;
                        } else {
                            j4 = j2;
                            TLRPC.MessageEntity messageEntity2 = message.entities.get(i46 - 3);
                            i45 = messageEntity2 instanceof TLRPC.TL_messageEntityMentionName ? ((TLRPC.TL_messageEntityMentionName) messageEntity2).user_id : 0;
                        }
                    }
                    if (i45 > 0) {
                        TLRPC.User user4 = concurrentHashMap4.get(Integer.valueOf(i45));
                        if (user4 == null || (!z11 && user4.min)) {
                            user4 = getUser(Integer.valueOf(i45));
                        }
                        if (user4 == null || (!z11 && user4.min)) {
                            user4 = getMessagesStorage().getUserSync(i45);
                            if (user4 != null && !z11 && user4.min) {
                                user4 = null;
                            }
                            putUser(user4, true);
                        }
                        if (user4 == null) {
                            if (BuildVars.LOGS_ENABLED) {
                                FileLog.d("not found user " + i45);
                                return false;
                            }
                            return false;
                        }
                        if (!message.out && i46 == 1 && user4.status != null && user4.status.expires <= 0 && Math.abs(getConnectionsManager().getCurrentTime() - message.date) < 30) {
                            this.onlinePrivacy.put(Integer.valueOf(i45), Integer.valueOf(message.date));
                            i4 |= 4;
                        }
                    }
                    i46++;
                    i44 = i5;
                    j2 = j4;
                }
                j3 = j2;
            }
            if (chat4 != null && chat4.megagroup) {
                message.flags |= Integer.MIN_VALUE;
            }
            if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                TLRPC.User user5 = concurrentHashMap4.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()) {
                    i22 = i4;
                    sparseLongArray7 = sparseLongArray2;
                    arrayList53 = arrayList7;
                    sparseArray8 = sparseArray3;
                    i21 = i3 + 1;
                    concurrentHashMap2 = concurrentHashMap5;
                    concurrentHashMap = concurrentHashMap4;
                    hashMap6 = hashMap;
                    size3 = i23;
                    arrayList52 = arrayList6;
                    j11 = j3;
                    arrayList45 = arrayList;
                }
            }
            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 (update2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                if (arrayList55 != null) {
                    arrayList10 = arrayList55;
                } else {
                    arrayList10 = new ArrayList<>();
                }
                arrayList10.add(message);
                sparseArray4 = sparseArray10;
                MessageObject messageObject4 = new MessageObject(this.currentAccount, message, concurrentHashMap4, concurrentHashMap5, this.createdScheduledDialogIds.contains(Long.valueOf(message.dialog_id)));
                messageObject4.scheduled = true;
                if (longSparseArray2 != null) {
                    longSparseArray6 = longSparseArray2;
                } else {
                    longSparseArray6 = new LongSparseArray<>();
                }
                ArrayList<MessageObject> arrayList68 = longSparseArray6.get(message.dialog_id);
                if (arrayList68 == null) {
                    arrayList68 = new ArrayList<>();
                    longSparseArray6.put(message.dialog_id, arrayList68);
                }
                arrayList68.add(messageObject4);
                arrayList55 = arrayList10;
                longSparseArray2 = longSparseArray6;
            } else {
                sparseArray4 = sparseArray10;
                if (arrayList51 != null) {
                    arrayList8 = arrayList51;
                } else {
                    arrayList8 = new ArrayList<>();
                }
                arrayList8.add(message);
                ConcurrentHashMap<Long, Integer> concurrentHashMap11 = message.out ? this.dialogs_read_outbox_max : this.dialogs_read_inbox_max;
                Integer num6 = concurrentHashMap11.get(Long.valueOf(message.dialog_id));
                if (num6 == null) {
                    num6 = Integer.valueOf(getMessagesStorage().getDialogReadMax(message.out, message.dialog_id));
                    concurrentHashMap11.put(Long.valueOf(message.dialog_id), num6);
                }
                message.unread = num6.intValue() < message.id && !((chat4 != null && ChatObject.isNotInChat(chat4)) || (message.action instanceof TLRPC.TL_messageActionChatMigrateTo) || (message.action instanceof TLRPC.TL_messageActionChannelCreate));
                ArrayList<TLRPC.Message> arrayList69 = arrayList8;
                if (message.dialog_id == clientUserId2) {
                    if (message.from_scheduled) {
                        z4 = false;
                    } else {
                        z4 = false;
                        message.unread = false;
                    }
                    message.media_unread = z4;
                    message.out = true;
                }
                MessageObject messageObject5 = new MessageObject(this.currentAccount, message, concurrentHashMap4, concurrentHashMap5, this.createdDialogIds.contains(Long.valueOf(message.dialog_id)));
                if (messageObject5.type == 11) {
                    i4 |= 8;
                } else if (messageObject5.type == 10) {
                    i4 |= 16;
                }
                if (longSparseArray13 == null) {
                    longSparseArray13 = new LongSparseArray<>();
                }
                ArrayList<MessageObject> arrayList70 = longSparseArray13.get(message.dialog_id);
                if (arrayList70 == null) {
                    arrayList70 = new ArrayList<>();
                    longSparseArray13.put(message.dialog_id, arrayList70);
                }
                arrayList70.add(messageObject5);
                if ((!messageObject5.isOut() || messageObject5.messageOwner.from_scheduled) && messageObject5.isUnread()) {
                    if (arrayList49 != null) {
                        arrayList9 = arrayList49;
                    } else {
                        arrayList9 = new ArrayList<>();
                    }
                    arrayList9.add(messageObject5);
                    arrayList49 = arrayList9;
                    arrayList51 = arrayList69;
                } else {
                    arrayList51 = arrayList69;
                }
            }
            i22 = i4;
            sparseLongArray7 = sparseLongArray2;
            sparseArray10 = sparseArray4;
            arrayList53 = arrayList7;
            sparseArray8 = sparseArray3;
            i21 = i3 + 1;
            concurrentHashMap2 = concurrentHashMap5;
            concurrentHashMap = concurrentHashMap4;
            hashMap6 = hashMap;
            size3 = i23;
            arrayList52 = arrayList6;
            j11 = j3;
            arrayList45 = arrayList;
        }
        ConcurrentHashMap<Integer, TLRPC.User> concurrentHashMap12 = concurrentHashMap;
        final ArrayList<Long> arrayList71 = arrayList52;
        final SparseArray sparseArray13 = sparseArray8;
        ArrayList<Integer> arrayList72 = arrayList53;
        long j20 = j11;
        ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap13 = concurrentHashMap2;
        final int i47 = i22;
        final SparseArray sparseArray14 = sparseArray10;
        final SparseLongArray sparseLongArray8 = sparseLongArray7;
        if (longSparseArray13 != null) {
            int size11 = longSparseArray13.size();
            for (int i48 = 0; i48 < size11; i48++) {
                if (updatePrintingUsersWithNewMessages(longSparseArray13.keyAt(i48), longSparseArray13.valueAt(i48))) {
                    z2 = true;
                }
            }
        }
        if (z2) {
            updatePrintingStrings();
        }
        final SparseArray<SparseIntArray> sparseArray15 = sparseArray9;
        final SparseIntArray sparseIntArray9 = sparseIntArray5;
        final boolean z12 = z2;
        if (arrayList72 == null) {
            arrayList4 = arrayList72;
        } else {
            arrayList4 = arrayList72;
            getContactsController().processContactsUpdates(arrayList4, concurrentHashMap12);
        }
        if (arrayList49 == null) {
            j = j20;
        } else {
            final ArrayList<MessageObject> arrayList73 = arrayList49;
            j = j20;
            getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                @Override
                public final void run() {
                    MessagesController.this.lambda$processUpdateArray$281$MessagesController(arrayList73);
                }
            });
        }
        if (arrayList55 != null) {
            getMessagesStorage().putMessages(arrayList55, true, true, false, getDownloadController().getAutodownloadMask(), true);
        }
        if (arrayList51 != null) {
            getStatsController().incrementReceivedItemsCount(ApplicationLoader.getCurrentNetworkType(), 1, arrayList51.size());
            getMessagesStorage().putMessages(arrayList51, true, true, false, getDownloadController().getAutodownloadMask(), false);
        }
        if (longSparseArray14 == null) {
            concurrentHashMap3 = concurrentHashMap13;
            longSparseArray4 = longSparseArray13;
            longSparseArray5 = longSparseArray14;
        } else {
            int i49 = 0;
            int size12 = longSparseArray14.size();
            while (i49 < size12) {
                TLRPC.TL_messages_messages tL_messages_messages = new TLRPC.TL_messages_messages();
                LongSparseArray longSparseArray19 = longSparseArray14;
                int i50 = size12;
                ArrayList arrayList74 = (ArrayList) longSparseArray19.valueAt(i49);
                ConcurrentHashMap<Integer, TLRPC.Chat> concurrentHashMap14 = concurrentHashMap13;
                int size13 = arrayList74.size();
                LongSparseArray<ArrayList<MessageObject>> longSparseArray20 = longSparseArray13;
                int i51 = 0;
                while (i51 < size13) {
                    tL_messages_messages.messages.add(((MessageObject) arrayList74.get(i51)).messageOwner);
                    i51++;
                    size13 = size13;
                    arrayList74 = arrayList74;
                }
                getMessagesStorage().putMessages((TLRPC.messages_Messages) tL_messages_messages, longSparseArray19.keyAt(i49), -2, 0, false, false);
                i49++;
                longSparseArray14 = longSparseArray19;
                size12 = i50;
                longSparseArray13 = longSparseArray20;
                concurrentHashMap13 = concurrentHashMap14;
            }
            concurrentHashMap3 = concurrentHashMap13;
            longSparseArray4 = longSparseArray13;
            longSparseArray5 = longSparseArray14;
        }
        if (sparseArray15 != null) {
            getMessagesStorage().putChannelViews(sparseArray15, true);
        }
        final ArrayList<Integer> arrayList75 = arrayList4;
        final LongSparseArray<TLRPC.WebPage> longSparseArray21 = longSparseArray15;
        final LongSparseArray<ArrayList<MessageObject>> longSparseArray22 = longSparseArray4;
        final LongSparseArray<ArrayList<MessageObject>> longSparseArray23 = longSparseArray2;
        final ArrayList arrayList76 = arrayList50;
        final ArrayList arrayList77 = arrayList54;
        ArrayList arrayList78 = arrayList48;
        final SparseIntArray sparseIntArray10 = sparseIntArray4;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processUpdateArray$286$MessagesController(i47, arrayList77, longSparseArray21, longSparseArray22, longSparseArray23, longSparseArray5, z12, arrayList75, arrayList76, sparseArray15);
            }
        });
        SparseLongArray sparseLongArray9 = sparseLongArray6;
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                MessagesController.this.lambda$processUpdateArray$288$MessagesController(sparseLongArray6, sparseLongArray8, sparseIntArray9, arrayList71, sparseArray14, sparseArray13, sparseIntArray10);
            }
        });
        if (longSparseArray21 != null) {
            getMessagesStorage().putWebPages(longSparseArray21);
        }
        if (sparseLongArray9 == null) {
            sparseLongArray = sparseLongArray8;
            if (sparseLongArray == null) {
                sparseIntArray = sparseIntArray9;
                if (sparseIntArray == null) {
                    arrayList5 = arrayList71;
                    if (arrayList5 == null) {
                        if (arrayList5 != null) {
                            getMessagesStorage().markMessagesContentAsRead(arrayList5, getConnectionsManager().getCurrentTime());
                        }
                        sparseArray = sparseArray14;
                        if (sparseArray == null) {
                            int size14 = sparseArray.size();
                            int i52 = 0;
                            while (i52 < size14) {
                                int i53 = size14;
                                final int keyAt = sparseArray.keyAt(i52);
                                ArrayList<Long> arrayList79 = arrayList5;
                                final ArrayList arrayList80 = (ArrayList) sparseArray.valueAt(i52);
                                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                    @Override
                                    public final void run() {
                                        MessagesController.this.lambda$processUpdateArray$289$MessagesController(arrayList80, keyAt);
                                    }
                                });
                                i52++;
                                size14 = i53;
                                longSparseArray22 = longSparseArray22;
                                arrayList5 = arrayList79;
                                sparseArray = sparseArray;
                            }
                        }
                        sparseArray2 = sparseArray13;
                        if (sparseArray2 == null) {
                            int i54 = 0;
                            int size15 = sparseArray2.size();
                            while (i54 < size15) {
                                MessagesStorage.getInstance(this.currentAccount).markMessagesAsDeleted((ArrayList) sparseArray2.valueAt(i54), true, sparseArray2.keyAt(i54), false, true);
                                i54++;
                                sparseArray2 = sparseArray2;
                            }
                        }
                        sparseIntArray2 = sparseIntArray10;
                        if (sparseIntArray2 == null) {
                            int i55 = 0;
                            int size16 = sparseIntArray2.size();
                            while (i55 < size16) {
                                final int keyAt2 = sparseIntArray2.keyAt(i55);
                                final int valueAt = sparseIntArray2.valueAt(i55);
                                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                    @Override
                                    public final void run() {
                                        MessagesController.this.lambda$processUpdateArray$290$MessagesController(keyAt2, valueAt);
                                    }
                                });
                                i55++;
                                size16 = size16;
                                sparseIntArray2 = sparseIntArray2;
                            }
                        }
                        if (arrayList78 == null) {
                            int i56 = 0;
                            for (int size17 = arrayList78.size(); i56 < size17; size17 = size17) {
                                TLRPC.TL_updateEncryptedMessagesRead tL_updateEncryptedMessagesRead2 = (TLRPC.TL_updateEncryptedMessagesRead) arrayList78.get(i56);
                                getMessagesStorage().createTaskForSecretChat(tL_updateEncryptedMessagesRead2.chat_id, tL_updateEncryptedMessagesRead2.max_date, tL_updateEncryptedMessagesRead2.date, 1, null);
                                i56++;
                            }
                            return true;
                        }
                        return true;
                    }
                } else {
                    arrayList5 = arrayList71;
                }
            } else {
                sparseIntArray = sparseIntArray9;
                arrayList5 = arrayList71;
            }
        } else {
            sparseIntArray = sparseIntArray9;
            sparseLongArray = sparseLongArray8;
            arrayList5 = arrayList71;
        }
        if (sparseLongArray9 == null && arrayList5 == null) {
            z3 = true;
        } else {
            z3 = true;
            getMessagesStorage().updateDialogsWithReadMessages(sparseLongArray9, sparseLongArray, arrayList5, true);
        }
        getMessagesStorage().markMessagesAsRead(sparseLongArray9, sparseLongArray, sparseIntArray, z3);
        if (arrayList5 != null) {
        }
        sparseArray = sparseArray14;
        if (sparseArray == null) {
        }
        sparseArray2 = sparseArray13;
        if (sparseArray2 == null) {
        }
        sparseIntArray2 = sparseIntArray10;
        if (sparseIntArray2 == null) {
        }
        if (arrayList78 == 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 i, ArrayList arrayList, LongSparseArray longSparseArray, LongSparseArray longSparseArray2, LongSparseArray longSparseArray3, LongSparseArray longSparseArray4, boolean z, ArrayList arrayList2, ArrayList arrayList3, SparseArray sparseArray) {
        ?? r2;
        int i2;
        Object obj;
        int i3;
        boolean z2;
        int i4;
        HashMap<String, ArrayList<MessageObject>> hashMap;
        LongSparseArray<ArrayList<MessageObject>> longSparseArray5;
        boolean z3;
        ArrayList<TLRPC.User> arrayList4;
        int i5;
        ArrayList<TLRPC.User> arrayList5;
        int i6;
        long j;
        long j2;
        long j3;
        long j4;
        int i7;
        TLRPC.Dialog dialog;
        SharedPreferences.Editor editor;
        long j5;
        int i8;
        ArrayList<Long> arrayList6;
        long j6;
        long j7;
        ArrayList arrayList7 = arrayList;
        int i9 = i;
        boolean z4 = false;
        int i10 = 0;
        if (arrayList7 == null) {
            r2 = 0;
            i2 = 1;
        } else {
            ArrayList<TLRPC.User> arrayList8 = new ArrayList<>();
            ArrayList<TLRPC.User> arrayList9 = new ArrayList<>();
            int size = arrayList.size();
            int i11 = 0;
            SharedPreferences.Editor editor2 = null;
            boolean z5 = false;
            int i12 = i9;
            while (i11 < size) {
                int i13 = size;
                TLRPC.Update update = (TLRPC.Update) arrayList7.get(i11);
                if (update instanceof TLRPC.TL_updatePrivacy) {
                    TLRPC.TL_updatePrivacy tL_updatePrivacy = (TLRPC.TL_updatePrivacy) update;
                    if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyStatusTimestamp) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, i10);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyChatInvite) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 1);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyMoment) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 8);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyPhoneCall) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 2);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyPhoneP2P) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 3);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyProfilePhoto) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 4);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyForwards) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 5);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyPhoneNumber) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 6);
                    } else if (tL_updatePrivacy.key instanceof TLRPC.TL_privacyKeyAddedByPhone) {
                        getContactsController().setPrivacyRules(tL_updatePrivacy.rules, 7);
                    }
                    i6 = i12;
                    arrayList4 = arrayList9;
                    i5 = i13;
                    arrayList5 = arrayList8;
                } else if (update instanceof TLRPC.TL_updateUserStatus) {
                    TLRPC.TL_updateUserStatus tL_updateUserStatus = (TLRPC.TL_updateUserStatus) update;
                    TLRPC.User user = getUser(Integer.valueOf(tL_updateUserStatus.user_id));
                    if (tL_updateUserStatus.status instanceof TLRPC.TL_userStatusRecently) {
                        tL_updateUserStatus.status.expires = -100;
                    } else if (tL_updateUserStatus.status instanceof TLRPC.TL_userStatusLastWeek) {
                        tL_updateUserStatus.status.expires = -101;
                    } else if (tL_updateUserStatus.status instanceof TLRPC.TL_userStatusLastMonth) {
                        tL_updateUserStatus.status.expires = -102;
                    }
                    if (user != null) {
                        user.id = tL_updateUserStatus.user_id;
                        user.status = tL_updateUserStatus.status;
                    }
                    TLRPC.TL_user tL_user = new TLRPC.TL_user();
                    tL_user.id = tL_updateUserStatus.user_id;
                    tL_user.status = tL_updateUserStatus.status;
                    arrayList9.add(tL_user);
                    int i14 = i12;
                    if (tL_updateUserStatus.user_id == getUserConfig().getClientUserId()) {
                        getNotificationsController().setLastOnlineFromOtherDevice(tL_updateUserStatus.status.expires);
                    }
                    arrayList4 = arrayList9;
                    i5 = i13;
                    i6 = i14;
                    arrayList5 = arrayList8;
                } else {
                    int i15 = i12;
                    if (update instanceof TLRPC.TL_updateUserName) {
                        TLRPC.TL_updateUserName tL_updateUserName = (TLRPC.TL_updateUserName) update;
                        TLRPC.User user2 = getUser(Integer.valueOf(tL_updateUserName.user_id));
                        if (user2 != null) {
                            if (!UserObject.isContact(user2)) {
                                user2.first_name = tL_updateUserName.first_name;
                                user2.last_name = tL_updateUserName.last_name;
                            }
                            if (!TextUtils.isEmpty(user2.username)) {
                                this.objectsByUsernames.remove(user2.username);
                            }
                            if (TextUtils.isEmpty(tL_updateUserName.username)) {
                                this.objectsByUsernames.put(tL_updateUserName.username, user2);
                            }
                            user2.username = tL_updateUserName.username;
                        }
                        TLRPC.TL_user tL_user2 = new TLRPC.TL_user();
                        tL_user2.id = tL_updateUserName.user_id;
                        tL_user2.first_name = tL_updateUserName.first_name;
                        tL_user2.last_name = tL_updateUserName.last_name;
                        tL_user2.username = tL_updateUserName.username;
                        arrayList8.add(tL_user2);
                        arrayList4 = arrayList9;
                        i5 = i13;
                        i6 = i15;
                        arrayList5 = arrayList8;
                    } else if (update instanceof TLRPC.TL_updateDialogPinned) {
                        TLRPC.TL_updateDialogPinned tL_updateDialogPinned = (TLRPC.TL_updateDialogPinned) update;
                        if (tL_updateDialogPinned.peer instanceof TLRPC.TL_dialogPeer) {
                            j7 = DialogObject.getPeerDialogId(((TLRPC.TL_dialogPeer) tL_updateDialogPinned.peer).peer);
                        } else {
                            j7 = 0;
                        }
                        ArrayList<TLRPC.User> arrayList10 = arrayList8;
                        arrayList4 = arrayList9;
                        long j8 = j7;
                        i5 = i13;
                        if (!pinDialog(j7, tL_updateDialogPinned.pinned, null, -1L)) {
                            getUserConfig().setPinnedDialogsLoaded(tL_updateDialogPinned.folder_id, false);
                            getUserConfig().saveConfig(false);
                            loadPinnedDialogs(tL_updateDialogPinned.folder_id, j8, null);
                        }
                        i6 = i15;
                        arrayList5 = arrayList10;
                    } else {
                        ArrayList<TLRPC.User> arrayList11 = arrayList8;
                        arrayList4 = arrayList9;
                        i5 = i13;
                        if (update instanceof TLRPC.TL_updatePinnedDialogs) {
                            TLRPC.TL_updatePinnedDialogs tL_updatePinnedDialogs = (TLRPC.TL_updatePinnedDialogs) update;
                            getUserConfig().setPinnedDialogsLoaded(tL_updatePinnedDialogs.folder_id, false);
                            getUserConfig().saveConfig(false);
                            if ((tL_updatePinnedDialogs.flags & 1) != 0) {
                                arrayList6 = new ArrayList<>();
                                ArrayList<TLRPC.DialogPeer> arrayList12 = tL_updatePinnedDialogs.order;
                                int size2 = arrayList12.size();
                                for (int i16 = 0; i16 < size2; i16++) {
                                    TLRPC.DialogPeer dialogPeer = arrayList12.get(i16);
                                    if (dialogPeer instanceof TLRPC.TL_dialogPeer) {
                                        TLRPC.Peer peer = ((TLRPC.TL_dialogPeer) dialogPeer).peer;
                                        if (peer.user_id != 0) {
                                            j6 = peer.user_id;
                                        } else if (peer.chat_id != 0) {
                                            j6 = -peer.chat_id;
                                        } else {
                                            j6 = -peer.channel_id;
                                        }
                                    } else {
                                        j6 = 0;
                                    }
                                    arrayList6.add(Long.valueOf(j6));
                                }
                            } else {
                                arrayList6 = null;
                            }
                            loadPinnedDialogs(tL_updatePinnedDialogs.folder_id, 0L, arrayList6);
                            i6 = i15;
                            arrayList5 = arrayList11;
                        } else {
                            if (update instanceof TLRPC.TL_updateFolderPeers) {
                                TLRPC.TL_updateFolderPeers tL_updateFolderPeers = (TLRPC.TL_updateFolderPeers) update;
                                int size3 = tL_updateFolderPeers.folder_peers.size();
                                for (int i17 = 0; i17 < size3; i17++) {
                                    TLRPC.TL_folderPeer tL_folderPeer = tL_updateFolderPeers.folder_peers.get(i17);
                                    TLRPC.Dialog dialog2 = this.dialogs_dict.get(DialogObject.getPeerDialogId(tL_folderPeer.peer));
                                    if (dialog2 != null && dialog2.folder_id != tL_folderPeer.folder_id) {
                                        dialog2.pinned = false;
                                        dialog2.pinnedNum = 0;
                                        dialog2.folder_id = tL_folderPeer.folder_id;
                                        ensureFolderDialogExists(tL_folderPeer.folder_id, null);
                                    }
                                }
                                z5 = true;
                                i12 = i15;
                                arrayList5 = arrayList11;
                            } else if (update instanceof TLRPC.TL_updateUserPhoto) {
                                TLRPC.TL_updateUserPhoto tL_updateUserPhoto = (TLRPC.TL_updateUserPhoto) update;
                                TLRPC.User user3 = getUser(Integer.valueOf(tL_updateUserPhoto.user_id));
                                if (user3 != null) {
                                    user3.photo = tL_updateUserPhoto.photo;
                                }
                                TLRPC.TL_user tL_user3 = new TLRPC.TL_user();
                                tL_user3.id = tL_updateUserPhoto.user_id;
                                tL_user3.photo = tL_updateUserPhoto.photo;
                                arrayList5 = arrayList11;
                                arrayList5.add(tL_user3);
                                i6 = i15;
                            } else {
                                arrayList5 = arrayList11;
                                if (update instanceof TLRPC.TL_updateUserPhone) {
                                    TLRPC.TL_updateUserPhone tL_updateUserPhone = (TLRPC.TL_updateUserPhone) update;
                                    final TLRPC.User user4 = getUser(Integer.valueOf(tL_updateUserPhone.user_id));
                                    if (user4 != null) {
                                        user4.phone = tL_updateUserPhone.phone;
                                        Utilities.phoneBookQueue.postRunnable(new Runnable() {
                                            @Override
                                            public final void run() {
                                                MessagesController.this.lambda$null$282$MessagesController(user4);
                                            }
                                        });
                                        if (UserObject.isUserSelf(user4)) {
                                            getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
                                        }
                                    }
                                    TLRPC.TL_user tL_user4 = new TLRPC.TL_user();
                                    tL_user4.id = tL_updateUserPhone.user_id;
                                    tL_user4.phone = tL_updateUserPhone.phone;
                                    arrayList5.add(tL_user4);
                                    i6 = i15;
                                } else if (update instanceof TLRPC.TL_updateNotifySettings) {
                                    TLRPC.TL_updateNotifySettings tL_updateNotifySettings = (TLRPC.TL_updateNotifySettings) update;
                                    if (tL_updateNotifySettings.notify_settings instanceof TLRPC.TL_peerNotifySettings) {
                                        if (editor2 != null) {
                                            editor = editor2;
                                        } else {
                                            editor = this.notificationsPreferences.edit();
                                        }
                                        int currentTime = getConnectionsManager().getCurrentTime();
                                        if (tL_updateNotifySettings.peer instanceof TLRPC.TL_notifyPeer) {
                                            TLRPC.TL_notifyPeer tL_notifyPeer = (TLRPC.TL_notifyPeer) tL_updateNotifySettings.peer;
                                            if (tL_notifyPeer.peer.user_id != 0) {
                                                j5 = tL_notifyPeer.peer.user_id;
                                            } else if (tL_notifyPeer.peer.chat_id != 0) {
                                                j5 = -tL_notifyPeer.peer.chat_id;
                                            } else {
                                                j5 = -tL_notifyPeer.peer.channel_id;
                                            }
                                            TLRPC.Dialog dialog3 = this.dialogs_dict.get(j5);
                                            if (dialog3 != null) {
                                                dialog3.notify_settings = tL_updateNotifySettings.notify_settings;
                                            }
                                            if ((tL_updateNotifySettings.notify_settings.flags & 2) != 0) {
                                                editor.putBoolean("silent_" + j5, tL_updateNotifySettings.notify_settings.silent);
                                            } else {
                                                editor.remove("silent_" + j5);
                                            }
                                            if ((tL_updateNotifySettings.notify_settings.flags & 4) != 0) {
                                                if (tL_updateNotifySettings.notify_settings.mute_until > currentTime) {
                                                    int i18 = 0;
                                                    if (tL_updateNotifySettings.notify_settings.mute_until > currentTime + 31536000) {
                                                        editor.putInt("notify2_" + j5, 2);
                                                        if (dialog3 != null) {
                                                            tL_updateNotifySettings.notify_settings.mute_until = Integer.MAX_VALUE;
                                                        }
                                                    } else {
                                                        i18 = tL_updateNotifySettings.notify_settings.mute_until;
                                                        editor.putInt("notify2_" + j5, 3);
                                                        editor.putInt("notifyuntil_" + j5, tL_updateNotifySettings.notify_settings.mute_until);
                                                        if (dialog3 != null) {
                                                            tL_updateNotifySettings.notify_settings.mute_until = i18;
                                                        }
                                                    }
                                                    getMessagesStorage().setDialogFlags(j5, (i18 << 32) | 1);
                                                    getNotificationsController().removeNotificationsForDialog(j5);
                                                } else {
                                                    if (dialog3 == null) {
                                                        i8 = 0;
                                                    } else {
                                                        i8 = 0;
                                                        tL_updateNotifySettings.notify_settings.mute_until = 0;
                                                    }
                                                    editor.putInt("notify2_" + j5, i8);
                                                    getMessagesStorage().setDialogFlags(j5, 0L);
                                                }
                                            } else {
                                                if (dialog3 != null) {
                                                    tL_updateNotifySettings.notify_settings.mute_until = 0;
                                                }
                                                editor.remove("notify2_" + j5);
                                                getMessagesStorage().setDialogFlags(j5, 0L);
                                            }
                                        } else if (tL_updateNotifySettings.peer instanceof TLRPC.TL_notifyChats) {
                                            if ((tL_updateNotifySettings.notify_settings.flags & 1) != 0) {
                                                editor.putBoolean("EnablePreviewGroup", tL_updateNotifySettings.notify_settings.show_previews);
                                            }
                                            int i19 = tL_updateNotifySettings.notify_settings.flags;
                                            if ((tL_updateNotifySettings.notify_settings.flags & 4) != 0) {
                                                editor.putInt("EnableGroup2", tL_updateNotifySettings.notify_settings.mute_until);
                                            }
                                        } else if (tL_updateNotifySettings.peer instanceof TLRPC.TL_notifyUsers) {
                                            if ((tL_updateNotifySettings.notify_settings.flags & 1) != 0) {
                                                editor.putBoolean("EnablePreviewAll", tL_updateNotifySettings.notify_settings.show_previews);
                                            }
                                            int i20 = tL_updateNotifySettings.notify_settings.flags;
                                            if ((tL_updateNotifySettings.notify_settings.flags & 4) != 0) {
                                                editor.putInt("EnableAll2", tL_updateNotifySettings.notify_settings.mute_until);
                                            }
                                        } else if (tL_updateNotifySettings.peer instanceof TLRPC.TL_notifyBroadcasts) {
                                            if ((tL_updateNotifySettings.notify_settings.flags & 1) != 0) {
                                                editor.putBoolean("EnablePreviewChannel", tL_updateNotifySettings.notify_settings.show_previews);
                                            }
                                            int i21 = tL_updateNotifySettings.notify_settings.flags;
                                            if ((tL_updateNotifySettings.notify_settings.flags & 4) != 0) {
                                                editor.putInt("EnableChannel2", tL_updateNotifySettings.notify_settings.mute_until);
                                            }
                                        }
                                        editor2 = editor;
                                    }
                                    i12 = i15;
                                } else if (update instanceof TLRPC.TL_updateChannel) {
                                    final TLRPC.TL_updateChannel tL_updateChannel = (TLRPC.TL_updateChannel) update;
                                    TLRPC.Dialog dialog4 = this.dialogs_dict.get(-tL_updateChannel.channel_id);
                                    TLRPC.Chat chat = getChat(Integer.valueOf(tL_updateChannel.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(tL_updateChannel);
                                                }
                                            });
                                        } else if (chat.left && dialog4 != null && ((dialog = this.proxyDialog) == null || dialog.id != dialog4.id)) {
                                            deleteDialog(dialog4.id, 0);
                                        }
                                    }
                                    loadFullChat(tL_updateChannel.channel_id, 0, true);
                                    i12 = i15 | 8192;
                                } else {
                                    i6 = i15;
                                    if (update instanceof TLRPC.TL_updateChatDefaultBannedRights) {
                                        TLRPC.TL_updateChatDefaultBannedRights tL_updateChatDefaultBannedRights = (TLRPC.TL_updateChatDefaultBannedRights) update;
                                        if (tL_updateChatDefaultBannedRights.peer.channel_id != 0) {
                                            i7 = tL_updateChatDefaultBannedRights.peer.channel_id;
                                        } else {
                                            i7 = tL_updateChatDefaultBannedRights.peer.chat_id;
                                        }
                                        final TLRPC.Chat chat2 = getChat(Integer.valueOf(i7));
                                        if (chat2 != null) {
                                            chat2.default_banned_rights = tL_updateChatDefaultBannedRights.default_banned_rights;
                                            AndroidUtilities.runOnUIThread(new Runnable() {
                                                @Override
                                                public final void run() {
                                                    MessagesController.this.lambda$null$284$MessagesController(chat2);
                                                }
                                            });
                                        }
                                    } else if (update instanceof TLRPC.TL_updateStickerSets) {
                                        getMediaDataController().loadStickers(0, false, true);
                                    } else if (update instanceof TLRPC.TL_updateStickerSetsOrder) {
                                        getMediaDataController().reorderStickers(((TLRPC.TL_updateStickerSetsOrder) update).masks ? 1 : 0, ((TLRPC.TL_updateStickerSetsOrder) update).order);
                                    } else if (update instanceof TLRPC.TL_updateFavedStickers) {
                                        getMediaDataController().loadRecents(2, false, false, true);
                                    } else if (update instanceof TLRPC.TL_updateContactsReset) {
                                        getContactsController().forceImportContacts();
                                    } else if (update instanceof TLRPC.TL_updateNewStickerSet) {
                                        getMediaDataController().addNewStickerSet(((TLRPC.TL_updateNewStickerSet) update).stickerset);
                                    } else if (update instanceof TLRPC.TL_updateSavedGifs) {
                                        this.emojiPreferences.edit().putLong("lastGifLoadTime", 0L).commit();
                                    } else if (update instanceof TLRPC.TL_updateRecentStickers) {
                                        this.emojiPreferences.edit().putLong("lastStickersLoadTime", 0L).commit();
                                    } else if (update instanceof TLRPC.TL_updateDraftMessage) {
                                        TLRPC.TL_updateDraftMessage tL_updateDraftMessage = (TLRPC.TL_updateDraftMessage) update;
                                        z5 = true;
                                        TLRPC.Peer peer2 = ((TLRPC.TL_updateDraftMessage) update).peer;
                                        if (peer2.user_id != 0) {
                                            j4 = peer2.user_id;
                                        } else if (peer2.channel_id != 0) {
                                            j4 = -peer2.channel_id;
                                        } else {
                                            j4 = -peer2.chat_id;
                                        }
                                        getMediaDataController().saveDraft(j4, tL_updateDraftMessage.draft, null, true);
                                        i12 = i6;
                                    } else if (update instanceof TLRPC.TL_updateReadFeaturedStickers) {
                                        getMediaDataController().markFaturedStickersAsRead(false);
                                    } else if (update instanceof TLRPC.TL_updatePhoneCall) {
                                        TLRPC.PhoneCall phoneCall = ((TLRPC.TL_updatePhoneCall) update).phone_call;
                                        VoIPService sharedInstance = VoIPService.getSharedInstance();
                                        if (BuildVars.LOGS_ENABLED) {
                                            FileLog.d("Received call in update: " + phoneCall);
                                            FileLog.d("call id " + phoneCall.id);
                                        }
                                        if (phoneCall instanceof TLRPC.TL_phoneCallRequested) {
                                            if (phoneCall.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 telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService("phone");
                                                if (sharedInstance != null || VoIPService.callIShouldHavePutIntoIntent != null || telephonyManager.getCallState() != 0) {
                                                    if (BuildVars.LOGS_ENABLED) {
                                                        FileLog.d("Auto-declining call " + phoneCall.id + " because there's already active one");
                                                    }
                                                    TLRPC.TL_phone_discardCall tL_phone_discardCall = new TLRPC.TL_phone_discardCall();
                                                    tL_phone_discardCall.peer = new TLRPC.TL_inputPhoneCall();
                                                    tL_phone_discardCall.peer.access_hash = phoneCall.access_hash;
                                                    tL_phone_discardCall.peer.id = phoneCall.id;
                                                    tL_phone_discardCall.reason = new TLRPC.TL_phoneCallDiscardReasonBusy();
                                                    getConnectionsManager().sendRequest(tL_phone_discardCall, 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 " + phoneCall.id);
                                                    }
                                                    VoIPService.callIShouldHavePutIntoIntent = phoneCall;
                                                    Intent intent = new Intent(ApplicationLoader.applicationContext, (Class<?>) VoIPService.class);
                                                    intent.putExtra("is_outgoing", false);
                                                    intent.putExtra("user_id", phoneCall.participant_id == getUserConfig().getClientUserId() ? phoneCall.admin_id : phoneCall.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 th) {
                                                        FileLog.e(th);
                                                    }
                                                }
                                            }
                                        } else if (sharedInstance != null && phoneCall != null) {
                                            sharedInstance.onCallUpdated(phoneCall);
                                        } else if (VoIPService.callIShouldHavePutIntoIntent != null) {
                                            if (BuildVars.LOGS_ENABLED) {
                                                FileLog.d("Updated the call while the service is starting");
                                            }
                                            if (phoneCall.id == VoIPService.callIShouldHavePutIntoIntent.id) {
                                                VoIPService.callIShouldHavePutIntoIntent = phoneCall;
                                            }
                                        }
                                    } else if (update instanceof TLRPC.TL_updateDialogUnreadMark) {
                                        TLRPC.TL_updateDialogUnreadMark tL_updateDialogUnreadMark = (TLRPC.TL_updateDialogUnreadMark) update;
                                        if (tL_updateDialogUnreadMark.peer instanceof TLRPC.TL_dialogPeer) {
                                            TLRPC.TL_dialogPeer tL_dialogPeer = (TLRPC.TL_dialogPeer) tL_updateDialogUnreadMark.peer;
                                            if (tL_dialogPeer.peer.user_id != 0) {
                                                j3 = tL_dialogPeer.peer.user_id;
                                            } else if (tL_dialogPeer.peer.chat_id != 0) {
                                                j3 = -tL_dialogPeer.peer.chat_id;
                                            } else {
                                                j3 = -tL_dialogPeer.peer.channel_id;
                                            }
                                        } else {
                                            j3 = 0;
                                        }
                                        getMessagesStorage().setDialogUnread(j3, tL_updateDialogUnreadMark.unread);
                                        TLRPC.Dialog dialog5 = this.dialogs_dict.get(j3);
                                        if (dialog5 != null && dialog5.unread_mark != tL_updateDialogUnreadMark.unread) {
                                            dialog5.unread_mark = tL_updateDialogUnreadMark.unread;
                                            if (dialog5.unread_count == 0 && !isDialogMuted(j3)) {
                                                if (dialog5.unread_mark) {
                                                    this.unreadUnmutedDialogs++;
                                                } else {
                                                    this.unreadUnmutedDialogs--;
                                                }
                                            }
                                            if (dialog5.unread_count == 0 && dialog5.unread_mark) {
                                                this.dialogsUnreadOnly.add(dialog5);
                                            }
                                            i12 = i6 | 256;
                                        } else {
                                            i12 = i6;
                                        }
                                    } else if (update instanceof TLRPC.TL_updateMessagePoll) {
                                        TLRPC.TL_updateMessagePoll tL_updateMessagePoll = (TLRPC.TL_updateMessagePoll) update;
                                        getNotificationCenter().postNotificationName(NotificationCenter.didUpdatePollResults, Long.valueOf(tL_updateMessagePoll.poll_id), tL_updateMessagePoll.poll, tL_updateMessagePoll.results);
                                    } else if (update instanceof TLRPC.TL_updatePeerSettings) {
                                        TLRPC.TL_updatePeerSettings tL_updatePeerSettings = (TLRPC.TL_updatePeerSettings) update;
                                        if (tL_updatePeerSettings.peer instanceof TLRPC.TL_peerUser) {
                                            j2 = tL_updatePeerSettings.peer.user_id;
                                        } else if (tL_updatePeerSettings.peer instanceof TLRPC.TL_peerChat) {
                                            j2 = -tL_updatePeerSettings.peer.chat_id;
                                        } else {
                                            j2 = -tL_updatePeerSettings.peer.channel_id;
                                        }
                                        savePeerSettings(j2, tL_updatePeerSettings.settings, true);
                                    } else if (update instanceof TLRPC.TL_updatePeerLocated) {
                                        getNotificationCenter().postNotificationName(NotificationCenter.newPeopleNearbyAvailable, update);
                                    } else if (update instanceof TLRPC.TL_updateMessageReactions) {
                                        TLRPC.TL_updateMessageReactions tL_updateMessageReactions = (TLRPC.TL_updateMessageReactions) update;
                                        if (tL_updateMessageReactions.peer.chat_id != 0) {
                                            j = -tL_updateMessageReactions.peer.chat_id;
                                        } else if (tL_updateMessageReactions.peer.channel_id != 0) {
                                            j = -tL_updateMessageReactions.peer.channel_id;
                                        } else {
                                            j = tL_updateMessageReactions.peer.user_id;
                                        }
                                        getNotificationCenter().postNotificationName(NotificationCenter.didUpdateReactions, Long.valueOf(j), Integer.valueOf(tL_updateMessageReactions.msg_id), tL_updateMessageReactions.reactions);
                                    } else if (update instanceof TLRPC.TL_updateTheme) {
                                        Theme.setThemeUploadInfo(null, (TLRPC.TL_theme) ((TLRPC.TL_updateTheme) update).theme, true);
                                    }
                                }
                            }
                            i11++;
                            arrayList7 = arrayList;
                            arrayList8 = arrayList5;
                            size = i5;
                            arrayList9 = arrayList4;
                            i10 = 0;
                        }
                    }
                }
                i12 = i6;
                i11++;
                arrayList7 = arrayList;
                arrayList8 = arrayList5;
                size = i5;
                arrayList9 = arrayList4;
                i10 = 0;
            }
            int i22 = i12;
            ArrayList<TLRPC.User> arrayList13 = arrayList9;
            ArrayList<TLRPC.User> arrayList14 = arrayList8;
            if (editor2 == null) {
                z3 = false;
            } else {
                editor2.commit();
                z3 = false;
                getNotificationCenter().postNotificationName(NotificationCenter.notificationsSettingsUpdated, new Object[0]);
            }
            i2 = 1;
            getMessagesStorage().updateUsers(arrayList13, true, true, true);
            getMessagesStorage().updateUsers(arrayList14, z3, true, true);
            i9 = i22;
            z4 = z5;
            r2 = z3;
        }
        if (longSparseArray != null) {
            NotificationCenter notificationCenter = getNotificationCenter();
            int i23 = NotificationCenter.didReceivedWebpagesInUpdates;
            Object[] objArr = new Object[i2];
            objArr[r2] = longSparseArray;
            notificationCenter.postNotificationName(i23, objArr);
            int i24 = 0;
            while (i24 < 2) {
                HashMap<String, ArrayList<MessageObject>> hashMap2 = i24 == i2 ? this.reloadingScheduledWebpages : this.reloadingWebpages;
                LongSparseArray<ArrayList<MessageObject>> longSparseArray6 = i24 == i2 ? this.reloadingScheduledWebpagesPending : this.reloadingWebpagesPending;
                int i25 = 0;
                int size4 = longSparseArray.size();
                while (i25 < size4) {
                    long keyAt = longSparseArray.keyAt(i25);
                    ArrayList<MessageObject> arrayList15 = longSparseArray6.get(keyAt);
                    longSparseArray6.remove(keyAt);
                    if (arrayList15 == null) {
                        hashMap = hashMap2;
                        longSparseArray5 = longSparseArray6;
                    } else {
                        TLRPC.WebPage webPage = (TLRPC.WebPage) longSparseArray.valueAt(i25);
                        ArrayList<TLRPC.Message> arrayList16 = new ArrayList<>();
                        long j9 = 0;
                        hashMap = hashMap2;
                        if (!(webPage instanceof TLRPC.TL_webPage) && !(webPage instanceof TLRPC.TL_webPageEmpty)) {
                            longSparseArray6.put(webPage.id, arrayList15);
                            if (!arrayList16.isEmpty()) {
                                longSparseArray5 = longSparseArray6;
                            } else {
                                getMessagesStorage().putMessages(arrayList16, true, true, false, getDownloadController().getAutodownloadMask(), i24 == 1);
                                longSparseArray5 = longSparseArray6;
                                getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(j9), arrayList15);
                            }
                        }
                        int size5 = arrayList15.size();
                        for (int i26 = 0; i26 < size5; i26++) {
                            arrayList15.get(i26).messageOwner.media.webpage = webPage;
                            if (i26 == 0) {
                                j9 = arrayList15.get(i26).getDialogId();
                                ImageLoader.saveMessageThumbs(arrayList15.get(i26).messageOwner);
                            }
                            arrayList16.add(arrayList15.get(i26).messageOwner);
                        }
                        if (!arrayList16.isEmpty()) {
                        }
                    }
                    i25++;
                    hashMap2 = hashMap;
                    longSparseArray6 = longSparseArray5;
                }
                i24++;
                i2 = 1;
            }
        }
        int i27 = 0;
        if (longSparseArray2 != null) {
            int size6 = longSparseArray2.size();
            for (int i28 = 0; i28 < size6; i28++) {
                updateInterfaceWithMessages(longSparseArray2.keyAt(i28), (ArrayList) longSparseArray2.valueAt(i28), false);
            }
            i27 = 1;
            obj = null;
        } else if (!z4) {
            obj = null;
        } else {
            obj = null;
            sortDialogs(null);
            i27 = 1;
        }
        Object obj2 = obj;
        if (longSparseArray3 != null) {
            int size7 = longSparseArray3.size();
            for (int i29 = 0; i29 < size7; i29++) {
                updateInterfaceWithMessages(longSparseArray3.keyAt(i29), (ArrayList) longSparseArray3.valueAt(i29), true);
            }
        }
        if (longSparseArray4 != null) {
            int i30 = 0;
            int size8 = longSparseArray4.size();
            while (i30 < size8) {
                long keyAt2 = longSparseArray4.keyAt(i30);
                ArrayList<MessageObject> arrayList17 = (ArrayList) longSparseArray4.valueAt(i30);
                MessageObject messageObject = this.dialogMessage.get(keyAt2);
                if (messageObject == null) {
                    z2 = z4;
                    i4 = i27;
                } else {
                    int i31 = 0;
                    int size9 = arrayList17.size();
                    while (true) {
                        if (i31 >= size9) {
                            z2 = z4;
                            i4 = i27;
                            break;
                        }
                        z2 = z4;
                        MessageObject messageObject2 = arrayList17.get(i31);
                        int i32 = i27;
                        if (messageObject.getId() == messageObject2.getId()) {
                            this.dialogMessage.put(keyAt2, messageObject2);
                            if (messageObject2.messageOwner.to_id != null && messageObject2.messageOwner.to_id.channel_id == 0) {
                                this.dialogMessagesByIds.put(messageObject2.getId(), messageObject2);
                            }
                            i4 = 1;
                        } else if (messageObject.getDialogId() != messageObject2.getDialogId() || !(messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) || messageObject.replyMessageObject == null || messageObject.replyMessageObject.getId() != messageObject2.getId()) {
                            i31++;
                            i27 = i32;
                            z4 = z2;
                        } else {
                            messageObject.replyMessageObject = messageObject2;
                            messageObject.generatePinMessageText(null, null);
                            i4 = 1;
                            break;
                        }
                    }
                }
                getMediaDataController().loadReplyMessagesForMessages(arrayList17, keyAt2, false);
                getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(keyAt2), arrayList17, false);
                i30++;
                i27 = i4;
                z4 = z2;
                obj2 = null;
            }
        }
        if (i27 != 0) {
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
        }
        if (z) {
            i9 |= 64;
        }
        if (arrayList2 != null) {
            i9 = i9 | 1 | 128;
        }
        if (arrayList3 != null) {
            int size10 = arrayList3.size();
            for (int i33 = 0; i33 < size10; i33++) {
                getMessagesStorage().updateChatParticipants((TLRPC.ChatParticipants) arrayList3.get(i33));
            }
        }
        if (sparseArray == null) {
            i3 = 1;
        } else {
            i3 = 1;
            getNotificationCenter().postNotificationName(NotificationCenter.didUpdatedMessagesViews, sparseArray);
        }
        if (i9 != 0) {
            NotificationCenter notificationCenter2 = getNotificationCenter();
            int i34 = NotificationCenter.updateInterfaces;
            Object[] objArr2 = new Object[i3];
            objArr2[0] = Integer.valueOf(i9);
            notificationCenter2.postNotificationName(i34, 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) {
                                    break;
                                }
                                if (obj4.getId() != arrayList.get(b4).intValue()) {
                                    b4++;
                                } else {
                                    obj4.deleted = i;
                                    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) {
        int mute_type = this.notificationsPreferences.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) {
            int mute_until = this.notificationsPreferences.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;
        }
        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;
        }
        return false;
    }

    public void updateInterfaceWithMessages(final long j, ArrayList<MessageObject> arrayList, boolean z) {
        if (arrayList == null || arrayList.isEmpty()) {
            return;
        }
        boolean z2 = ((int) j) == 0;
        MessageObject messageObject = null;
        int i = 0;
        boolean z3 = false;
        boolean z4 = false;
        if (!z) {
            for (int i2 = 0; i2 < arrayList.size(); i2++) {
                MessageObject messageObject2 = arrayList.get(i2);
                if (messageObject == null || ((!z2 && messageObject2.getId() > messageObject.getId()) || (((z2 || (messageObject2.getId() < 0 && messageObject.getId() < 0)) && messageObject2.getId() < messageObject.getId()) || messageObject2.messageOwner.date > messageObject.messageOwner.date))) {
                    messageObject = messageObject2;
                    if (messageObject2.messageOwner.to_id.channel_id != 0) {
                        i = messageObject2.messageOwner.to_id.channel_id;
                    }
                }
                if (!z4 && !messageObject2.isOut()) {
                    z4 = true;
                }
                if (messageObject2.isOut() && !messageObject2.isSending() && !messageObject2.isForwarded()) {
                    if (messageObject2.isNewGif()) {
                        getMediaDataController().addRecentGif(messageObject2.messageOwner.media.document, messageObject2.messageOwner.date);
                    } else if (!messageObject2.isAnimatedEmoji() && (messageObject2.isSticker() || messageObject2.isAnimatedSticker())) {
                        getMediaDataController().addRecentSticker(0, messageObject2, messageObject2.messageOwner.media.document, messageObject2.messageOwner.date, false);
                    }
                }
                if (messageObject2.isOut() && messageObject2.isSent()) {
                    z3 = true;
                }
            }
        }
        getMediaDataController().loadReplyMessagesForMessages(arrayList, j, z);
        getNotificationCenter().postNotificationName(NotificationCenter.didReceiveNewMessages, Long.valueOf(j), arrayList, Boolean.valueOf(z));
        if (messageObject == null || z) {
            return;
        }
        TLRPC.TL_dialog tL_dialog = (TLRPC.TL_dialog) this.dialogs_dict.get(j);
        if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
            if (tL_dialog != null) {
                this.allDialogs.remove(tL_dialog);
                this.dialogsServerOnly.remove(tL_dialog);
                this.dialogsCanAddUsers.remove(tL_dialog);
                this.dialogsChannelsOnly.remove(tL_dialog);
                this.dialogsGroupsOnly.remove(tL_dialog);
                this.dialogsUnreadOnly.remove(tL_dialog);
                this.dialogsUsersOnly.remove(tL_dialog);
                this.dialogsForward.remove(tL_dialog);
                this.dialogs_dict.remove(tL_dialog.id);
                this.dialogs_read_inbox_max.remove(Long.valueOf(tL_dialog.id));
                this.dialogs_read_outbox_max.remove(Long.valueOf(tL_dialog.id));
                int i3 = this.nextDialogsCacheOffset.get(tL_dialog.folder_id, 0);
                if (i3 > 0) {
                    this.nextDialogsCacheOffset.put(tL_dialog.folder_id, i3 - 1);
                }
                this.dialogMessage.remove(tL_dialog.id);
                ArrayList<TLRPC.Dialog> arrayList2 = this.dialogsByFolder.get(tL_dialog.folder_id);
                if (arrayList2 != null) {
                    arrayList2.remove(tL_dialog);
                }
                MessageObject messageObject3 = this.dialogMessagesByIds.get(tL_dialog.top_message);
                this.dialogMessagesByIds.remove(tL_dialog.top_message);
                if (messageObject3 != null && messageObject3.messageOwner.random_id != 0) {
                    this.dialogMessagesByRandomIds.remove(messageObject3.messageOwner.random_id);
                }
                tL_dialog.top_message = 0;
                getNotificationsController().removeNotificationsForDialog(tL_dialog.id);
                getNotificationCenter().postNotificationName(NotificationCenter.needReloadRecentDialogsSearch, new Object[0]);
                return;
            }
            return;
        }
        boolean z5 = false;
        if (tL_dialog == null) {
            TLRPC.Chat chat = getChat(Integer.valueOf(i));
            if (i != 0 && chat == null) {
                return;
            }
            if (chat != null && ChatObject.isNotInChat(chat)) {
                return;
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("not found dialog with id " + j + " dictCount = " + this.dialogs_dict.size() + " allCount = " + this.allDialogs.size());
            }
            final TLRPC.TL_dialog tL_dialog2 = new TLRPC.TL_dialog();
            tL_dialog2.id = j;
            tL_dialog2.unread_count = 0;
            tL_dialog2.top_message = messageObject.getId();
            tL_dialog2.last_message_date = messageObject.messageOwner.date;
            tL_dialog2.flags = ChatObject.isChannel(chat) ? 1 : 0;
            this.dialogs_dict.put(j, tL_dialog2);
            this.allDialogs.add(tL_dialog2);
            this.dialogMessage.put(j, messageObject);
            if (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);
                }
            }
            z5 = true;
            getMessagesStorage().getDialogFolderId(j, new MessagesStorage.IntCallback() {
                @Override
                public final void run(int i4) {
                    MessagesController.this.lambda$updateInterfaceWithMessages$291$MessagesController(tL_dialog2, j, i4);
                }
            });
        } else {
            if (z4 && tL_dialog.folder_id == 1 && !isDialogMuted(tL_dialog.id)) {
                tL_dialog.folder_id = 0;
                tL_dialog.pinned = false;
                tL_dialog.pinnedNum = 0;
                getMessagesStorage().setDialogsFolderId(null, null, tL_dialog.id, 0);
                z5 = true;
            }
            if ((tL_dialog.top_message > 0 && messageObject.getId() > 0 && messageObject.getId() > tL_dialog.top_message) || ((tL_dialog.top_message < 0 && messageObject.getId() < 0 && messageObject.getId() < tL_dialog.top_message) || this.dialogMessage.indexOfKey(j) < 0 || tL_dialog.top_message < 0 || tL_dialog.last_message_date <= messageObject.messageOwner.date)) {
                MessageObject messageObject4 = this.dialogMessagesByIds.get(tL_dialog.top_message);
                this.dialogMessagesByIds.remove(tL_dialog.top_message);
                if (messageObject4 != null && messageObject4.messageOwner.random_id != 0) {
                    this.dialogMessagesByRandomIds.remove(messageObject4.messageOwner.random_id);
                }
                tL_dialog.top_message = messageObject.getId();
                tL_dialog.last_message_date = messageObject.messageOwner.date;
                z5 = true;
                this.dialogMessage.put(j, messageObject);
                if (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);
                    }
                }
            }
        }
        if (z5) {
            sortDialogs(null);
        }
        if (z3) {
            getMediaDataController().increasePeerRaiting(j);
        }
    }

    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);
            return;
        }
        if (index == -2) {
            if (dialogs.isEmpty() || !(dialogs.get(0) instanceof TLRPC.TL_dialogFolder)) {
                dialogs.add(0, dialog);
                return;
            } else {
                dialogs.add(1, dialog);
                return;
            }
        }
        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(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() {
            AnonymousClass2() {
            }

            @Override
            public void onClick(DialogInterface dialog, int which) {
                BaseFragment.this.finishFragment();
            }
        });
        builder.setMessage(reason);
        fragment.showDialog(builder.create());
    }

    public static class AnonymousClass2 implements DialogInterface.OnClickListener {
        AnonymousClass2() {
        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            BaseFragment.this.finishFragment();
        }
    }

    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;
        }
        if (messageId == 0 || originalMessage == null || chat == null || chat.access_hash != 0 || (did = (int) originalMessage.getDialogId()) == 0) {
            return true;
        }
        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;
        }
        if (messageId == 0 || originalMessage == null || chat == null || chat.access_hash != 0 || (did = (int) originalMessage.getDialogId()) == 0) {
            return true;
        }
        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);
                return;
            }
            if (chat != null) {
                openChatOrProfileWith(null, chat, fragment, 1, closeLast);
                return;
            }
            if (fragment.getParentActivity() == null) {
                return;
            }
            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);
                return;
            } else {
                if (!res.users.isEmpty()) {
                    if (res.users.get(0).contact) {
                        openChatOrProfileWith(res.users.get(0), null, fragment, type, closeLast);
                        return;
                    } else {
                        fragment.presentFragment(new AddContactsInfoActivity(null, res.users.get(0)));
                        return;
                    }
                }
                return;
            }
        }
        if (fragment != null && fragment.getParentActivity() != null) {
            if (type == 0) {
                ToastUtils.show(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(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(R.string.ForbidViewUserInfoTips);
                    return;
                }
                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));
                    return;
                }
                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));
                return;
            }
            if (chat != null) {
                openChatOrProfileWith(null, chat, fragment, 1, closeLast);
                return;
            }
            if (fragment.getParentActivity() == null) {
                return;
            }
            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);
                return;
            }
            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(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));
                return;
            }
            return;
        }
        if (fragment != null && fragment.getParentActivity() != null) {
            try {
                ToastUtils.show(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();
                    }
                });
                return;
            }
            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());
                    return;
                }
                return;
            }
            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));
    }
}