missing ask option in add_rosteritem HTTP API and CLI.
It will be great if we can use ask option in add_rosteritem API.
Thanks.
Even if mod_admin_extra provides the Ask attribute to mod_roster, that module doesn't take it into account in that scenario; it only cares about JID, nickname, subscription and groups, see the function in line 440 https://github.com/processone/ejabberd/blob/master/src/mod_roster.erl#L440
Hello @badlop thanks for feedback
What I am trying to do is integrate ejabberd with nodejs API and use firebase for offline notification (when app is in background).
the friend request will go through nodejs and it will add 2 rows in DB one for sender with ask "O" and one for receiver with ask "I".
The problem is ejabberd does not see these changes until I restart it, I know the problem is ejabberd has some cache techniques, I thought if I edited the mod_admin_extra to provide new endpoint to use ask option it will be solved, but that's mean I need to edit mod_roster also.
it will be great if you guide me how to achieve that
Regarding the initial topic, it can be done with this patch, you can use it if it helps your task. However, I will not include those changes in ejabberd:
diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl
index 79b5c8d67..4aa4002ef 100644
--- a/src/mod_admin_extra.erl
+++ b/src/mod_admin_extra.erl
@@ -56,7 +56,7 @@
set_vcard/5,
% Roster
- add_rosteritem/7, delete_rosteritem/4,
+ add_rosteritem/8, delete_rosteritem/4,
get_roster/2, push_roster/3,
push_roster_all/1, push_alltoall/2,
push_roster_item/5, build_roster_item/3,
@@ -484,17 +484,18 @@ get_commands_spec() ->
#ejabberd_commands{name = add_rosteritem, tags = [roster],
desc = "Add an item to a user's roster (supports ODBC)",
- longdesc = "Group can be several groups separated by ; for example: \"g1;g2;g3\"",
+ longdesc = "Group can be several groups separated by ; for example: \"g1;g2;g3\". "
+ "Ask can be either \"undefined\" or \"subscribe\".",
module = ?MODULE, function = add_rosteritem,
args = [{localuser, binary}, {localhost, binary},
{user, binary}, {host, binary},
{nick, binary}, {group, binary},
- {subs, binary}],
+ {subs, binary}, {ask, binary}],
args_rename = [{localserver, localhost}, {server, host}],
args_example = [<<"user1">>,<<"myserver.com">>,<<"user2">>, <<"myserver.com">>,
- <<"User 2">>, <<"Friends">>, <<"both">>],
+ <<"User 2">>, <<"Friends">>, <<"both">>, <<"undefined">>],
args_desc = ["User name", "Server name", "Contact user name", "Contact server name",
- "Nickname", "Group", "Subscription"],
+ "Nickname", "Group", "Subscription", "Ask"],
result = {res, rescode}},
%%{"", "subs= none, from, to or both"},
%%{"", "example: add-roster peter localhost mike server.com MiKe Employees both"},
@@ -1241,9 +1242,9 @@ update_vcard_els(Data, ContentList, Els1) ->
%%% Roster
%%%
-add_rosteritem(LocalUser, LocalServer, User, Server, Nick, Group, Subs) ->
+add_rosteritem(LocalUser, LocalServer, User, Server, Nick, Group, Subs, Ask) ->
Jid = jid:make(LocalUser, LocalServer),
- RosterItem = build_roster_item(User, Server, {add, Nick, Subs, Group}),
+ RosterItem = build_roster_item(User, Server, {add, Nick, Subs, Group, Ask}),
case mod_roster:set_item_and_notify_clients(Jid, RosterItem, true) of
ok -> ok;
_ -> error
@@ -1350,10 +1351,13 @@ push_roster_item(LU, LS, R, U, S, Action) ->
xmpp:set_from_to(ResIQ, jid:remove_resource(LJID), LJID)).
build_roster_item(U, S, {add, Nick, Subs, Group}) ->
+ build_roster_item(U, S, {add, Nick, Subs, Group, <<"undefined">>});
+build_roster_item(U, S, {add, Nick, Subs, Group, Ask}) ->
Groups = binary:split(Group,<<";">>, [global]),
#roster_item{jid = jid:make(U, S),
name = Nick,
subscription = misc:binary_to_atom(Subs),
+ ask = misc:binary_to_atom(Ask),
groups = Groups};
build_roster_item(U, S, remove) ->
#roster_item{jid = jid:make(U, S), subscription = remove}.
diff --git a/src/mod_roster.erl b/src/mod_roster.erl
index e2d98ec13..980e12900 100644
--- a/src/mod_roster.erl
+++ b/src/mod_roster.erl
@@ -440,6 +440,7 @@ decode_item(#roster_item{subscription = remove} = Item, R, _) ->
decode_item(Item, R, Managed) ->
R#roster{jid = jid:tolower(Item#roster_item.jid),
name = Item#roster_item.name,
+ ask = Item#roster_item.ask,
subscription = case Item#roster_item.subscription of
Sub when Managed -> Sub;
_ -> R#roster.subscription
Most helpful comment
Regarding the initial topic, it can be done with this patch, you can use it if it helps your task. However, I will not include those changes in ejabberd: