Search in sources :

Example 96 with Jid

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

the class XmppConnectionService method fetchConferenceMembers.

private void fetchConferenceMembers(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final AxolotlService axolotlService = account.getAxolotlService();
    final String[] affiliations = { "member", "admin", "owner" };
    OnIqPacketReceived callback = new OnIqPacketReceived() {

        private int i = 0;

        private boolean success = true;

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            final boolean omemoEnabled = conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL;
            Element query = packet.query("http://jabber.org/protocol/muc#admin");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                for (Element child : query.getChildren()) {
                    if ("item".equals(child.getName())) {
                        MucOptions.User user = AbstractParser.parseItem(conversation, child);
                        if (!user.realJidMatchesAccount()) {
                            boolean isNew = conversation.getMucOptions().updateUser(user);
                            Contact contact = user.getContact();
                            if (omemoEnabled && isNew && user.getRealJid() != null && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
                                axolotlService.fetchDeviceIds(user.getRealJid());
                            }
                        }
                    }
                }
            } else {
                success = false;
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().asBareJid());
            }
            ++i;
            if (i >= affiliations.length) {
                List<Jid> members = conversation.getMucOptions().getMembers(true);
                if (success) {
                    List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
                    boolean changed = false;
                    for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
                        Jid jid = iterator.next();
                        if (!members.contains(jid) && !members.contains(jid.getDomain())) {
                            iterator.remove();
                            Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
                            changed = true;
                        }
                    }
                    if (changed) {
                        conversation.setAcceptedCryptoTargets(cryptoTargets);
                        updateConversation(conversation);
                    }
                }
                getAvatarService().clear(conversation);
                updateMucRosterUi();
                updateConversationUi();
            }
        }
    };
    for (String affiliation : affiliations) {
        sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
    }
    Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching members for " + conversation.getName());
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Contact(eu.siacs.conversations.entities.Contact) JabberIdContact(eu.siacs.conversations.android.JabberIdContact) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) MucOptions(eu.siacs.conversations.entities.MucOptions)

Example 97 with Jid

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

the class BlocklistActivity method filterContacts.

@Override
protected void filterContacts(final String needle) {
    getListItems().clear();
    if (account != null) {
        for (final Jid jid : account.getBlocklist()) {
            ListItem item;
            if (jid.isFullJid()) {
                item = new RawBlockable(account, jid);
            } else {
                item = account.getRoster().getContact(jid);
            }
            if (item.match(this, needle)) {
                getListItems().add(item);
            }
        }
        Collections.sort(getListItems());
    }
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Jid(eu.siacs.conversations.xmpp.Jid) RawBlockable(eu.siacs.conversations.entities.RawBlockable) ListItem(eu.siacs.conversations.entities.ListItem)

Example 98 with Jid

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

the class ConversationFragment method trustKeysIfNeeded.

protected boolean trustKeysIfNeeded(int requestCode) {
    AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
    final List<Jid> targets = axolotlService.getCryptoTargets(conversation);
    boolean hasUnaccepted = !conversation.getAcceptedCryptoTargets().containsAll(targets);
    boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided()).isEmpty();
    boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets).isEmpty();
    boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(conversation).isEmpty();
    boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
    boolean downloadInProgress = axolotlService.hasPendingKeyFetches(targets);
    if (hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted || downloadInProgress) {
        axolotlService.createSessionsIfNeeded(conversation);
        Intent intent = new Intent(getActivity(), 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, conversation.getAccount().getJid().asBareJid().toEscapedString());
        intent.putExtra("conversation", conversation.getUuid());
        startActivityForResult(intent, requestCode);
        return true;
    } else {
        return false;
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Jid(eu.siacs.conversations.xmpp.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 99 with Jid

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

the class XmppConnectionService method requestEasyOnboardingInvite.

public void requestEasyOnboardingInvite(final Account account, final EasyOnboardingInvite.OnInviteRequested callback) {
    final XmppConnection connection = account.getXmppConnection();
    final Jid jid = connection == null ? null : connection.getJidForCommand(Namespace.EASY_ONBOARDING_INVITE);
    if (jid == null) {
        callback.inviteRequestFailed(getString(R.string.server_does_not_support_easy_onboarding_invites));
        return;
    }
    final IqPacket request = new IqPacket(IqPacket.TYPE.SET);
    request.setTo(jid);
    final Element command = request.addChild("command", Namespace.COMMANDS);
    command.setAttribute("node", Namespace.EASY_ONBOARDING_INVITE);
    command.setAttribute("action", "execute");
    sendIqPacket(account, request, (a, response) -> {
        if (response.getType() == IqPacket.TYPE.RESULT) {
            final Element resultCommand = response.findChild("command", Namespace.COMMANDS);
            final Element x = resultCommand == null ? null : resultCommand.findChild("x", Namespace.DATA);
            if (x != null) {
                final Data data = Data.parse(x);
                final String uri = data.getValue("uri");
                final String landingUrl = data.getValue("landing-url");
                if (uri != null) {
                    final EasyOnboardingInvite invite = new EasyOnboardingInvite(jid.getDomain().toEscapedString(), uri, landingUrl);
                    callback.inviteRequested(invite);
                    return;
                }
            }
            callback.inviteRequestFailed(getString(R.string.unable_to_parse_invite));
            Log.d(Config.LOGTAG, response.toString());
        } else if (response.getType() == IqPacket.TYPE.ERROR) {
            callback.inviteRequestFailed(IqParser.errorMessage(response));
        } else {
            callback.inviteRequestFailed(getString(R.string.remote_server_timeout));
        }
    });
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) EasyOnboardingInvite(eu.siacs.conversations.utils.EasyOnboardingInvite) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 100 with Jid

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

the class UIHelper method getMessageDisplayName.

public static String getMessageDisplayName(final Message message) {
    final Conversational conversation = message.getConversation();
    if (message.getStatus() == Message.STATUS_RECEIVED) {
        final Contact contact = message.getContact();
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            if (contact != null) {
                return contact.getDisplayName();
            } else {
                return getDisplayedMucCounterpart(message.getCounterpart());
            }
        } else {
            return contact != null ? contact.getDisplayName() : "";
        }
    } else {
        if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_MULTI) {
            return ((Conversation) conversation).getMucOptions().getSelf().getName();
        } else {
            final Account account = conversation.getAccount();
            final Jid jid = account.getJid();
            final String displayName = account.getDisplayName();
            if (Strings.isNullOrEmpty(displayName)) {
                return jid.getLocal() != null ? jid.getLocal() : jid.getDomain().toString();
            } else {
                return displayName;
            }
        }
    }
}
Also used : Conversational(eu.siacs.conversations.entities.Conversational) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) Conversation(eu.siacs.conversations.entities.Conversation) Contact(eu.siacs.conversations.entities.Contact)

Aggregations

Jid (eu.siacs.conversations.xmpp.Jid)106 Account (eu.siacs.conversations.entities.Account)35 Element (eu.siacs.conversations.xml.Element)24 Conversation (eu.siacs.conversations.entities.Conversation)22 Contact (eu.siacs.conversations.entities.Contact)17 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)16 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)16 Intent (android.content.Intent)15 ArrayList (java.util.ArrayList)13 MucOptions (eu.siacs.conversations.entities.MucOptions)12 Bookmark (eu.siacs.conversations.entities.Bookmark)10 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)7 Message (eu.siacs.conversations.entities.Message)7 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 Map (java.util.Map)6 XmppUri (eu.siacs.conversations.utils.XmppUri)5 XmppConnectionService (eu.siacs.conversations.services.XmppConnectionService)4 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)4 HashMap (java.util.HashMap)4