MUCRole.java 6.38 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
Matt Tucker's avatar
Matt Tucker committed
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
Matt Tucker's avatar
Matt Tucker committed
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
Matt Tucker's avatar
Matt Tucker committed
11

Matt Tucker's avatar
Matt Tucker committed
12 13
package org.jivesoftware.messenger.muc;

14 15
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
Matt Tucker's avatar
Matt Tucker committed
16
import org.xmpp.packet.Packet;
17
import org.dom4j.Element;
Matt Tucker's avatar
Matt Tucker committed
18 19 20 21 22 23 24 25 26 27

/**
 * Defines the permissions and actions that a MUCUser may use in
 * a particular room. Each MUCRole defines the relationship between
 * a MUCRoom and a MUCUser.
 * <p/>
 * MUCUsers can play different roles in different chatrooms.
 *
 * @author Gaston Dombiak
 */
Matt Tucker's avatar
Matt Tucker committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
public interface MUCRole {

    public enum Role {

        /**
         * Runs moderated discussions. Is allowed to kick users, grant and revoke voice, etc.
         */
        moderator(0),

        /**
         * A normal occupant of the room. An occupant who does not have administrative privileges; in
         * a moderated room, a participant is further defined as having voice
         */
        participant(1),

        /**
         * An occupant who does not have voice  (can't speak in the room)
         */
        visitor(2),

        /**
         * An occupant who does not permission to stay in the room (was banned)
         */
        none(3);

        private int value;

        Role(int value) {
            this.value = value;
        }

        /**
         * Returns the value for the role.
         *
         * @return the value.
         */
        public int getValue() {
            return value;
        }

        /**
         * Returns the affiliation associated with the specified value.
         *
         * @param value the value.
         * @return the associated affiliation.
         */
        public static Role valueOf(int value) {
            switch (value) {
                case 0: return moderator;
                case 1: return participant;
                case 2: return visitor;
                default: return none;
            }
        }
    }

    public enum Affiliation {

        /**
         * Owner of the room.
         */
        owner(10),

        /**
         * Administrator of the room.
         */
        admin(20),

        /**
         * A user who is on the "whitelist" for a members-only room or who is registered
         * with an open room.
         */
        member(30),

        /**
         * A user who has been banned from a room.
         */
        outcast(40),

        /**
         * A user who doesn't have an affiliation. This kind of users can register with members-only
         * rooms and may enter an open room.
         */
        none(50);

        private int value;

        Affiliation(int value) {
            this.value = value;
        }

        /**
         * Returns the value for the role.
         *
         * @return the value.
         */
        public int getValue() {
            return value;
        }

        /**
         * Returns the affiliation associated with the specified value.
         *
         * @param value the value.
         * @return the associated affiliation.
         */
        public static Affiliation valueOf(int value) {
            switch (value) {
                case 10: return owner;
                case 20: return admin;
                case 30: return member;
                case 40: return outcast;
                default: return none;
            }
        }
    }
Matt Tucker's avatar
Matt Tucker committed
144 145 146 147 148 149

    /**
     * Obtain the current presence status of a user in a chatroom.
     *
     * @return The presence of the user in the room.
     */
Matt Tucker's avatar
Matt Tucker committed
150
    public Presence getPresence();
Matt Tucker's avatar
Matt Tucker committed
151 152 153 154 155 156 157 158

    /**
     * Returns the extended presence information that includes information about roles,
     * affiliations, JIDs, etc.
     *
     * @return the extended presence information that includes information about roles,
     *         affiliations.
     */
Matt Tucker's avatar
Matt Tucker committed
159
    public Element getExtendedPresenceInformation();
Matt Tucker's avatar
Matt Tucker committed
160 161 162 163 164 165

    /**
     * Set the current presence status of a user in a chatroom.
     *
     * @param presence The presence of the user in the room.
     */
Matt Tucker's avatar
Matt Tucker committed
166
    public void setPresence(Presence presence);
Matt Tucker's avatar
Matt Tucker committed
167 168 169 170 171 172 173 174 175 176 177 178 179

    /**
     * Call this method to promote or demote a user's role in a chatroom.
     * It is common for the chatroom or other chat room members to change
     * the role of users (a moderator promoting another user to moderator
     * status for example).<p>
     * <p/>
     * Owning ChatUsers should have their membership roles updated.
     *
     * @param newRole The new role that the user will play.
     * @throws NotAllowedException   Thrown if trying to change the moderator role to an owner or
     *                               administrator.
     */
Matt Tucker's avatar
Matt Tucker committed
180
    public void setRole(Role newRole) throws NotAllowedException;
Matt Tucker's avatar
Matt Tucker committed
181 182 183 184 185 186

    /**
     * Obtain the role state of the user.
     *
     * @return The role status of this user.
     */
Matt Tucker's avatar
Matt Tucker committed
187
    public Role getRole();
Matt Tucker's avatar
Matt Tucker committed
188 189 190 191

    /**
     * Call this method to promote or demote a user's affiliation in a chatroom.
     *
Matt Tucker's avatar
Matt Tucker committed
192 193
     * @param newAffiliation the new affiliation that the user will play.
     * @throws NotAllowedException thrown if trying to ban an owner or an administrator.
Matt Tucker's avatar
Matt Tucker committed
194
     */
Matt Tucker's avatar
Matt Tucker committed
195
    public void setAffiliation(Affiliation newAffiliation) throws NotAllowedException;
Matt Tucker's avatar
Matt Tucker committed
196 197 198 199 200 201

    /**
     * Obtain the affiliation state of the user.
     *
     * @return The affiliation status of this user.
     */
Matt Tucker's avatar
Matt Tucker committed
202
    public Affiliation getAffiliation();
Matt Tucker's avatar
Matt Tucker committed
203 204 205 206 207 208

    /**
     * Obtain the nickname for the user in the chatroom.
     *
     * @return The user's nickname in the room or null if invisible.
     */
Matt Tucker's avatar
Matt Tucker committed
209
    public String getNickname();
Matt Tucker's avatar
Matt Tucker committed
210 211 212 213 214 215

    /**
     * Changes the nickname of the occupant within the room to the new nickname.
     *
     * @param nickname the new nickname of the occupant in the room.
     */
Matt Tucker's avatar
Matt Tucker committed
216
    public void changeNickname(String nickname);
Matt Tucker's avatar
Matt Tucker committed
217 218 219 220 221 222

    /**
     * Obtain the chat user that plays this role.
     *
     * @return The chatuser playing this role.
     */
Matt Tucker's avatar
Matt Tucker committed
223
    public MUCUser getChatUser();
Matt Tucker's avatar
Matt Tucker committed
224 225 226 227 228 229

    /**
     * Obtain the chat room that hosts this user's role.
     *
     * @return The chatroom hosting this role.
     */
Matt Tucker's avatar
Matt Tucker committed
230
    public MUCRoom getChatRoom();
Matt Tucker's avatar
Matt Tucker committed
231 232 233 234 235 236

    /**
     * Obtain the XMPPAddress representing this role in a room: room@server/nickname
     *
     * @return The Jabber ID that represents this role in the room.
     */
Matt Tucker's avatar
Matt Tucker committed
237 238 239 240 241 242 243 244 245
    public JID getRoleAddress();

    /**
     * Sends a packet to the user.
     *
     * @param packet The packet to send
     */
    public void send(Packet packet);
}