25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

In response with list of room subscriptions include also events (#2272)

This commit is contained in:
Badlop 2018-08-10 17:46:47 +02:00
parent dfd96b6037
commit 8f0e066135
4 changed files with 19 additions and 13 deletions

View File

@ -25,7 +25,7 @@
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.23"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.23"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.12"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.12"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.32"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.32"}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "8bf26b9e208bd0059cd8fd4e6593d88548c136cf"}}, {xmpp, ".*", {git, "https://github.com/processone/xmpp", "305e9c3"}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.15"}}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.15"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}}, {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}}, {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},

View File

@ -106,7 +106,7 @@
-callback unregister_online_user(binary(), ljid(), binary(), binary()) -> any(). -callback unregister_online_user(binary(), ljid(), binary(), binary()) -> any().
-callback count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer(). -callback count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer().
-callback get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}]. -callback get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}].
-callback get_subscribed_rooms(binary(), binary(), jid()) -> [ljid()] | []. -callback get_subscribed_rooms(binary(), binary(), jid()) -> [{ljid(), [binary()]}] | [].
%%==================================================================== %%====================================================================
%% API %% API
@ -614,8 +614,8 @@ process_mucsub(#iq{type = get, from = From, to = To,
sub_els = [#muc_subscriptions{}]} = IQ) -> sub_els = [#muc_subscriptions{}]} = IQ) ->
Host = To#jid.lserver, Host = To#jid.lserver,
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
RoomJIDs = get_subscribed_rooms(ServerHost, Host, From), Subs = get_subscribed_rooms(ServerHost, Host, From),
xmpp:make_iq_result(IQ, #muc_subscriptions{list = RoomJIDs}); xmpp:make_iq_result(IQ, #muc_subscriptions{list = Subs});
process_mucsub(#iq{lang = Lang} = IQ) -> process_mucsub(#iq{lang = Lang} = IQ) ->
Txt = <<"No module is handling this query">>, Txt = <<"No module is handling this query">>,
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)). xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
@ -745,14 +745,15 @@ get_subscribed_rooms(ServerHost, Host, From) ->
lists:flatmap( lists:flatmap(
fun({Name, _, Pid}) -> fun({Name, _, Pid}) ->
case p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of case p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of
true -> [jid:make(Name, Host)]; {true, Nodes} ->
[#muc_subscription{jid = jid:make(Name, Host), events = Nodes}];
false -> [] false -> []
end; end;
(_) -> (_) ->
[] []
end, Rooms); end, Rooms);
V -> V ->
V [#muc_subscription{jid = Jid, events = Nodes} || {Jid, Nodes} <- V]
end. end.
get_nick(ServerHost, Host, From) -> get_nick(ServerHost, Host, From) ->

View File

@ -586,7 +586,12 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName, StateData) ->
{reply, {error, get_error_text(Err)}, StateName, StateData} {reply, {error, get_error_text(Err)}, StateName, StateData}
end; end;
handle_sync_event({is_subscribed, From}, _From, StateName, StateData) -> handle_sync_event({is_subscribed, From}, _From, StateName, StateData) ->
IsSubs = ?DICT:is_key(jid:split(From), StateData#state.subscribers), IsSubs = case (?DICT):find(jid:split(From), StateData#state.subscribers) of
{ok, #subscriber{nodes = Nodes}} ->
{true, Nodes};
error ->
false
end,
{reply, IsSubs, StateName, StateData}; {reply, IsSubs, StateName, StateData};
handle_sync_event(_Event, _From, StateName, handle_sync_event(_Event, _From, StateName,
StateData) -> StateData) ->
@ -4090,11 +4095,11 @@ process_iq_mucsub(From, #iq{type = get, lang = Lang,
FAffiliation = get_affiliation(From, StateData), FAffiliation = get_affiliation(From, StateData),
FRole = get_role(From, StateData), FRole = get_role(From, StateData),
if FRole == moderator; FAffiliation == owner; FAffiliation == admin -> if FRole == moderator; FAffiliation == owner; FAffiliation == admin ->
JIDs = dict:fold( Subs = dict:fold(
fun(_, #subscriber{jid = J}, Acc) -> fun(_, #subscriber{jid = J, nodes = Nodes}, Acc) ->
[J|Acc] [#muc_subscription{jid = J, events = Nodes}|Acc]
end, [], StateData#state.subscribers), end, [], StateData#state.subscribers),
{result, #muc_subscriptions{list = JIDs}, StateData}; {result, #muc_subscriptions{list = Subs}, StateData};
true -> true ->
Txt = <<"Moderator privileges required">>, Txt = <<"Moderator privileges required">>,
{error, xmpp:err_forbidden(Txt, Lang)} {error, xmpp:err_forbidden(Txt, Lang)}

View File

@ -411,10 +411,10 @@ get_subscribed_rooms(LServer, Host, Jid) ->
JidS = jid:encode(Jid), JidS = jid:encode(Jid),
case catch ejabberd_sql:sql_query( case catch ejabberd_sql:sql_query(
LServer, LServer,
?SQL("select @(room)s from muc_room_subscribers where jid=%(JidS)s" ?SQL("select @(room)s, @(nodes)s from muc_room_subscribers where jid=%(JidS)s"
" and host=%(Host)s")) of " and host=%(Host)s")) of
{selected, Subs} -> {selected, Subs} ->
[jid:make(Room, Host, <<>>) || {Room} <- Subs]; [{jid:make(Room, Host, <<>>), ejabberd_sql:decode_term(Nodes)} || {Room, Nodes} <- Subs];
_Error -> _Error ->
[] []
end. end.