use of eu.siacs.conversations.entities.Presence in project Conversations by siacs.
the class JingleConnection method upgradeNamespace.
private void upgradeNamespace() {
Jid jid = this.message.getCounterpart();
String resource = jid != null ? jid.getResourcepart() : null;
if (resource != null) {
Presence presence = this.account.getRoster().getContact(jid).getPresences().getPresences().get(resource);
ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null;
if (result != null) {
List<String> features = result.getFeatures();
if (features.contains(Content.Version.FT_4.getNamespace())) {
this.ftVersion = Content.Version.FT_4;
}
}
}
}
use of eu.siacs.conversations.entities.Presence in project Conversations by siacs.
the class PresenceParser method parseContactPresence.
public void parseContactPresence(final PresencePacket packet, final Account account) {
final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
final Jid from = packet.getFrom();
if (from == null || from.equals(account.getJid())) {
return;
}
final String type = packet.getAttribute("type");
final Contact contact = account.getRoster().getContact(from);
if (type == null) {
final String resource = from.isBareJid() ? "" : from.getResourcepart();
contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) {
avatar.owner = from.toBareJid();
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
if (avatar.owner.equals(account.getJid().toBareJid())) {
account.setAvatar(avatar.getFilename());
mXmppConnectionService.databaseBackend.updateAccount(account);
mXmppConnectionService.getAvatarService().clear(account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
} else if (contact.setAvatar(avatar)) {
mXmppConnectionService.getAvatarService().clear(contact);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
}
} else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(account, avatar);
}
}
int sizeBefore = contact.getPresences().size();
final String show = packet.findChildContent("show");
final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
final String message = packet.findChildContent("status");
final Presence presence = Presence.parse(show, caps, message);
contact.updatePresence(resource, presence);
if (presence.hasCaps()) {
mXmppConnectionService.fetchCaps(account, from, presence);
}
final Element idle = packet.findChild("idle", "urn:xmpp:idle:1");
if (idle != null) {
contact.flagInactive();
String since = idle.getAttribute("since");
try {
contact.setLastseen(AbstractParser.parseTimestamp(since));
} catch (NullPointerException | ParseException e) {
contact.setLastseen(System.currentTimeMillis());
}
} else {
contact.flagActive();
contact.setLastseen(AbstractParser.parseTimestamp(packet));
}
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
Element x = packet.findChild("x", "jabber:x:signed");
if (pgp != null && x != null) {
Element status = packet.findChild("status");
String msg = status != null ? status.getContent() : "";
contact.setPgpKeyId(pgp.fetchKeyId(account, msg, x.getContent()));
}
boolean online = sizeBefore < contact.getPresences().size();
mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online);
} else if (type.equals("unavailable")) {
if (from.isBareJid()) {
contact.clearPresences();
} else {
contact.removePresence(from.getResourcepart());
}
mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
} else if (type.equals("subscribe")) {
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
mXmppConnectionService.sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
} else {
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, contact.getJid().toBareJid(), false);
final String statusMessage = packet.findChildContent("status");
if (statusMessage != null && !statusMessage.isEmpty() && conversation.countMessages() == 0) {
conversation.add(new Message(conversation, statusMessage, Message.ENCRYPTION_NONE, Message.STATUS_RECEIVED));
}
}
}
mXmppConnectionService.updateRosterUi();
}
use of eu.siacs.conversations.entities.Presence in project Conversations by siacs.
the class MessageParser method clientMightSendHtml.
private static boolean clientMightSendHtml(Account account, Jid from) {
String resource = from.getResourcepart();
if (resource == null) {
return false;
}
Presence presence = account.getRoster().getContact(from).getPresences().getPresences().get(resource);
ServiceDiscoveryResult disco = presence == null ? null : presence.getServiceDiscoveryResult();
if (disco == null) {
return false;
}
return hasIdentityKnowForSendingHtml(disco.getIdentities());
}
Aggregations