All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.org.retep.xmpp.muc.room.EnteredRoomBroadcast Maven / Gradle / Ivy

The newest version!
/*
 * 

Copyright (c) 1998-2010, Peter T Mount
* All rights reserved.

* *

* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. *

* *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *

* *

* You should have received a copy of the GNU General Public License along * with this program. If not, see . *

* *

* GNU GENERAL PUBLIC LICENSE - CLASSPATH EXCEPTION *

* *

* Linking this library statically or dynamically with other modules * is making a combined work based on this library. Thus, the terms * and conditions of the GNU General Public License cover the whole * combination. *

* *

* As a special exception, the copyright holders of this library give * you permission to link this library with independent modules to * produce an executable, regardless of the license terms of these * independent modules, and to copy and distribute the resulting * executable under terms of your choice, provided that you also meet, * for each linked independent module, the terms and conditions of the * license of that module. *

* *

* An independent module is a module which is either not derived from or based * on this library, or a module who's classes extend those within this library * as part of the implementation of the library. *

* *

* If you modify this library, you may extend this exception to your version * of the library, but you are not obligated to do so. If you do not wish to * do so, delete this exception statement from your version. *

*/ package uk.org.retep.xmpp.muc.room; import org.jabber.protocol.muc_user.XBuilder; import uk.org.retep.util.messaging.MessageException; import uk.org.retep.xmpp.JID; import uk.org.retep.xmpp.XMPPServer; import uk.org.retep.xmpp.message.PresenceBuilder; import uk.org.retep.xmpp.logic.XMPPLogic; import uk.org.retep.xmpp.message.Presence; import uk.org.retep.xmpp.muc.MucFeature; import uk.org.retep.xmpp.muc.MucRoom; import uk.org.retep.xmpp.muc.MucRoomMember; import uk.org.retep.xmpp.muc.MucService; import uk.org.retep.xmpp.util.Role; import static uk.org.retep.xmpp.XMPPConstants.*; /** * {@link XMPPLogic} implementation created by another to generate responses * for when a user joins a chat room * * @author peter */ public class EnteredRoomBroadcast extends AbstractRoomBroadcast { private final JID chatRoomJid; private final MucRoomMember joiningMember; private final JID userJid; private final String requestedNickName; private final String nickName; public EnteredRoomBroadcast( final JID chatRoomJid, final MucRoomMember joiningMember, final JID userJid, final String requestedNickName, final String nickName ) { this.chatRoomJid = chatRoomJid; this.joiningMember = joiningMember; this.userJid = userJid; this.requestedNickName = requestedNickName; this.nickName = nickName; } @Override public XMPPLogic process( final XMPPServer server, final MucService service, final MucRoom room, final Presence presence ) throws MessageException { getLog().info( "%s entered %s", userJid, chatRoomJid ); final boolean nicknameRewritten = !requestedNickName.equals( nickName ); final boolean joiningMod = joiningMember.getRole() == Role.MODERATOR; // Cache semiAnon state final boolean roomSemiAnon = room.hasFeature( MucFeature.MUC_SEMIANONYMOUS ); final boolean roomNonAnon = room.hasFeature( MucFeature.MUC_NONANONYMOUS ); if( roomNonAnon || roomSemiAnon ) { for( MucRoomMember member : room.getMembers() ) { if( !member.equals( joiningMember ) ) { if( roomNonAnon || joiningMod ) { // Sent from members to joining user PresenceBuilder response = presence.builder(). // 7.1.3 ex19 Send broadcast to joining member of who is in the room setFrom( chatRoomJid.cloneBuilder().setResource( member.getNickname() ) ). setTo( userJid ); addMembershipItem( response, member, roomNonAnon, null ); server.send( response ); } // FIXME 7.3 on the change should the presence showing the new nick to everyone go regardless of anonimity etc? if( roomNonAnon || joiningMod || member.getRole() == Role.MODERATOR ) { // 7.1.3 ex20 send presence of joining member to all occupants // 7.1.6 but only moderators in semi-anonymous rooms PresenceBuilder response = presence.builder(). setFrom( chatRoomJid ). setTo( member.getJID() ); addMembershipItem( response, joiningMember, roomNonAnon, null ); server.send( response ); } } } } // Send the users own response last as PRESENCE_OWN_PRESENCE marks the end of the list for some clients final PresenceBuilder response = presence.respondTo(); addMembershipItem( response, joiningMember, roomNonAnon, null ); final XBuilder xb = new XBuilder().addStatus( PRESENCE_OWN_PRESENCE ); // 7.1.3 ex21 inform of nick changed if( nicknameRewritten ) { xb.addStatus( PRESENCE_NICK_CHANGED ); } // 7.1.5 non-anonymous room - warn the joining user that there's no anonymity if( room.hasFeature( MucFeature.MUC_NONANONYMOUS ) ) { xb.addStatus( PRESENCE_NOT_ANONYMOUS ); } // TODO 7.1.14 Room Logging //if( room.hasFeature( MucFeature.PUBLIC_LOG)) //{ // MucUtil.addMucUserStatus( response, PRESENCE_ROOM_PUBLIC_LOG_ARCHIVE ); //} server.send( response ); // TODO 7.1.15 Discussion History // TODO 7.1.16 Managing Discussion History // FIXME remove once implemented - http://thedailywtf.com/Articles/Tell-a-programmer.aspx // FIXME this was presence.getBuilderFactory(). but would server.getBuilderFactory() do? //MessageBuilder debug = presence.getBuilderFactory().createMessageBuilder(); //debug.setTo( presence.getFrom() ). // setFrom( presence.getTo().copyWithoutResource().setResource( // "tux" ) ). // setType( "chathistory" ). // addBody( HISTORY ); //server.send( debug ); return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy