aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomMemberJabberImpl.java
blob: 22916c51cf81e9ccabe10459ec37c49ce8e5983b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * Jitsi, 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 net.java.sip.communicator.service.protocol.jabber.*;

import org.jivesoftware.smack.util.*;
import org.jivesoftware.smackx.muc.*;

/**
 * A Jabber implementation of the chat room member.
 *
 * @author Emil Ivov
 */
public class ChatRoomMemberJabberImpl
    implements JabberChatRoomMember
{
    /**
     * The chat room that we are a member of.
     */
    private final ChatRoomJabberImpl containingRoom;

    /**
     * The role that this member has in its member room.
     */
    private ChatRoomMemberRole  role;

    /**
     * The jabber id of the member (will only be visible to members with
     * necessary permissions)
     */
    private final String jabberID;

    /**
     * The nick name that this member is using inside its containing chat room.
     */
    private String nickName;

    /**
     * The contact from our server stored contact list corresponding to this
     * member.
     */
    private Contact contact;

    /**
     * The avatar of this chat room member.
     */
    private byte[] avatar;

    /**
     * The <tt>ConferenceDescription</tt> published by this
     * <tt>ChatRoomMember</tt>
     */
    private ConferenceDescription conferenceDescription = 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.
     */
    public ChatRoomMemberJabberImpl(ChatRoomJabberImpl containingChatRoom,
                                    String             nickName,
                                    String             jabberID)
    {
        this.jabberID = jabberID;
        this.nickName = nickName;
        this.containingRoom = containingChatRoom;

        OperationSetPersistentPresenceJabberImpl presenceOpSet
            = (OperationSetPersistentPresenceJabberImpl) containingChatRoom
                .getParentProvider().getOperationSet(
                    OperationSetPersistentPresence.class);

        this.contact = presenceOpSet.findContactByID(
            StringUtils.parseBareAddress(jabberID));

        // If we have found a contact we set also its avatar.
        if (contact != null)
        {
            this.avatar = contact.getImage();
        }

        // just query the stack for role, if its present will be set
        getRole();
    }
    /**
     * 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 jabber id of the member.
     * @return the jabber id.
     */
    public String getJabberID()
    {
        return jabberID;
    }

    /**
     * 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 nickName;
    }

    /**
     * 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;
    }

    /**
     * Update the name of this parcipant
     * @param newNick the newNick of the participant
     */
    protected void setName(String newNick)
    {
        if ((newNick == null) || !(newNick.length() > 0))
            throw new IllegalArgumentException(
                "a room member nickname could not be null");
        nickName = newNick;
    }

    /**
     * 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()
    {
        if(role == null)
        {
            Occupant o =
                containingRoom.getMultiUserChat().getOccupant(
                    containingRoom.getIdentifier() + "/" + nickName);

            if(o == null)
            {
                return ChatRoomMemberRole.GUEST;
            }
            else
                role = ChatRoomJabberImpl.smackRoleToScRole(
                    o.getRole(), o.getAffiliation());
        }

        return role;
    }

    /**
     * Returns the current role without trying to query it in the stack.
     * Mostly used for event creating on member role change.
     *
     * @return the current role of this member.
     */
    ChatRoomMemberRole getCurrentRole()
    {
        return this.role;
    }

    /**
     * Sets the role of this member.
     * @param role the role to set
     */
    public void setRole(ChatRoomMemberRole role)
    {
        this.role = role;
    }

    /**
     * Returns the avatar of this member, that can be used when including it in
     * user interface.
     *
     * @return an avatar (e.g. user photo) of this member.
     */
     public byte[] getAvatar()
     {
         return avatar;
     }

     /**
      * Sets the avatar for this member.
      *
      * @param avatar the avatar to set.
      */
     public void setAvatar(byte[] avatar)
     {
         this.avatar = avatar;
     }

    /**
     * Returns the protocol contact corresponding to this member in our contact
     * list. The contact returned here could be used by the user interface to
     * check if this member is contained in our contact list and in function of
     * this to show additional information add additional functionality.
     *
     * @return the protocol contact corresponding to this member in our contact
     * list.
     */
     public Contact getContact()
     {
         return contact;
     }

    /**
     * Sets the given contact to this member.
     *
     * @param contact the contact to set.
     */
     public void setContact(Contact contact)
     {
         this.contact = contact;
     }
}