working on multi chat and a jabber implementation

cusax-fix
Emil Ivov 19 years ago
parent c1a1868fd3
commit cab5660d1a

@ -0,0 +1,118 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber;
import net.java.sip.communicator.service.protocol.*;
import org.jivesoftware.smackx.muc.*;
/**
* A Jabber implementation of the chat room member.
*
* @author Emil Ivov
*/
public class ChatRoomMemberJabberImpl
implements ChatRoomMember
{
/**
* The chat room that we are a member of.
*/
private ChatRoomJabberImpl containingRoom = null;
/**
* The role that this member has in its member room.
*/
private ChatRoomMemberRole role = null;
/**
* The jabber id of the member (will only be visible to members with
* necessary permissions)
*/
private String jabberID = null;
/**
* The nick name that this member is using inside its containing chat room.
*/
private String nickName = null;
/**
* Creates a jabber chat room member with the specified containing chat
* room parent.
* @param containingChatRoom the room that this
* <tt>ChatRoomMemberJabberImpl</tt> is a member of.
* @param nickName the nick name that the member is using to participate
* in the chat room
* @param jabberID the jabber id, if available, of the member or null
* otherwise.
* @param role the role that the member has in this room.
*/
public ChatRoomMemberJabberImpl(ChatRoomJabberImpl containingChatRoom,
String nickName,
String jabberID,
ChatRoomMemberRole role)
{
this.jabberID = jabberID;
this.nickName = nickName;
this.containingRoom = containingChatRoom;
this.role = role;
}
/**
* Returns the chat room that this member is participating in.
*
* @return the <tt>ChatRoom</tt> instance that this member belongs to.
*/
public ChatRoom getChatRoom()
{
return containingRoom;
}
/**
* Returns the contact identifier representing this contact.
*
* @return a String (contact address), uniquely representing the contact
* over the service the service being used by the associated protocol
* provider instance/
*/
public String getContactAddress()
{
return jabberID;
}
/**
* Returns the name of this member as it is known in its containing
* chatroom (aka a nickname).
*
* @return the name of this member as it is known in the containing chat
* room (aka a nickname).
*/
public String getName()
{
return nickName;
}
/**
* Returns the protocol provider instance that this member has originated
* in.
*
* @return the <tt>ProtocolProviderService</tt> instance that created
* this member and its containing cht room
*/
public ProtocolProviderService getProtocolProvider()
{
return containingRoom.getParentProvider();
}
/**
* Returns the role of this chat room member in its containing room.
*
* @return a <tt>ChatRoomMemberRole</tt> instance indicating the role
* the this member in its containing chat room.
*/
public ChatRoomMemberRole getRole()
{
return role;
}
}

@ -0,0 +1,64 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol;
/**
* This interface representes chat room participants. Instances are retrieved
* through implementations of the <tt>ChatRoom</tt> interface and offer methods
* that allow querying member properties, such as, moderation permissions,
* associated chat room and other.
*
* @author Emil Ivov
*/
public interface ChatRoomMember
{
/**
* Returns the chat room that this member is participating in.
*
* @return the <tt>ChatRoom</tt> instance that this member belongs to.
*/
public ChatRoom getChatRoom();
/**
* Returns the protocol provider instance that this member has originated
* in.
*
* @return the <tt>ProtocolProviderService</tt> instance that created this
* member and its containing cht room
*/
public ProtocolProviderService getProtocolProvider();
/**
* Returns the contact identifier representing this contact. In protocols
* like IRC this method would return the same as getName() but in others
* like Jabber, this method would return a full contact id uri.
*
* @return a String (contact address), uniquely representing the contact
* over the service the service being used by the associated protocol
* provider instance/
*/
public String getContactAddress();
/**
* Returns the name of this member as it is known in its containing
* chatroom (aka a nickname). The name returned by this method, may
* sometimes match the string returned by getContactID() which is actually
* the address of a contact in the realm of the corresponding protocol.
*
* @return the name of this member as it is known in the containing chat
* room (aka a nickname).
*/
public String getName();
/**
* Returns the role of this chat room member in its containing room.
*
* @return a <tt>ChatRoomMemberRole</tt> instance indicating the role
* the this member in its containing chat room.
*/
public ChatRoomMemberRole getRole();
}

@ -0,0 +1,183 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol;
/**
* Indicates roles that a chat room member detains in its containing chat room.
*
* @author Emil Ivov
*/
public class ChatRoomMemberRole
implements Comparable
{
/**
* A role implying the full set of chat room permissions
*/
public static final ChatRoomMemberRole OWNER
= new ChatRoomMemberRole("Owner", 70);
/**
* A role implying administrative permissions.
*/
public static final ChatRoomMemberRole ADMINISTRATOR
= new ChatRoomMemberRole("Administrator", 60);
/**
* A role implying moderator permissions.
*/
public static final ChatRoomMemberRole MODERATOR
= new ChatRoomMemberRole("Moderator", 50);
/**
* A role implying standard participant permissions.
*/
public static final ChatRoomMemberRole MEMBER
= new ChatRoomMemberRole("Member", 40);
/**
* A role implying standard participant permissions.
*/
public static final ChatRoomMemberRole GUEST
= new ChatRoomMemberRole("Guest", 30);
/**
* A role implying standard participant permissions without the right to
* send messages/speak.
*/
public static final ChatRoomMemberRole SILENT_MEMBER
= new ChatRoomMemberRole("SilentMember", 30);
/**
* A role implying an explicit ban for the user to join the room.
*/
public static final ChatRoomMemberRole OUTCAST
= new ChatRoomMemberRole("Outcast", 20);
/**
* the name of this role.
*/
private String roleName = null;
/**
* The index of a role is used to allow ordering of roles by other modules
* (like the UI) that would not necessarily "know" all possible roles.
* Higher values of the role index indicate roles with more permissions and
* lower values pertain to more restrictive roles.
*/
private int roleIndex;
/**
* Creates a role with the specified <tt>roleName</tt>. The constructor
* is protected in case protocol implementations need to add extra roles
* (this should only be done when absolutely necessary in order to assert
* smooth interoperability with the user interface).
*
* @param roleName the name of this role.
* @param roleIndex an int that would allow to compare this role to others
* according to the set of permissions that it implies.
*
* @throws java.lang.NullPointerException if roleName is null.
*/
protected ChatRoomMemberRole(String roleName, int roleIndex)
throws NullPointerException
{
if(roleName == null)
throw new NullPointerException("Role Name can't be null.");
this.roleName = roleName;
this.roleIndex = roleIndex;
}
/**
* Returns the name of this role.
*
* @return the name of this role.
*/
public String getRoleName()
{
return this.roleName;
}
/**
* Returns a localized (i18n) name role name.
*
* @return a i18n version of this role name.
*/
public String getLocalizedRoleName()
{
return this.roleName;
}
/**
* Returns a role index that can be used to allow ordering of roles by
* other modules (like the UI) that would not necessarily "know" all
* possible roles. Higher values of the role index indicate roles with
* more permissions and lower values pertain to more restrictive roles.
*
* @return an <tt>int</tt> that when compared to role indexes of other
* roles can provide an ordering for the different role instances.
*/
public int getRoleIndex()
{
return roleIndex;
}
/**
* Indicates whether some other object is "equal to" this role instance.
* <p>
* @param obj the reference object with which to compare.
* @return <code>true</code> if obj is a role instance that has the same
* name and role index as this one.
*/
public boolean equals(Object obj)
{
if( obj == null
|| !(obj instanceof ChatRoomMemberRole)
|| !((ChatRoomMemberRole)obj).getRoleName().equals(roleName)
|| ((ChatRoomMemberRole)obj).getRoleIndex() != getRoleIndex())
{
return false;
}
else
{
return true;
}
}
/**
* Returns a hash code value for the object. This method is
* supported for the benefit of hashtables such as those provided by
* <code>java.util.Hashtable</code>.
* <p>
* @return a hash code value for this object.
*/
public int hashCode()
{
return getRoleName().hashCode();
}
/**
* Compares this role's role index with that of the specified object for
* order. Returns a negative integer, zero, or a positive integer as this
* role is less than, equal to, or greater than the specified object.
*
* @param obj the object to be compared.
* @return a negative integer, zero, or a positive integer as this object
* is less than, equal to, or greater than the specified object.
*
* @throws ClassCastException if the specified object's type is not an
* instance of ChatRoomMemberRole.
*/
public int compareTo(Object obj)
throws ClassCastException
{
return new Integer(getRoleIndex())
.compareTo(new Integer(((ChatRoomMemberRole)obj).getRoleIndex()));
}
}

@ -0,0 +1,124 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol.event;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
* Dispatched to notify interested parties that a change in the status of the
* source room participant has changed. Changes may include the participant
* being kicked, banned, or granted admin permissions.
*
* @author Emil Ivov
*/
public class ChatRoomMemberEvent
extends EventObject
{
/**
* Indicates that this event was triggered as a result of the source
* participant joining the source chat room.
*/
public static final String MEMBER_JOINED = "MemberJoined";
/**
* Indicates that this event was triggered as a result of the source
* participant being "kicked" out of the chat room.
*/
public static final String MEMBER_LEFT = "MemberJoined";
/**
* Indicates that this event was triggered as a result of the source
* participant leaving the source chat room.
*/
public static final String MEMBER_KICKED = "MemberKicked";
/**
* The member that the event relates to.
*/
private ChatRoomMember sourceMember = null;
/**
* The type of this event. Values can be any of the MEMBER_XXX-ED fields.
*/
private String eventType = null;
/**
* An optional String indicating a possible reason as to why the event
* might have occurred.
*/
private String reason = null;
public ChatRoomMemberEvent(ChatRoom sourceRoom,
ChatRoomMember sourceMember,
String eventType,
String reason )
{
super(sourceRoom);
this.sourceMember = sourceMember;
this.eventType = eventType;
this.reason = reason;
}
/**
* Returns the source chat room for this event.
*
* @return the <tt>ChatRoom</tt> associated with that is the source of this
* event and that the corresponding ChatRoomMemberBelongs to.
*/
public ChatRoom getChatRoom()
{
return (ChatRoom)getSource();
}
/**
* Returns the member that this event is pertaining to.
* @return the <tt>ChatRoomMember</tt> that this event is pertaining to.
*/
public ChatRoomMember getChatRoomMember()
{
return sourceMember;
}
/**
* A reason string indicating a human readable reason for this event.
*
* @return a human readable String containing the reason for this event,
* or null if no particular reason was specified.
*/
public String getReason()
{
return reason;
}
/**
* Returns the type of this event which could be one of the MEMBER_XXX-ed
* member field values.
*
* @return one of the MEMBER_XXXed member field values indicating the type
* of this event.
*/
public String getEventType()
{
return eventType;
}
/**
* Returns a String representation of this event.
*/
public String toString()
{
return "ChatRoomMemberEvent[type="
+ getEventType()
+ " sourceRoom="
+ getChatRoom()
+ " member="
+ getChatRoomMember()
+ "]";
}
}

@ -0,0 +1,27 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol.event;
import java.util.*;
/**
* Adds a listener that will be notified of changes in the status of the chat
* participants in a particular chat room, such as us being kicked, banned, or
* granted admin permissions.
* @author Emil Ivov
*/
public interface ChatRoomMemberListener
extends EventListener
{
/**
* Called to notify interested parties that a change in the status of the
* source room participant has changed. Changes may include the participant
* being kicked, banned, or granted admin permissions.
*/
public void memberStatusChanged( ChatRoomMemberEvent evt );
}

@ -0,0 +1,23 @@
package net.java.sip.communicator.service.protocol.event;
import java.util.*;
/**
* <p> </p>
*
* <p> </p>
*
* <p> </p>
*
* <p> </p>
*
* @author Emil Ivov
*/
public class ChatRoomMemberRoleChangeEvent
extends EventObject
{
public ChatRoomMemberRoleChangeEvent(Object source)
{
super(source);
}
}
Loading…
Cancel
Save