Search in sources :

Example 46 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class XmppConnectionService method joinMuc.

private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
    Account account = conversation.getAccount();
    account.pendingConferenceJoins.remove(conversation);
    account.pendingConferenceLeaves.remove(conversation);
    if (account.getStatus() == Account.State.ONLINE) {
        conversation.resetMucOptions();
        if (onConferenceJoined != null) {
            conversation.getMucOptions().flagNoAutoPushConfiguration();
        }
        conversation.setHasMessagesLeftOnServer(false);
        fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() {

            private void join(Conversation conversation) {
                Account account = conversation.getAccount();
                final MucOptions mucOptions = conversation.getMucOptions();
                final Jid joinJid = mucOptions.getSelf().getFullJid();
                Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString());
                PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous());
                packet.setTo(joinJid);
                Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
                if (conversation.getMucOptions().getPassword() != null) {
                    x.addChild("password").setContent(mucOptions.getPassword());
                }
                if (mucOptions.mamSupport()) {
                    // Use MAM instead of the limited muc history to get history
                    x.addChild("history").setAttribute("maxchars", "0");
                } else {
                    // Fallback to muc history
                    x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted()));
                }
                sendPresencePacket(account, packet);
                if (onConferenceJoined != null) {
                    onConferenceJoined.onConferenceJoined(conversation);
                }
                if (!joinJid.equals(conversation.getJid())) {
                    conversation.setContactJid(joinJid);
                    databaseBackend.updateConversation(conversation);
                }
                if (mucOptions.mamSupport()) {
                    getMessageArchiveService().catchupMUC(conversation);
                }
                if (mucOptions.membersOnly() && mucOptions.nonanonymous()) {
                    fetchConferenceMembers(conversation);
                    if (followedInvite && conversation.getBookmark() == null) {
                        saveConversationAsBookmark(conversation, null);
                    }
                }
                sendUnsentMessages(conversation);
            }

            @Override
            public void onConferenceConfigurationFetched(Conversation conversation) {
                join(conversation);
            }

            @Override
            public void onFetchFailed(final Conversation conversation, Element error) {
                if (error != null && "remote-server-not-found".equals(error.getName())) {
                    conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND);
                } else {
                    join(conversation);
                    fetchConferenceConfiguration(conversation);
                }
            }
        });
        updateConversationUi();
    } else {
        account.pendingConferenceJoins.add(conversation);
        conversation.resetMucOptions();
        conversation.setHasMessagesLeftOnServer(false);
        updateConversationUi();
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Example 47 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class XmppConnectionService method deleteContactOnServer.

public void deleteContactOnServer(Contact contact) {
    contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
    contact.resetOption(Contact.Options.DIRTY_PUSH);
    contact.setOption(Contact.Options.DIRTY_DELETE);
    Account account = contact.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        Element item = iq.query(Namespace.ROSTER).addChild("item");
        item.setAttribute("jid", contact.getJid().toString());
        item.setAttribute("subscription", "remove");
        account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 48 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class XmppConnectionService method fetchMamPreferences.

public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
    final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.addChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
    sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element prefs = packet.findChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
            if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
                callback.onPreferencesFetched(prefs);
            } else {
                callback.onPreferencesFetchFailed();
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 49 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class MessageParser method extractInvite.

private Invite extractInvite(Account account, Element message) {
    Element x = message.findChild("x", "http://jabber.org/protocol/muc#user");
    if (x != null) {
        Element invite = x.findChild("invite");
        if (invite != null) {
            Element pw = x.findChild("password");
            Jid from = invite.getAttributeAsJid("from");
            Contact contact = from == null ? null : account.getRoster().getContact(from);
            return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent() : null, contact);
        }
    } else {
        x = message.findChild("x", "jabber:x:conference");
        if (x != null) {
            Jid from = message.getAttributeAsJid("from");
            Contact contact = from == null ? null : account.getRoster().getContact(from);
            return new Invite(x.getAttributeAsJid("jid"), x.getAttribute("password"), contact);
        }
    }
    return null;
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) Contact(eu.siacs.conversations.entities.Contact)

Example 50 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class MessageParser method parseEvent.

private void parseEvent(final Element event, final Jid from, final Account account) {
    Element items = event.findChild("items");
    String node = items == null ? null : items.getAttribute("node");
    if ("urn:xmpp:avatar:metadata".equals(node)) {
        Avatar avatar = Avatar.parseMetadata(items);
        if (avatar != null) {
            avatar.owner = from.toBareJid();
            if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
                if (account.getJid().toBareJid().equals(from)) {
                    if (account.setAvatar(avatar.getFilename())) {
                        mXmppConnectionService.databaseBackend.updateAccount(account);
                    }
                    mXmppConnectionService.getAvatarService().clear(account);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateAccountUi();
                } else {
                    Contact contact = account.getRoster().getContact(from);
                    contact.setAvatar(avatar);
                    mXmppConnectionService.getAvatarService().clear(contact);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateRosterUi();
                }
            } else if (mXmppConnectionService.isDataSaverDisabled()) {
                mXmppConnectionService.fetchAvatar(account, avatar);
            }
        }
    } else if ("http://jabber.org/protocol/nick".equals(node)) {
        Element i = items.findChild("item");
        Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick");
        if (nick != null && nick.getContent() != null) {
            Contact contact = account.getRoster().getContact(from);
            contact.setPresenceName(nick.getContent());
            mXmppConnectionService.getAvatarService().clear(account);
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.updateAccountUi();
        }
    } else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
        Element item = items.findChild("item");
        Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list (" + deviceIds + ") update from " + from + ", processing...");
        AxolotlService axolotlService = account.getAxolotlService();
        axolotlService.registerDevices(from, deviceIds);
        mXmppConnectionService.updateAccountUi();
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Element(eu.siacs.conversations.xml.Element) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) Contact(eu.siacs.conversations.entities.Contact)

Aggregations

Element (eu.siacs.conversations.xml.Element)93 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)43 Account (eu.siacs.conversations.entities.Account)21 Jid (eu.siacs.conversations.xmpp.jid.Jid)17 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)16 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Contact (eu.siacs.conversations.entities.Contact)7 Conversation (eu.siacs.conversations.entities.Conversation)6 ArrayList (java.util.ArrayList)6 Data (eu.siacs.conversations.xmpp.forms.Data)5 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)5 IOException (java.io.IOException)5 MucOptions (eu.siacs.conversations.entities.MucOptions)4 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)4 Pair (android.util.Pair)3 Bookmark (eu.siacs.conversations.entities.Bookmark)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3