Search in sources :

Example 56 with Jid

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

the class MagicCreateActivity method afterTextChanged.

@Override
public void afterTextChanged(Editable s) {
    if (s.toString().trim().length() > 0) {
        try {
            mFullJidDisplay.setVisibility(View.VISIBLE);
            Jid jid = Jid.fromParts(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
            mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString()));
        } catch (InvalidJidException e) {
            mFullJidDisplay.setVisibility(View.INVISIBLE);
        }
    } else {
        mFullJidDisplay.setVisibility(View.INVISIBLE);
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException)

Example 57 with Jid

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

the class StartConversationActivity method showJoinConferenceDialog.

@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.join_conference);
    final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
    final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
    final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
    final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
    jabberIdDesc.setText(R.string.conference_address);
    jid.setHint(R.string.conference_address_example);
    jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
    if (prefilledJid != null) {
        jid.append(prefilledJid);
    }
    populateAccountSpinner(this, mActivatedAccounts, spinner);
    final Checkable bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.join, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    mCurrentDialog = dialog;
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            if (!xmppConnectionServiceBound) {
                return;
            }
            final Account account = getSelectedAccount(spinner);
            if (account == null) {
                return;
            }
            final Jid conferenceJid;
            try {
                conferenceJid = Jid.fromString(jid.getText().toString());
            } catch (final InvalidJidException e) {
                jid.setError(getString(R.string.invalid_jid));
                return;
            }
            if (bookmarkCheckBox.isChecked()) {
                if (account.hasBookmarkFor(conferenceJid)) {
                    jid.setError(getString(R.string.bookmark_already_exists));
                } else {
                    final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
                    bookmark.setAutojoin(getPreferences().getBoolean("autojoin", true));
                    String nick = conferenceJid.getResourcepart();
                    if (nick != null && !nick.isEmpty()) {
                        bookmark.setNick(nick);
                    }
                    account.getBookmarks().add(bookmark);
                    xmppConnectionService.pushBookmarks(account);
                    final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true);
                    conversation.setBookmark(bookmark);
                    dialog.dismiss();
                    mCurrentDialog = null;
                    switchToConversation(conversation);
                }
            } else {
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true);
                dialog.dismiss();
                mCurrentDialog = null;
                switchToConversation(conversation);
            }
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Spinner(android.widget.Spinner) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Bookmark(eu.siacs.conversations.entities.Bookmark) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Checkable(android.widget.Checkable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint)

Example 58 with Jid

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

the class XmppActivity method selectPresence.

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 {
        final 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.toResourceArray()[0];
            try {
                conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        } else {
            showPresenceSelectionDialog(presences, conversation, listener);
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Presences(eu.siacs.conversations.entities.Presences) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SessionID(net.java.otr4j.session.SessionID) Contact(eu.siacs.conversations.entities.Contact)

Example 59 with Jid

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

the class TrustKeysActivity method reloadFingerprints.

private boolean reloadFingerprints() {
    List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
    ownKeysToTrust.clear();
    AxolotlService service = this.mAccount.getAxolotlService();
    Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided());
    for (final IdentityKey identityKey : ownKeysSet) {
        if (!ownKeysToTrust.containsKey(identityKey)) {
            ownKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
        }
    }
    synchronized (this.foreignKeysToTrust) {
        foreignKeysToTrust.clear();
        for (Jid jid : contactJids) {
            Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), jid);
            if (hasNoOtherTrustedKeys(jid) && ownKeysSet.size() == 0) {
                foreignKeysSet.addAll(service.getKeysWithTrust(FingerprintStatus.createActive(false), jid));
            }
            Map<String, Boolean> foreignFingerprints = new HashMap<>();
            for (final IdentityKey identityKey : foreignKeysSet) {
                if (!foreignFingerprints.containsKey(identityKey)) {
                    foreignFingerprints.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
                }
            }
            if (foreignFingerprints.size() > 0 || !acceptedTargets.contains(jid)) {
                foreignKeysToTrust.put(jid, foreignFingerprints);
            }
        }
    }
    return ownKeysSet.size() + foreignKeysToTrust.size() > 0;
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) IdentityKey(org.whispersystems.libaxolotl.IdentityKey) Jid(eu.siacs.conversations.xmpp.jid.Jid) HashMap(java.util.HashMap)

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