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

Add mucsub event for subscribers list changes

This commit is contained in:
Paweł Chmielowski 2017-10-30 12:05:18 +01:00
parent 2aeee9eab4
commit 2b363c7aee
2 changed files with 40 additions and 2 deletions

View File

@ -25,7 +25,7 @@
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.16"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.24"}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "6c8f891"}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "3289a6b4e3f3d82e5be513524d2293c0c2b3e7fd"}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.11"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},

View File

@ -1625,6 +1625,13 @@ set_subscriber(JID, Nick, Nodes, StateData) ->
NewStateData = StateData#state{subscribers = Subscribers,
subscriber_nicks = Nicks},
store_room(NewStateData),
case not ?DICT:is_key(LBareJID, StateData#state.subscribers) of
true ->
send_subscriptions_change_notifications(jid:replace_resource(StateData#state.jid, Nick),
Nick, subscribe, NewStateData);
_ ->
ok
end,
NewStateData.
-spec add_online_user(jid(), binary(), role(), state()) -> state().
@ -3795,6 +3802,8 @@ process_iq_mucsub(From, #iq{type = set, sub_els = [#muc_unsubscribe{}]},
NewStateData = StateData#state{subscribers = Subscribers,
subscriber_nicks = Nicks},
store_room(NewStateData),
send_subscriptions_change_notifications(jid:replace_resource(StateData#state.jid, Nick),
Nick, unsubscribe, StateData),
NewStateData2 = case close_room_if_temporary_and_empty(NewStateData) of
{stop, normal, _} -> stop;
{next_state, normal_state, SD} -> SD
@ -3839,7 +3848,8 @@ get_subscription_nodes(#iq{sub_els = [#muc_subscribe{events = Nodes}]}) ->
?NS_MUCSUB_NODES_AFFILIATIONS,
?NS_MUCSUB_NODES_SUBJECT,
?NS_MUCSUB_NODES_CONFIG,
?NS_MUCSUB_NODES_PARTICIPANTS])
?NS_MUCSUB_NODES_PARTICIPANTS,
?NS_MUCSUB_NODES_SUBSCRIBERS])
end, Nodes);
get_subscription_nodes(_) ->
[].
@ -4068,6 +4078,34 @@ store_room(StateData) ->
ok
end.
-spec send_subscriptions_change_notifications(jid(), binary(), subscribe|unsubscribe, state()) -> ok.
send_subscriptions_change_notifications(From, Nick, Type, State) ->
?DICT:fold(fun(_, #subscriber{nodes = Nodes, jid = JID}, _) ->
case lists:member(?NS_MUCSUB_NODES_SUBSCRIBERS, Nodes) of
true ->
ShowJid = case (State#state.config)#config.anonymous == false orelse
get_role(JID, State) == moderator orelse
get_default_role(get_affiliation(JID, State), State) == moderator of
true -> true;
_ -> false
end,
Packet = case {Type, ShowJid} of
{subscribe, true} ->
#muc_subscribe{jid = From, nick = Nick};
{subscribe, _} ->
#muc_subscribe{nick = Nick};
{unsubscribe, true} ->
#muc_unsubscribe{jid = From, nick = Nick};
{unsubscribe, _} ->
#muc_unsubscribe{nick = Nick}
end,
NewPacket = wrap(From, JID, Packet, ?NS_MUCSUB_NODES_SUBSCRIBERS),
ejabberd_router:route(xmpp:set_from_to(NewPacket, From, JID));
false ->
ok
end
end, ok, State#state.subscribers).
-spec send_wrapped(jid(), jid(), stanza(), binary(), state()) -> ok.
send_wrapped(From, To, Packet, Node, State) ->
LTo = jid:tolower(To),