use of org.jivesoftware.smackx.disco.packet.DiscoverInfo 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.smackx.disco.packet.DiscoverInfo in project xabber-android by redsolution.
the class CapabilitiesManager method request.
/**
* Requests disco info.
*
* @param account
* @param user
* @param capability
*/
private void request(String account, String user, Capability capability) {
for (DiscoverInfoRequest check : requests) {
if (capability.equals(check.getCapability())) {
return;
}
}
DiscoverInfo packet = new DiscoverInfo();
packet.setTo(user);
packet.setType(Type.get);
if (capability.getNode() != null && capability.getVersion() != null)
packet.setNode(capability.getNode() + "#" + capability.getVersion());
try {
ConnectionManager.getInstance().sendStanza(account, packet);
} catch (NetworkException e) {
return;
}
requests.add(new DiscoverInfoRequest(account, Jid.getStringPrep(user), packet.getStanzaId(), capability));
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project xabber-android by redsolution.
the class ServerInfoManager method onReceived.
@Override
public void onReceived(String account, String packetId, IQ iq) {
if (!(iq instanceof DiscoverInfo)) {
onError(account, packetId, iq);
return;
}
ArrayList<String> features = new ArrayList<String>();
DiscoverInfo discoverInfo = (DiscoverInfo) iq;
for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
features.add(feature.getVar());
}
protocols.put(account, features);
onAvailable(AccountManager.getInstance().getAccount(account));
}
Aggregations