001/**
002 *
003 * Copyright 2003-2007 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.muc;
019
020import java.util.Date;
021
022import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
023
024/**
025 * The DiscussionHistory class controls the number of characters or messages to receive
026 * when entering a room. The room will decide the amount of history to return if you don't
027 * specify a DiscussionHistory while joining a room.<p>
028 *
029 * You can use some or all of these variable to control the amount of history to receive:
030 * <ul>
031 *  <li>maxchars -&gt; total number of characters to receive in the history.
032 *  <li>maxstanzas -&gt; total number of messages to receive in the history.
033 *  <li>seconds -&gt; only the messages received in the last "X" seconds will be included in the
034 * history.
035 *  <li>since -&gt; only the messages received since the datetime specified will be included in
036 * the history.
037 * </ul>
038 *
039 * Note: Setting maxchars to 0 indicates that the user requests to receive no history.
040 *
041 * @author Gaston Dombiak
042 * @deprecated use {@link org.jivesoftware.smackx.muc.MucEnterConfiguration} instead.
043 */
044@Deprecated
045public class DiscussionHistory {
046
047    private int maxChars = -1;
048    private int maxStanzas = -1;
049    private int seconds = -1;
050    private Date since;
051
052    /**
053     * Returns the total number of characters to receive in the history.
054     *
055     * @return total number of characters to receive in the history.
056     */
057    public int getMaxChars() {
058        return maxChars;
059    }
060
061    /**
062     * Returns the total number of messages to receive in the history.
063     *
064     * @return the total number of messages to receive in the history.
065     */
066    public int getMaxStanzas() {
067        return maxStanzas;
068    }
069
070    /**
071     * Returns the number of seconds to use to filter the messages received during that time.
072     * In other words, only the messages received in the last "X" seconds will be included in
073     * the history.
074     *
075     * @return the number of seconds to use to filter the messages received during that time.
076     */
077    public int getSeconds() {
078        return seconds;
079    }
080
081    /**
082     * Returns the since date to use to filter the messages received during that time.
083     * In other words, only the messages received since the datetime specified will be
084     * included in the history.
085     *
086     * @return the since date to use to filter the messages received during that time.
087     */
088    public Date getSince() {
089        return since;
090    }
091
092    /**
093     * Sets the total number of characters to receive in the history.
094     *
095     * @param maxChars the total number of characters to receive in the history.
096     */
097    public void setMaxChars(int maxChars) {
098        this.maxChars = maxChars;
099    }
100
101    /**
102     * Sets the total number of messages to receive in the history.
103     *
104     * @param maxStanzas the total number of messages to receive in the history.
105     */
106    public void setMaxStanzas(int maxStanzas) {
107        this.maxStanzas = maxStanzas;
108    }
109
110    /**
111     * Sets the number of seconds to use to filter the messages received during that time.
112     * In other words, only the messages received in the last "X" seconds will be included in
113     * the history.
114     *
115     * @param seconds the number of seconds to use to filter the messages received during
116     * that time.
117     */
118    public void setSeconds(int seconds) {
119        this.seconds = seconds;
120    }
121
122    /**
123     * Sets the since date to use to filter the messages received during that time.
124     * In other words, only the messages received since the datetime specified will be
125     * included in the history.
126     *
127     * @param since the since date to use to filter the messages received during that time.
128     */
129    public void setSince(Date since) {
130        this.since = since;
131    }
132
133    /**
134     * Returns true if the history has been configured with some values.
135     *
136     * @return true if the history has been configured with some values.
137     */
138    private boolean isConfigured() {
139        return maxChars > -1 || maxStanzas > -1 || seconds > -1 || since != null;
140    }
141
142    /**
143     * Returns the History that manages the amount of discussion history provided on entering a
144     * room.
145     *
146     * @return the History that manages the amount of discussion history provided on entering a
147     * room.
148     */
149    MUCInitialPresence.History getMUCHistory() {
150        // Return null if the history was not properly configured
151        if (!isConfigured()) {
152            return null;
153        }
154
155        return new MUCInitialPresence.History(maxChars, maxStanzas, seconds, since);
156    }
157}