Search in sources :

Example 1 with OmemoDeviceListElement

use of org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement in project Smack by igniterealtime.

the class OmemoService method refreshAndRepublishDeviceList.

/**
 * Refresh our own device list and publish it to the server.
 *
 * @param connection XMPPConnection
 * @param userDevice our OMEMO device
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 * @throws IOException if an I/O error occurred.
 */
private void refreshAndRepublishDeviceList(XMPPConnection connection, OmemoDevice userDevice) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException {
    // refreshOmemoDeviceList;
    OmemoDeviceListElement publishedList;
    try {
        publishedList = fetchDeviceList(connection, userDevice.getJid());
    } catch (PubSubException.NotAPubSubNodeException e) {
        // Node is not a PubSub node. This might happen on some ejabberd servers.
        publishedList = null;
    } catch (XMPPException.XMPPErrorException e) {
        if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
            // Items not found -> items do not exist
            publishedList = null;
        } else {
            // Some other error -> throw
            throw e;
        }
    }
    if (publishedList == null) {
        publishedList = new OmemoDeviceListElement_VAxolotl(Collections.<Integer>emptySet());
    }
    getOmemoStoreBackend().mergeCachedDeviceList(userDevice, userDevice.getJid(), publishedList);
    OmemoCachedDeviceList cachedList = cleanUpDeviceList(userDevice);
    // Republish our deviceId if it is missing from the published list.
    if (!publishedList.getDeviceIds().equals(cachedList.getActiveDevices())) {
        publishDeviceList(connection, new OmemoDeviceListElement_VAxolotl(cachedList));
    }
}
Also used : OmemoDeviceListElement_VAxolotl(org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl) OmemoDeviceListElement(org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement) PubSubException(org.jivesoftware.smackx.pubsub.PubSubException) XMPPException(org.jivesoftware.smack.XMPPException) OmemoCachedDeviceList(org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList)

Aggregations

XMPPException (org.jivesoftware.smack.XMPPException)1 OmemoDeviceListElement (org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement)1 OmemoDeviceListElement_VAxolotl (org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl)1 OmemoCachedDeviceList (org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList)1 PubSubException (org.jivesoftware.smackx.pubsub.PubSubException)1