public OccupantLeftEvent(LocalMUCRoom room, MUCRole role) { super(room); this.role = role; this.nickname = role.getNickname(); this.userAddress = role.getUserAddress(); }
JID userAddress = leaveRole.getUserAddress();
public MUCRole getRole() { if (role == null) { try { // If there are multiple entries, get one with same full JID List<MUCRole> roles = getRoom().getOccupantsByNickname(nickname); for (MUCRole r : roles) { if (userAddress.equals(r.getUserAddress())) { role = r; break; } } // TODO: if no matching full JID, what to do? } catch (UserNotFoundException e) { // Ignore } } return role; }
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()); } }
@Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); ExternalizableUtil.getInstance().writeSafeUTF(out, nickname); ExternalizableUtil.getInstance().writeSerializable(out, role.getUserAddress()); }
@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); } } }
JID existingJID = occupants.get(0).getUserAddress().asBareJID(); if (!bareJID.equals(existingJID)) { Log.warn(MessageFormat.format("Conflict detected; {0} requested nickname '{1}'; already being used by {2}", bareJID, nickname, existingJID));
kickPresence(presence, senderRole.getUserAddress(), senderRole.getNickname());
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(); }
senderAddress = senderRole.getUserAddress();
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()); 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()); throw new ForbiddenException(); presences.add(room.kickOccupant(jid, senderRole.getUserAddress(), senderRole.getNickname(), item.elementTextTrim("reason")));
@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); }
List<MUCRole> occupants = occupantsByNickname.get(nickname.toLowerCase()); MUCRole occupant = occupants.size() > 0 ? occupants.get(0) : null; if (occupant != null && !occupant.getUserAddress().toBareJID().equals(bareJID.toBareJID())) { if (mucRole.getUserAddress().equals(user.getAddress())) { clientOnlyJoin = true; break;
if (!role.getUserAddress().equals(packet.getFrom())) { sendErrorPacket(packet, PacketError.Condition.conflict);
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());
delayElement.addAttribute("from", role.getUserAddress().toString()); delayInformation.addAttribute("from", role.getUserAddress().toString());
if (!role.getUserAddress().equals(packet.getFrom())) { sendErrorPacket(packet, PacketError.Condition.conflict);
@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 (destroyElement != null) { if (((MultiUserChatServiceImpl)room.getMUCService()).getMUCDelegate() != null) { if (!((MultiUserChatServiceImpl)room.getMUCService()).getMUCDelegate().destroyingRoom(room.getName(), role.getUserAddress())) {
if (!role.getUserAddress().equals(packet.getFrom())) { sendErrorPacket(packet, PacketError.Condition.conflict);