Search in sources :

Example 1 with PresencePacket

use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.

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) {
        // disabled for testing strange MUC leaves
        sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
        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() || onConferenceJoined != null);
                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().getTimestamp()));
                }
                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.isPrivateAndNonAnonymous()) {
                    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);
                    updateConversationUi();
                } else {
                    join(conversation);
                    fetchConferenceConfiguration(conversation);
                }
            }
        });
        updateConversationUi();
    } else {
        account.pendingConferenceJoins.add(conversation);
        conversation.resetMucOptions();
        conversation.setHasMessagesLeftOnServer(false);
        updateConversationUi();
    }
}
Also used : Account(de.pixart.messenger.entities.Account) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 2 with PresencePacket

use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.

the class PresenceGenerator method selfPresence.

public PresencePacket selfPresence(Account account, Presence.Status status, boolean includePgpAnnouncement) {
    PresencePacket packet = new PresencePacket();
    if (status.toShowString() != null) {
        packet.addChild("show").setContent(status.toShowString());
    }
    packet.setFrom(account.getJid());
    String sig = account.getPgpSignature();
    if (includePgpAnnouncement && sig != null && mXmppConnectionService.getPgpEngine() != null) {
        packet.addChild("x", "jabber:x:signed").setContent(sig);
    }
    String capHash = getCapHash();
    if (capHash != null) {
        Element cap = packet.addChild("c", "http://jabber.org/protocol/caps");
        cap.setAttribute("hash", "sha-1");
        cap.setAttribute("node", "http://jabber.pix-art.de");
        cap.setAttribute("ver", capHash);
    }
    return packet;
}
Also used : Element(de.pixart.messenger.xml.Element) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 3 with PresencePacket

use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.

the class PresenceGenerator method subscription.

private PresencePacket subscription(String type, Contact contact) {
    PresencePacket packet = new PresencePacket();
    packet.setAttribute("type", type);
    packet.setTo(contact.getJid());
    packet.setFrom(contact.getAccount().getJid().toBareJid());
    return packet;
}
Also used : PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 4 with PresencePacket

use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.

the class PresenceGenerator method sendOfflinePresence.

public PresencePacket sendOfflinePresence(Account account) {
    PresencePacket packet = new PresencePacket();
    packet.setFrom(account.getJid());
    packet.setAttribute("type", "unavailable");
    return packet;
}
Also used : PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 5 with PresencePacket

use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.

the class XmppConnection method processPresence.

private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
    PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
    this.presenceListener.onPresencePacketReceived(account, packet);
}
Also used : PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Aggregations

PresencePacket (de.pixart.messenger.xmpp.stanzas.PresencePacket)9 Element (de.pixart.messenger.xml.Element)4 Account (de.pixart.messenger.entities.Account)2 MucOptions (de.pixart.messenger.entities.MucOptions)2 Jid (de.pixart.messenger.xmpp.jid.Jid)2 Bookmark (de.pixart.messenger.entities.Bookmark)1 Conversation (de.pixart.messenger.entities.Conversation)1 OnRenameListener (de.pixart.messenger.entities.MucOptions.OnRenameListener)1 Presence (de.pixart.messenger.entities.Presence)1 Tag (de.pixart.messenger.xml.Tag)1 JinglePacket (de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)1 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)1 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)1 IOException (java.io.IOException)1