DiscussionHistory.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.muc;

  18. import java.util.Date;

  19. import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;

  20. /**
  21.  * The DiscussionHistory class controls the number of characters or messages to receive
  22.  * when entering a room. The room will decide the amount of history to return if you don't
  23.  * specify a DiscussionHistory while joining a room.<p>
  24.  *
  25.  * You can use some or all of these variable to control the amount of history to receive:
  26.  * <ul>
  27.  *  <li>maxchars -&gt; total number of characters to receive in the history.
  28.  *  <li>maxstanzas -&gt; total number of messages to receive in the history.
  29.  *  <li>seconds -&gt; only the messages received in the last "X" seconds will be included in the
  30.  * history.
  31.  *  <li>since -&gt; only the messages received since the datetime specified will be included in
  32.  * the history.
  33.  * </ul>
  34.  *
  35.  * Note: Setting maxchars to 0 indicates that the user requests to receive no history.
  36.  *
  37.  * @author Gaston Dombiak
  38.  * @deprecated use {@link org.jivesoftware.smackx.muc.MucEnterConfiguration} instead.
  39.  */
  40. @Deprecated
  41. public class DiscussionHistory {

  42.     private int maxChars = -1;
  43.     private int maxStanzas = -1;
  44.     private int seconds = -1;
  45.     private Date since;

  46.     /**
  47.      * Returns the total number of characters to receive in the history.
  48.      *
  49.      * @return total number of characters to receive in the history.
  50.      */
  51.     public int getMaxChars() {
  52.         return maxChars;
  53.     }

  54.     /**
  55.      * Returns the total number of messages to receive in the history.
  56.      *
  57.      * @return the total number of messages to receive in the history.
  58.      */
  59.     public int getMaxStanzas() {
  60.         return maxStanzas;
  61.     }

  62.     /**
  63.      * Returns the number of seconds to use to filter the messages received during that time.
  64.      * In other words, only the messages received in the last "X" seconds will be included in
  65.      * the history.
  66.      *
  67.      * @return the number of seconds to use to filter the messages received during that time.
  68.      */
  69.     public int getSeconds() {
  70.         return seconds;
  71.     }

  72.     /**
  73.      * Returns the since date to use to filter the messages received during that time.
  74.      * In other words, only the messages received since the datetime specified will be
  75.      * included in the history.
  76.      *
  77.      * @return the since date to use to filter the messages received during that time.
  78.      */
  79.     public Date getSince() {
  80.         return since;
  81.     }

  82.     /**
  83.      * Sets the total number of characters to receive in the history.
  84.      *
  85.      * @param maxChars the total number of characters to receive in the history.
  86.      */
  87.     public void setMaxChars(int maxChars) {
  88.         this.maxChars = maxChars;
  89.     }

  90.     /**
  91.      * Sets the total number of messages to receive in the history.
  92.      *
  93.      * @param maxStanzas the total number of messages to receive in the history.
  94.      */
  95.     public void setMaxStanzas(int maxStanzas) {
  96.         this.maxStanzas = maxStanzas;
  97.     }

  98.     /**
  99.      * Sets the number of seconds to use to filter the messages received during that time.
  100.      * In other words, only the messages received in the last "X" seconds will be included in
  101.      * the history.
  102.      *
  103.      * @param seconds the number of seconds to use to filter the messages received during
  104.      * that time.
  105.      */
  106.     public void setSeconds(int seconds) {
  107.         this.seconds = seconds;
  108.     }

  109.     /**
  110.      * Sets the since date to use to filter the messages received during that time.
  111.      * In other words, only the messages received since the datetime specified will be
  112.      * included in the history.
  113.      *
  114.      * @param since the since date to use to filter the messages received during that time.
  115.      */
  116.     public void setSince(Date since) {
  117.         this.since = since;
  118.     }

  119.     /**
  120.      * Returns true if the history has been configured with some values.
  121.      *
  122.      * @return true if the history has been configured with some values.
  123.      */
  124.     private boolean isConfigured() {
  125.         return maxChars > -1 || maxStanzas > -1 || seconds > -1 || since != null;
  126.     }

  127.     /**
  128.      * Returns the History that manages the amount of discussion history provided on entering a
  129.      * room.
  130.      *
  131.      * @return the History that manages the amount of discussion history provided on entering a
  132.      * room.
  133.      */
  134.     MUCInitialPresence.History getMUCHistory() {
  135.         // Return null if the history was not properly configured
  136.         if (!isConfigured()) {
  137.             return null;
  138.         }

  139.         return new MUCInitialPresence.History(maxChars, maxStanzas, seconds, since);
  140.     }
  141. }