gt:                     if (error == null) {
context: /*
   * This is the source code of Telegram for Android v. 1.3.2.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013.
   */
  
  package org.telegram.android;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.SharedPreferences;
  import android.content.pm.PackageInfo;
  import android.os.Build;
  import android.text.Html;
  
  import org.telegram.messenger.BuffersStorage;
  import org.telegram.messenger.ByteBufferDesc;
  import org.telegram.messenger.ConnectionsManager;
  import org.telegram.messenger.FileLoader;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.MessageKeyData;
  import org.telegram.messenger.R;
  import org.telegram.messenger.RPCRequest;
  import org.telegram.messenger.TLClassStore;
  import org.telegram.messenger.TLObject;
  import org.telegram.messenger.TLRPC;
  import org.telegram.messenger.UserConfig;
  import org.telegram.messenger.Utilities;
  import org.telegram.ui.ApplicationLoader;
  
  import java.math.BigInteger;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.Locale;
  import java.util.concurrent.ConcurrentHashMap;
  import java.util.concurrent.Semaphore;
  
  public class MessagesController implements NotificationCenter.NotificationCenterDelegate {
      private ConcurrentHashMap<Integer, TLRPC.Chat> chats = new ConcurrentHashMap<Integer, TLRPC.Chat>(100, 1.0f, 2);
      private ConcurrentHashMap<Integer, TLRPC.EncryptedChat> encryptedChats = new ConcurrentHashMap<Integer, TLRPC.EncryptedChat>(10, 1.0f, 2);
      private ConcurrentHashMap<Integer, TLRPC.User> users = new ConcurrentHashMap<Integer, TLRPC.User>(100, 1.0f, 2);
  
      public ArrayList<TLRPC.TL_dialog> dialogs = new ArrayList<TLRPC.TL_dialog>();
      public ArrayList<TLRPC.TL_dialog> dialogsServerOnly = new ArrayList<TLRPC.TL_dialog>();
      public ConcurrentHashMap<Long, TLRPC.TL_dialog> dialogs_dict = new ConcurrentHashMap<Long, TLRPC.TL_dialog>(100, 1.0f, 2);
      public HashMap<Integer, MessageObject> dialogMessage = new HashMap<Integer, MessageObject>();
      public ConcurrentHashMap<Long, ArrayList<PrintingUser>> printingUsers = new ConcurrentHashMap<Long, ArrayList<PrintingUser>>(100, 1.0f, 2);
      public HashMap<Long, CharSequence> printingStrings = new HashMap<Long, CharSequence>();
      public HashMap<Long, Boolean> sendingTypings = new HashMap<Long, Boolean>();
      private int lastPrintingStringCount = 0;
  
      public boolean loadingBlockedUsers = false;
      public ArrayList<Integer> blockedUsers = new ArrayList<Integer>();
  
      public HashMap<Integer, TLRPC.User> hidenAddToContacts = new HashMap<Integer, TLRPC.User>();
      private HashMap<Integer, TLRPC.EncryptedChat> acceptingChats = new HashMap<Integer, TLRPC.EncryptedChat>();
      private ArrayList<TLRPC.Updates> updatesQueue = new ArrayList<TLRPC.Updates>();
      private ArrayList<Long> pendingEncMessagesToDelete = new ArrayList<Long>();
      private long updatesStartWaitTime = 0;
      public ArrayList<TLRPC.Update> delayedEncryptedChatUpdates = new ArrayList<TLRPC.Update>();
      private boolean startingSecretChat = false;
  
      private boolean gettingNewDeleteTask = false;
      private int currentDeletingTaskTime = 0;
      private Long currentDeletingTask = null;
      private ArrayList<Integer> currentDeletingTaskMids = null;
  
      public int totalDialogsCount = 0;
      public boolean loadingDialogs = false;
      public boolean dialogsEndReached = false;
      public boolean gettingDifference = false;
      public boolean gettingDifferenceAgain = false;
      public boolean updatingState = false;
      public boolean firstGettingTask = false;
      public boolean registeringForPush = false;
  
      private long lastStatusUpdateTime = 0;
      private long statusRequest = 0;
      private int statusSettingState = 0;
      private boolean offlineSent = false;
      private String uploadingAvatar = null;
  
      public boolean enableJoined = true;
      public int fontSize = AndroidUtilities.dp(16);
      public int maxGroupCount = 200;
      public int maxBroadcastCount = 100;
  
      private class UserActionUpdates extends TLRPC.Updates {
  
      }
  
      public static final int UPDATE_MASK_NAME = 1;
      public static final int UPDATE_MASK_AVATAR = 2;
      public static final int UPDATE_MASK_STATUS = 4;
      public static final int UPDATE_MASK_CHAT_AVATAR = 8;
      public static final int UPDATE_MASK_CHAT_NAME = 16;
      public static final int UPDATE_MASK_CHAT_MEMBERS = 32;
      public static final int UPDATE_MASK_USER_PRINT = 64;
      public static final int UPDATE_MASK_USER_PHONE = 128;
      public static final int UPDATE_MASK_READ_DIALOG_MESSAGE = 256;
      public static final int UPDATE_MASK_ALL = UPDATE_MASK_AVATAR | UPDATE_MASK_STATUS | UPDATE_MASK_NAME | UPDATE_MASK_CHAT_AVATAR | UPDATE_MASK_CHAT_NAME | UPDATE_MASK_CHAT_MEMBERS | UPDATE_MASK_USER_PRINT | UPDATE_MASK_USER_PHONE | UPDATE_MASK_READ_DIALOG_MESSAGE;
  
      public static class PrintingUser {
          public long lastTime;
          public int userId;
      }
  
      private static volatile MessagesController Instance = null;
      public static MessagesController getInstance() {
          MessagesController localInstance = Instance;
          if (localInstance == null) {
              synchronized (MessagesController.class) {
                  localInstance = Instance;
                  if (localInstance == null) {
                      Instance = localInstance = new MessagesController();
                  }
              }
          }
          return localInstance;
      }
  
      public MessagesController() {
          ImageLoader.getInstance();
          MessagesStorage.getInstance();
          NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidUpload);
          NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailUpload);
          NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
          NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
          NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByServer);
          addSupportUser();
          SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
          enableJoined = preferences.getBoolean("EnableContactJoined", true);
  
          preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
          maxGroupCount = preferences.getInt("maxGroupCount", 200);
          maxBroadcastCount = preferences.getInt("maxBroadcastCount", 100);
          fontSize = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16);
      }
  
      public void updateConfig(final TLRPC.TL_config config) {
          AndroidUtilities.RunOnUIThread(new Runnable() {
              @Override
              public void run() {
                  maxBroadcastCount = config.broadcast_size_max;
                  maxGroupCount = config.chat_size_max;
                  SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                  SharedPreferences.Editor editor = preferences.edit();
                  editor.putInt("maxGroupCount", maxGroupCount);
                  editor.putInt("maxBroadcastCount", maxBroadcastCount);
                  editor.commit();
              }
          });
      }
  
      public void addSupportUser() {
          TLRPC.TL_userForeign user = new TLRPC.TL_userForeign();
          user.phone = "333";
          user.id = 333000;
          user.first_name = "Telegram";
          user.last_name = "";
          user.status = null;
          user.photo = new TLRPC.TL_userProfilePhotoEmpty();
          putUser(user, true);
  
          user = new TLRPC.TL_userForeign();
          user.phone = "42777";
          user.id = 777000;
          user.first_name = "Telegram";
          user.last_name = "Notifications";
          user.status = null;
          user.photo = new TLRPC.TL_userProfilePhotoEmpty();
          putUser(user, true);
      }
  
      public static TLRPC.InputUser getInputUser(TLRPC.User user) {
          if (user == null) {
              return null;
          }
          TLRPC.InputUser inputUser = null;
          if (user.id == UserConfig.getClientUserId()) {
              inputUser = new TLRPC.TL_inputUserSelf();
          } else if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
              inputUser = new TLRPC.TL_inputUserForeign();
              inputUser.user_id = user.id;
              inputUser.access_hash = user.access_hash;
          } else {
              inputUser = new TLRPC.TL_inputUserContact();
              inputUser.user_id = user.id;
          }
          return inputUser;
      }
  
      @Override
      public void didReceivedNotification(int id, Object... args) {
          if (id == NotificationCenter.FileDidUpload) {
              final String location = (String)args[0];
              final TLRPC.InputFile file = (TLRPC.InputFile)args[1];
              final TLRPC.InputEncryptedFile encryptedFile = (TLRPC.InputEncryptedFile)args[2];
  
              if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
                  TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
                  req.caption = "";
                  req.crop = new TLRPC.TL_inputPhotoCropAuto();
                  req.file = file;
                  req.geo_point = new TLRPC.TL_inputGeoPointEmpty();
                  ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
                      @Override
                      public void run(TLObject response, TLRPC.TL_error error) {
                          if (error == null) {
                              TLRPC.User user = getUser(UserConfig.getClientUserId());
                              if (user == null) {
                                  user = UserConfig.getCurrentUser();
                                  putUser(user, true);
                              } else {
                                  UserConfig.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;
                              }
                              MessagesStorage.getInstance().clearUserPhotos(user.id);
                              ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
                              users.add(user);
                              MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
                              AndroidUtilities.RunOnUIThread(new Runnable() {
                                  @Override
                                  public void run() {
                                      NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_AVATAR);
                                      UserConfig.saveConfig(true);
                                  }
                              });
                          }
                      }
                  });
              }
          } else if (id == NotificationCenter.FileDidFailUpload) {
              final String location = (String) args[0];
              final boolean enc = (Boolean) args[1];
  
              if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
                  uploadingAvatar = null;
              }
          } else if (id == NotificationCenter.messageReceivedByServer) {
              Integer msgId = (Integer)args[0];
              MessageObject obj = dialogMessage.get(msgId);
              if (obj != null) {
                  Integer newMsgId = (Integer)args[1];
                  dialogMessage.remove(msgId);
                  dialogMessage.put(newMsgId, obj);
                  obj.messageOwner.id = newMsgId;
                  obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
  
                  long uid;
                  if (obj.messageOwner.to_id.chat_id != 0) {
                      uid = -obj.messageOwner.to_id.chat_id;
                  } else {
                      if (obj.messageOwner.to_id.user_id == UserConfig.getClientUserId()) {
                          obj.messageOwner.to_id.user_id = obj.messageOwner.from_id;
                      }
                      uid = obj.messageOwner.to_id.user_id;
                  }
  
                  TLRPC.TL_dialog dialog = dialogs_dict.get(uid);
                  if (dialog != null) {
                      if (dialog.top_message == msgId) {
                          dialog.top_message = newMsgId;
                      }
                  }
                  NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
              }
          } else {
              NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
              NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
          }
      }
  
      public void cleanUp() {
          ContactsController.getInstance().cleanup();
          MediaController.getInstance().cleanup();
          NotificationsController.getInstance().cleanup();
          SendMessagesHelper.getInstance().cleanUp();
  
          dialogs_dict.clear();
          dialogs.clear();
          dialogsServerOnly.clear();
          acceptingChats.clear();
          users.clear();
          chats.clear();
          dialogMessage.clear();
          printingUsers.clear();
          printingStrings.clear();
          totalDialogsCount = 0;
          lastPrintingStringCount = 0;
          hidenAddToContacts.clear();
          updatesQueue.clear();
          pendingEncMessagesToDelete.clear();
          delayedEncryptedChatUpdates.clear();
          blockedUsers.clear();
          sendingTypings.clear();
  
          updatesStartWaitTime = 0;
          currentDeletingTaskTime = 0;
          currentDeletingTaskMids = null;
          gettingNewDeleteTask = false;
          currentDeletingTask = null;
          loadingDialogs = false;
          dialogsEndReached = false;
          gettingDifference = false;
          gettingDifferenceAgain = false;
          loadingBlockedUsers = false;
          firstGettingTask = false;
          updatingState = false;
          lastStatusUpdateTime = 0;
          offlineSent = false;
          registeringForPush = false;
          uploadingAvatar = null;
          startingSecretChat = false;
          statusRequest = 0;
          statusSettingState = 0;
          addSupportUser();
      }
  
      public TLRPC.User getUser(Integer id) {
          return users.get(id);
      }
  
      public TLRPC.Chat getChat(Integer id) {
          return chats.get(id);
      }
  
      public TLRPC.EncryptedChat getEncryptedChat(Integer id) {
          return encryptedChats.get(id);
      }
  
      public TLRPC.EncryptedChat getEncryptedChatDB(int chat_id) {
          TLRPC.EncryptedChat chat = encryptedChats.get(chat_id);
          if (chat == null) {
              Semaphore semaphore = new Semaphore(0);
              ArrayList<TLObject> result = new ArrayList<TLObject>();
              MessagesStorage.getInstance().getEncryptedChat(chat_id, semaphore, result);
              try {
                  semaphore.acquire();
              } catch (Exception e) {
                  FileLog.e("tmessages", e);
              }
              if (result.size() == 2) {
                  chat = (TLRPC.EncryptedChat)result.get(0);
                  TLRPC.User user = (TLRPC.User)result.get(1);
                  putEncryptedChat(chat, false);
                  putUser(user, true);
              }
          }
          return chat;
      }
  
      public boolean putUser(TLRPC.User user, boolean fromCache) {
          if (user == null) {
              return false;
          }
          fromCache = fromCache && user.id / 1000 != 333;
          TLRPC.User oldUser = users.get(user.id);
          if (!fromCache) {
              users.put(user.id, user);
              if (user.id == UserConfig.getClientUserId()) {
                  UserConfig.setCurrentUser(user);
              }
              if (oldUser != null && user.status != null && oldUser.status != null && user.status.expires != oldUser.status.expires) {
                  return true;
              }
          } else if (oldUser == null) {
              users.put(user.id, user);
          }
          return false;
      }
  
      public void putUsers(ArrayList<TLRPC.User> users, boolean fromCache) {
          if (users == null || users.isEmpty()) {
              return;
          }
          boolean updateStatus = false;
          for (TLRPC.User user : users) {
              if (putUser(user, fromCache)) {
                  updateStatus = true;
              }
          }
          if (updateStatus) {
              AndroidUtilities.RunOnUIThread(new Runnable() {
                  @Override
                  public void run() {
                      NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_STATUS);
                  }
              });
          }
      }
  
      public void putChat(TLRPC.Chat chat, boolean fromCache) {
          if (chat == null) {
              return;
          }
          if (fromCache) {
              chats.putIfAbsent(chat.id, chat);
          } else {
              chats.put(chat.id, chat);
          }
      }
  
      public void putChats(ArrayList<TLRPC.Chat> chats, boolean fromCache) {
          if (chats == null || chats.isEmpty()) {
              return;
          }
          for (TLRPC.Chat chat : chats) {
              putChat(chat, fromCache);
          }
      }
  
      public void putEncryptedChat(TLRPC.EncryptedChat encryptedChat, boolean fromCache) {
          if (encryptedChat == null) {
              return;
          }
          if (fromCache) {
              encryptedChats.putIfAbsent(encryptedChat.id, encryptedChat);
          } else {
              encryptedChats.put(encryptedChat.id, encryptedChat);
          }
      }
  
      public void putEncryptedChats(ArrayList<TLRPC.EncryptedChat> encryptedChats, boolean fromCache) {
          if (encryptedChats == null || encryptedChats.isEmpty()) {
              return;
          }
          for (TLRPC.EncryptedChat encryptedChat : encryptedChats) {
              putEncryptedChat(encryptedChat, fromCache);
          }
      }
  
      public void loadFullUser(final TLRPC.User user, final int classGuid) {
          if (user == null) {
              return;
          }
          TLRPC.TL_users_getFullUser req = new TLRPC.TL_users_getFullUser();
          req.id = getInputUser(user);
          long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
              @Override
              public void run(final TLObject response, TLRPC.TL_error error) {
                  if (error == null) {
                      AndroidUtilities.RunOnUIThread(new Runnable() {
                          @Override
                          public void run() {
                              TLRPC.TL_userFull userFull = (TLRPC.TL_userFull)response;
                              ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
                              users.add(userFull.user);
                              putUsers(users, false);
                          }
                      });
                  }
              }
          });
          ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
      }
  
      protected void processNewDifferenceParams(int seq, int pts, int date) {
          if (MessagesStorage.lastSeqValue + 1 == seq) {
              if (seq != -1) {
                  MessagesStorage.lastSeqValue = seq;
              }
              if (date != -1) {
                  MessagesStorage.lastDateValue = date;
              }
              if (pts != -1) {
                  MessagesStorage.lastPtsValue = pts;
              }
              MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
          } else if (MessagesStorage.lastSeqValue != seq) {
              if (gettingDifference || updatesStartWaitTime == 0 || updatesStartWaitTime != 0 && updatesStartWaitTime + 1500 > System.currentTimeMillis()) {
                  if (updatesStartWaitTime == 0) {
                      updatesStartWaitTime = System.currentTimeMillis();
                  }
                  UserActionUpdates updates = new UserActionUpdates();
                  updates.seq = seq;
                  updatesQueue.add(updates);
              } else {
                  getDifference();
              }
          }
      }
  
      public void didAddedNewTask(final int minDate) {
          Utilities.stageQueue.postRunnable(new Runnable() {
              @Override
              public void run() {
                  if (currentDeletingTask == null && !gettingNewDeleteTask || currentDeletingTaskTime != 0 && minDate < currentDeletingTaskTime) {
                      getNewDeleteTask(null);
                  }
              }
          });
      }
  
      public void getNewDeleteTask(final Long oldTask) {
          Utilities.stageQueue.postRunnable(new Runnable() {
              @Override
              public void run() {
                  gettingNewDeleteTask = true;
                  MessagesStorage.getInstance().getNewTask(oldTask);
              }
          });
      }
  
      private void checkDeletingTask() {
          int currentServerTime = ConnectionsManager.getInstance().getCurrentTime();
  
          if (currentDeletingTask != null && currentDeletingTaskTime != 0 && currentDeletingTaskTime <= currentServerTime) {
              currentDeletingTaskTime = 0;
              AndroidUtilities.RunOnUIThread(new Runnable() {
                  @Override
                  public void run() {
                      deleteMessages(currentDeletingTaskMids, null, null);
  
                      Utilities.stageQueue.postRunnable(new Runnable() {
                          @Override
                          public void run() {
                              getNewDeleteTask(currentDeletingTask);
                              currentDeletingTaskTime = 0;
                              currentDeletingTask = null;
                          }
                      });
                  }
              });
          }
      }
  
      public void processLoadedDeleteTask(final Long taskId, final int taskTime, final ArrayList<Integer> messages) {
          Utilities.stageQueue.postRunnable(new Runnable() {
              @Override
              public void run() {
                  gettingNewDeleteTask = false;
                  if (taskId != null) {
                      currentDeletingTaskTime = taskTime;
                      currentDeletingTask = taskId;
                      currentDeletingTaskMids = messages;
  
                      checkDeletingTask();
                  } else {
                      currentDeletingTaskTime = 0;
                      currentDeletingTask = null;
                      currentDeletingTaskMids = null;
                  }
              }
          });
      }
  
      public void loadUserPhotos(final int uid, final int offset, final int count, final long max_id, final boolean fromCache, final int classGuid) {
          if (fromCache) {
              MessagesStorage.getInstance().getUserPhotos(uid, offset, count, max_id, classGuid);
          } else {
              TLRPC.User user = getUser(uid);
              if (user == null) {
                  return;
              }
              TLRPC.TL_photos_getUserPhotos req = new TLRPC.TL_photos_getUserPhotos();
              req.limit = count;
              req.offset = offset;
              req.max_id = (int)max_id;
              req.user_id = getInputUser(user);
              long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
                  @Override
                  public void run(TLObject response, TLRPC.TL_error error) {
                      if (error == null) {
                          TLRPC.photos_Photos res = (TLRPC.photos_Photos) response;
                          processLoadedUserPhotos(res, uid, offset, count, max_id, fromCache, classGuid);
                      }
                  }
              });
              ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
          }
      }
  
      public void blockUser(int user_id) {
          final TLRPC.User user = getUser(user_id);
          if (user == null || MessagesController.getInstance().blockedUsers.contains(user_id)) {
              return;
          }
          blockedUsers.add(user_id);
          NotificationCenter.getInstance().postNotificationName(NotificationCenter.blockedUsersDidLoaded);
          TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
          req.id = MessagesController.getInputUser(user);
          ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
              @Override
              public void run(TLObject response, TLRPC.TL_error error) {
                  if (error == null) {
                      ArrayList<Integer> ids = new ArrayList<Integer>();
                      ids.add(user.id);
                      MessagesStorage.getInstance().putBlockedUsers(ids, false);
                  }
              }
          });
      }
  
      public void unblockUser(int user_id) {
          TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock();
          final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
          if (user == null) {
              return;
          }
          blockedUsers.remove((Integer)user.id);
          req.id = MessagesController.getInputUser(user);
          NotificationCenter.getInstance().postNotificationName(NotificationCenter.blockedUsersDidLoaded);
          ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
              @Override
              public void run(TLObject response, TLRPC.TL_error error) {
                  MessagesStorage.getInstance().deleteBlockedUser(user.id);
              }
          });
      }
  
      public void getBlockedUsers(boolean cache) {
          if (!UserConfig.isClientActivated() || loadingBlockedUsers) {
              return;
          }
          loadingBlockedUsers = true;
          if (cache) {
              MessagesStorage.getInstance().getBlockedUsers();
          } else {
              TLRPC.TL_contacts_getBlocked req = new TLRPC.TL_contacts_getBlocked();
              req.offset = 0;
              req.limit = 200;
              ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
                  @Override
                  public void run(TLObject response, TLRPC.TL_error error) {
                      ArrayList<Integer> blocked = new ArrayList<Integer>();
                      ArrayList<TLRPC.User> users = null;
  