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;
}
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;
}
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;
}
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);
}
Aggregations