python-omemo icon indicating copy to clipboard operation
python-omemo copied to clipboard

Add method to clear the device list

Open Syndace opened this issue 5 months ago • 11 comments

Context: https://github.com/Syndace/slixmpp-omemo/issues/14

Syndace avatar Aug 10 '25 13:08 Syndace

I'm creating a function for my CLI that lists the device_ids for a JID. For my bot, on the conversation side, I only see one device_id, but with my CLI, I have device_ids that I assume come from the JSON. It would be good to remove them from the JSON as well.

xylle avatar Aug 10 '25 17:08 xylle

Nope, you just have to filter inactive devices out if you don't want to list them. The DeviceInformation structure contains a field active for that.

Syndace avatar Aug 10 '25 17:08 Syndace

I created a loop to display the device values after a get_device_information I see all active devices frozenset({(‘urn:xmpp:omemo:2’, True)})

Some of them also have (‘eu.siacs.conversations.axolotl’, False), and I only have one with True, the good device_id

I understand that urn:xmpp:omemo:2 is the future, so if I search for ‘eu.siacs.conversations.axolotl’, False, it won't be sustainable. Is there an easier way to find the active ones?

xylle avatar Aug 10 '25 17:08 xylle

Ah yes, I forgot that slixmpp-omemo adds itself to the omemo:2 device list as well, so you will want to clear that device list in addition to the oldmemo one. You can use await session_manager._upload_device_list(twomemo.twomemo.NAMESPACE, []) for that.

Syndace avatar Aug 11 '25 07:08 Syndace

Thanks, it works. I remember why I didn't use _upload_device_list. My IDE didn't want to suggest it to me and complained, saying: “Access to a protected member _upload_device_list of a class.”

xylle avatar Aug 11 '25 15:08 xylle

In the public version of _upload_device_list, wouldn't it be better to give it the device_map and let it figure out how to clean up oldmemo or twomemo? That would be better for those who use this library. (At least for me ;o)) )

xylle avatar Aug 11 '25 15:08 xylle

Haha I have questions about every part of your message :D

  1. What do you mean by "public version of _upload_device_list"? I won't add public API for that, I'll add a public method to clear your device list only.
  2. What is device_map? It's not part of my code I think ^^
  3. Is calling _upload_device_list with the namespace and [] really that difficult? You literally don't have to pass anything else than what I told you. If you pass anything other than (NAMESPACE, []), then you are doing too much.

Syndace avatar Aug 11 '25 18:08 Syndace

Oooh I'm sorry it's {} not [], you need an empty dict, not a list. Maybe that's why you did more?

Syndace avatar Aug 11 '25 18:08 Syndace

1: To clear the device list, I provide a list of device_ids containing only the current device_id, to avoid subsequent error messages, rather than an empty list. 2: Sorry, device_map is part of my code. 3: Doing what you said is not difficult, but requires a slightly deeper understanding of how XMPP works. You have to choose the right namespace and provide the list of devices you want to keep. Given the level of code I'm using, the namespace is too low level. What I need is a function that allows me to either delete a list of devices or keep only one list of devices, without providing the namespace. The details of the omemo implementation remain at the slixmpp-omemo level. When we switch from oldmemo to twomemo, I will have to modify my code, whereas it would provide better abstraction if it remained at the slixmpp-omemo level.

My code :

    async def _publish_device_list(self, device_ids: List[int]) -> bool:
        try:
            sm = await self.get_session_manager()
            device_map = {did: None for did in device_ids}

            # TODO : remplacer par la methode publique quand elle existera.
            await sm._upload_device_list(oldmemo.oldmemo.NAMESPACE, device_map)
            await sm._upload_device_list(twomemo.twomemo.NAMESPACE, device_map)

            logger.info("Published device_id %s to oldmemo and cleared twomemo device list", device_ids)
            return True
        except Exception as e:
            logger.error("Failed to publish/clear device lists: %s", e)
            return False

xylle avatar Aug 12 '25 08:08 xylle

What I need is a function that allows me to either delete a list of devices or keep only one list of devices, without providing the namespace.

Well yeah, that's what this issue is open for..

Syndace avatar Aug 12 '25 08:08 Syndace

Yes, it will be nice to clear the device list :)

Neustradamus avatar Aug 29 '25 00:08 Neustradamus