@@ -342,7 +342,7 @@ public class MucOptions {
return null;
}
- public User findUserByOccupantId(final String id) {
+ public User findUserByOccupantId(final String id, final Jid counterpart) {
if (id == null) {
return null;
}
@@ -353,21 +353,24 @@ public class MucOptions {
}
}
}
- return new User(this, null, id, null, new HashSet<>());
+ final var user = new User(this, counterpart, id, null, new HashSet<>());
+ user.setOnline(false);
+ return user;
}
- public User findOrCreateUserByRealJid(Jid jid, Jid fullJid) {
+ public User findOrCreateUserByRealJid(Jid jid, Jid fullJid, final String occupantId) {
User user = findUserByRealJid(jid);
if (user == null) {
- user = new User(this, fullJid, null, null, new HashSet<>());
+ user = new User(this, fullJid, occupantId, null, new HashSet<>());
user.setRealJid(jid);
+ user.setOnline(false);
}
return user;
}
public User findUser(ReadByMarker readByMarker) {
if (readByMarker.getRealJid() != null) {
- return findOrCreateUserByRealJid(readByMarker.getRealJid().asBareJid(), readByMarker.getFullJid());
+ return findOrCreateUserByRealJid(readByMarker.getRealJid().asBareJid(), readByMarker.getFullJid(), null);
} else if (readByMarker.getFullJid() != null) {
return findUserByFullJid(readByMarker.getFullJid());
} else {
@@ -376,11 +379,15 @@ public class MucOptions {
}
public boolean isContactInRoom(Contact contact) {
- return contact != null && findUserByRealJid(contact.getJid().asBareJid()) != null;
+ return contact != null && isUserInRoom(findUserByRealJid(contact.getJid().asBareJid()));
}
public boolean isUserInRoom(Jid jid) {
- return findUserByFullJid(jid) != null;
+ return isUserInRoom(findUserByFullJid(jid));
+ }
+
+ public boolean isUserInRoom(User user) {
+ return user != null && user.isOnline();
}
public boolean setOnline() {
@@ -847,6 +854,7 @@ public class MucOptions {
private ChatState chatState = Config.DEFAULT_CHAT_STATE;
protected Set<Hat> hats;
protected String occupantId;
+ protected boolean online = true;
public User(MucOptions options, Jid fullJid, final String occupantId, final String nick, final Set<Hat> hats) {
this.options = options;
@@ -872,6 +880,14 @@ public class MucOptions {
return nick == null ? getName() : nick;
}
+ public void setOnline(final boolean o) {
+ online = o;
+ }
+
+ public boolean isOnline() {
+ return fullJid != null && online;
+ }
+
public Role getRole() {
return this.role;
}
@@ -493,7 +493,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
final MucOptions mucOptions = ((Conversation) conversation).getMucOptions();
MucOptions.User user;
if (trueCounterpart != null) {
- user = mucOptions.findOrCreateUserByRealJid(trueCounterpart, message.getCounterpart());
+ user = mucOptions.findOrCreateUserByRealJid(trueCounterpart, message.getCounterpart(), null);
} else {
user = mucOptions.findUserByFullJid(message.getCounterpart());
}
@@ -4453,14 +4453,14 @@ public class ConversationFragment extends XmppFragment
return;
}
final Jid tcp = message.getTrueCounterpart();
+ final String occupantId = message.getOccupantId();
final User userByRealJid =
tcp != null
- ? conversation.getMucOptions().findOrCreateUserByRealJid(tcp, cp)
+ ? conversation.getMucOptions().findOrCreateUserByRealJid(tcp, cp, occupantId)
: null;
- final String occupantId = message.getOccupantId();
final User userByOccupantId =
occupantId != null
- ? conversation.getMucOptions().findUserByOccupantId(occupantId)
+ ? conversation.getMucOptions().findUserByOccupantId(occupantId, cp)
: null;
final User user =
userByRealJid != null
@@ -166,9 +166,9 @@ public final class MucDetailsContextMenuHelper {
}
}
managePermissions.setVisible(managePermissionsVisible);
- sendPrivateMessage.setVisible(user.getFullJid() != null && !isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
+ sendPrivateMessage.setVisible(user.isOnline() && !isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
} else {
- sendPrivateMessage.setVisible(user != null && user.getFullJid() != null);
+ sendPrivateMessage.setVisible(user != null && user.isOnline());
sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
}
}