Commit f0de75f6 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/branches@10229 b35dd754-fafc-0310-a699-88a17e54d16e
parent bc4363fd
......@@ -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)];
}
}
}
......@@ -3,7 +3,7 @@
* $Revision: 3158 $
* $Date: 2005-12-04 22:55:49 -0300 (Sun, 04 Dec 2005) $
*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
......@@ -1145,6 +1145,7 @@ public class LocalMUCRoom implements MUCRoom {
// Try looking the role in the bare JID list
MUCRole role = occupantsByFullJID.get(jid);
if (role != null) {
if (role.isLocal()) {
// Update the presence with the new role
role.setRole(newRole);
// Notify the othe cluster nodes to update the occupant
......@@ -1152,6 +1153,21 @@ public class LocalMUCRoom implements MUCRoom {
// 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;
}
......@@ -1504,7 +1520,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 {
......@@ -1515,7 +1532,9 @@ public class LocalMUCRoom implements MUCRoom {
public Presence updateOccupant(UpdateOccupantRequest updateRequest) throws NotAllowedException {
MUCRole occupantRole = occupants.get(updateRequest.getNickname().toLowerCase());
if (occupantRole != null) {
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