Permalink
Browse files

VYSPER-318: add option: visitors can speak in unmoderated rooms

git-svn-id: https://svn.apache.org/repos/asf/mina/vysper/trunk@1347674 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 0667d78 commit 2871ec5e30c1d689bac62294a03d3cfad77e3ea6 Bernd Fondermann committed Jun 7, 2012
@@ -64,7 +64,7 @@ public Conference(String name, MUCFeatures mucFeatures) {
}
public void initialize() {
- roomStorageProvider.initialize();
+ if (roomStorageProvider != null) roomStorageProvider.initialize();
if (occupantStorageProvider != null) occupantStorageProvider.initialize();
}
@@ -77,7 +77,9 @@ public synchronized Room createRoom(Entity jid, String name, RoomType... types)
throw new IllegalArgumentException("Room already exists with JID: " + jid);
}
- return roomStorageProvider.createRoom(mucFeatures, jid, name, types);
+ final Room room = roomStorageProvider.createRoom(mucFeatures, jid, name, types);
+ if (occupantStorageProvider != null) room.setOccupantStorageProvider(occupantStorageProvider);
+ return room;
}
public void deleteRoom(Entity jid) {
@@ -80,7 +80,9 @@ public Entity getJid() {
}
public boolean hasVoice() {
- return role == Role.Moderator || role == Role.Participant;
+ if (role == Role.Moderator || role == Role.Participant) return true;
+ if (room.isRoomType(RoomType.Unmoderated) && room.doVisitorsHaveVoice()) return true;
+ return false;
}
@Override
@@ -31,6 +31,7 @@
import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.modules.extension.xep0045_muc.storage.OccupantStorageProvider;
import org.apache.vysper.xmpp.modules.servicediscovery.management.Feature;
import org.apache.vysper.xmpp.modules.servicediscovery.management.Identity;
import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoElement;
@@ -58,6 +59,8 @@
private String password;
private boolean rewriteDuplicateNick = true;
+
+ private boolean visitorsHaveVoice = false;
private DiscussionHistory history = new DiscussionHistory();
@@ -66,7 +69,9 @@
// keep in a map to allow for quick access
private Map<Entity, Occupant> occupants = new ConcurrentHashMap<Entity, Occupant>();
- private Map<Entity, PresenceStanza> occupantsLatestPresence = new ConcurrentHashMap<Entity, PresenceStanza>();
+ private Map<Entity, PresenceStanza> occupantsLatestPresence = new ConcurrentHashMap<Entity, PresenceStanza>();
+
+ protected OccupantStorageProvider occupantStorageProvider;
public Room(Entity jid, String name, RoomType... types) {
if (jid == null) {
@@ -95,6 +100,10 @@ public Room(Entity jid, String name, RoomType... types) {
this.roomTypes = RoomType.complement(potentialTypes);
}
+ public void setOccupantStorageProvider(OccupantStorageProvider occupantStorageProvider) {
+ this.occupantStorageProvider = occupantStorageProvider;
+ }
+
public Entity getJID() {
return jid;
}
@@ -123,6 +132,14 @@ public void setMaxRoomHistoryItems(int maxItems) {
history.setMaxItems(maxItems);
}
+ public boolean doVisitorsHaveVoice() {
+ return visitorsHaveVoice;
+ }
+
+ public void setVisitorsHaveVoice(boolean visitorsHaveVoice) {
+ this.visitorsHaveVoice = visitorsHaveVoice;
+ }
+
public Occupant addOccupant(Entity occupantJid, String name) {
Affiliation affiliation = affiliations.getAffiliation(occupantJid);
@@ -144,6 +161,7 @@ public Occupant addOccupant(Entity occupantJid, String name) {
} else {
occupants.put(occupantJid, occupant);
}
+ if (occupantStorageProvider != null) occupantStorageProvider.occupantAdded(this, occupant);
return occupant;
}
@@ -191,8 +209,9 @@ public boolean isInRoom(String nick) {
}
public void removeOccupant(Entity occupantJid) {
- occupants.remove(occupantJid);
+ final Occupant removed = occupants.remove(occupantJid);
occupantsLatestPresence.remove(occupantJid);
+ if (occupantStorageProvider != null) occupantStorageProvider.occupantRemoved(this, removed);
}
public int getOccupantCount() {
@@ -19,6 +19,9 @@
*/
package org.apache.vysper.xmpp.modules.extension.xep0045_muc.storage;
+import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Occupant;
+import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Room;
+
/**
*
* @author The Apache MINA Project (dev@mina.apache.org)
@@ -29,4 +32,12 @@ public void initialize() {
// do nothing
}
+ public void occupantAdded(Room room, Occupant occupant) {
+ // do nothing
+ }
+
+ public void occupantRemoved(Room room, Occupant occupant) {
+ // do nothing
+ }
+
}
@@ -20,9 +20,14 @@
package org.apache.vysper.xmpp.modules.extension.xep0045_muc.storage;
import org.apache.vysper.storage.StorageProvider;
+import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Occupant;
+import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Room;
public interface OccupantStorageProvider extends StorageProvider {
void initialize();
+ void occupantAdded(Room room, Occupant occupant);
+
+ void occupantRemoved(Room room, Occupant occupant);
}

0 comments on commit 2871ec5

Please sign in to comment.