001/**
002 *
003 * Copyright 2018 Paul Schaub
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 */
017package org.jivesoftware.smackx.omemo.exceptions;
018
019import java.util.Date;
020
021import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
022
023public class StaleDeviceException extends Exception {
024    private static final long serialVersionUID = 1L;
025
026    private final OmemoDevice device;
027    private final Date lastMessageDate;
028    private final Date lastDeviceIdPublication;
029
030    /**
031     * This exception gets thrown if a message cannot be encrypted for a device due to the device being inactive for too long (stale).
032     *
033     * @param device OmemoDevice.
034     * @param lastMessageDate date of the last received message from the device.
035     * @param lastDeviceIdPublicationDate date on which the device ID was last published via pubsub.
036     */
037    public StaleDeviceException(OmemoDevice device, Date lastMessageDate, Date lastDeviceIdPublicationDate) {
038        this.device = device;
039        this.lastMessageDate = lastMessageDate;
040        this.lastDeviceIdPublication = lastDeviceIdPublicationDate;
041    }
042
043    /**
044     * Return the date on which the last OMEMO message sent from the device was received.
045     *
046     * @return last messages date
047     */
048    public Date getLastMessageDate() {
049        return lastMessageDate;
050    }
051
052    /**
053     * Return the date of the last time the deviceId was republished after being inactive/non-existent before.
054     *
055     * @return date of last deviceId (re)publication.
056     */
057    public Date getLastDeviceIdPublicationDate() {
058        return lastDeviceIdPublication;
059    }
060
061    /**
062     * Return the stale OMEMO device.
063     *
064     * @return stale device
065     */
066    public OmemoDevice getDevice() {
067        return device;
068    }
069}