use of org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList in project Smack by igniterealtime.
the class OmemoStore method isAvailableDeviceId.
/**
* Check, if our freshly generated deviceId is available (unique) in our deviceList.
*
* @param userDevice our current device.
* @param id deviceId to check for.
* @return true if list did not contain our id, else false
*
* @throws IOException if an I/O error occurred.
*/
boolean isAvailableDeviceId(OmemoDevice userDevice, int id) throws IOException {
LOGGER.log(Level.INFO, "Check if id " + id + " is available...");
// Lookup local cached device list
BareJid ownJid = userDevice.getJid();
OmemoCachedDeviceList cachedDeviceList;
cachedDeviceList = loadCachedDeviceList(userDevice, ownJid);
if (cachedDeviceList == null) {
cachedDeviceList = new OmemoCachedDeviceList();
}
// Does the list already contain that id?
return !cachedDeviceList.contains(id);
}
use of org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList in project Smack by igniterealtime.
the class DeviceListTest method mergeDeviceListsTest.
/**
* Test, whether deviceList updates are correctly merged into the cached device list.
* IDs in the update become active devices, active IDs that were not in the update become inactive.
* Inactive IDs that were not in the update stay inactive.
*/
@Test
public void mergeDeviceListsTest() {
OmemoCachedDeviceList cached = new OmemoCachedDeviceList();
assertNotNull(cached.getActiveDevices());
assertNotNull(cached.getInactiveDevices());
cached.getInactiveDevices().add(1);
cached.getInactiveDevices().add(2);
cached.getActiveDevices().add(3);
Set<Integer> update = new HashSet<>();
update.add(4);
update.add(1);
cached.merge(update);
assertTrue(cached.getActiveDevices().contains(1) && !cached.getActiveDevices().contains(2) && !cached.getActiveDevices().contains(3) && cached.getActiveDevices().contains(4));
assertTrue(!cached.getInactiveDevices().contains(1) && cached.getInactiveDevices().contains(2) && cached.getInactiveDevices().contains(3) && !cached.getInactiveDevices().contains(4));
assertTrue(cached.getAllDevices().size() == 4);
assertFalse(cached.contains(17));
cached.addDevice(17);
assertTrue(cached.getActiveDevices().contains(17));
assertNotNull(cached.toString());
}
Aggregations