aboutsummaryrefslogtreecommitdiff
path: root/src/org/jivesoftware/smackx/MultipleRecipientInfo.java
blob: 87383199a83003cad9a6e71af7b3aad4d978a1c4 (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
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
 * Copyright 2003-2006 Jive Software.
 *
 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jivesoftware.smackx;

import org.jivesoftware.smackx.packet.MultipleAddresses;

import java.util.List;

/**
 * MultipleRecipientInfo keeps information about the multiple recipients extension included
 * in a received packet. Among the information we can find the list of TO and CC addresses.
 *
 * @author Gaston Dombiak
 */
public class MultipleRecipientInfo {

    MultipleAddresses extension;

    MultipleRecipientInfo(MultipleAddresses extension) {
        this.extension = extension;
    }

    /**
     * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address}
     * that were the primary recipients of the packet.
     *
     * @return list of primary recipients of the packet.
     */
    public List<MultipleAddresses.Address> getTOAddresses() {
        return extension.getAddressesOfType(MultipleAddresses.TO);
    }

    /**
     * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address}
     * that were the secondary recipients of the packet.
     *
     * @return list of secondary recipients of the packet.
     */
    public List<MultipleAddresses.Address> getCCAddresses() {
        return extension.getAddressesOfType(MultipleAddresses.CC);
    }

    /**
     * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
     * no specific address was provided. When no specific address was provided then the reply
     * can be sent to any or all recipients. Otherwise, the user should join the specified room
     * and send the reply to the room.
     *
     * @return the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
     *         no specific address was provided.
     */
    public String getReplyRoom() {
        List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.REPLY_ROOM);
        return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid();
    }

    /**
     * Returns true if the received packet should not be replied. Use
     * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.Connection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)}
     * to send replies. 
     *
     * @return true if the received packet should not be replied.
     */
    public boolean shouldNotReply() {
        return !extension.getAddressesOfType(MultipleAddresses.NO_REPLY).isEmpty();
    }

    /**
     * Returns the address to which all replies are requested to be sent or <tt>null</tt> if
     * no specific address was provided. When no specific address was provided then the reply
     * can be sent to any or all recipients.
     *
     * @return the address to which all replies are requested to be sent or <tt>null</tt> if
     *         no specific address was provided.
     */
    public MultipleAddresses.Address getReplyAddress() {
        List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.REPLY_TO);
        return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0);
    }
}