25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Improve get_roster command to return groups in a list instead of newlines

This commit is contained in:
Badlop 2023-09-21 12:45:27 +02:00
parent 426fd14b11
commit 739a231259

View File

@ -574,7 +574,10 @@ get_commands_spec() ->
]}} ]}}
}}}, }}},
#ejabberd_commands{name = get_roster, tags = [roster], #ejabberd_commands{name = get_roster, tags = [roster],
desc = "Get roster of a local user", desc = "Get list of contacts in a local user roster",
longdesc =
"Subscription can be: \"none\", \"from\", \"to\", \"both\". "
"Pending can be: \"in\", \"out\", \"none\".",
policy = user, policy = user,
module = ?MODULE, function = get_roster, module = ?MODULE, function = get_roster,
args = [], args = [],
@ -583,8 +586,8 @@ get_commands_spec() ->
{jid, string}, {jid, string},
{nick, string}, {nick, string},
{subscription, string}, {subscription, string},
{ask, string}, {pending, string},
{group, string} {groups, {list, {group, string}}}
]}}}}}, ]}}}}},
#ejabberd_commands{name = push_roster, tags = [roster], #ejabberd_commands{name = push_roster, tags = [roster],
desc = "Push template roster from file to a user", desc = "Push template roster from file to a user",
@ -1334,25 +1337,16 @@ get_roster(User, Server) ->
make_roster_xmlrpc(Items) make_roster_xmlrpc(Items)
end. end.
%% Note: if a contact is in several groups, the contact is returned
%% several times, each one in a different group.
make_roster_xmlrpc(Roster) -> make_roster_xmlrpc(Roster) ->
lists:foldl( lists:map(
fun(#roster_item{jid = JID, name = Nick, subscription = Sub, ask = Ask} = Item, Res) -> fun(#roster_item{jid = JID, name = Nick, subscription = Sub, ask = Ask, groups = Groups} = Item) ->
JIDS = jid:encode(JID), JIDS = jid:encode(JID),
Subs = atom_to_list(Sub), Subs = atom_to_list(Sub),
Asks = atom_to_list(Ask), Asks = atom_to_list(Ask),
Groups = case Item#roster_item.groups of {JIDS, Nick, Subs, Asks, Groups}
[] -> [<<>>];
Gs -> Gs
end,
ItemsX = [{JIDS, Nick, Subs, Asks, Group} || Group <- Groups],
ItemsX ++ Res
end, end,
[],
Roster). Roster).
%%----------------------------- %%-----------------------------
%% Push Roster from file %% Push Roster from file
%%----------------------------- %%-----------------------------