diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomMemberJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomMemberJabberImpl.java new file mode 100644 index 000000000..ada6c6ebc --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomMemberJabberImpl.java @@ -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 + * ChatRoomMemberJabberImpl 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 ChatRoom 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 ProtocolProviderService 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 ChatRoomMemberRole instance indicating the role + * the this member in its containing chat room. + */ + public ChatRoomMemberRole getRole() + { + return role; + } +} diff --git a/src/net/java/sip/communicator/service/protocol/ChatRoomMember.java b/src/net/java/sip/communicator/service/protocol/ChatRoomMember.java new file mode 100644 index 000000000..12e08c38a --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/ChatRoomMember.java @@ -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 ChatRoom 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 ChatRoom instance that this member belongs to. + */ + public ChatRoom getChatRoom(); + + /** + * Returns the protocol provider instance that this member has originated + * in. + * + * @return the ProtocolProviderService 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 ChatRoomMemberRole instance indicating the role + * the this member in its containing chat room. + */ + public ChatRoomMemberRole getRole(); +} diff --git a/src/net/java/sip/communicator/service/protocol/ChatRoomMemberRole.java b/src/net/java/sip/communicator/service/protocol/ChatRoomMemberRole.java new file mode 100644 index 000000000..01c238d71 --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/ChatRoomMemberRole.java @@ -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 roleName. 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 int 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. + *

+ * @param obj the reference object with which to compare. + * @return true 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 + * java.util.Hashtable. + *

+ * @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())); + } + +} diff --git a/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberEvent.java b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberEvent.java new file mode 100644 index 000000000..cf4ae27df --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberEvent.java @@ -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 ChatRoom 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 ChatRoomMember 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() + + "]"; + } +} diff --git a/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberListener.java b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberListener.java new file mode 100644 index 000000000..22db3d3fa --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberListener.java @@ -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 ); + +} diff --git a/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberRoleChangeEvent.java b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberRoleChangeEvent.java new file mode 100644 index 000000000..2e4e3cf11 --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/event/ChatRoomMemberRoleChangeEvent.java @@ -0,0 +1,23 @@ +package net.java.sip.communicator.service.protocol.event; + +import java.util.*; + +/** + *

+ * + *

+ * + *

+ * + *

+ * + * @author Emil Ivov + */ +public class ChatRoomMemberRoleChangeEvent + extends EventObject +{ + public ChatRoomMemberRoleChangeEvent(Object source) + { + super(source); + } +}