Search in sources :

Example 36 with Jid

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

the class ConversationActivity method quickOmemoDebugger.

private boolean quickOmemoDebugger(Conversation c) {
    if (c != null) {
        boolean single = c.getMode() == Conversation.MODE_SINGLE;
        AxolotlService axolotlService = c.getAccount().getAxolotlService();
        Pair<AxolotlService.AxolotlCapability, Jid> capabilityJidPair = axolotlService.isConversationAxolotlCapableDetailed(c);
        switch(capabilityJidPair.first) {
            case MISSING_PRESENCE:
                Toast.makeText(ConversationActivity.this, single ? getString(R.string.missing_presence_subscription) : getString(R.string.missing_presence_subscription_with_x, capabilityJidPair.second.toBareJid().toString()), Toast.LENGTH_SHORT).show();
                return true;
            case MISSING_KEYS:
                Toast.makeText(ConversationActivity.this, single ? getString(R.string.missing_omemo_keys) : getString(R.string.missing_keys_from_x, capabilityJidPair.second.toBareJid().toString()), Toast.LENGTH_SHORT).show();
                return true;
            case WRONG_CONFIGURATION:
                Toast.makeText(ConversationActivity.this, R.string.wrong_conference_configuration, Toast.LENGTH_SHORT).show();
                return true;
            case NO_MEMBERS:
                Toast.makeText(ConversationActivity.this, R.string.this_conference_has_no_members, Toast.LENGTH_SHORT).show();
                return true;
        }
    }
    return false;
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 37 with Jid

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

the class ConversationActivity method handleViewConversationIntent.

private void handleViewConversationIntent(final Intent intent) {
    final String uuid = intent.getStringExtra(CONVERSATION);
    final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID);
    final String text = intent.getStringExtra(TEXT);
    final String nick = intent.getStringExtra(NICK);
    final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
    if (selectConversationByUuid(uuid)) {
        this.mConversationFragment.reInit(getSelectedConversation());
        if (nick != null) {
            if (pm) {
                Jid jid = getSelectedConversation().getJid();
                try {
                    Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
                    this.mConversationFragment.privateMessageWith(next);
                } catch (final InvalidJidException ignored) {
                //do nothing
                }
            } else {
                this.mConversationFragment.highlightInConference(nick);
            }
        } else {
            this.mConversationFragment.appendText(text);
        }
        hideConversationsOverview();
        mUnprocessedNewIntent = false;
        openConversation();
        if (mContentView instanceof SlidingPaneLayout) {
            //fixes bug where slp isn't properly closed yet
            updateActionBarTitle(true);
        }
        if (downloadUuid != null) {
            final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
            if (message != null) {
                startDownloadable(message);
            }
        }
    } else {
        mUnprocessedNewIntent = false;
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Message(eu.siacs.conversations.entities.Message) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SlidingPaneLayout(android.support.v4.widget.SlidingPaneLayout)

Example 38 with Jid

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

the class ConversationActivity method trustKeysIfNeeded.

protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
    AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
    final List<Jid> targets = axolotlService.getCryptoTargets(mSelectedConversation);
    boolean hasUnaccepted = !mSelectedConversation.getAcceptedCryptoTargets().containsAll(targets);
    boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided()).isEmpty();
    boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets).isEmpty();
    boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
    boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
    if (hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted) {
        axolotlService.createSessionsIfNeeded(mSelectedConversation);
        Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
        String[] contacts = new String[targets.size()];
        for (int i = 0; i < contacts.length; ++i) {
            contacts[i] = targets.get(i).toString();
        }
        intent.putExtra("contacts", contacts);
        intent.putExtra(EXTRA_ACCOUNT, mSelectedConversation.getAccount().getJid().toBareJid().toString());
        intent.putExtra("choice", attachmentChoice);
        intent.putExtra("conversation", mSelectedConversation.getUuid());
        startActivityForResult(intent, requestCode);
        return true;
    } else {
        return false;
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Jid(eu.siacs.conversations.xmpp.jid.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 39 with Jid

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

the class XmppConnectionService method fetchBookmarks.

public void fetchBookmarks(final Account account) {
    final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
    final Element query = iqPacket.query("jabber:iq:private");
    query.addChild("storage", "storage:bookmarks");
    final OnIqPacketReceived callback = new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                final Element query = packet.query();
                final HashMap<Jid, Bookmark> bookmarks = new HashMap<>();
                final Element storage = query.findChild("storage", "storage:bookmarks");
                final boolean autojoin = respectAutojoin();
                if (storage != null) {
                    for (final Element item : storage.getChildren()) {
                        if (item.getName().equals("conference")) {
                            final Bookmark bookmark = Bookmark.parse(item, account);
                            Bookmark old = bookmarks.put(bookmark.getJid(), bookmark);
                            if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) {
                                bookmark.setBookmarkName(old.getBookmarkName());
                            }
                            Conversation conversation = find(bookmark);
                            if (conversation != null) {
                                conversation.setBookmark(bookmark);
                            } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) {
                                conversation = findOrCreateConversation(account, bookmark.getJid(), true, true);
                                conversation.setBookmark(bookmark);
                            }
                        }
                    }
                }
                account.setBookmarks(new ArrayList<>(bookmarks.values()));
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks");
            }
        }
    };
    sendIqPacket(account, iqPacket, callback);
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.jid.Jid) Bookmark(eu.siacs.conversations.entities.Bookmark) HashMap(java.util.HashMap) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 40 with Jid

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

the class XmppConnectionService method createAdhocConference.

public boolean createAdhocConference(final Account account, final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
    if (account.getStatus() == Account.State.ONLINE) {
        try {
            String server = findConferenceServer(account);
            if (server == null) {
                if (callback != null) {
                    callback.error(R.string.no_conference_server_found, null);
                }
                return false;
            }
            final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
            final Conversation conversation = findOrCreateConversation(account, jid, true, false);
            joinMuc(conversation, new OnConferenceJoined() {

                @Override
                public void onConferenceJoined(final Conversation conversation) {
                    pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConfigurationPushed() {

                        @Override
                        public void onPushSucceeded() {
                            if (subject != null && !subject.trim().isEmpty()) {
                                pushSubjectToConference(conversation, subject.trim());
                            }
                            for (Jid invite : jids) {
                                invite(conversation, invite);
                            }
                            if (account.countPresences() > 1) {
                                directInvite(conversation, account.getJid().toBareJid());
                            }
                            saveConversationAsBookmark(conversation, subject);
                            if (callback != null) {
                                callback.success(conversation);
                            }
                        }

                        @Override
                        public void onPushFailed() {
                            archiveConversation(conversation);
                            if (callback != null) {
                                callback.error(R.string.conference_creation_failed, conversation);
                            }
                        }
                    });
                }
            });
            return true;
        } catch (InvalidJidException e) {
            if (callback != null) {
                callback.error(R.string.conference_creation_failed, null);
            }
            return false;
        }
    } else {
        if (callback != null) {
            callback.error(R.string.not_connected_try_again, null);
        }
        return false;
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) BigInteger(java.math.BigInteger) 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