How to know if the user is online providing only the username/nick/participant but not the whole JID (Ejabberd)

StackOverflow https://stackoverflow.com/questions/14901135

Frage

I am customising module mod_muc_room and I would like to add a function that knows if the user is online but only providing the username. In the module I can find the function is_user_online:

is_user_online(JID, StateData) ->

LJID = jlib:jid_tolower(JID),

?DICT:is_key(LJID, StateData#state.users).

I understand I have to provide username, server, and resource. LJID, would be resulting to something like {"user", "myserver.com, "someid"}

I would like add a function that returns the same but providing only the "user" something like

User = "user",

is_member_online(User, StateData) ->

?DICT:is_key(User, StateData#state.users).

Can I have some advice on how to achieve this?

War es hilfreich?

Lösung

You can use this to get the list of hosts:

ejabberd_config:get_global_option(hosts)

Then use this to check if a user is online:

ejabberd_sm:get_user_resources(User, Host)

This will return an empty array if the user is offline.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top