aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/jabber/VolatileContactJabberImpl.java
blob: 42e3d45aa2ab0adc4ec343f6faaf6bc6107c2487 (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
/*
 * 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 org.jivesoftware.smack.util.*;

/**
 * The Jabber implementation for Volatile Contact
 * @author Damian Minkov
 */
public class VolatileContactJabberImpl
    extends ContactJabberImpl
{
    /**
     * This contact id
     */
    private String contactId = null;

    /**
     * Indicates whether the contact is private messaging contact or not.
     */
    private boolean isPrivateMessagingContact = false;

    /**
     * The display name of the contact. This property is used only for private
     * messaging contacts.
     */
    protected String displayName = null;

    /**
     * Creates an Volatile JabberContactImpl with the specified id
     * @param id String the user id/address
     * @param ssclCallback a reference to the ServerStoredContactListImpl
     * instance that created us.
     */
    VolatileContactJabberImpl(String id,
                              ServerStoredContactListJabberImpl ssclCallback)
    {
        this(id, ssclCallback, false, null);
    }

    /**
     * Creates an Volatile JabberContactImpl with the specified id
     * @param id String the user id/address
     * @param ssclCallback a reference to the ServerStoredContactListImpl
     * instance that created us.
     * @param isPrivateMessagingContact if <tt>true</tt> this should be private
     * messaging contact.
     */
    VolatileContactJabberImpl(String id,
          ServerStoredContactListJabberImpl ssclCallback,
          boolean isPrivateMessagingContact)
    {
        this(id, ssclCallback, isPrivateMessagingContact, null);
    }

    /**
     * Creates an Volatile JabberContactImpl with the specified id
     * @param id String the user id/address
     * @param ssclCallback a reference to the ServerStoredContactListImpl
     * instance that created us.
     * @param isPrivateMessagingContact if <tt>true</tt> this should be private
     * messaging contact.
     * @param displayName the display name of the contact
     */
    VolatileContactJabberImpl(String id,
          ServerStoredContactListJabberImpl ssclCallback,
          boolean isPrivateMessagingContact, String displayName)
    {
        super(null, ssclCallback, false, false);

        this.isPrivateMessagingContact = isPrivateMessagingContact;

        if(this.isPrivateMessagingContact)
        {
            this.displayName = StringUtils.parseResource(id) + " from " +
                StringUtils.parseBareAddress(id);
            this.contactId = id;
            setJid(id);
        }
        else
        {
            this.contactId = StringUtils.parseBareAddress(id);
            this.displayName = (displayName == null)? contactId : displayName;
            String resource = StringUtils.parseResource(id);
            if(resource != null)
            {
                setJid(id);
            }
        }
    }

    /**
     * Returns the Jabber Userid of this contact
     * @return the Jabber Userid of this contact
     */
    @Override
    public String getAddress()
    {
        return contactId;
    }

    /**
     * Returns a String that could be used by any user interacting modules for
     * referring to this contact. An alias is not necessarily unique but is
     * often more human readable than an address (or id).
     * @return a String that can be used for referring to this contact when
     * interacting with the user.
     */
    @Override
    public String getDisplayName()
    {
        return displayName;
    }

    /**
     * Returns a string representation of this contact, containing most of its
     * representative details.
     *
     * @return  a string representation of this contact.
     */
    @Override
    public String toString()
    {
        StringBuffer buff =  new StringBuffer("VolatileJabberContact[ id=");
        buff.append(getAddress()).append("]");

        return buff.toString();
    }

    /**
     * Determines whether or not this contact group is being stored by the
     * server. Non persistent contact groups exist for the sole purpose of
     * containing non persistent contacts.
     * @return true if the contact group is persistent and false otherwise.
     */
    @Override
    public boolean isPersistent()
    {
        return false;
    }

    /**
     * Checks if the contact is private messaging contact or not.
     *
     * @return <tt>true</tt> if this is private messaging contact and
     * <tt>false</tt> if it isn't.
     */
    public boolean isPrivateMessagingContact()
    {
        return isPrivateMessagingContact;
    }

    /**
     * Returns the real address of the contact. If the contact is not private
     * messaging contact the result will be the same as <tt>getAddress</tt>'s
     * result.
     *
     * @return the real address of the contact.
     */
    @Override
    public String getPersistableAddress()
    {
        if(!isPrivateMessagingContact)
            return getAddress();


        ChatRoomMemberJabberImpl chatRoomMember = null;
        OperationSetMultiUserChatJabberImpl mucOpSet =
            (OperationSetMultiUserChatJabberImpl)getProtocolProvider()
                .getOperationSet(OperationSetMultiUserChat.class);
        if(mucOpSet != null)
        {
            chatRoomMember = mucOpSet
                .getChatRoom(StringUtils.parseBareAddress(contactId))
                .findMemberForNickName(
                    StringUtils.parseResource(contactId));
        }
        return ((chatRoomMember == null)? null : StringUtils.parseBareAddress(
            chatRoomMember.getJabberID()));
    }

}