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));
}
}
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);
}
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);
}
Aggregations