Search in sources :

Example 6 with PresencePacket

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

the class XmppConnection method processPacket.

private Element processPacket(final Tag currentTag, final int packetType) throws XmlPullParserException, IOException {
    Element element;
    switch(packetType) {
        case PACKET_IQ:
            element = new IqPacket();
            break;
        case PACKET_MESSAGE:
            element = new MessagePacket();
            break;
        case PACKET_PRESENCE:
            element = new PresencePacket();
            break;
        default:
            return null;
    }
    element.setAttributes(currentTag.getAttributes());
    Tag nextTag = tagReader.readTag();
    if (nextTag == null) {
        throw new IOException("interrupted mid tag");
    }
    while (!nextTag.isEnd(element.getName())) {
        if (!nextTag.isNo()) {
            final Element child = tagReader.readElement(nextTag);
            final String type = currentTag.getAttribute("type");
            if (packetType == PACKET_IQ && "jingle".equals(child.getName()) && ("set".equalsIgnoreCase(type) || "get".equalsIgnoreCase(type))) {
                element = new JinglePacket();
                element.setAttributes(currentTag.getAttributes());
            }
            element.addChild(child);
        }
        nextTag = tagReader.readTag();
        if (nextTag == null) {
            throw new IOException("interrupted mid tag");
        }
    }
    if (stanzasReceived == Integer.MAX_VALUE) {
        resetStreamId();
        throw new IOException("time to restart the session. cant handle >2 billion pcks");
    }
    if (inSmacksSession) {
        ++stanzasReceived;
    } else if (features.sm()) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": not counting stanza(" + element.getClass().getSimpleName() + "). Not in smacks session.");
    }
    lastPacketReceived = SystemClock.elapsedRealtime();
    if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) {
        Log.d(Config.LOGTAG, "[background stanza] " + element);
    }
    return element;
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) Element(de.pixart.messenger.xml.Element) Tag(de.pixart.messenger.xml.Tag) IOException(java.io.IOException) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 7 with PresencePacket

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

the class PresenceGenerator method leave.

public PresencePacket leave(final MucOptions mucOptions) {
    PresencePacket presencePacket = new PresencePacket();
    presencePacket.setTo(mucOptions.getSelf().getFullJid());
    presencePacket.setFrom(mucOptions.getAccount().getJid());
    presencePacket.setAttribute("type", "unavailable");
    return presencePacket;
}
Also used : PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 8 with PresencePacket

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

the class XmppConnectionService method renameInMuc.

public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
    final MucOptions options = conversation.getMucOptions();
    final Jid joinJid = options.createJoinJid(nick);
    if (joinJid == null) {
        return false;
    }
    if (options.online()) {
        Account account = conversation.getAccount();
        options.setOnRenameListener(new OnRenameListener() {

            @Override
            public void onSuccess() {
                callback.success(conversation);
            }

            @Override
            public void onFailure() {
                callback.error(R.string.nick_in_use, conversation);
            }
        });
        PresencePacket packet = new PresencePacket();
        packet.setTo(joinJid);
        packet.setFrom(conversation.getAccount().getJid());
        String sig = account.getPgpSignature();
        if (sig != null) {
            packet.addChild("status").setContent("online");
            packet.addChild("x", "jabber:x:signed").setContent(sig);
        }
        sendPresencePacket(account, packet);
    } else {
        conversation.setContactJid(joinJid);
        databaseBackend.updateConversation(conversation);
        if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
            Bookmark bookmark = conversation.getBookmark();
            if (bookmark != null) {
                bookmark.setNick(nick);
                pushBookmarks(bookmark.getAccount());
            }
            joinMuc(conversation);
        }
    }
    return true;
}
Also used : Account(de.pixart.messenger.entities.Account) OnRenameListener(de.pixart.messenger.entities.MucOptions.OnRenameListener) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Bookmark(de.pixart.messenger.entities.Bookmark) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 9 with PresencePacket

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

the class XmppConnectionService method sendPresence.

public void sendPresence(final Account account, final boolean includeIdleTimestamp) {
    Presence.Status status;
    if (manuallyChangePresence()) {
        status = account.getPresenceStatus();
    } else {
        status = getTargetPresence();
    }
    PresencePacket packet = mPresenceGenerator.selfPresence(account, status);
    String message = account.getPresenceStatusMessage();
    if (message != null && !message.isEmpty()) {
        packet.addChild(new Element("status").setContent(message));
    }
    if (mLastActivity > 0 && includeIdleTimestamp) {
        // don't send future dates
        long since = Math.min(mLastActivity, System.currentTimeMillis());
        packet.addChild("idle", Namespace.IDLE).setAttribute("since", AbstractGenerator.getTimestamp(since));
    }
    sendPresencePacket(account, packet);
}
Also used : Element(de.pixart.messenger.xml.Element) Presence(de.pixart.messenger.entities.Presence) 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