use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class CapabilitiesManager method isValid.
private boolean isValid(DiscoverInfo discoverInfo) {
Set<DiscoverInfo.Identity> identities = new TreeSet<>(new Comparator<DiscoverInfo.Identity>() {
private int compare(String string1, String string2) {
return (string1 == null ? "" : string1).compareTo(string2 == null ? "" : string2);
}
@Override
public int compare(DiscoverInfo.Identity identity1, DiscoverInfo.Identity identity2) {
int result;
result = compare(identity1.getCategory(), identity2.getCategory());
if (result != 0) {
return result;
}
result = compare(identity1.getType(), identity2.getType());
if (result != 0) {
return result;
}
result = compare(identity1.getLanguage(), identity2.getLanguage());
if (result != 0) {
return result;
}
result = compare(identity1.getName(), identity2.getName());
if (result != 0) {
return result;
}
return 0;
}
});
for (DiscoverInfo.Identity identity : discoverInfo.getIdentities()) {
if (!identities.add(identity)) {
return false;
}
}
Set<String> features = new HashSet<>();
for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
if (!features.add(feature.getVar())) {
return false;
}
}
Set<String> formTypes = new HashSet<>();
for (ExtensionElement packetExtension : discoverInfo.getExtensions()) if (packetExtension instanceof DataForm) {
DataForm dataForm = (DataForm) packetExtension;
String formType = null;
for (FormField formField : dataForm.getFields()) {
if (FORM_TYPE.equals(formField.getVariable())) {
for (String value : formField.getValues()) {
if (formType != null && !formType.equals(value)) {
return false;
}
formType = value;
}
}
}
if (!formTypes.add(formType)) {
return false;
}
}
return true;
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class ChatStateManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
final String resource = Jid.getResource(packet.getFrom());
if (resource == null)
return;
final String account = ((AccountItem) connection).getAccount();
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
if (presence.getType() != Type.unavailable)
return;
chatStates.remove(account, bareAddress, resource);
removeCallback(account, bareAddress, resource);
supports.remove(account, bareAddress, resource);
} else if (packet instanceof Message) {
boolean support = false;
for (ExtensionElement extension : packet.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareAddress, resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account, bareAddress, resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account, bareAddress, resource))
return;
chatStates.remove(account, bareAddress, resource);
removeCallback(account, bareAddress, resource);
RosterManager.getInstance().onContactChanged(account, bareAddress);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account, bareAddress, resource, runnable);
}
RosterManager.getInstance().onContactChanged(account, bareAddress);
support = true;
break;
}
Message message = (Message) packet;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat)
return;
if (support)
supports.put(account, bareAddress, resource, true);
else if (supports.get(account, bareAddress, resource) == null)
// Disable only if there no information about support.
supports.put(account, bareAddress, resource, false);
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class AvatarManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(packet instanceof Presence) || bareAddress == null) {
return;
}
if (!(connection instanceof AccountItem)) {
return;
}
String account = ((AccountItem) connection).getAccount();
Presence presence = (Presence) packet;
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()) {
onPhotoReady(account, bareAddress, vCardUpdate);
}
}
}
}
Aggregations