@Override public Collection<MUCRole> getParticipants() { List<MUCRole> participants = new ArrayList<>(); for (MUCRole role : occupantsByFullJID.values()) { if (MUCRole.Role.participant == role.getRole()) { participants.add(role); } } return participants; }
@Override public void sendPublicMessage(Message message, MUCRole senderRole) throws ForbiddenException { // Check that if the room is moderated then the sender of the message has to have voice if (isModerated() && senderRole.getRole().compareTo(MUCRole.Role.participant) > 0) { throw new ForbiddenException(); } // Send the message to all occupants message.setFrom(senderRole.getRoleAddress()); send(message); // Fire event that message was received by the room MUCEventDispatcher.messageReceived(getRole().getRoleAddress(), senderRole.getUserAddress(), senderRole.getNickname(), message); }
public OccupantAddedEvent(LocalMUCRoom room, MUCRole occupant) { super(room); presence = occupant.getPresence(); role = occupant.getRole().ordinal(); affiliation = occupant.getAffiliation().ordinal(); voiceOnly = occupant.isVoiceOnly(); roleAddress = occupant.getRoleAddress(); userAddress = occupant.getUserAddress(); nodeID = XMPPServer.getInstance().getNodeID(); }
@Override public Collection<MUCRole> getModerators() { List<MUCRole> moderators = new ArrayList<>(); for (MUCRole role : occupantsByFullJID.values()) { if (MUCRole.Role.moderator == role.getRole()) { moderators.add(role); } } return moderators; }
@Override public void changeSubject(Message packet, MUCRole role) throws ForbiddenException { if ((canOccupantsChangeSubject() && role.getRole().compareTo(MUCRole.Role.visitor) < 0) || MUCRole.Role.moderator == role.getRole()) { // Set the new subject to the room subject = packet.getSubject(); MUCPersistenceManager.updateRoomSubject(this); // Notify all the occupants that the subject has changed packet.setFrom(role.getRoleAddress()); send(packet); // Fire event signifying that the room's subject has changed. MUCEventDispatcher.roomSubjectChanged(getJID(), role.getUserAddress(), subject); // Let other cluster nodes that the room has been updated CacheFactory.doClusterTask(new RoomUpdatedEvent(this)); } else { throw new ForbiddenException(); } }
@Override public Presence addVisitor(JID jid, MUCRole senderRole) throws NotAllowedException, ForbiddenException { if (MUCRole.Role.moderator != senderRole.getRole()) { throw new ForbiddenException(); } return changeOccupantRole(jid, MUCRole.Role.visitor); }
@Override public void sendPrivatePacket(Packet packet, MUCRole senderRole) throws NotFoundException, ForbiddenException { switch (senderRole.getRole()) { // intended fall-through case none: throw new ForbiddenException(); default: case visitor: if (canSendPrivateMessage().equals( "participants" )) throw new ForbiddenException(); case participant: if (canSendPrivateMessage().equals( "moderators" )) throw new ForbiddenException(); case moderator: if (canSendPrivateMessage().equals( "none" )) throw new ForbiddenException(); } String resource = packet.getTo().getResource(); List<MUCRole> occupants = occupantsByNickname.get(resource.toLowerCase()); if (occupants == null || occupants.size() == 0) { throw new NotFoundException(); } for (MUCRole occupant : occupants) { packet.setFrom(senderRole.getRoleAddress()); occupant.send(packet); if(packet instanceof Message) { Message message = (Message) packet; MUCEventDispatcher.privateMessageRecieved(occupant.getUserAddress(), senderRole.getUserAddress(), message); } } }
@Override public Presence addParticipant(JID jid, String reason, MUCRole senderRole) throws NotAllowedException, ForbiddenException { if (MUCRole.Role.moderator != senderRole.getRole()) { throw new ForbiddenException(); } // Update the presence with the new role and inform all occupants Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.participant); if (updatedPresence != null) { Element frag = updatedPresence.getChildElement( "x", "http://jabber.org/protocol/muc#user"); // Add the reason why the user was granted voice if (reason != null && reason.trim().length() > 0) { frag.element("item").addElement("reason").setText(reason); } } return updatedPresence; }
@Override public void sendPublicMessage(Message message, MUCRole senderRole) throws ForbiddenException { // Check that if the room is moderated then the sender of the message has to have voice if (isModerated() && senderRole.getRole().compareTo(MUCRole.Role.participant) > 0) { throw new ForbiddenException(); } // Send the message to all occupants message.setFrom(senderRole.getRoleAddress()); send(message); // Fire event that message was received by the room MUCEventDispatcher.messageReceived(getRole().getRoleAddress(), senderRole.getUserAddress(), senderRole.getNickname(), message); }
public UpdateOccupant(LocalMUCRoom room, MUCRole role) { super(room); this.presence = role.getPresence(); this.nickname = role.getNickname(); this.role = role.getRole().ordinal(); this.affiliation = role.getAffiliation().ordinal(); }
public OccupantAddedEvent(LocalMUCRoom room, MUCRole occupant) { super(room); presence = occupant.getPresence(); role = occupant.getRole().ordinal(); affiliation = occupant.getAffiliation().ordinal(); voiceOnly = occupant.isVoiceOnly(); roleAddress = occupant.getRoleAddress(); userAddress = occupant.getUserAddress(); nodeID = XMPPServer.getInstance().getNodeID(); }
private Element addAffiliationToResult(String affiliation, Element parent, JID jid) { Element result = parent.addElement("item", "http://jabber.org/protocol/muc#admin"); result.addAttribute("affiliation", affiliation); result.addAttribute("jid", jid.toString()); try { List<MUCRole> roles = room.getOccupantsByBareJID(jid); MUCRole role = roles.get(0); result.addAttribute("role", role.getRole().toString()); result.addAttribute("nick", role.getNickname()); } catch (UserNotFoundException e) { // the JID is note currently an occupant } return result; } }
@Override public void changeSubject(Message packet, MUCRole role) throws ForbiddenException { if ((canOccupantsChangeSubject() && role.getRole().compareTo(MUCRole.Role.visitor) < 0) || MUCRole.Role.moderator == role.getRole()) { // Set the new subject to the room subject = packet.getSubject(); MUCPersistenceManager.updateRoomSubject(this); // Notify all the occupants that the subject has changed packet.setFrom(role.getRoleAddress()); send(packet); // Fire event signifying that the room's subject has changed. MUCEventDispatcher.roomSubjectChanged(getJID(), role.getUserAddress(), subject); // Let other cluster nodes that the room has been updated CacheFactory.doClusterTask(new RoomUpdatedEvent(this)); } else { throw new ForbiddenException(); } }
if (MUCRole.Role.moderator == occupant.getRole()) { frag.element("item").addAttribute("jid", jid);
@Override public Collection<MUCRole> getModerators() { List<MUCRole> moderators = new ArrayList<>(); for (MUCRole role : occupantsByFullJID.values()) { if (MUCRole.Role.moderator == role.getRole()) { moderators.add(role); } } return moderators; }
@Override public Collection<MUCRole> getParticipants() { List<MUCRole> participants = new ArrayList<>(); for (MUCRole role : occupantsByFullJID.values()) { if (MUCRole.Role.participant == role.getRole()) { participants.add(role); } } return participants; }
@Override public Presence addVisitor(JID jid, MUCRole senderRole) throws NotAllowedException, ForbiddenException { if (MUCRole.Role.moderator != senderRole.getRole()) { throw new ForbiddenException(); } return changeOccupantRole(jid, MUCRole.Role.visitor); }
public UpdateOccupant(LocalMUCRoom room, MUCRole role) { super(room); this.presence = role.getPresence(); this.nickname = role.getNickname(); this.role = role.getRole().ordinal(); this.affiliation = role.getAffiliation().ordinal(); }
private Element addAffiliationToResult(String affiliation, Element parent, JID jid) { Element result = parent.addElement("item", "http://jabber.org/protocol/muc#admin"); result.addAttribute("affiliation", affiliation); result.addAttribute("jid", jid.toString()); try { List<MUCRole> roles = room.getOccupantsByBareJID(jid); MUCRole role = roles.get(0); result.addAttribute("role", role.getRole().toString()); result.addAttribute("nick", role.getNickname()); } catch (UserNotFoundException e) { // the JID is note currently an occupant } return result; } }