0

I am currently trying to get the occupants of a room in a custom Ejabberd module within the muc_filter_message hook, but all attempts to get the room state are timing out.

error:

2016-07-25 10:43:04.802 [error] <0.13909.0>@ejabberd_hooks:run_fold1:368 {timeout,{gen_fsm,sync_send_all_state_event,[<0.13909.0>,get_state]}}

imports + hook function (cut down)

-behaviour(gen_mod).

-include("ejabberd.hrl").
-include("logger.hrl").
-include("jlib.hrl").
-include("mod_muc_room.hrl").
-include("mod_muc.hrl").
-include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl").
-include("ejabberd_commands.hrl").

muc_message_sent(Stanza, MUCState, RoomJID, FromJID, FromNick) ->

  {_, RoomName, Host, _, _, _, _} = RoomJID,
  OccuList = get_room_occupants(RoomName, Host),
  ?INFO_MSG("muc_message_sent OccuList ~p~n", [OccuList]),
Stanza.

Code for room occupants retrieval:

get_room_occupants(Room, Host) ->
case get_room_pid(Room, Host) of
  room_not_found ->
  ?INFO_MSG("muc_message_sent get_room_occ ~p~n", [room]);
  Pid -> get_room_occupants(Pid)
end.

get_room_occupants(Pid) ->
  ?INFO_MSG("muc_message_sent get_room_pstate ~p~n", [Pid]),
  S = get_room_state(Pid),
  ?INFO_MSG("muc_message_sent get_room_state S ~p~n", [S]),
  lists:map(
    fun({_LJID, Info}) ->
      {jid:to_string(Info#user.jid),
       Info#user.nick,
       atom_to_list(Info#user.role)}
    end,
  dict:to_list(S#state.users)).

%% @doc Get the Pid of an existing MUC room, or 'room_not_found'.
get_room_pid(Name, Service) ->
  case mnesia:dirty_read(muc_online_room, {Name, Service}) of
      [] ->
        ?INFO_MSG("muc_message_sent get_room_pid ~p~n", [failed]),
        room_not_found;
      [Room] ->
        ?INFO_MSG("muc_message_sent get_room_pid ~p~n", [pid]),
          Room#muc_online_room.pid
end.


get_room_state(Room_pid) ->
  {ok, R} = gen_fsm:sync_send_all_state_event(Room_pid, get_state),
  R.

The get_room_occupants code is pulled directly from mod_muc_admin where it works fine (but I couldn't find a way to directly use the functions within that module). Been stuck on this for a while now so any ideas appreciated.

kgpmurray
  • 192
  • 2
  • 2
  • 11
  • muc_filter_message is used for getting muc message, you need to try with other hook for getting users presence in muc. – Mani Kandan Jul 26 '16 at 06:30
  • Unfortunately, I need to get the users so I can send them a push notification. Also, I can't see i hook that would provide a room roster anyway. – kgpmurray Jul 26 '16 at 10:43

0 Answers0