Commit cd70e1fa authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Keep extensions of presences sent to group chat rooms. JM-93


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@764 b35dd754-fafc-0310-a699-88a17e54d16e
parent 70f77fb1
......@@ -190,6 +190,7 @@ public interface MUCRoom extends ChatDeliverer {
* @param password The password provided by the user to enter the chatroom or null if none.
* @param historyRequest The amount of history that the user request or null meaning default.
* @param user The user joining.
* @param presence The presence sent by the user to join the room.
* @return The role created for the user.
* @throws UnauthorizedException If the user doesn't have permision to join the room.
* @throws UserAlreadyExistsException If the nickname is already taken.
......@@ -200,10 +201,10 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ConflictException If another user attempts to join the room with a nickname reserved
* by the first user.
*/
MUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest, MUCUser user)
throws UnauthorizedException, UserAlreadyExistsException, RoomLockedException,
ForbiddenException, RegistrationRequiredException, NotAllowedException,
ConflictException;
MUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest, MUCUser user,
Presence presence) throws UnauthorizedException, UserAlreadyExistsException,
RoomLockedException, ForbiddenException, RegistrationRequiredException,
NotAllowedException, ConflictException;
/**
* Remove a member from the chat room.
......
......@@ -15,7 +15,6 @@ import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import org.dom4j.QName;
import org.jivesoftware.messenger.PacketRouter;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.muc.MUCRole;
import org.jivesoftware.messenger.muc.MUCRoom;
import org.jivesoftware.messenger.muc.MUCUser;
......@@ -94,13 +93,12 @@ public class MUCRoleImpl implements MUCRole {
* @param role the role of the user in the room.
* @param affiliation the affiliation of the user in the room.
* @param chatuser the user on the chat server.
* @param presence the presence sent by the user to join the room.
* @param packetRouter the packet router for sending messages from this role.
* @throws UnauthorizedException if the role could not be created due to security or permission
* violations
*/
public MUCRoleImpl(MultiUserChatServer chatserver, MUCRoomImpl chatroom,
String nickname, int role, int affiliation, MUCUserImpl chatuser,
PacketRouter packetRouter) throws UnauthorizedException
public MUCRoleImpl(MultiUserChatServer chatserver, MUCRoomImpl chatroom, String nickname,
int role, int affiliation, MUCUserImpl chatuser, Presence presence,
PacketRouter packetRouter)
{
this.room = chatroom;
this.nick = nickname;
......@@ -113,7 +111,7 @@ public class MUCRoleImpl implements MUCRole {
DocumentHelper.createElement(QName.get("x", "http://jabber.org/protocol/muc#user"));
calculateExtendedInformation();
rJID = new JID(room.getName(), server.getServiceName(), nick);
setPresence(room.createPresence(null));
setPresence(presence);
}
public Presence getPresence() {
......@@ -125,7 +123,14 @@ public class MUCRoleImpl implements MUCRole {
}
public void setPresence(Presence newPresence) {
// Try to remove the element whose namespace is "http://jabber.org/protocol/muc" since we
// don't need to include that element in future presence broadcasts
Element element = newPresence.getElement().element(QName.get("x", "http://jabber.org/protocol/muc"));
if (element != null) {
newPresence.getElement().remove(element);
}
this.presence = newPresence;
this.presence.setFrom(getRoleAddress());
if (extendedInformation != null) {
extendedInformation.setParent(null);
presence.getElement().add(extendedInformation);
......@@ -149,6 +154,7 @@ public class MUCRoleImpl implements MUCRole {
role = newRole;
if (MUCRole.NONE_ROLE == role) {
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
}
calculateExtendedInformation();
}
......@@ -212,7 +218,7 @@ public class MUCRoleImpl implements MUCRole {
public void changeNickname(String nickname) {
this.nick = nickname;
rJID = new JID(room.getName(), server.getServiceName(), nick);
setRoleAddress(new JID(room.getName(), server.getServiceName(), nick));
}
public MUCUser getChatUser() {
......@@ -227,6 +233,12 @@ public class MUCRoleImpl implements MUCRole {
return rJID;
}
private void setRoleAddress(JID jid) {
rJID = jid;
// Set the new sender of the user presence in the room
presence.setFrom(jid);
}
public void send(Presence packet) {
packet.setTo(user.getAddress());
router.route(packet);
......
......@@ -388,9 +388,9 @@ public class MUCRoomImpl implements MUCRoom {
}
public MUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest,
MUCUser user) throws UnauthorizedException, UserAlreadyExistsException,
RoomLockedException, ForbiddenException, RegistrationRequiredException,
NotAllowedException, ConflictException {
MUCUser user, Presence presence) throws UnauthorizedException,
UserAlreadyExistsException, RoomLockedException, ForbiddenException,
RegistrationRequiredException, NotAllowedException, ConflictException {
MUCRoleImpl joinRole = null;
lock.writeLock().lock();
try {
......@@ -463,13 +463,13 @@ public class MUCRoomImpl implements MUCRoom {
affiliation = MUCRole.NONE;
}
// Create a new role for this user in this room
joinRole = new MUCRoleImpl(server, this, nickname, role, affiliation,
(MUCUserImpl) user, router);
joinRole =
new MUCRoleImpl(server, this, nickname, role, affiliation, (MUCUserImpl) user,
presence, router);
// Send presence of existing occupants to new occupant
for (MUCRole occupantsRole : occupants.values()) {
Presence occupantsPresence = (Presence) occupantsRole.getPresence()
.createCopy();
Presence occupantsPresence = occupantsRole.getPresence().createCopy();
// Skip to the next occupant if we cannot send presence of this occupant
if (hasToCheckRoleToBroadcastPresence()) {
Element frag = occupantsPresence.getChildElement("x",
......@@ -479,7 +479,6 @@ public class MUCRoomImpl implements MUCRoom {
continue;
}
}
occupantsPresence.setFrom(occupantsRole.getRoleAddress());
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID() && MUCRole.MODERATOR != joinRole.getRole()) {
......@@ -516,7 +515,6 @@ public class MUCRoomImpl implements MUCRoom {
"x", "http://jabber.org/protocol/muc#user");
frag.addElement("status").addAttribute("code", "201");
}
joinPresence.setFrom(joinRole.getRoleAddress());
broadcastPresence(joinPresence);
}
catch (Exception e) {
......@@ -604,10 +602,10 @@ public class MUCRoomImpl implements MUCRoom {
if (leaveRole != null) {
try {
Presence presence = (Presence) leaveRole.getPresence().createCopy();
Presence presence = leaveRole.getPresence().createCopy();
// Switch the presence to OFFLINE
presence.setType(Presence.Type.unavailable);
presence.setFrom(leaveRole.getRoleAddress());
presence.setStatus(null);
broadcastPresence(presence);
leaveRole.kick();
}
......@@ -939,9 +937,7 @@ public class MUCRoomImpl implements MUCRoom {
role.setAffiliation(newAffiliation);
role.setRole(newRole);
// Prepare a new presence to be sent to all the room occupants
Presence presence = role.getPresence().createCopy();
presence.setFrom(role.getRoleAddress());
presences.add(presence);
presences.add(role.getPresence().createCopy());
}
// Answer all the updated presences
return presences;
......@@ -963,9 +959,7 @@ public class MUCRoomImpl implements MUCRoom {
// Update the presence with the new role
role.setRole(newRole);
// Prepare a new presence to be sent to all the room occupants
Presence presence = role.getPresence().createCopy();
presence.setFrom(role.getRoleAddress());
return presence;
return role.getPresence().createCopy();
}
return null;
}
......@@ -1229,6 +1223,7 @@ public class MUCRoomImpl implements MUCRoom {
for (Presence presence : updatedPresences) {
// Set the presence as an unavailable presence
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Add the status code 321 that indicates that the user was removed because of
// an affiliation change
......
......@@ -352,7 +352,8 @@ public class MUCUserImpl implements MUCUser {
role = room.joinRoom(recipient.getResource().trim(),
password,
historyRequest,
this);
this,
packet.createCopy());
roles.put(group, role);
// If the client that created the room is non-MUC compliant then
// unlock the room thus creating an "instant" room
......@@ -423,11 +424,8 @@ public class MUCUserImpl implements MUCUser {
if (resource == null
|| role.getNickname().equalsIgnoreCase(resource)) {
// Occupant has changed his availability status
role.setPresence(packet);
Presence presence = (Presence) role.getPresence()
.createCopy();
presence.setFrom(role.getRoleAddress());
role.getChatRoom().send(presence);
role.setPresence(packet.createCopy());
role.getChatRoom().send(role.getPresence().createCopy());
}
else {
// Occupant has changed his nickname. Send two presences
......@@ -439,10 +437,10 @@ public class MUCUserImpl implements MUCUser {
}
else {
// Send "unavailable" presence for the old nickname
Presence presence = (Presence) role.getPresence().createCopy();
Presence presence = role.getPresence().createCopy();
// Switch the presence to OFFLINE
presence.setType(Presence.Type.unavailable);
presence.setFrom(role.getRoleAddress());
presence.setStatus(null);
// Add the new nickname and status 303 as properties
Element frag = presence.getChildElement("x",
"http://jabber.org/protocol/muc#user");
......@@ -452,12 +450,10 @@ public class MUCUserImpl implements MUCUser {
// Send availability presence for the new nickname
String oldNick = role.getNickname();
role.setPresence(packet);
role.setPresence(packet.createCopy());
role.changeNickname(resource);
role.getChatRoom().nicknameChanged(oldNick, resource);
presence = (Presence) role.getPresence().createCopy();
presence.setFrom(role.getRoleAddress());
role.getChatRoom().send(presence);
role.getChatRoom().send(role.getPresence().createCopy());
}
}
}
......
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