diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be955f..0cf2df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed +- Attempt to fix a storage data inconsistency where namespace support is stored for a device but activity information is not + ## [1.0.3] - 9th of July, 2024 ### Changed diff --git a/omemo/session_manager.py b/omemo/session_manager.py index dfc68fd..37da924 100644 --- a/omemo/session_manager.py +++ b/omemo/session_manager.py @@ -438,18 +438,18 @@ async def create( f" {loaded_namespaces} vs. {active_namespaces} (now vs. previous run)" ) - # Store the updated list of loaded namespaces - await storage.store( - f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/namespaces", - list(loaded_namespaces) - ) - # Set the device active for all loaded namespaces await storage.store( f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/active", { namespace: True for namespace in loaded_namespaces } ) + # Store the updated list of loaded namespaces + await storage.store( + f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/namespaces", + list(loaded_namespaces) + ) + # Take care of the initialization of newly added backends for backend in self.__backends: if backend.namespace not in active_namespaces: @@ -539,13 +539,13 @@ async def purge_backend(self, namespace: str) -> None: device = device._replace(active=frozenset(active.items())) await self.__storage.store( - f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/namespaces", - list(device.namespaces) + f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/active", + dict(device.active) ) await self.__storage.store( - f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/active", - dict(device.active) + f"/devices/{self.__own_bare_jid}/{self.__own_device_id}/namespaces", + list(device.namespaces) ) # If the backend is currently loaded, remove it from the list of loaded backends @@ -1046,9 +1046,9 @@ async def update_device_list( # Add new device information entries for new devices for device_id in new_devices: - await storage.store(f"/devices/{bare_jid}/{device_id}/namespaces", [ namespace ]) await storage.store(f"/devices/{bare_jid}/{device_id}/active", { namespace: True }) await storage.store(f"/devices/{bare_jid}/{device_id}/label", device_list[device_id]) + await storage.store(f"/devices/{bare_jid}/{device_id}/namespaces", [ namespace ]) # Update namespaces, label and status for previously known devices for device_id in old_device_list: @@ -1060,11 +1060,6 @@ async def update_device_list( active = (await storage.load_dict(f"/devices/{bare_jid}/{device_id}/active", bool)).from_just() if device_id in device_list: - # Add the namespace if required - if namespace not in namespaces: - namespaces.add(namespace) - await storage.store(f"/devices/{bare_jid}/{device_id}/namespaces", list(namespaces)) - # Update the status if required if namespace not in active or active[namespace] is False: active[namespace] = True @@ -1081,6 +1076,11 @@ async def update_device_list( # doesn't support labels". if device_list[device_id] is not None and device_list[device_id] != label: await storage.store(f"/devices/{bare_jid}/{device_id}/label", device_list[device_id]) + + # Add the namespace if required + if namespace not in namespaces: + namespaces.add(namespace) + await storage.store(f"/devices/{bare_jid}/{device_id}/namespaces", list(namespaces)) else: # Update the status if required if namespace in namespaces: @@ -1386,7 +1386,7 @@ async def __get_device_information( bundle_cache: Set[Bundle] = set() for device_id in device_list: - namespaces = frozenset((await storage.load_list( + namespaces = set((await storage.load_list( f"/devices/{bare_jid}/{device_id}/namespaces", str )).from_just()) @@ -1451,8 +1451,17 @@ async def __get_device_information( str )).maybe(self.__undecided_trust_level_name) + if any(namespace not in active for namespace in namespaces): + logging.getLogger(SessionManager.LOG_TAG).warning( + f"Inconsistent device information loaded from storage: allegedly supported namespaces are" + f" {namespaces}, but activity information is only available for {set(active.keys())}." + f" Removing the namespaces with missing activity information from storage." + ) + namespaces = namespaces & set(active.keys()) + await storage.store(f"/devices/{bare_jid}/{device_id}/namespaces", list(namespaces)) + devices.add(DeviceInformation( - namespaces=namespaces, + namespaces=frozenset(namespaces), active=frozenset(active.items()), bare_jid=bare_jid, device_id=device_id,