StaleDeviceException.java

  1. /**
  2.  *
  3.  * Copyright 2018 Paul Schaub
  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.omemo.exceptions;

  18. import java.util.Date;

  19. import org.jivesoftware.smackx.omemo.internal.OmemoDevice;

  20. public class StaleDeviceException extends Exception {
  21.     private static final long serialVersionUID = 1L;

  22.     private final OmemoDevice device;
  23.     private final Date lastMessageDate;
  24.     private final Date lastDeviceIdPublication;

  25.     /**
  26.      * This exception gets thrown if a message cannot be encrypted for a device due to the device being inactive for too long (stale).
  27.      *
  28.      * @param device OmemoDevice.
  29.      * @param lastMessageDate date of the last received message from the device.
  30.      * @param lastDeviceIdPublicationDate date on which the device ID was last published via pubsub.
  31.      */
  32.     public StaleDeviceException(OmemoDevice device, Date lastMessageDate, Date lastDeviceIdPublicationDate) {
  33.         this.device = device;
  34.         this.lastMessageDate = lastMessageDate;
  35.         this.lastDeviceIdPublication = lastDeviceIdPublicationDate;
  36.     }

  37.     /**
  38.      * Return the date on which the last OMEMO message sent from the device was received.
  39.      *
  40.      * @return last messages date
  41.      */
  42.     public Date getLastMessageDate() {
  43.         return lastMessageDate;
  44.     }

  45.     /**
  46.      * Return the date of the last time the deviceId was republished after being inactive/non-existent before.
  47.      *
  48.      * @return date of last deviceId (re)publication.
  49.      */
  50.     public Date getLastDeviceIdPublicationDate() {
  51.         return lastDeviceIdPublication;
  52.     }

  53.     /**
  54.      * Return the stale OMEMO device.
  55.      *
  56.      * @return stale device
  57.      */
  58.     public OmemoDevice getDevice() {
  59.         return device;
  60.     }
  61. }