public void nicknameChanged(ChangeNickname changeNickname) { List<MUCRole> occupants = occupantsByNickname.get(changeNickname.getOldNick().toLowerCase()); if (occupants != null && occupants.size() > 0) { for (MUCRole occupant : occupants) { // Update the role with the new info occupant.setPresence(changeNickname.getPresence()); occupant.changeNickname(changeNickname.getNewNick()); } if (changeNickname.isOriginator()) { // Fire event that user changed his nickname MUCEventDispatcher.nicknameChanged(getRole().getRoleAddress(), occupants.get(0).getUserAddress(), changeNickname.getOldNick(), changeNickname.getNewNick()); } // Associate the existing MUCRole with the new nickname occupantsByNickname.put(changeNickname.getNewNick().toLowerCase(), occupants); // Remove the old nickname occupantsByNickname.remove(changeNickname.getOldNick().toLowerCase()); } }
JID userAddress = leaveRole.getUserAddress(); leaveRole.destroy(); String nickname = leaveRole.getNickname(); List<MUCRole> occupants = occupantsByNickname.get(nickname.toLowerCase()); if (occupants != null) { if (originator) { MUCEventDispatcher.occupantLeft(getRole().getRoleAddress(), userAddress);
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(); }
public OccupantLeftEvent(LocalMUCRoom room, MUCRole role) { super(room); this.role = role; this.nickname = role.getNickname(); this.userAddress = role.getUserAddress(); }
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(); }
if (role.isLocal()) { role.setRole(newRole); return role.getPresence().createCopy(); new UpdateOccupantRequest(this, role.getNickname(), null, newRole), role.getNodeID().toByteArray()); if (element != null) {
if (occupant.isLocal() && !occupant.isVoiceOnly()) { occupant.send(message); senderAddress = getRole().getRoleAddress(); senderAddress = senderRole.getUserAddress();
@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); }
@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 void leaveRoom(MUCRole leaveRole) { if (leaveRole.isLocal()) { Presence originalPresence = leaveRole.getPresence(); Presence presence = originalPresence.createCopy(); presence.setType(Presence.Type.unavailable); leaveRole.send(presence); if (getOccupantsByNickname(leaveRole.getNickname()).size() <= 1) {
if (!occupant.isLocal()) { continue; if (MUCRole.Role.moderator == occupant.getRole()) { frag.element("item").addAttribute("jid", jid); if (occupant.getPresence().getFrom().equals(to)) { Presence selfPresence = presence.createCopy(); Element fragSelfPresence = selfPresence.getChildElement("x", "http://jabber.org/protocol/muc#user"); occupant.send(selfPresence); } else { occupant.send(presence);
if (!role.getUserAddress().equals(packet.getFrom())) { sendErrorPacket(packet, PacketError.Condition.conflict); role.getChatRoom().leaveRoom(role); : recipient.getResource().trim()); if (resource == null || role.getNickname().equalsIgnoreCase(resource)) { role.getChatRoom().presenceUpdated(role, packet); if (role.getChatRoom().getOccupantsByBareJID(packet.getFrom().asBareJID()).size() > 1) { sendErrorPacket(packet, PacketError.Condition.not_acceptable); else if (!role.getChatRoom().canChangeNickname()) { sendErrorPacket(packet, PacketError.Condition.not_acceptable); else if (role.getChatRoom().hasOccupant(resource)) { sendErrorPacket(packet, PacketError.Condition.conflict); Presence presence = role.getPresence().createCopy(); frag.element("item").addAttribute("nick", resource); frag.addElement("status").addAttribute("code", "303"); role.getChatRoom().send(presence); String oldNick = role.getNickname(); role.getChatRoom().nicknameChanged(role, packet, oldNick, resource);
if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) { throw new ForbiddenException(); && MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) { throw new ForbiddenException(); if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) { throw new ForbiddenException(); metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin"); metaData.addAttribute("role", "moderator"); metaData.addAttribute("jid", role.getUserAddress().toString()); metaData.addAttribute("nick", role.getNickname()); metaData.addAttribute("affiliation", role.getAffiliation().toString()); if (MUCRole.Role.moderator != senderRole.getRole()) { throw new ForbiddenException(); metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin"); metaData.addAttribute("role", "participant"); metaData.addAttribute("jid", role.getUserAddress().toString()); metaData.addAttribute("nick", role.getNickname()); metaData.addAttribute("affiliation", role.getAffiliation().toString()); if (!jids.contains(role.getUserAddress())) { jids.add(role.getUserAddress());
@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(); } }
public Presence updateOccupant(UpdateOccupantRequest updateRequest) throws NotAllowedException { Presence result = null; List <MUCRole> occupants = occupantsByNickname.get(updateRequest.getNickname().toLowerCase()); if (occupants == null || occupants.size() == 0) { Log.debug("Failed to update information of local room occupant; nickname: " + updateRequest.getNickname()); } else { for (MUCRole occupant : occupants) { if (updateRequest.isAffiliationChanged()) { occupant.setAffiliation(updateRequest.getAffiliation()); } occupant.setRole(updateRequest.getRole()); // Notify the the cluster nodes to update the occupant CacheFactory.doClusterTask(new UpdateOccupant(this, occupant)); if (result == null) { result = occupant.getPresence(); } } } return result; }
throws ForbiddenException, CannotBeInvitedException { if (!isMembersOnly() || canOccupantsInvite() || MUCRole.Affiliation.admin == senderRole.getAffiliation() || MUCRole.Affiliation.owner == senderRole.getAffiliation()) { message.setFrom(role.getRoleAddress()); message.setTo(to); switch(((MultiUserChatServiceImpl)mucService).getMUCDelegate().sendingInvitation(this, to, senderRole.getUserAddress(), reason)) { case HANDLED_BY_DELEGATE: if (senderRole.getUserAddress() != null) { frag.addElement("invite").addAttribute("from", senderRole.getUserAddress().toBareJID()); frag.addAttribute("jid", role.getRoleAddress().toBareJID());
if (leaveRole.isLocal()) { removedRoles.add(leaveRole); presence.setFrom(removedRole.getRoleAddress()); removedRole.send(presence); MUCEventDispatcher.roomDestroyed(getRole().getRoleAddress());
@Override public Presence addModerator(JID jid, MUCRole senderRole) throws ForbiddenException { if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) { throw new ForbiddenException(); } // Update the presence with the new role and inform all occupants try { return changeOccupantRole(jid, MUCRole.Role.moderator); } catch (NotAllowedException e) { // We should never receive this exception....in theory return null; } }
try { role.getChatRoom().sendPrivatePacket(packet, role); if (!role.getUserAddress().equals(packet.getFrom())) { sendErrorPacket(packet, PacketError.Condition.conflict); if (query != null && "http://jabber.org/protocol/muc#owner".equals(query.getNamespaceURI())) { role.getChatRoom().getIQOwnerHandler().handleIQ(packet, role); role.getChatRoom().getIQAdminHandler().handleIQ(packet, role); if ( selfPingEnabled && toNickname.equals( role.getNickname() ) && packet.isRequest() && packet.getElement().element( QName.get( IQPingHandler.ELEMENT_NAME, IQPingHandler.NAMESPACE ) ) != null ) role.getChatRoom().sendPrivatePacket( packet, role );
@Override public Presence createPresence(Presence.Type presenceType) throws UnauthorizedException { Presence presence = new Presence(); presence.setType(presenceType); presence.setFrom(role.getRoleAddress()); return presence; }