diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/parser/PresenceParser.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/parser/PresenceParser.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 4e90cda8c..635f29327 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -9,6 +9,7 @@ import eu.siacs.conversations.generator.PresenceGenerator; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnPresencePacketReceived; +import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; public class PresenceParser extends AbstractParser implements @@ -21,8 +22,9 @@ public class PresenceParser extends AbstractParser implements public void parseConferencePresence(PresencePacket packet, Account account) { PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine(); if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { - Conversation muc = mXmppConnectionService.find(account, packet - .getAttribute("from").split("/", 2)[0]); + final Conversation muc = packet.getFrom() == null ? null : mXmppConnectionService.find( + account, + packet.getFrom().toBareJid()); if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); @@ -32,8 +34,8 @@ public class PresenceParser extends AbstractParser implements mXmppConnectionService.getAvatarService().clear(muc); } } else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) { - Conversation muc = mXmppConnectionService.find(account, packet - .getAttribute("from").split("/", 2)[0]); + final Conversation muc = mXmppConnectionService.find(account, + packet.getFrom().toBareJid()); if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); @@ -51,15 +53,15 @@ public class PresenceParser extends AbstractParser implements if (packet.getFrom() == null) { return; } - String[] fromParts = packet.getFrom().split("/", 2); + final Jid from = packet.getFrom(); String type = packet.getAttribute("type"); - if (fromParts[0].equals(account.getJid())) { - if (fromParts.length == 2) { + if (from.toBareJid().equals(account.getJid().toBareJid())) { + if (!from.isBareJid()) { if (type == null) { - account.updatePresence(fromParts[1], + account.updatePresence(from.getResourcepart(), Presences.parseShow(packet.findChild("show"))); } else if (type.equals("unavailable")) { - account.removePresence(fromParts[1]); + account.removePresence(from.getResourcepart()); account.deactivateGracePeriod(); } } @@ -67,8 +69,8 @@ public class PresenceParser extends AbstractParser implements Contact contact = account.getRoster().getContact(packet.getFrom()); if (type == null) { String presence; - if (fromParts.length >= 2) { - presence = fromParts[1]; + if (!from.isBareJid()) { + presence = from.getResourcepart(); } else { presence = ""; } @@ -95,10 +97,10 @@ public class PresenceParser extends AbstractParser implements mXmppConnectionService.onContactStatusChanged .onContactStatusChanged(contact, online); } else if (type.equals("unavailable")) { - if (fromParts.length != 2) { + if (from.isBareJid()) { contact.clearPresences(); } else { - contact.removePresence(fromParts[1]); + contact.removePresence(from.getResourcepart()); } mXmppConnectionService.onContactStatusChanged .onContactStatusChanged(contact, false); |