]> granicus.if.org Git - ejabberd/commitdiff
Add mucsub event for subscribers list changes
authorPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 30 Oct 2017 11:05:18 +0000 (12:05 +0100)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 30 Oct 2017 11:34:09 +0000 (12:34 +0100)
rebar.config
src/mod_muc_room.erl

index 85f99849a1806fe64abfae20cd6088ac26d964fb..1932be6cd244230d90ea4855400e366ba972b43f 100644 (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"}}},
index 6e83a374ff0e2e8e119fc03426f5be2396abe8fe..891807209345fa9ccc47d013467d93e9e43859bf 100644 (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),