parse nick and avatar only from available presences to avoid potential error reflection
This commit is contained in:
parent
0f6f6adca0
commit
165965bb83
|
@ -45,65 +45,17 @@ public class PresenceParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseContactPresence(PresencePacket packet, Account account) {
|
public void parseContactPresence(PresencePacket packet, Account account) {
|
||||||
PresenceGenerator mPresenceGenerator = mXmppConnectionService
|
PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
|
||||||
.getPresenceGenerator();
|
final Jid from = packet.getFrom();
|
||||||
if (packet.getFrom() == null) {
|
if (from == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Jid from = packet.getFrom();
|
final String type = packet.getAttribute("type");
|
||||||
String type = packet.getAttribute("type");
|
final Contact contact = account.getRoster().getContact(from);
|
||||||
Contact contact = account.getRoster().getContact(packet.getFrom());
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
String presence;
|
String presence = from.isBareJid() ? "" : from.getResourcepart();
|
||||||
if (!from.isBareJid()) {
|
contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
|
||||||
presence = from.getResourcepart();
|
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
|
||||||
} else {
|
|
||||||
presence = "";
|
|
||||||
}
|
|
||||||
int sizeBefore = contact.getPresences().size();
|
|
||||||
contact.updatePresence(presence,
|
|
||||||
Presences.parseShow(packet.findChild("show")));
|
|
||||||
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
|
|
||||||
if (pgp != null) {
|
|
||||||
Element x = packet.findChild("x", "jabber:x:signed");
|
|
||||||
if (x != null) {
|
|
||||||
Element status = packet.findChild("status");
|
|
||||||
String msg;
|
|
||||||
if (status != null) {
|
|
||||||
msg = status.getContent();
|
|
||||||
} else {
|
|
||||||
msg = "";
|
|
||||||
}
|
|
||||||
contact.setPgpKeyId(pgp.fetchKeyId(account, msg,
|
|
||||||
x.getContent()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean online = sizeBefore < contact.getPresences().size();
|
|
||||||
updateLastseen(packet, account, false);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Element nick = packet.findChild("nick",
|
|
||||||
"http://jabber.org/protocol/nick");
|
|
||||||
if (nick != null) {
|
|
||||||
contact.setPresenceName(nick.getContent());
|
|
||||||
}
|
|
||||||
Element x = packet.findChild("x","vcard-temp:x:update");
|
|
||||||
Avatar avatar = Avatar.parsePresence(x);
|
|
||||||
if (avatar != null && !contact.isSelf()) {
|
if (avatar != null && !contact.isSelf()) {
|
||||||
avatar.owner = from.toBareJid();
|
avatar.owner = from.toBareJid();
|
||||||
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
|
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
|
||||||
|
@ -116,6 +68,33 @@ public class PresenceParser extends AbstractParser implements
|
||||||
mXmppConnectionService.fetchAvatar(account, avatar);
|
mXmppConnectionService.fetchAvatar(account, avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int sizeBefore = contact.getPresences().size();
|
||||||
|
contact.updatePresence(presence, Presences.parseShow(packet.findChild("show")));
|
||||||
|
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();
|
||||||
|
updateLastseen(packet, account, false);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
mXmppConnectionService.updateRosterUi();
|
mXmppConnectionService.updateRosterUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue