Search in sources :

Example 1 with OmemoDeviceListElement_VAxolotl

use of org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl 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)

Example 2 with OmemoDeviceListElement_VAxolotl

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

the class OmemoDeviceListVAxolotlElementTest method serializationTest.

@Test
public void serializationTest() throws Exception {
    HashSet<Integer> ids = new HashSet<>();
    ids.add(1234);
    ids.add(9876);
    OmemoDeviceListElement_VAxolotl element = new OmemoDeviceListElement_VAxolotl(ids);
    String xml = element.toXML().toString();
    XmlPullParser parser = TestUtils.getParser(xml);
    OmemoDeviceListElement_VAxolotl parsed = new OmemoDeviceListVAxolotlProvider().parse(parser);
    assertTrue("Parsed element must equal the original.", parsed.getDeviceIds().equals(element.getDeviceIds()));
    assertEquals("Generated XML must match.", "<list xmlns='eu.siacs.conversations.axolotl'>" + "<device id='1234'/>" + "<device id='9876'/>" + "</list>", xml);
}
Also used : OmemoDeviceListVAxolotlProvider(org.jivesoftware.smackx.omemo.provider.OmemoDeviceListVAxolotlProvider) OmemoDeviceListElement_VAxolotl(org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with OmemoDeviceListElement_VAxolotl

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

the class OmemoService method purgeDeviceList.

/**
 * Publish a new DeviceList with just our device in it.
 *
 * @param managerGuard authenticated OmemoManager.
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @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.
 * @throws NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
 */
public void purgeDeviceList(OmemoManager.LoggedInOmemoManager managerGuard) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException, NotALeafNodeException {
    OmemoManager omemoManager = managerGuard.get();
    OmemoDevice userDevice = omemoManager.getOwnDevice();
    OmemoDeviceListElement_VAxolotl newList = new OmemoDeviceListElement_VAxolotl(Collections.singleton(userDevice.getDeviceId()));
    // Merge list
    getOmemoStoreBackend().mergeCachedDeviceList(userDevice, userDevice.getJid(), newList);
    OmemoService.publishDeviceList(omemoManager.getConnection(), newList);
}
Also used : OmemoDeviceListElement_VAxolotl(org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl) OmemoDevice(org.jivesoftware.smackx.omemo.internal.OmemoDevice)

Aggregations

OmemoDeviceListElement_VAxolotl (org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl)3 HashSet (java.util.HashSet)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 OmemoDeviceListElement (org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement)1 OmemoCachedDeviceList (org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList)1 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)1 OmemoDeviceListVAxolotlProvider (org.jivesoftware.smackx.omemo.provider.OmemoDeviceListVAxolotlProvider)1 PubSubException (org.jivesoftware.smackx.pubsub.PubSubException)1 Test (org.junit.Test)1