How can I override the EJabberd mod_roster get_user_roster (Acc, US) function?

I want to have a custom Ejabberd registry mechanism, and as I test, I try to set arbitrary data to the user's friend list.

I replaced the contents of the get_user_roster function in the mod_roster.erl file with a hard-coded element, but it still does not appear on the client. I know that the method works, there are no errors.

Is there anything else I need to override? or is my code wrong? 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.
+3
source share
1 answer

Locate {mod_roster, []} in the ejabberd.cfg file and replace mod_roster with your module.

And we need to override the following atleast methods

-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]).
0
source

All Articles