Example #1
0
 private boolean hasSameBareAddress(String account) {
   String bareAddress = Jid.getBareAddress(account);
   for (AccountItem check : accountItems.values())
     if (!check.getAccount().equals(account)
         && Jid.getBareAddress(check.getAccount()).equals(bareAddress)) return true;
   return false;
 }
 /**
  * Open chat with specified contact.
  *
  * <p>Show dialog to choose account if necessary.
  *
  * @param user
  * @param text can be <code>null</code>.
  */
 private void openChat(String user, String text) {
   String bareAddress = Jid.getBareAddress(user);
   ArrayList<BaseEntity> entities = new ArrayList<>();
   for (AbstractChat check : MessageManager.getInstance().getChats()) {
     if (check.isActive() && check.getUser().equals(bareAddress)) {
       entities.add(check);
     }
   }
   if (entities.size() == 1) {
     openChat(entities.get(0), text);
     return;
   }
   entities.clear();
   for (RosterContact check : RosterManager.getInstance().getContacts()) {
     if (check.isEnabled() && check.getUser().equals(bareAddress)) {
       entities.add(check);
     }
   }
   if (entities.size() == 1) {
     openChat(entities.get(0), text);
     return;
   }
   Collection<String> accounts = AccountManager.getInstance().getAccounts();
   if (accounts.isEmpty()) {
     return;
   }
   if (accounts.size() == 1) {
     openChat(new BaseEntity(accounts.iterator().next(), bareAddress), text);
     return;
   }
   AccountChooseDialogFragment.newInstance(bareAddress, text)
       .show(getFragmentManager(), "OPEN_WITH_ACCOUNT");
 }
 @Override
 public void onContactsChanged(Collection<BaseEntity> entities) {
   String thisBareAddress = Jid.getBareAddress(user);
   for (BaseEntity entity : entities)
     if (entity.equals(account, thisBareAddress)) {
       update();
       break;
     }
 }
Example #4
0
  /**
   * @param account
   * @return Verbose account name.
   */
  public String getVerboseName(String account) {
    AccountItem accountItem = getAccount(account);
    if (accountItem == null) return account;
    if (accountItem.getConnectionSettings().getProtocol().isOAuth()) {
      String jid = OAuthManager.getInstance().getAssignedJid(account);
      AccountProtocol accountProtocol = accountItem.getConnectionSettings().getProtocol();
      String name;
      if (jid == null) {
        if (hasSameProtocol(account)) name = accountItem.getConnectionSettings().getUserName();
        else return application.getString(accountProtocol.getNameResource());

      } else {
        name = Jid.getBareAddress(jid);
        if (!hasSameBareAddress(jid)) return name;
      }
      return application.getString(accountProtocol.getShortResource()) + " - " + name;
    } else {
      if (hasSameBareAddress(account)) return account;
      else return Jid.getBareAddress(account);
    }
  }
 public void processPacket(ConnectionThread connectionThread, Packet packet) {
   if (!managedConnections.contains(connectionThread)) return;
   ConnectionItem connectionItem = connectionThread.getConnectionItem();
   if (packet instanceof IQ && connectionItem instanceof AccountItem) {
     IQ iq = (IQ) packet;
     String packetId = iq.getPacketID();
     if (packetId != null && (iq.getType() == Type.RESULT || iq.getType() == Type.ERROR)) {
       String account = ((AccountItem) connectionItem).getAccount();
       RequestHolder requestHolder = requests.remove(account, packetId);
       if (requestHolder != null) {
         if (iq.getType() == Type.RESULT)
           requestHolder.getListener().onReceived(account, packetId, iq);
         else requestHolder.getListener().onError(account, packetId, iq);
       }
     }
   }
   for (OnPacketListener listener : Application.getInstance().getManagers(OnPacketListener.class))
     listener.onPacket(connectionItem, Jid.getBareAddress(packet.getFrom()), packet);
 }
Example #6
0
 /**
  * @param account
  * @return Account vCard based nick name or verbose name if nick is not specified.
  */
 public String getNickName(String account) {
   String jid = OAuthManager.getInstance().getAssignedJid(account);
   String result = VCardManager.getInstance().getName(Jid.getBareAddress(jid));
   if ("".equals(result)) return getVerboseName(account);
   else return result;
 }