use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class CapabilitiesManager method onPresenceChanged.
public void onPresenceChanged(final String account, final Presence presence) {
final String user = Jid.getStringPrep(presence.getFrom());
if (user == null)
return;
if (presence.getType() == Presence.Type.error)
return;
if (presence.getType() == Presence.Type.unavailable) {
userCapabilities.remove(account, user);
return;
}
LogManager.i(this, "onPresenceChanged " + user);
for (ExtensionElement packetExtension : presence.getExtensions()) {
if (packetExtension instanceof CapsExtension) {
CapsExtension capsExtension = (CapsExtension) packetExtension;
if (capsExtension.getNode() == null || capsExtension.getVer() == null) {
continue;
}
Capability capability = new Capability(account, user, capsExtension.getHash(), capsExtension.getNode(), capsExtension.getVer());
if (capability.equals(userCapabilities.get(account, user))) {
continue;
}
userCapabilities.put(account, user, capability);
ClientInfo clientInfo = clientInformations.get(capability);
if (clientInfo == null || clientInfo == INVALID_CLIENT_INFO) {
request(account, presence.getFrom(), capability);
}
}
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class CapabilitiesManager method calculateString.
private String calculateString(DiscoverInfo discoverInfo) {
StringBuilder s = new StringBuilder();
SortedSet<String> identities = new TreeSet<>();
for (DiscoverInfo.Identity identity : discoverInfo.getIdentities()) {
StringBuilder builder = new StringBuilder();
builder.append(identity.getCategory());
builder.append("/");
String type = identity.getType();
if (type != null) {
builder.append(type);
}
builder.append("/");
String lang = identity.getLanguage();
if (lang != null) {
builder.append(lang);
}
builder.append("/");
String name = identity.getName();
if (name != null) {
builder.append(name);
}
identities.add(builder.toString());
}
for (String identity : identities) {
s.append(identity);
s.append("<");
}
SortedSet<String> features = new TreeSet<>();
for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
features.add(feature.getVar());
}
for (String feature : features) {
s.append(feature);
s.append("<");
}
// Maps prepared value to FORM_TYPE key.
// Extensions with equal FORM_TYPEs are not allowed.
SortedMap<String, String> extendeds = new TreeMap<>();
for (ExtensionElement packetExtension : discoverInfo.getExtensions()) {
if (packetExtension instanceof DataForm) {
DataForm dataForm = (DataForm) packetExtension;
// Fields with equal var are allowed for fixed type.
SortedSet<FormField> formFields = new TreeSet<>(new Comparator<FormField>() {
@Override
public int compare(FormField f1, FormField f2) {
// Var may not exists for fixed type.
String s1 = f1.getVariable();
String s2 = f2.getVariable();
return (s1 == null ? "" : s1).compareTo(s2 == null ? "" : s2);
}
});
String formType = null;
for (FormField formField : dataForm.getFields()) {
if (FORM_TYPE.equals(formField.getVariable())) {
if (formField.getType() != FormField.Type.hidden) {
continue;
}
for (String value : formField.getValues()) {
formType = value;
}
} else {
formFields.add(formField);
}
}
if (formType == null) {
continue;
}
StringBuilder builder = new StringBuilder();
builder.append(formType);
builder.append("<");
for (FormField formField : formFields) {
builder.append(formField.getVariable());
builder.append("<");
SortedSet<String> values = new TreeSet<>();
for (String value : formField.getValues()) {
values.add(value);
}
for (String value : values) {
builder.append(value);
builder.append("<");
}
}
extendeds.put(formType, builder.toString());
}
}
for (Entry<String, String> extended : extendeds.entrySet()) {
s.append(extended.getValue());
}
return s.toString();
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class MessageManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem)) {
return;
}
String account = ((AccountItem) connection).getAccount();
if (bareAddress == null) {
return;
}
if (packet instanceof Message && MessageArchiveManager.getInstance().isModificationsSucceed(account) && Delay.isOfflineMessage(Jid.getServer(account), packet)) {
// archive have been received.
return;
}
String contact = bareAddress;
if (packet instanceof Message) {
Message message = (Message) packet;
if (MUCManager.getInstance().hasRoom(account, bareAddress) && message.getType() != Message.Type.groupchat) {
contact = packet.getFrom();
}
}
final String user = packet.getFrom();
boolean processed = false;
for (AbstractChat chat : chats.getNested(account).values()) {
if (chat.onPacket(contact, packet)) {
processed = true;
break;
}
}
final AbstractChat chat = getChat(account, user);
if (chat != null && packet instanceof Message) {
if (chat.isPrivateMucChat() && !chat.isPrivateMucChatAccepted()) {
if (mucPrivateChatRequestProvider.get(chat.getAccount(), chat.getUser()) == null) {
if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(chat.getUser())) {
mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
}
}
}
return;
}
if (!processed && packet instanceof Message) {
final Message message = (Message) packet;
final String body = message.getBody();
if (body == null) {
return;
}
if (message.getType() == Message.Type.chat && MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user))) {
createPrivateMucChat(account, user).onPacket(contact, packet);
if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(user)) {
mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
}
return;
}
for (ExtensionElement packetExtension : message.getExtensions()) {
if (packetExtension instanceof MUCUser) {
return;
}
}
createChat(account, user).onPacket(contact, packet);
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class AttentionManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
if (!(packet instanceof Message))
return;
if (!SettingsManager.chatsAttention())
return;
final String account = ((AccountItem) connection).getAccount();
if (bareAddress == null)
return;
for (ExtensionElement packetExtension : packet.getExtensions()) {
if (packetExtension instanceof Attention) {
MessageManager.getInstance().openChat(account, bareAddress);
MessageManager.getInstance().getOrCreateChat(account, bareAddress).newAction(null, null, ChatAction.attention_requested);
attentionRequestProvider.add(new AttentionRequest(account, bareAddress), true);
}
}
}
use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.
the class SSNManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
String from = packet.getFrom();
if (from == null)
return;
if (!(connection instanceof AccountItem) || !(packet instanceof Message))
return;
String account = ((AccountItem) connection).getAccount();
Message message = (Message) packet;
String session = message.getThread();
if (session == null)
return;
for (ExtensionElement packetExtension : packet.getExtensions()) if (packetExtension instanceof Feature) {
Feature feature = (Feature) packetExtension;
if (!feature.isValid())
continue;
DataFormType type = feature.getDataFormType();
if (type == DataFormType.form)
onFormReceived(account, from, bareAddress, session, feature);
else if (type == DataFormType.submit)
onSubmitReceived(account, from, bareAddress, session, feature);
else if (type == DataFormType.result)
onResultReceived(account, from, bareAddress, session, feature);
}
}
Aggregations