Commit 441cfe79 authored by Guus der Kinderen's avatar Guus der Kinderen

Merge pull request #412 from surevine/dwd/muc-join

Assume a client with MUC elements in presence needs to join
parents b46d89a1 b853644c
...@@ -563,6 +563,8 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -563,6 +563,8 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
} }
LocalMUCRole joinRole = null; LocalMUCRole joinRole = null;
lock.writeLock().lock(); lock.writeLock().lock();
boolean clientOnlyJoin = false;
// A "client only join" here is one where the client is already joined, but has re-joined.
try { try {
// If the room has a limit of max user then check if the limit has been reached // If the room has a limit of max user then check if the limit has been reached
if (!canJoinRoom(user)) { if (!canJoinRoom(user)) {
...@@ -584,6 +586,9 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -584,6 +586,9 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
// Nickname is already used, and not by the same JID // Nickname is already used, and not by the same JID
throw new UserAlreadyExistsException(); throw new UserAlreadyExistsException();
} }
if (occupant.getUserAddress().equals(user.getAddress())) {
clientOnlyJoin = true; // This user is already an occupant. The client thinks it isn't. (Or else this is a broken gmail).
}
} }
// If the room is password protected and the provided password is incorrect raise a // If the room is password protected and the provided password is incorrect raise a
// Unauthorized exception // Unauthorized exception
...@@ -650,23 +655,29 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -650,23 +655,29 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
role = (isModerated() ? MUCRole.Role.visitor : MUCRole.Role.participant); role = (isModerated() ? MUCRole.Role.visitor : MUCRole.Role.participant);
affiliation = MUCRole.Affiliation.none; affiliation = MUCRole.Affiliation.none;
} }
// Create a new role for this user in this room if (!clientOnlyJoin) {
joinRole = new LocalMUCRole(mucService, this, nickname, role, affiliation, user, presence, router); // Create a new role for this user in this room
// Add the new user as an occupant of this room joinRole = new LocalMUCRole(mucService, this, nickname, role,
List<MUCRole> occupants = occupantsByNickname.get(nickname.toLowerCase()); affiliation, user, presence, router);
if (occupants == null) { // Add the new user as an occupant of this room
occupants = new ArrayList<>(); List<MUCRole> occupants = occupantsByNickname.get(nickname.toLowerCase());
occupantsByNickname.put(nickname.toLowerCase(), occupants); if (occupants == null) {
} occupants = new ArrayList<>();
occupants.add(joinRole); occupantsByNickname.put(nickname.toLowerCase(), occupants);
// Update the tables of occupants based on the bare and full JID }
List<MUCRole> list = occupantsByBareJID.get(bareJID); occupants.add(joinRole);
if (list == null) { // Update the tables of occupants based on the bare and full JID
list = new ArrayList<>(); List<MUCRole> list = occupantsByBareJID.get(bareJID);
occupantsByBareJID.put(bareJID, list); if (list == null) {
} list = new ArrayList<>();
list.add(joinRole); occupantsByBareJID.put(bareJID, list);
occupantsByFullJID.put(user.getAddress(), joinRole); }
list.add(joinRole);
occupantsByFullJID.put(user.getAddress(), joinRole);
} else {
// Grab the existing one.
joinRole = (LocalMUCRole) occupantsByFullJID.get(user.getAddress());
}
} }
finally { finally {
lock.writeLock().unlock(); lock.writeLock().unlock();
...@@ -706,10 +717,13 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -706,10 +717,13 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
else { else {
historyRequest.sendHistory(joinRole, roomHistory); historyRequest.sendHistory(joinRole, roomHistory);
} }
// Update the date when the last occupant left the room if (!clientOnlyJoin) {
setEmptyDate(null); // Update the date when the last occupant left the room
// Fire event that occupant joined the room setEmptyDate(null);
MUCEventDispatcher.occupantJoined(getRole().getRoleAddress(), user.getAddress(), joinRole.getNickname()); // Fire event that occupant joined the room
MUCEventDispatcher.occupantJoined(getRole().getRoleAddress(),
user.getAddress(), joinRole.getNickname());
}
return joinRole; return joinRole;
} }
......
...@@ -71,7 +71,7 @@ import org.xmpp.packet.Presence; ...@@ -71,7 +71,7 @@ import org.xmpp.packet.Presence;
*/ */
public class LocalMUCUser implements MUCUser { public class LocalMUCUser implements MUCUser {
private static final Logger Log = LoggerFactory.getLogger(LocalMUCUser.class); private static final Logger Log = LoggerFactory.getLogger(LocalMUCUser.class);
/** The chat server this user belongs to. */ /** The chat server this user belongs to. */
private MultiUserChatService server; private MultiUserChatService server;
...@@ -462,9 +462,12 @@ public class LocalMUCUser implements MUCUser { ...@@ -462,9 +462,12 @@ public class LocalMUCUser implements MUCUser {
String group = recipient.getNode(); String group = recipient.getNode();
if (group != null) { if (group != null) {
MUCRole role = roles.get(group); MUCRole role = roles.get(group);
if (role == null) { Element mucInfo = packet.getChildElement("x",
// If we're not already in a room, we either are joining it or it's not "http://jabber.org/protocol/muc");
if (role == null || mucInfo != null) {
// If we're not already in a room (role == null), we either are joining it or it's not
// properly addressed and we drop it silently // properly addressed and we drop it silently
// Alternative is that mucInfo is not null, in which case the client thinks it isn't in the room, so we should join anyway.
if (recipient.getResource() != null if (recipient.getResource() != null
&& recipient.getResource().trim().length() > 0) { && recipient.getResource().trim().length() > 0) {
if (packet.isAvailable()) { if (packet.isAvailable()) {
...@@ -472,8 +475,6 @@ public class LocalMUCUser implements MUCUser { ...@@ -472,8 +475,6 @@ public class LocalMUCUser implements MUCUser {
// Get or create the room // Get or create the room
MUCRoom room = server.getChatRoom(group, packet.getFrom()); MUCRoom room = server.getChatRoom(group, packet.getFrom());
// User must support MUC in order to create a room // User must support MUC in order to create a room
Element mucInfo = packet.getChildElement("x",
"http://jabber.org/protocol/muc");
HistoryRequest historyRequest = null; HistoryRequest historyRequest = null;
String password = null; String password = null;
// Check for password & requested history if client supports MUC // Check for password & requested history if client supports MUC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment