001/**
002 *
003 * Copyright 2003-2006 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smackx.address;
019
020import org.jivesoftware.smackx.address.packet.MultipleAddresses;
021import org.jxmpp.jid.Jid;
022
023import java.util.List;
024
025/**
026 * MultipleRecipientInfo keeps information about the multiple recipients extension included
027 * in a received packet. Among the information we can find the list of TO and CC addresses.
028 *
029 * @author Gaston Dombiak
030 */
031public class MultipleRecipientInfo {
032
033    MultipleAddresses extension;
034
035    MultipleRecipientInfo(MultipleAddresses extension) {
036        this.extension = extension;
037    }
038
039    /**
040     * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address}
041     * that were the primary recipients of the packet.
042     *
043     * @return list of primary recipients of the packet.
044     */
045    public List<MultipleAddresses.Address> getTOAddresses() {
046        return extension.getAddressesOfType(MultipleAddresses.Type.to);
047    }
048
049    /**
050     * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address}
051     * that were the secondary recipients of the packet.
052     *
053     * @return list of secondary recipients of the packet.
054     */
055    public List<MultipleAddresses.Address> getCCAddresses() {
056        return extension.getAddressesOfType(MultipleAddresses.Type.cc);
057    }
058
059    /**
060     * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
061     * no specific address was provided. When no specific address was provided then the reply
062     * can be sent to any or all recipients. Otherwise, the user should join the specified room
063     * and send the reply to the room.
064     *
065     * @return the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
066     *         no specific address was provided.
067     */
068    // TODO should return EntityBareJid
069    public Jid getReplyRoom() {
070        List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.Type.replyroom);
071        return replyRoom.isEmpty() ? null : replyRoom.get(0).getJid();
072    }
073
074    /**
075     * Returns true if the received stanza(/packet) should not be replied. Use
076     * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.XMPPConnection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)}
077     * to send replies. 
078     *
079     * @return true if the received stanza(/packet) should not be replied.
080     */
081    public boolean shouldNotReply() {
082        return !extension.getAddressesOfType(MultipleAddresses.Type.noreply).isEmpty();
083    }
084
085    /**
086     * Returns the address to which all replies are requested to be sent or <tt>null</tt> if
087     * no specific address was provided. When no specific address was provided then the reply
088     * can be sent to any or all recipients.
089     *
090     * @return the address to which all replies are requested to be sent or <tt>null</tt> if
091     *         no specific address was provided.
092     */
093    public MultipleAddresses.Address getReplyAddress() {
094        List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.Type.replyto);
095        return replyTo.isEmpty() ? null : replyTo.get(0);
096    }
097}