如何覆盖EJabberd的mod_roster模块get_user_roster(Acc,US)函数?

时间:2011-05-20 20:00:49

标签: erlang ejabberd

我希望有一个自定义的Ejabberd名册机制,因为我测试我试图将任意数据设置为给定用户的朋友列表名单。

我将mod_roster.erl文件中的get_user_roster函数的内容替换为硬编码项,但它仍未显示在客户端中。我知道方法运行没有错误。

还有什么我需要覆盖的吗?或者我的代码不正确? 任何见解都将不胜感激。

我的代码如下所示:

get_user_roster(Acc, US) ->
    ?INFO_MSG("Mod Roster get_user_roster ~p XX ~p XX ~p XX ~p",[Acc, US, roster, #roster.us]),
    #roster{us = US, jid = "test#localhost", name = "Test Name", subscription = "both", ask = "none", askmessage = "ASk Message"},
    case catch mnesia:dirty_index_read(roster, US, #roster.us) of
    Items when is_list(Items) ->
        ?INFO_MSG("Mod Roster get_user_roster items ~p",[Items]),
        FItems = lists:filter(fun(#roster{subscription = none, ask = in}) -> false; (_) -> true end, Items),
        ?INFO_MSG("Mod Roster get_user_roster fitems ~p",[FItems]),
        FItems ++ Acc;
    _ ->
        ?INFO_MSG("No Items",[]),
        Acc
    end.

1 个答案:

答案 0 :(得分:1)

在ejabberd.cfg文件中查找{mod_roster,[]},并将mod_roster替换为您的模块。

我们需要至少重写以下方法

-export([start/2, stop/1,
 process_iq/3,
 process_local_iq/3,
 get_user_roster/2,
 item_to_xml/1,
 get_versioning_feature/2,
 roster_versioning_enabled/1,
 roster_version/2]).