Best way of listening of listening to someone's presence on any room



What’s the preferred way of listening to all presence on all rooms? We want to basically create a hook to where we can act on someone’s presence.



The best place for this is custom lua module in prosody, something like:


Awesome, thanks @damencho!


So I tried it, and I can’t seem to find a way to know if the user left the room. Is this possible?


If you are using prosody trunk you have events like:


Hum, it doesn’t kept my line number, so here it is:

muc_module:hook("muc-room-created", room_created, -1);
muc_module:hook("muc-occupant-joined", occupant_joined, -1);
muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
muc_module:hook("muc-room-destroyed", room_destroyed, -1);

There is also muc-occupant-leave


Thank you this works. The version of prosody that I have installed doesn’t have muc-occupant-leave, but the muc-occupant-pre-leave should be good enough.

The only thing is that when the user leaves, it doesn’t have the nick name or email in the stanza. This is fine, we’ll just have to do some lookup on the other side of the code.



You can get the occupant object and its latest presence, maybe will have it. In the PR above I’m extracting the display name on leave.


Thank you again, I was able to use the occupant.sessions table and look for name == "email" to get a unique id that we need.