Commit 6761a2dc authored by csh's avatar csh

OF-742 MUC Service sends "disturbing" service messages.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13982 b35dd754-fafc-0310-a699-88a17e54d16e
parent e4b5b96f
...@@ -643,6 +643,12 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -643,6 +643,12 @@ public class LocalMUCRoom implements MUCRoom {
try { try {
// Send the presence of this new occupant to existing occupants // Send the presence of this new occupant to existing occupants
Presence joinPresence = joinRole.getPresence().createCopy(); Presence joinPresence = joinRole.getPresence().createCopy();
if (canAnyoneDiscoverJID()) {
// // XEP-0045: Example 26.
// If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
Element frag = joinPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
frag.addElement("status").addAttribute("code", "100");
}
if (isRoomNew) { if (isRoomNew) {
Element frag = joinPresence.getChildElement("x", "http://jabber.org/protocol/muc#user"); Element frag = joinPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
frag.addElement("status").addAttribute("code", "201"); frag.addElement("status").addAttribute("code", "201");
...@@ -655,30 +661,43 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -655,30 +661,43 @@ public class LocalMUCRoom implements MUCRoom {
// If the room has just been created send the "room locked until configuration is // If the room has just been created send the "room locked until configuration is
// confirmed" message // confirmed" message
if (isRoomNew) { if (isRoomNew) {
Message message = new Message(); // Nothing in XEP-0045 says, that a message must be sent upon entering a room.
message.setType(Message.Type.groupchat); // Instead, only MUC status code 201 MUST be included in the initial presence.
message.setBody(LocaleUtils.getLocalizedString("muc.new")); // Message message = new Message();
message.setFrom(role.getRoleAddress()); // message.setType(Message.Type.groupchat);
joinRole.send(message); // message.setBody(LocaleUtils.getLocalizedString("muc.new"));
// message.setFrom(role.getRoleAddress());
// joinRole.send(message);
} }
else if (isLocked()) { else if (isLocked()) {
// Warn the owner that the room is locked but it's not new // http://xmpp.org/extensions/xep-0045.html#enter-locked
Message message = new Message(); Presence presenceItemNotFound = new Presence(Presence.Type.error);
message.setType(Message.Type.groupchat); presenceItemNotFound.setError(PacketError.Condition.item_not_found);
message.setBody(LocaleUtils.getLocalizedString("muc.locked")); presenceItemNotFound.setFrom(role.getRoleAddress());
message.setFrom(role.getRoleAddress()); joinRole.send(presenceItemNotFound);
joinRole.send(message);
// // Warn the owner that the room is locked but it's not new
// Message message = new Message();
// message.setType(Message.Type.groupchat);
// message.setBody(LocaleUtils.getLocalizedString("muc.locked"));
// message.setFrom(role.getRoleAddress());
// joinRole.send(message);
} }
else if (canAnyoneDiscoverJID()) { else if (canAnyoneDiscoverJID()) {
// Warn the new occupant that the room is non-anonymous (i.e. his JID will be // Warn the new occupant that the room is non-anonymous (i.e. his JID will be
// public) // public)
Message message = new Message();
message.setType(Message.Type.groupchat); // The following warning should not be sent as message, but instead as status code 100 in presence.
message.setBody(LocaleUtils.getLocalizedString("muc.warnnonanonymous")); // XEP-0045: Example 26.
message.setFrom(role.getRoleAddress()); // If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
Element frag = message.addChildElement("x", "http://jabber.org/protocol/muc#user");
frag.addElement("status").addAttribute("code", "100"); // Message message = new Message();
joinRole.send(message); // message.setType(Message.Type.groupchat);
// message.setBody(LocaleUtils.getLocalizedString("muc.warnnonanonymous"));
// message.setFrom(role.getRoleAddress());
// Element frag = message.addChildElement("x", "http://jabber.org/protocol/muc#user");
// frag.addElement("status").addAttribute("code", "100");
// joinRole.send(message);
} }
if (historyRequest == null) { if (historyRequest == null) {
Iterator<Message> history = roomHistory.getMessageHistory(); Iterator<Message> history = roomHistory.getMessageHistory();
...@@ -2262,14 +2281,14 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -2262,14 +2281,14 @@ public class LocalMUCRoom implements MUCRoom {
return; return;
} }
setLocked(true); setLocked(true);
if (senderRole.getUserAddress() != null) { // if (senderRole.getUserAddress() != null) {
// Send to the occupant that locked the room a message saying so // // Send to the occupant that locked the room a message saying so
Message message = new Message(); // Message message = new Message();
message.setType(Message.Type.groupchat); // message.setType(Message.Type.groupchat);
message.setBody(LocaleUtils.getLocalizedString("muc.locked")); // message.setBody(LocaleUtils.getLocalizedString("muc.locked"));
message.setFrom(getRole().getRoleAddress()); // message.setFrom(getRole().getRoleAddress());
senderRole.send(message); // senderRole.send(message);
} // }
} }
public void unlock(MUCRole senderRole) throws ForbiddenException { public void unlock(MUCRole senderRole) throws ForbiddenException {
...@@ -2281,14 +2300,17 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -2281,14 +2300,17 @@ public class LocalMUCRoom implements MUCRoom {
return; return;
} }
setLocked(false); setLocked(false);
if (senderRole.getUserAddress() != null) {
// Send to the occupant that unlocked the room a message saying so // Nothing in XEP-0045 says, that a message must be sent upon unlocking a room, only this:
Message message = new Message(); // Once the service receives the completed configuration form from the initial room owner (or receives a request for an instant room), the service MUST "unlock" the room (i.e., allow other users to enter the room) and send an IQ of type "result" to the room owner.
message.setType(Message.Type.groupchat); // if (senderRole.getUserAddress() != null) {
message.setBody(LocaleUtils.getLocalizedString("muc.unlocked")); // // Send to the occupant that unlocked the room a message saying so
message.setFrom(getRole().getRoleAddress()); // Message message = new Message();
senderRole.send(message); // message.setType(Message.Type.groupchat);
} // message.setBody(LocaleUtils.getLocalizedString("muc.unlocked"));
// message.setFrom(getRole().getRoleAddress());
// senderRole.send(message);
// }
} }
private void setLocked(boolean locked) { private void setLocked(boolean locked) {
......
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