private void updateSnackBar(final Conversation conversation) {
   final Account account = conversation.getAccount();
   final Contact contact = conversation.getContact();
   final int mode = conversation.getMode();
   if (conversation.isBlocked()) {
     showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
   } else if (!contact.showInRoster()
       && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
     showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener);
   } else if (mode == Conversation.MODE_MULTI
       && !conversation.getMucOptions().online()
       && account.getStatus() == Account.State.ONLINE) {
     switch (conversation.getMucOptions().getError()) {
       case MucOptions.ERROR_NICK_IN_USE:
         showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
         break;
       case MucOptions.ERROR_UNKNOWN:
         showSnackbar(R.string.conference_not_found, R.string.leave, leaveMuc);
         break;
       case MucOptions.ERROR_PASSWORD_REQUIRED:
         showSnackbar(
             R.string.conference_requires_password, R.string.enter_password, enterPassword);
         break;
       case MucOptions.ERROR_BANNED:
         showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
         break;
       case MucOptions.ERROR_MEMBERS_ONLY:
         showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
         break;
       case MucOptions.KICKED_FROM_ROOM:
         showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
         break;
       default:
         break;
     }
   } else if (askForPassphraseIntent != null) {
     showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
   } else if (mode == Conversation.MODE_SINGLE && conversation.smpRequested()) {
     showSnackbar(R.string.smp_requested, R.string.verify, this.mAnswerSmpClickListener);
   } else if (mode == Conversation.MODE_SINGLE
       && conversation.hasValidOtrSession()
       && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED)
       && (!conversation.isOtrFingerprintVerified())) {
     showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
   } else if (conversation.isMuted()) {
     showSnackbar(R.string.notifications_disabled, R.string.enable, this.mUnmuteClickListener);
   } else {
     hideSnackbar();
   }
 }
  public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    if (conversation.hasValidOtrSession()) {
      SessionID id = conversation.getOtrSession().getSessionID();
      Jid jid;
      try {
        jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
      } catch (InvalidJidException e) {
        jid = null;
      }
      conversation.setNextCounterpart(jid);
      listener.onPresenceSelected();
    } else if (!contact.showInRoster()) {
      showAddToRosterDialog(conversation);
    } else {
      Presences presences = contact.getPresences();
      if (presences.size() == 0) {
        if (!contact.getOption(Contact.Options.TO)
            && !contact.getOption(Contact.Options.ASKING)
            && contact.getAccount().getStatus() == Account.State.ONLINE) {
          showAskForPresenceDialog(contact);
        } else if (!contact.getOption(Contact.Options.TO)
            || !contact.getOption(Contact.Options.FROM)) {
          warnMutalPresenceSubscription(conversation, listener);
        } else {
          conversation.setNextCounterpart(null);
          listener.onPresenceSelected();
        }
      } else if (presences.size() == 1) {
        String presence = presences.asStringArray()[0];
        try {
          conversation.setNextCounterpart(
              Jid.fromParts(
                  contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
        } catch (InvalidJidException e) {
          conversation.setNextCounterpart(null);
        }
        listener.onPresenceSelected();
      } else {
        final StringBuilder presence = new StringBuilder();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.choose_presence));
        final String[] presencesArray = presences.asStringArray();
        int preselectedPresence = 0;
        for (int i = 0; i < presencesArray.length; ++i) {
          if (presencesArray[i].equals(contact.lastseen.presence)) {
            preselectedPresence = i;
            break;
          }
        }
        presence.append(presencesArray[preselectedPresence]);
        builder.setSingleChoiceItems(
            presencesArray,
            preselectedPresence,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                presence.delete(0, presence.length());
                presence.append(presencesArray[which]);
              }
            });
        builder.setNegativeButton(R.string.cancel, null);
        builder.setPositiveButton(
            R.string.ok,
            new OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                try {
                  conversation.setNextCounterpart(
                      Jid.fromParts(
                          contact.getJid().getLocalpart(),
                          contact.getJid().getDomainpart(),
                          presence.toString()));
                } catch (InvalidJidException e) {
                  conversation.setNextCounterpart(null);
                }
                listener.onPresenceSelected();
              }
            });
        builder.create().show();
      }
    }
  }