如何覆盖 EJabberd 的 mod_roster 模块 get_user_roster(Acc, US) 函数?
我想要一个自定义的 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.
I want to have a custom Ejabberd roster mechanism and as I test I am trying to set arbitrary data to a given user's friends list roster.
I replaced the get_user_roster function's content in the mod_roster.erl file with a hardcoded item but it still does not display in the client. I know the method is running an there are no errors.
Is there anything else I need to override? or is my code incorrect?
Any insight would be appreciated.
My code is shown below:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ejabberd.cfg 文件中查找 {mod_roster, []} 并将 mod_roster 替换为您的模块。
我们至少需要重写以下方法
Look for {mod_roster, []}, in the ejabberd.cfg file and replace mod_roster with your module.
And we need to override the following methods atleast