use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class ReceiptManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
if (!(connection instanceof AccountItem)) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final Jid from = packet.getFrom();
if (from == null) {
return;
}
if (!(packet instanceof Message)) {
return;
}
final Message message = (Message) packet;
if (message.getType() == Message.Type.error) {
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
markAsError(account, message);
}
});
} else {
// TODO setDefaultAutoReceiptMode should be used
for (ExtensionElement packetExtension : message.getExtensions()) {
if (packetExtension instanceof DeliveryReceiptRequest) {
String id = message.getStanzaId();
if (id == null) {
continue;
}
Message receipt = new Message(from);
receipt.addExtension(new DeliveryReceipt(id));
// the key problem is Thread - smack does not keep it in auto reply
receipt.setThread(message.getThread());
try {
StanzaSender.sendStanza(account, receipt);
} catch (NetworkException e) {
LogManager.exception(this, e);
}
}
}
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class AvatarManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(stanza instanceof Presence)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Presence presence = (Presence) stanza;
if (presence.getType() == Presence.Type.error) {
return;
}
for (ExtensionElement packetExtension : presence.getExtensions()) {
if (packetExtension instanceof VCardUpdate) {
VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
try {
onPhotoReady(account, UserJid.from(stanza.getFrom()), vCardUpdate);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
}
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class ChatStateManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (stanza.getFrom() == null) {
return;
}
final Resourcepart resource = stanza.getFrom().getResourceOrNull();
if (resource == null) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final UserJid bareUserJid;
try {
bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
if (stanza instanceof Presence) {
Presence presence = (Presence) stanza;
if (presence.getType() != Type.unavailable) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
supports.remove(account.toString(), bareUserJid.toString(), resource);
} else if (stanza instanceof Message) {
boolean support = false;
for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareUserJid.getBareJid(), resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
RosterManager.onChatStateChanged(account, bareUserJid);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
}
RosterManager.onChatStateChanged(account, bareUserJid);
support = true;
break;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
return;
}
if (support) {
supports.put(account.toString(), bareUserJid.toString(), resource, true);
} else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
// Disable only if there no information about support.
supports.put(account.toString(), bareUserJid.toString(), resource, false);
}
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class SSNManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
Jid from = stanza.getFrom();
if (from == null) {
return;
}
if (!(connection instanceof AccountItem) || !(stanza instanceof Message)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Message message = (Message) stanza;
String session = message.getThread();
if (session == null) {
return;
}
for (ExtensionElement packetExtension : stanza.getExtensions()) {
if (packetExtension instanceof Feature) {
Feature feature = (Feature) packetExtension;
if (!feature.isValid()) {
continue;
}
DataForm.Type dataFormType = feature.getDataFormType();
if (dataFormType == DataForm.Type.form) {
onFormReceived(account, from, session, feature);
} else if (dataFormType == DataForm.Type.submit) {
onSubmitReceived(account, from, session, feature);
} else if (dataFormType == DataForm.Type.result) {
onResultReceived(account, session, feature);
}
}
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class AttentionManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(stanza instanceof Message)) {
return;
}
if (!SettingsManager.chatsAttention()) {
return;
}
final AccountJid account = connection.getAccount();
UserJid from;
try {
from = UserJid.from(stanza.getFrom());
} catch (UserJid.UserJidCreateException e) {
e.printStackTrace();
return;
}
for (ExtensionElement packetExtension : stanza.getExtensions()) {
if (packetExtension instanceof AttentionExtension) {
MessageManager.getInstance().openChat(account, from);
MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested);
attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
}
}
}
Aggregations