From 1d3167b52021bf0fa3186db0a4f20848d3decf6e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 13 Nov 2016 19:25:58 +0100 Subject: extract affiliations from unavailable presence --- .../eu/siacs/conversations/entities/MucOptions.java | 2 +- .../eu/siacs/conversations/parser/AbstractParser.java | 17 +++++++++++------ .../eu/siacs/conversations/parser/MessageParser.java | 2 +- .../eu/siacs/conversations/parser/PresenceParser.java | 16 +++++++++------- .../conversations/services/XmppConnectionService.java | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 29b94850..8e67aa41 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -409,7 +409,7 @@ public class MucOptions { return user; } - public void addUser(User user) { + public void updateUser(User user) { User old; if (user.fullJid == null && user.realJid != null) { old = findUserByRealJid(user.realJid); diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java index 3835d36b..b4859e90 100644 --- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java @@ -74,19 +74,24 @@ public abstract class AbstractParser { } public static MucOptions.User parseItem(Conversation conference, Element item) { + return parseItem(conference,item, null); + } + + public static MucOptions.User parseItem(Conversation conference, Element item, Jid fullJid) { final String local = conference.getJid().getLocalpart(); final String domain = conference.getJid().getDomainpart(); String affiliation = item.getAttribute("affiliation"); String role = item.getAttribute("role"); String nick = item.getAttribute("nick"); - Jid fullJid; - try { - fullJid = nick != null ? Jid.fromParts(local, domain, nick) : null; - } catch (InvalidJidException e) { - fullJid = null; + if (nick != null && fullJid == null) { + try { + fullJid = Jid.fromParts(local, domain, nick); + } catch (InvalidJidException e) { + fullJid = null; + } } Jid realJid = item.getAttributeAsJid("jid"); - MucOptions.User user = new MucOptions.User(conference.getMucOptions(), nick == null ? null : fullJid); + MucOptions.User user = new MucOptions.User(conference.getMucOptions(), fullJid); user.setRealJid(realJid); user.setAffiliation(affiliation); user.setRole(role); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index eaed0fbc..c8ae1fdc 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -612,7 +612,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece +user.getRealJid()+" to "+user.getAffiliation()+" in " +conversation.getJid().toBareJid()); if (!user.realJidMatchesAccount()) { - conversation.getMucOptions().addUser(user); + conversation.getMucOptions().updateUser(user); mXmppConnectionService.getAvatarService().clear(conversation); mXmppConnectionService.updateMucRosterUi(); mXmppConnectionService.updateConversationUi(); diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 46ce61b7..63bec8bf 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -38,7 +38,7 @@ public class PresenceParser extends AbstractParser implements boolean before = mucOptions.online(); int count = mucOptions.getUserCount(); final List tileUserBefore = mucOptions.getUsers(5); - processConferencePresence(packet, mucOptions); + processConferencePresence(packet, conversation); final List tileUserAfter = mucOptions.getUsers(5); if (!tileUserAfter.equals(tileUserBefore)) { mXmppConnectionService.getAvatarService().clear(mucOptions); @@ -51,7 +51,8 @@ public class PresenceParser extends AbstractParser implements } } - private void processConferencePresence(PresencePacket packet, MucOptions mucOptions) { + private void processConferencePresence(PresencePacket packet, Conversation conversation) { + MucOptions mucOptions = conversation.getMucOptions(); final Jid from = packet.getFrom(); if (!from.isBareJid()) { final String type = packet.getAttribute("type"); @@ -63,10 +64,7 @@ public class PresenceParser extends AbstractParser implements Element item = x.findChild("item"); if (item != null && !from.isBareJid()) { mucOptions.setError(MucOptions.Error.NONE); - MucOptions.User user = new MucOptions.User(mucOptions, from); - user.setAffiliation(item.getAttribute("affiliation")); - user.setRole(item.getAttribute("role")); - user.setRealJid(item.getAttributeAsJid("jid")); + MucOptions.User user = parseItem(conversation, item, from); if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(mucOptions.getConversation().getJid())) { mucOptions.setOnline(); mucOptions.setSelf(user); @@ -77,7 +75,7 @@ public class PresenceParser extends AbstractParser implements mucOptions.mNickChangingInProgress = false; } } else { - mucOptions.addUser(user); + mucOptions.updateUser(user); } if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) { Log.d(Config.LOGTAG,mucOptions.getAccount().getJid().toBareJid() @@ -131,6 +129,10 @@ public class PresenceParser extends AbstractParser implements Log.d(Config.LOGTAG, "unknown error in conference: " + packet); } } else if (!from.isBareJid()){ + Element item = x.findChild("item"); + if (item != null) { + mucOptions.updateUser(parseItem(conversation, item, from)); + } MucOptions.User user = mucOptions.deleteUser(from); if (user != null) { mXmppConnectionService.getAvatarService().clear(user); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 2fb13ce8..9f3eea3f 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2127,7 +2127,7 @@ public class XmppConnectionService extends Service { if ("item".equals(child.getName())) { MucOptions.User user = AbstractParser.parseItem(conversation,child); if (!user.realJidMatchesAccount()) { - conversation.getMucOptions().addUser(user); + conversation.getMucOptions().updateUser(user); } } } -- cgit v1.2.3