Ejabberd在模块内获得空间在线占用者

时间:2016-07-25 10:11:30

标签: erlang ejabberd ejabberd-module ejabberd-hooks

我目前正在尝试在muc_filter_message挂钩内的自定义Ejabberd模块中获取房间的占用者,但是所有尝试获取房间状态都是超时的。

错误:

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]}}

导入+钩子功能(减少)

-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.

客房检索代码:

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.

get_room_occupants代码直接从mod_muc_admin中提取,在那里工作正常(但我找不到直接使用该模块中的函数的方法)。已经坚持了一段时间,所以任何想法都赞赏。

0 个答案:

没有答案