Search in sources :

Example 16 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class TrustKeysActivity method populateView.

private void populateView() {
    setTitle(getString(R.string.trust_omemo_fingerprints));
    ownKeys.removeAllViews();
    foreignKeys.removeAllViews();
    boolean hasOwnKeys = false;
    boolean hasForeignKeys = false;
    for (final String fingerprint : ownKeysToTrust.keySet()) {
        hasOwnKeys = true;
        addFingerprintRowWithListeners(ownKeys, mAccount, fingerprint, false, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)), false, false, new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                ownKeysToTrust.put(fingerprint, isChecked);
            // own fingerprints have no impact on locked status.
            }
        });
    }
    synchronized (this.foreignKeysToTrust) {
        for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
            hasForeignKeys = true;
            final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.keys_card, foreignKeys, false);
            final Jid jid = entry.getKey();
            final TextView header = (TextView) layout.findViewById(R.id.foreign_keys_title);
            final LinearLayout keysContainer = (LinearLayout) layout.findViewById(R.id.foreign_keys_details);
            final TextView informNoKeys = (TextView) layout.findViewById(R.id.no_keys_to_accept);
            header.setText(jid.toString());
            final Map<String, Boolean> fingerprints = entry.getValue();
            for (final String fingerprint : fingerprints.keySet()) {
                addFingerprintRowWithListeners(keysContainer, mAccount, fingerprint, false, FingerprintStatus.createActive(fingerprints.get(fingerprint)), false, false, new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        fingerprints.put(fingerprint, isChecked);
                        lockOrUnlockAsNeeded();
                    }
                });
            }
            if (fingerprints.size() == 0) {
                informNoKeys.setVisibility(View.VISIBLE);
                informNoKeys.setText(getString(R.string.no_keys_just_confirm, mAccount.getRoster().getContact(jid).getDisplayName()));
            } else {
                informNoKeys.setVisibility(View.GONE);
            }
            foreignKeys.addView(layout);
        }
    }
    ownKeysTitle.setText(mAccount.getJid().toBareJid().toString());
    ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE);
    foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE);
    if (hasPendingKeyFetches()) {
        setFetching();
        lock();
    } else {
        if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
            keyErrorMessageCard.setVisibility(View.VISIBLE);
            if (lastFetchReport == AxolotlService.FetchStatus.ERROR || mAccount.getAxolotlService().fetchMapHasErrors(contactJids)) {
                keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error);
            } else {
                keyErrorMessage.setText(R.string.error_no_keys_to_trust);
            }
            ownKeys.removeAllViews();
            ownKeysCard.setVisibility(View.GONE);
            foreignKeys.removeAllViews();
            foreignKeys.setVisibility(View.GONE);
        }
        lockOrUnlockAsNeeded();
        setDone();
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) TextView(android.widget.TextView) HashMap(java.util.HashMap) Map(java.util.Map) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Example 17 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class XmppActivity method showAddToRosterDialog.

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();
}
Also used : AlertDialog(android.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) Builder(android.app.AlertDialog.Builder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Contact(eu.siacs.conversations.entities.Contact)

Example 18 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class JingleConnection method upgradeNamespace.

private void upgradeNamespace() {
    Jid jid = this.message.getCounterpart();
    String resource = jid != null ? jid.getResourcepart() : null;
    if (resource != null) {
        Presence presence = this.account.getRoster().getContact(jid).getPresences().getPresences().get(resource);
        ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null;
        if (result != null) {
            List<String> features = result.getFeatures();
            if (features.contains(Content.Version.FT_4.getNamespace())) {
                this.ftVersion = Content.Version.FT_4;
            }
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Presence(eu.siacs.conversations.entities.Presence)

Example 19 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class JingleConnectionManager method getPrimaryCandidate.

public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
    if (Config.DISABLE_PROXY_LOOKUP) {
        listener.onPrimaryCandidateFound(false, null);
        return;
    }
    if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
        final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
        if (proxy != null) {
            IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
            iq.setTo(proxy);
            iq.query(Namespace.BYTE_STREAMS);
            account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
                    final String host = streamhost == null ? null : streamhost.getAttribute("host");
                    final String port = streamhost == null ? null : streamhost.getAttribute("port");
                    if (host != null && port != null) {
                        try {
                            JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
                            candidate.setHost(host);
                            candidate.setPort(Integer.parseInt(port));
                            candidate.setType(JingleCandidate.TYPE_PROXY);
                            candidate.setJid(proxy);
                            candidate.setPriority(655360 + 65535);
                            primaryCandidates.put(account.getJid().toBareJid(), candidate);
                            listener.onPrimaryCandidateFound(true, candidate);
                        } catch (final NumberFormatException e) {
                            listener.onPrimaryCandidateFound(false, null);
                            return;
                        }
                    } else {
                        listener.onPrimaryCandidateFound(false, null);
                    }
                }
            });
        } else {
            listener.onPrimaryCandidateFound(false, null);
        }
    } else {
        listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 20 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class OtrService method verify.

@Override
public void verify(SessionID id, String fingerprint, boolean approved) {
    Log.d(Config.LOGTAG, "OtrService.verify(" + id.toString() + "," + fingerprint + "," + String.valueOf(approved) + ")");
    try {
        final Jid jid = Jid.fromSessionID(id);
        Conversation conversation = this.mXmppConnectionService.find(this.account, jid);
        if (conversation != null) {
            if (approved) {
                conversation.getContact().addOtrFingerprint(fingerprint);
            }
            conversation.smp().hint = null;
            conversation.smp().status = Conversation.Smp.STATUS_VERIFIED;
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.syncRosterToDisk(conversation.getAccount());
        }
    } catch (final InvalidJidException ignored) {
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation)

Aggregations

Jid (eu.siacs.conversations.xmpp.jid.Jid)59 Account (eu.siacs.conversations.entities.Account)22 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)19 Element (eu.siacs.conversations.xml.Element)17 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)14 Conversation (eu.siacs.conversations.entities.Conversation)13 Contact (eu.siacs.conversations.entities.Contact)9 MucOptions (eu.siacs.conversations.entities.MucOptions)9 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)9 Message (eu.siacs.conversations.entities.Message)7 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 SuppressLint (android.annotation.SuppressLint)4 AlertDialog (android.app.AlertDialog)4 TextView (android.widget.TextView)4 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)4 Bookmark (eu.siacs.conversations.entities.Bookmark)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 HashMap (java.util.HashMap)4 PendingIntent (android.app.PendingIntent)3