extract affiliations from unavailable presence

This commit is contained in:
Daniel Gultsch 2016-11-13 19:25:58 +01:00
parent 035d0c7957
commit 1d3167b520
5 changed files with 23 additions and 16 deletions

View file

@ -409,7 +409,7 @@ public class MucOptions {
return user; return user;
} }
public void addUser(User user) { public void updateUser(User user) {
User old; User old;
if (user.fullJid == null && user.realJid != null) { if (user.fullJid == null && user.realJid != null) {
old = findUserByRealJid(user.realJid); old = findUserByRealJid(user.realJid);

View file

@ -74,19 +74,24 @@ public abstract class AbstractParser {
} }
public static MucOptions.User parseItem(Conversation conference, Element item) { 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 local = conference.getJid().getLocalpart();
final String domain = conference.getJid().getDomainpart(); final String domain = conference.getJid().getDomainpart();
String affiliation = item.getAttribute("affiliation"); String affiliation = item.getAttribute("affiliation");
String role = item.getAttribute("role"); String role = item.getAttribute("role");
String nick = item.getAttribute("nick"); String nick = item.getAttribute("nick");
Jid fullJid; if (nick != null && fullJid == null) {
try { try {
fullJid = nick != null ? Jid.fromParts(local, domain, nick) : null; fullJid = Jid.fromParts(local, domain, nick);
} catch (InvalidJidException e) { } catch (InvalidJidException e) {
fullJid = null; fullJid = null;
} }
}
Jid realJid = item.getAttributeAsJid("jid"); 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.setRealJid(realJid);
user.setAffiliation(affiliation); user.setAffiliation(affiliation);
user.setRole(role); user.setRole(role);

View file

@ -612,7 +612,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
+user.getRealJid()+" to "+user.getAffiliation()+" in " +user.getRealJid()+" to "+user.getAffiliation()+" in "
+conversation.getJid().toBareJid()); +conversation.getJid().toBareJid());
if (!user.realJidMatchesAccount()) { if (!user.realJidMatchesAccount()) {
conversation.getMucOptions().addUser(user); conversation.getMucOptions().updateUser(user);
mXmppConnectionService.getAvatarService().clear(conversation); mXmppConnectionService.getAvatarService().clear(conversation);
mXmppConnectionService.updateMucRosterUi(); mXmppConnectionService.updateMucRosterUi();
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();

View file

@ -38,7 +38,7 @@ public class PresenceParser extends AbstractParser implements
boolean before = mucOptions.online(); boolean before = mucOptions.online();
int count = mucOptions.getUserCount(); int count = mucOptions.getUserCount();
final List<MucOptions.User> tileUserBefore = mucOptions.getUsers(5); final List<MucOptions.User> tileUserBefore = mucOptions.getUsers(5);
processConferencePresence(packet, mucOptions); processConferencePresence(packet, conversation);
final List<MucOptions.User> tileUserAfter = mucOptions.getUsers(5); final List<MucOptions.User> tileUserAfter = mucOptions.getUsers(5);
if (!tileUserAfter.equals(tileUserBefore)) { if (!tileUserAfter.equals(tileUserBefore)) {
mXmppConnectionService.getAvatarService().clear(mucOptions); 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(); final Jid from = packet.getFrom();
if (!from.isBareJid()) { if (!from.isBareJid()) {
final String type = packet.getAttribute("type"); final String type = packet.getAttribute("type");
@ -63,10 +64,7 @@ public class PresenceParser extends AbstractParser implements
Element item = x.findChild("item"); Element item = x.findChild("item");
if (item != null && !from.isBareJid()) { if (item != null && !from.isBareJid()) {
mucOptions.setError(MucOptions.Error.NONE); mucOptions.setError(MucOptions.Error.NONE);
MucOptions.User user = new MucOptions.User(mucOptions, from); MucOptions.User user = parseItem(conversation, item, from);
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
user.setRealJid(item.getAttributeAsJid("jid"));
if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(mucOptions.getConversation().getJid())) { if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(mucOptions.getConversation().getJid())) {
mucOptions.setOnline(); mucOptions.setOnline();
mucOptions.setSelf(user); mucOptions.setSelf(user);
@ -77,7 +75,7 @@ public class PresenceParser extends AbstractParser implements
mucOptions.mNickChangingInProgress = false; mucOptions.mNickChangingInProgress = false;
} }
} else { } else {
mucOptions.addUser(user); mucOptions.updateUser(user);
} }
if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) { if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) {
Log.d(Config.LOGTAG,mucOptions.getAccount().getJid().toBareJid() 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); Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
} }
} else if (!from.isBareJid()){ } else if (!from.isBareJid()){
Element item = x.findChild("item");
if (item != null) {
mucOptions.updateUser(parseItem(conversation, item, from));
}
MucOptions.User user = mucOptions.deleteUser(from); MucOptions.User user = mucOptions.deleteUser(from);
if (user != null) { if (user != null) {
mXmppConnectionService.getAvatarService().clear(user); mXmppConnectionService.getAvatarService().clear(user);

View file

@ -2127,7 +2127,7 @@ public class XmppConnectionService extends Service {
if ("item".equals(child.getName())) { if ("item".equals(child.getName())) {
MucOptions.User user = AbstractParser.parseItem(conversation,child); MucOptions.User user = AbstractParser.parseItem(conversation,child);
if (!user.realJidMatchesAccount()) { if (!user.realJidMatchesAccount()) {
conversation.getMucOptions().addUser(user); conversation.getMucOptions().updateUser(user);
} }
} }
} }