]> granicus.if.org Git - ejabberd/commitdiff
Add hooks for tracking mucsub subscriptions changes
authorPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 15 Apr 2019 10:02:43 +0000 (12:02 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 15 Apr 2019 10:03:30 +0000 (12:03 +0200)
src/mod_muc_room.erl

index cbc967da42ab8b75fb9389e954856a32b58dfec4..4b02e0939efec3087aa5443ba910472e1074dc12 100644 (file)
@@ -1688,7 +1688,8 @@ update_online_user(JID, #user{nick = Nick} = User, StateData) ->
     end,
     NewStateData.
 
-set_subscriber(JID, Nick, Nodes, StateData) ->
+set_subscriber(JID, Nick, Nodes,
+              #state{room = Room, host = Host, server_host = ServerHost} = StateData) ->
     BareJID = case JID of
                  #jid{} -> jid:remove_resource(JID);
                  _ ->
@@ -1707,7 +1708,8 @@ set_subscriber(JID, Nick, Nodes, StateData) ->
     store_room(NewStateData, [{add_subscription, BareJID, Nick, Nodes}]),
     case not maps:is_key(LBareJID, StateData#state.subscribers) of
        true ->
-           send_subscriptions_change_notifications(BareJID, Nick, subscribe, NewStateData);
+           send_subscriptions_change_notifications(BareJID, Nick, subscribe, NewStateData),
+           ejabberd_hooks:run(muc_subscribed, ServerHost, [ServerHost, Room, Host, BareJID]);
        _ ->
            ok
     end,
@@ -4056,7 +4058,7 @@ process_iq_mucsub(From, #iq{type = set, lang = Lang,
            {error, xmpp:err_forbidden(Txt, Lang)}
     end;
 process_iq_mucsub(From, #iq{type = set, sub_els = [#muc_unsubscribe{}]},
-                 StateData) ->
+                 #state{room = Room, host = Host, server_host = ServerHost} = StateData) ->
     BareJID = jid:remove_resource(From),
     LBareJID = jid:tolower(BareJID),
     try maps:get(LBareJID, StateData#state.subscribers) of
@@ -4067,6 +4069,7 @@ process_iq_mucsub(From, #iq{type = set, sub_els = [#muc_unsubscribe{}]},
                                           subscriber_nicks = Nicks},
            store_room(NewStateData, [{del_subscription, LBareJID}]),
            send_subscriptions_change_notifications(BareJID, Nick, unsubscribe, StateData),
+           ejabberd_hooks:run(muc_unsubscribed, ServerHost, [ServerHost, Room, Host, BareJID]),
            NewStateData2 = case close_room_if_temporary_and_empty(NewStateData) of
                {stop, normal, _} -> stop;
                {next_state, normal_state, SD} -> SD