chat room support for jabber - work in progress (only committing for possible backup)

cusax-fix
Emil Ivov 19 years ago
parent d523e50b6b
commit 993f5a053e

@ -10,7 +10,11 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import org.jivesoftware.smack.*;
import net.java.sip.communicator.util.*;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.RoomInfo;
import org.jivesoftware.smack.packet.*;
/**
* A jabber implementation of the multi user chat operation set.
@ -20,6 +24,8 @@
public class OperationSetMultiUserChatJabberImpl
implements OperationSetMultiUserChat
{
private static final Logger logger
= Logger.getLogger(OperationSetMultiUserChatJabberImpl.class);
/**
* The currently valid jabber protocol provider service implementation.
@ -37,16 +43,27 @@ public class OperationSetMultiUserChatJabberImpl
*/
private Vector invitationRejectionListeners = new Vector();
/**
* A list of the rooms that are currently open by this account. (We have
* not necessarily joined these rooms).
*/
private Vector currentlyOpenChatRooms = new Vector();
/**
* Instantiates the user operation set with a currently valid instance of
* the jabber protocol provider.
* @param jImpl a currently valid instance of
* @param jabberProvider a currently valid instance of
* ProtocolProviderServiceJabberImpl.
*/
OperationSetMultiUserChatJabberImpl(
ProtocolProviderServiceJabberImpl jabberProvider)
{
this.jabberProvider = jabberProvider;
// throw new RuntimeException("implement invitation listeners");
/** @todo implement invitation listeners */
// MultiUserChat.addInvitationListener(jabberProvider.getConnection()
// , this);
}
/**
@ -63,6 +80,20 @@ public void addInvitationListener(InvitationListener listener)
}
}
/**
* Removes <tt>listener</tt> from the list of invitation listeners
* registered to receive invitation events.
*
* @param listener the invitation listener to remove.
*/
public void removeInvitationListener(InvitationListener listener)
{
synchronized(invitationListeners)
{
invitationListeners.remove(listener);
}
}
/**
* Subscribes <tt>listener</tt> so that it would receive events indicating
* rejection of a multi user chat invitation that we've sent earlier.
@ -78,7 +109,21 @@ public void addInvitationRejectionListener(
if (!invitationRejectionListeners.contains(listener))
invitationRejectionListeners.add(listener);
}
}
/**
* Removes <tt>listener</tt> from the list of invitation listeners
* registered to receive invitation rejection events.
*
* @param listener the invitation listener to remove.
*/
public void removeInvitationRejectionListener(InvitationRejectionListener
listener)
{
synchronized(invitationRejectionListeners)
{
invitationRejectionListeners.remove(listener);
}
}
/**
@ -89,16 +134,90 @@ public void addInvitationRejectionListener(
* @param roomName the name of the <tt>ChatRoom</tt> to create.
* @param roomProperties properties specifying how the room should be
* created.
*
* @throws OperationFailedException if the room couldn't be created for
* some reason (e.g. room already exists; user already joined to an
* existant room or user has no permissions to create a chat room).
* @throws OperationNotSupportedException if chat room creation is not
* supported by this server
*
* @return ChatRoom the chat room that we've just created.
*/
public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
throws OperationFailedException
throws OperationFailedException, OperationNotSupportedException
{
// return MultiUserChat.c;
return null;
if(MultiUserChat.isServiceEnabled(
getXmppConnection()
, jabberProvider.getAccountID().getUserID()))
{
throw new OperationNotSupportedException(
"Impossible to create chat rooms on server "
+ jabberProvider.getAccountID().getService()
+ " for user "
+ jabberProvider.getAccountID().getUserID());
}
//retrieve room info in order to determine whether the room actually
//exists
// RoomInfo roomInfo = null;
// try
// {
// roomInfo
// = MultiUserChat.getRoomInfo(getXmppConnection(), roomName);
// logger.error("RoomInfo=" + roomInfo.toString());
// }
// catch (XMPPException ex)
// {
// logger.error("Failed to retrieve room info.", ex);
// if(ex.getXMPPError().getCode() == 404)
// logger.warn("niama iaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
// throw new OperationFailedException("Failed to retrieve room info."
// , OperationFailedException.GENERAL_ERROR
// , ex);
// }
//
MultiUserChat muc
= new MultiUserChat(getXmppConnection(), roomName);
try
{
logger.error("MUCI=" + muc.toString());
logger.debug("muc.getRoom()=" + muc.getRoom());
logger.debug("muc.getConfigurationForm();=" +
muc.getConfigurationForm());
logger.debug("muc.getSubject();=" + muc.getSubject());
logger.debug("muc.getOwners();=" + muc.getOwners());
// muc.is
}
catch (XMPPException ex2)
{
ex2.printStackTrace(System.out);
throw new OperationFailedException("", 0, ex2);
}
try
{
try
{
muc.create("kiki");
}
catch (XMPPException ex1)
{
}
muc.join("kiki");
muc.sendMessage("created a room");
}
catch (XMPPException ex)
{
logger.error("Failed to create or join a chat room", ex);
throw new OperationFailedException(
"Failed to create or join a chat room"
, OperationFailedException.FORBIDDEN);
}
ChatRoomJabberImpl chatRoom = new ChatRoomJabberImpl(muc);
return chatRoom;
}
/**
@ -199,33 +318,16 @@ public void rejectInvitation(ChatRoomInvitation invitation)
}
/**
* Removes <tt>listener</tt> from the list of invitation listeners
* registered to receive invitation events.
*
* @param listener the invitation listener to remove.
* @todo Implement this
* net.java.sip.communicator.service.protocol.OperationSetMultiUserChat
* method
*/
public void removeInvitationListener(InvitationListener listener)
{
}
/**
* Removes <tt>listener</tt> from the list of invitation listeners
* registered to receive invitation rejection events.
* Almost all <tt>MultiUserChat</tt> methods require an xmpp connection
* param so I added this method only for the sake of utility.
*
* @param listener the invitation listener to remove.
* @todo Implement this
* net.java.sip.communicator.service.protocol.OperationSetMultiUserChat
* method
* @return the XMPPConnection currently in use by the jabber provider or
* null if jabber provider has yet to be initialized.
*/
public void removeInvitationRejectionListener(InvitationRejectionListener
listener)
{
}
public static void main(String[] args)
private XMPPConnection getXmppConnection()
{
return (jabberProvider == null)
? null
:jabberProvider.getConnection();
}
}

@ -6,11 +6,8 @@
*/
package net.java.sip.communicator.service.protocol;
import net.java.sip.communicator.service.protocol.event.ChatRoomPropertyChangeListener;
import net.java.sip.communicator.service.protocol.event.ChatRoomLocalUserStatusListener;
import net.java.sip.communicator.service.protocol.event.ChatRoomParticipantStatusListener;
import java.util.*;
import net.java.sip.communicator.service.protocol.event.*;
import java.util.*;
/**
* Represents a chat channel/room/rendez-vous point/ where multiple chat users
@ -32,7 +29,6 @@ public interface ChatRoom
* Joins this chat room with the nickname of the local user so that the
* user would start receiving events and messages for it.
*
* @param nickname the nickname to use.
* @throws OperationFailedException with the corresponding code if an error
* occurs while joining the room.
*/
@ -72,6 +68,8 @@ public void joinAs(String nickname)
* OperationFailedException with code IDENTIFICATION_CONFLICT.
*
* @param nickname the nickname to use.
* @param password a password necessary to authenticate when joining the
* room.
* @throws OperationFailedException with the corresponding code if an error
* occurs while joining the room.
*/
@ -157,7 +155,8 @@ public void setSubject(final String subject)
* method throws an OperationFailedException with the corresponding code.
*
* @param nickname the new nickname within the room.
* @throws OperationFaileEexception if the setting the new nickname changes
*
* @throws OperationFailedException if the setting the new nickname changes
* for some reason.
*/
public void setNickname(String nickname)
@ -247,6 +246,37 @@ public void removeParticipantStatusListener(
*/
public void removeMessageListener(ChatRoomMessageListener listener);
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject);
/**
* Create a Message instance for sending a simple text messages with default
* (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText);
/**
* Sends the <tt>message</tt> to the destination indicated by the
* <tt>to</tt> contact.
* @param message the <tt>Message</tt> to send.
* @throws java.lang.IllegalStateException if the underlying stack is
* not registered or initialized or if the chat room is not joined.
*/
public void sendMessage(Message message)
throws IllegalStateException;
//include - roominfo
/** @todo include room info */
}

@ -35,8 +35,8 @@ public interface OperationSetBasicInstantMessaging
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject);
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject);
/**
* Create a Message instance for sending a simple text messages with default
@ -45,7 +45,7 @@ Message createMessage(byte[] content, String contentType,
* @param messageText the string content of the message.
* @return Message the newly created message
*/
Message createMessage(String messageText);
public Message createMessage(String messageText);
/**
* Sends the <tt>message</tt> to the destination indicated by the

@ -63,11 +63,13 @@ public List getExistingChatRooms()
* @throws OperationFailedException if the room couldn't be created for some
* reason (e.g. room already exists; user already joined to an existant
* room or user has no permissions to create a chat room).
* @throws OperationNotSupportedException if chat room creation is not
* supported by this server
*
* @return the newly created <tt>ChatRoom</tt> named <tt>roomName</tt>.
*/
public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
throws OperationFailedException;
throws OperationFailedException, OperationNotSupportedException;
/**
* Returns a reference to a chatRoom named <tt>roomName</tt> or null if

Loading…
Cancel
Save