fixed potential NPEs

This commit is contained in:
iNPUTmice 2014-11-20 18:42:47 +01:00
parent a142dcc263
commit a207240881
1 changed files with 43 additions and 39 deletions

View File

@ -344,50 +344,54 @@ public class MessageParser extends AbstractParser implements
private void parseEvent(final Element event, final Jid from, final Account account) { private void parseEvent(final Element event, final Jid from, final Account account) {
Element items = event.findChild("items"); Element items = event.findChild("items");
if (items == null) {
return;
}
String node = items.getAttribute("node"); String node = items.getAttribute("node");
if (node != null) { if (node == null) {
if (node.equals("urn:xmpp:avatar:metadata")) { return;
Avatar avatar = Avatar.parseMetadata(items); }
if (avatar != null) { if (node.equals("urn:xmpp:avatar:metadata")) {
avatar.owner = from; Avatar avatar = Avatar.parseMetadata(items);
if (mXmppConnectionService.getFileBackend().isAvatarCached( if (avatar != null) {
avatar)) { avatar.owner = from;
if (account.getJid().toBareJid().equals(from)) { if (mXmppConnectionService.getFileBackend().isAvatarCached(
if (account.setAvatar(avatar.getFilename())) { avatar)) {
mXmppConnectionService.databaseBackend if (account.getJid().toBareJid().equals(from)) {
.updateAccount(account); if (account.setAvatar(avatar.getFilename())) {
} mXmppConnectionService.databaseBackend
mXmppConnectionService.getAvatarService().clear( .updateAccount(account);
account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(
from);
contact.setAvatar(avatar.getFilename());
mXmppConnectionService.getAvatarService().clear(
contact);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
} }
mXmppConnectionService.getAvatarService().clear(
account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
} else { } else {
mXmppConnectionService.fetchAvatar(account, avatar); Contact contact = account.getRoster().getContact(
from);
contact.setAvatar(avatar.getFilename());
mXmppConnectionService.getAvatarService().clear(
contact);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
} }
} else {
mXmppConnectionService.fetchAvatar(account, avatar);
} }
} else if (node.equals("http://jabber.org/protocol/nick")) { }
Element item = items.findChild("item"); } else if (node.equals("http://jabber.org/protocol/nick")) {
if (item != null) { Element item = items.findChild("item");
Element nick = item.findChild("nick", if (item != null) {
"http://jabber.org/protocol/nick"); Element nick = item.findChild("nick",
if (nick != null) { "http://jabber.org/protocol/nick");
if (from != null) { if (nick != null) {
Contact contact = account.getRoster().getContact( if (from != null) {
from); Contact contact = account.getRoster().getContact(
contact.setPresenceName(nick.getContent()); from);
mXmppConnectionService.getAvatarService().clear(account); contact.setPresenceName(nick.getContent());
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.getAvatarService().clear(account);
mXmppConnectionService.updateAccountUi(); mXmppConnectionService.updateConversationUi();
} mXmppConnectionService.updateAccountUi();
} }
} }
} }