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

发布于 2024-11-08 14:08:54 字数 935 浏览 0 评论 0原文

我想要一个自定义的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘亓 2024-11-15 14:08:54

在 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]).

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

-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]).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文