Ejemplo n.º 1
0
  public boolean isContactAxolotlCapable(Contact contact) {

    Jid jid = contact.getJid().toBareJid();
    AxolotlAddress address = new AxolotlAddress(jid.toString(), 0);
    return sessions.hasAny(address)
        || (deviceIds.containsKey(jid) && !deviceIds.get(jid).isEmpty());
  }
Ejemplo n.º 2
0
  @Nullable
  private XmppAxolotlMessage buildHeader(Contact contact) {
    final XmppAxolotlMessage axolotlMessage =
        new XmppAxolotlMessage(contact.getJid().toBareJid(), getOwnDeviceId());

    Set<XmppAxolotlSession> contactSessions = findSessionsforContact(contact);
    Set<XmppAxolotlSession> ownSessions = findOwnSessions();
    if (contactSessions.isEmpty()) {
      return null;
    }
    Log.d(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account) + "Building axolotl foreign keyElements...");
    for (XmppAxolotlSession session : contactSessions) {
      Log.v(
          Config.LOGTAG,
          AxolotlService.getLogprefix(account) + session.getRemoteAddress().toString());
      axolotlMessage.addDevice(session);
    }
    Log.d(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account) + "Building axolotl own keyElements...");
    for (XmppAxolotlSession session : ownSessions) {
      Log.v(
          Config.LOGTAG,
          AxolotlService.getLogprefix(account) + session.getRemoteAddress().toString());
      axolotlMessage.addDevice(session);
    }

    return axolotlMessage;
  }
Ejemplo n.º 3
0
 public void switchToContactDetails(Contact contact, String messageFingerprint) {
   Intent intent = new Intent(this, ContactDetailsActivity.class);
   intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
   intent.putExtra("account", contact.getAccount().getJid().toBareJid().toString());
   intent.putExtra("contact", contact.getJid().toString());
   intent.putExtra("fingerprint", messageFingerprint);
   startActivity(intent);
 }
Ejemplo n.º 4
0
 private void fillMap(SQLiteAxolotlStore store) {
   List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().toBareJid().toString());
   putDevicesForJid(account.getJid().toBareJid().toString(), deviceIds, store);
   for (Contact contact : account.getRoster().getContacts()) {
     Jid bareJid = contact.getJid().toBareJid();
     if (bareJid == null) {
       continue; // FIXME: handle this?
     }
     String address = bareJid.toString();
     deviceIds = store.getSubDeviceSessions(address);
     putDevicesForJid(address, deviceIds, store);
   }
 }
Ejemplo n.º 5
0
 private String key(Contact contact, int size) {
   synchronized (this.sizes) {
     if (!this.sizes.contains(size)) {
       this.sizes.add(size);
     }
   }
   return PREFIX_CONTACT
       + "_"
       + contact.getAccount().getJid()
       + "_"
       + contact.getJid()
       + "_"
       + String.valueOf(size);
 }
Ejemplo n.º 6
0
  protected void showAddToRosterDialog(final Contact contact) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(contact.getJid().toString());
    builder.setMessage(getString(R.string.not_in_roster));
    builder.setNegativeButton(getString(R.string.cancel), null);
    builder.setPositiveButton(
        getString(R.string.add_contact),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            final Jid jid = contact.getJid();
            Account account = contact.getAccount();
            Contact contact = account.getRoster().getContact(jid);
            xmppConnectionService.createContact(contact);
          }
        });
    builder.create().show();
  }
Ejemplo n.º 7
0
  private void showAskForPresenceDialog(final Contact contact) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(contact.getJid().toString());
    builder.setMessage(R.string.request_presence_updates);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(
        R.string.request_now,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            if (xmppConnectionServiceBound) {
              xmppConnectionService.sendPresencePacket(
                  contact.getAccount(),
                  xmppConnectionService.getPresenceGenerator().requestPresenceUpdatesFrom(contact));
            }
          }
        });
    builder.create().show();
  }
Ejemplo n.º 8
0
  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();
      }
    }
  }
Ejemplo n.º 9
0
 private boolean hasAny(Contact contact) {
   AxolotlAddress contactAddress = getAddressForJid(contact.getJid());
   return sessions.hasAny(contactAddress);
 }
Ejemplo n.º 10
0
 private Set<XmppAxolotlSession> findSessionsforContact(Contact contact) {
   AxolotlAddress contactAddress = getAddressForJid(contact.getJid());
   Set<XmppAxolotlSession> sessions = new HashSet<>(this.sessions.getAll(contactAddress).values());
   return sessions;
 }
Ejemplo n.º 11
0
 public long getNumTrustedKeys(Contact contact) {
   return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString());
 }
Ejemplo n.º 12
0
 public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact) {
   return axolotlStore.getContactKeysWithTrust(contact.getJid().toBareJid().toString(), trust);
 }
Ejemplo n.º 13
0
  public void parseContactPresence(final PresencePacket packet, final Account account) {
    final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
    final Jid from = packet.getFrom();
    if (from == null) {
      return;
    }
    final String type = packet.getAttribute("type");
    final Contact contact = account.getRoster().getContact(from);
    if (type == null) {
      final String resource = from.isBareJid() ? "" : from.getResourcepart();
      contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
      Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
      if (avatar != null && !contact.isSelf()) {
        avatar.owner = from.toBareJid();
        if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
          if (contact.setAvatar(avatar)) {
            mXmppConnectionService.getAvatarService().clear(contact);
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.updateRosterUi();
          }
        } else {
          mXmppConnectionService.fetchAvatar(account, avatar);
        }
      }
      int sizeBefore = contact.getPresences().size();

      final Element show = packet.findChild("show");
      final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
      final Presence presence = Presence.parse(show, caps);
      contact.updatePresence(resource, presence);
      if (presence.hasCaps() && Config.REQUEST_DISCO) {
        mXmppConnectionService.fetchCaps(account, from, presence);
      }

      PgpEngine pgp = mXmppConnectionService.getPgpEngine();
      Element x = packet.findChild("x", "jabber:x:signed");
      if (pgp != null && x != null) {
        Element status = packet.findChild("status");
        String msg = status != null ? status.getContent() : "";
        contact.setPgpKeyId(pgp.fetchKeyId(account, msg, x.getContent()));
      }
      boolean online = sizeBefore < contact.getPresences().size();
      updateLastseen(packet, account, false);
      mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online);
    } else if (type.equals("unavailable")) {
      if (from.isBareJid()) {
        contact.clearPresences();
      } else {
        contact.removePresence(from.getResourcepart());
      }
      mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
    } else if (type.equals("subscribe")) {
      if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
        mXmppConnectionService.sendPresencePacket(
            account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
      } else {
        contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
        final Conversation conversation =
            mXmppConnectionService.findOrCreateConversation(
                account, contact.getJid().toBareJid(), false);
        final String statusMessage = packet.findChildContent("status");
        if (statusMessage != null
            && !statusMessage.isEmpty()
            && conversation.countMessages() == 0) {
          conversation.add(
              new Message(
                  conversation, statusMessage, Message.ENCRYPTION_NONE, Message.STATUS_RECEIVED));
        }
      }
    }
    mXmppConnectionService.updateRosterUi();
  }