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

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

/*
 * 

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.ItemBuilder; import org.jabber.protocol.muc_user.StatusBuilder; 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.AbstractXMPPLogic; import uk.org.retep.xmpp.logic.XMPPLogic; import uk.org.retep.xmpp.message.Presence; 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.*; /** * * @author peter */ public class RoomLeaveBroadcast extends AbstractXMPPLogic { private final JID jidInRoom; private final MucRoomMember leavingMember; public RoomLeaveBroadcast( final JID jidInRoom, final MucRoomMember leavingMember ) { this.jidInRoom = jidInRoom; this.leavingMember = leavingMember; } @Override public XMPPLogic process( final XMPPServer server, final MucService service, final MucRoom room, final Presence presence ) throws MessageException { // Send response to the user leaving PresenceBuilder response = createResponse( jidInRoom, presence, leavingMember ); response.setTo( presence.getFrom() ); // For the user leaving we need an additional status createX( response, leavingMember ). addStatus( new StatusBuilder().setCode( PRESENCE_OWN_PRESENCE ) ); server.send( response ); // send to all remaining users, use one builder to save memory response = createResponse( jidInRoom, presence, leavingMember ); createX( response, leavingMember ); // TODO add XEP-0033 support here, so either this or a single stanza if 0033 is available for( JID to : room.getMemberJids() ) { server.send( response.setTo( to ) ); } return null; } protected PresenceBuilder createResponse( final JID jidInRoom, final Presence presence, final MucRoomMember leavingMember ) throws MessageException { final PresenceBuilder response = presence.builder(); response.setFrom( jidInRoom ). setType( UNAVAILABLE ). // This actually enables custom exit messages as per ex40 add( presence.getContent() ); // XEP-0172 Persistent Nickname support // FIXME: What to do if the user provides a nick in the leave and we // then add the existing one, there will be 2 here // XEP-0172 persistent Nickname support final String persistentNickname = leavingMember.getPersistentNickname(); if( persistentNickname != null ) { // FIXME ??? why didn't I write what this FIXME was for? response.add( persistentNickname ); } return response; } protected XBuilder createX( final PresenceBuilder response, final MucRoomMember member ) { final XBuilder x = new XBuilder(); x.setItem( new ItemBuilder().// setAffiliation( member.getAffiliation().cloneBuilder() ). setRole( Role.NONE.cloneBuilder() ) ); response.add( x ); return x; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy