Search in sources :

Example 21 with InvalidJidException

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

the class OtrService method sendOtrErrorMessage.

public void sendOtrErrorMessage(SessionID session, String errorText) {
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
        if (id != null) {
            MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid, id, errorText);
            packet.setFrom(account.getJid());
            mXmppConnectionService.sendMessagePacket(account, packet);
            Log.d(Config.LOGTAG, packet.toString());
            Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": unreadable OTR message in " + conversation.getName());
        }
    } catch (InvalidJidException e) {
        return;
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation)

Example 22 with InvalidJidException

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

the class Message method fromCursor.

public static Message fromCursor(Cursor cursor) {
    Jid jid;
    try {
        String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
        if (value != null) {
            jid = Jid.fromString(value, true);
        } else {
            jid = null;
        }
    } catch (InvalidJidException e) {
        jid = null;
    } catch (IllegalStateException e) {
        // message too long?
        return null;
    }
    Jid trueCounterpart;
    try {
        String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART));
        if (value != null) {
            trueCounterpart = Jid.fromString(value, true);
        } else {
            trueCounterpart = null;
        }
    } catch (InvalidJidException e) {
        trueCounterpart = null;
    }
    return new Message(cursor.getString(cursor.getColumnIndex(UUID)), cursor.getString(cursor.getColumnIndex(CONVERSATION)), jid, trueCounterpart, cursor.getString(cursor.getColumnIndex(BODY)), cursor.getLong(cursor.getColumnIndex(TIME_SENT)), cursor.getInt(cursor.getColumnIndex(ENCRYPTION)), cursor.getInt(cursor.getColumnIndex(STATUS)), cursor.getInt(cursor.getColumnIndex(TYPE)), cursor.getInt(cursor.getColumnIndex(CARBON)) > 0, cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)), cursor.getString(cursor.getColumnIndex(RELATIVE_FILE_PATH)), cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)), cursor.getString(cursor.getColumnIndex(FINGERPRINT)), cursor.getInt(cursor.getColumnIndex(READ)) > 0, cursor.getString(cursor.getColumnIndex(EDITED)), cursor.getInt(cursor.getColumnIndex(OOB)) > 0, cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)));
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException)

Example 23 with InvalidJidException

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

the class XmppActivity method showPresenceSelectionDialog.

private void showPresenceSelectionDialog(Presences presences, final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.choose_presence));
    final String[] resourceArray = presences.toResourceArray();
    Pair<Map<String, String>, Map<String, String>> typeAndName = presences.toTypeAndNameMap();
    final Map<String, String> resourceTypeMap = typeAndName.first;
    final Map<String, String> resourceNameMap = typeAndName.second;
    final String[] readableIdentities = new String[resourceArray.length];
    final AtomicInteger selectedResource = new AtomicInteger(0);
    for (int i = 0; i < resourceArray.length; ++i) {
        String resource = resourceArray[i];
        if (resource.equals(contact.getLastResource())) {
            selectedResource.set(i);
        }
        String type = resourceTypeMap.get(resource);
        String name = resourceNameMap.get(resource);
        if (type != null) {
            if (Collections.frequency(resourceTypeMap.values(), type) == 1) {
                readableIdentities[i] = UIHelper.tranlasteType(this, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = UIHelper.tranlasteType(this, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = UIHelper.tranlasteType(this, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = UIHelper.tranlasteType(this, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            selectedResource.set(which);
        }
    });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]);
                conversation.setNextCounterpart(next);
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) Jid(eu.siacs.conversations.xmpp.jid.Jid) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Builder(android.app.AlertDialog.Builder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Contact(eu.siacs.conversations.entities.Contact) OnClickListener(android.content.DialogInterface.OnClickListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OnClickListener(android.content.DialogInterface.OnClickListener) Map(java.util.Map)

Example 24 with InvalidJidException

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

the class EditAccountActivity method onBackendConnected.

protected void onBackendConnected() {
    boolean init = true;
    if (mSavedInstanceAccount != null) {
        try {
            this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(mSavedInstanceAccount));
            this.mInitMode = mSavedInstanceInit;
            init = false;
        } catch (InvalidJidException e) {
            this.mAccount = null;
        }
    } else if (this.jidToEdit != null) {
        this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
    }
    if (mAccount != null) {
        this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
        this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER);
        if (this.mAccount.getPrivateKeyAlias() != null) {
            this.mPassword.setHint(R.string.authenticate_with_certificate);
            if (this.mInitMode) {
                this.mPassword.requestFocus();
            }
        }
        if (mPendingFingerprintVerificationUri != null) {
            processFingerprintVerification(mPendingFingerprintVerificationUri);
            mPendingFingerprintVerificationUri = null;
        }
        updateAccountInformation(init);
    }
    if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) {
        this.mCancelButton.setEnabled(false);
        this.mCancelButton.setTextColor(getSecondaryTextColor());
    }
    if (mUsernameMode) {
        this.mAccountJidLabel.setText(R.string.username);
        this.mAccountJid.setHint(R.string.username_hint);
    } else {
        final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, R.layout.simple_list_item, xmppConnectionService.getKnownHosts());
        this.mAccountJid.setAdapter(mKnownHostsAdapter);
    }
    updateSaveButton();
    invalidateOptionsMenu();
}
Also used : KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException)

Example 25 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException 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)

Aggregations

InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)30 Jid (eu.siacs.conversations.xmpp.jid.Jid)18 Account (eu.siacs.conversations.entities.Account)13 Conversation (eu.siacs.conversations.entities.Conversation)11 AlertDialog (android.app.AlertDialog)4 View (android.view.View)4 Message (eu.siacs.conversations.entities.Message)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 DialogInterface (android.content.DialogInterface)3 TextView (android.widget.TextView)3 Contact (eu.siacs.conversations.entities.Contact)3 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)3 SuppressLint (android.annotation.SuppressLint)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2