Commit 7610bab6 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed change of role when running in a cluster. JM-1330

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10228 b35dd754-fafc-0310-a699-88a17e54d16e
parent dbffd658
......@@ -35,7 +35,7 @@ public class UpdateOccupantRequest extends MUCRoomTask {
private Element answer;
private String nickname;
private int role;
private int affiliation;
private MUCRole.Affiliation affiliation;
public UpdateOccupantRequest() {
......@@ -46,7 +46,7 @@ public class UpdateOccupantRequest extends MUCRoomTask {
super(room);
this.nickname = nickname;
this.role = newRole.ordinal();
this.affiliation = newAffiliation.ordinal();
this.affiliation = newAffiliation;
}
public String getNickname() {
......@@ -58,7 +58,11 @@ public class UpdateOccupantRequest extends MUCRoomTask {
}
public MUCRole.Affiliation getAffiliation() {
return MUCRole.Affiliation.values()[affiliation];
return affiliation;
}
public boolean isAffiliationChanged() {
return affiliation != null;
}
public Object getResult() {
......@@ -80,13 +84,18 @@ public class UpdateOccupantRequest extends MUCRoomTask {
super.writeExternal(out);
ExternalizableUtil.getInstance().writeSafeUTF(out, nickname);
ExternalizableUtil.getInstance().writeInt(out, role);
ExternalizableUtil.getInstance().writeInt(out, affiliation);
ExternalizableUtil.getInstance().writeBoolean(out, affiliation != null);
if (affiliation != null) {
ExternalizableUtil.getInstance().writeInt(out, affiliation.ordinal());
}
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
role = ExternalizableUtil.getInstance().readInt(in);
affiliation = ExternalizableUtil.getInstance().readInt(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) {
affiliation = MUCRole.Affiliation.values()[ExternalizableUtil.getInstance().readInt(in)];
}
}
}
\ No newline at end of file
......@@ -22,7 +22,10 @@ import org.jivesoftware.openfire.muc.*;
import org.jivesoftware.openfire.muc.cluster.*;
import org.jivesoftware.openfire.user.UserAlreadyExistsException;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.*;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.*;
......@@ -1175,12 +1178,28 @@ public class LocalMUCRoom implements MUCRoom {
// Try looking the role in the bare JID list
MUCRole role = occupantsByFullJID.get(jid);
if (role != null) {
// Update the presence with the new role
role.setRole(newRole);
// Notify the othe cluster nodes to update the occupant
CacheFactory.doClusterTask(new UpdateOccupant(this, role));
// Prepare a new presence to be sent to all the room occupants
return role.getPresence().createCopy();
if (role.isLocal()) {
// Update the presence with the new role
role.setRole(newRole);
// Notify the othe cluster nodes to update the occupant
CacheFactory.doClusterTask(new UpdateOccupant(this, role));
// Prepare a new presence to be sent to all the room occupants
return role.getPresence().createCopy();
}
else {
// Ask the cluster node hosting the occupant to make the changes. Note that if the change
// is not allowed a NotAllowedException will be thrown
Element element = (Element) CacheFactory.doSynchronousClusterTask(
new UpdateOccupantRequest(this, role.getNickname(), null, newRole),
role.getNodeID().toByteArray());
if (element != null) {
// Prepare a new presence to be sent to all the room occupants
return new Presence(element, true);
}
else {
throw new NotAllowedException();
}
}
}
return null;
}
......@@ -1534,7 +1553,8 @@ public class LocalMUCRoom implements MUCRoom {
}
else {
Log.error("Tried to update local occupant with info of local occupant?. Occupant nickname: " +
update.getNickname());
update.getNickname() + " new role: " + update.getRole() + " new affiliation: " +
update.getAffiliation());
}
}
else {
......@@ -1545,7 +1565,9 @@ public class LocalMUCRoom implements MUCRoom {
public Presence updateOccupant(UpdateOccupantRequest updateRequest) throws NotAllowedException {
MUCRole occupantRole = occupants.get(updateRequest.getNickname().toLowerCase());
if (occupantRole != null) {
occupantRole.setAffiliation(updateRequest.getAffiliation());
if (updateRequest.isAffiliationChanged()) {
occupantRole.setAffiliation(updateRequest.getAffiliation());
}
occupantRole.setRole(updateRequest.getRole());
// Notify the othe cluster nodes to update the occupant
CacheFactory.doClusterTask(new UpdateOccupant(this, occupantRole));
......
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