]> granicus.if.org Git - ejabberd/commitdiff
Send notifications on MUC configuration changes
authorHolger Weiss <holger@zedat.fu-berlin.de>
Wed, 1 Jul 2015 22:36:16 +0000 (00:36 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Wed, 1 Jul 2015 22:36:16 +0000 (00:36 +0200)
Notify clients when the room configuration changes, as mandated by
XEP-0045, #10.2.1.

Closes #623.

src/mod_muc_room.erl
test/ejabberd_SUITE.erl

index ff2ab5653059c6e662ff3004f08bd7f6d059ed53..7b4cfbf6dafe2c8bfe867bb8d4941370d18fd778 100644 (file)
@@ -3732,6 +3732,7 @@ set_xoption([_ | _Opts], _Config) ->
     {error, ?ERR_BAD_REQUEST}.
 
 change_config(Config, StateData) ->
+    send_config_change_info(Config, StateData),
     NSD = StateData#state{config = Config},
     case {(StateData#state.config)#config.persistent,
          Config#config.persistent}
@@ -3752,6 +3753,39 @@ change_config(Config, StateData) ->
       _ -> {result, [], NSD}
     end.
 
+send_config_change_info(Config, #state{config = Config}) -> ok;
+send_config_change_info(New, #state{config = Old} = StateData) ->
+    Codes = case {Old#config.logging, New#config.logging} of
+             {false, true} -> [<<"170">>];
+             {true, false} -> [<<"171">>];
+             _ -> []
+           end
+             ++
+             case {Old#config.anonymous, New#config.anonymous} of
+               {true, false} -> [<<"172">>];
+               {false, true} -> [<<"173">>];
+               _ -> []
+             end
+               ++
+               case Old#config{anonymous = New#config.anonymous,
+                               logging = New#config.logging} of
+                 New -> [];
+                 _ -> [<<"104">>]
+               end,
+    StatusEls = [#xmlel{name = <<"status">>,
+                       attrs = [{<<"code">>, Code}],
+                       children = []} || Code <- Codes],
+    Message = #xmlel{name = <<"message">>,
+                    attrs = [{<<"type">>, <<"groupchat">>},
+                             {<<"id">>, randoms:get_string()}],
+                    children = [#xmlel{name = <<"x">>,
+                                       attrs = [{<<"xmlns">>, ?NS_MUC_USER}],
+                                       children = StatusEls}]},
+    send_multiple(StateData#state.jid,
+                 StateData#state.server_host,
+                 StateData#state.users,
+                 Message).
+
 remove_nonmembers(StateData) ->
     lists:foldl(fun ({_LJID, #user{jid = JID}}, SD) ->
                        Affiliation = get_affiliation(JID, SD),
index 4d1a1fc7b4338c8fac85f7b701692e8d76d0e6a6..dc528d79a65c000dea18274238b932585bb989bf 100644 (file)
@@ -1122,10 +1122,11 @@ muc_master(Config) ->
                   end
           end, RoomCfg#xdata.fields),
     NewRoomCfg = #xdata{type = submit, fields = NewFields},
-    %% BUG: We should not receive any sub_els!
-    #iq{type = result, sub_els = [_|_]} =
-        send_recv(Config, #iq{type = set, to = Room,
-                              sub_els = [#muc_owner{config = NewRoomCfg}]}),
+    ID = send(Config, #iq{type = set, to = Room,
+                         sub_els = [#muc_owner{config = NewRoomCfg}]}),
+    ?recv2(#iq{type = result, id = ID},
+          #message{from = Room, type = groupchat,
+                   sub_els = [#muc_user{status_codes = [104]}]}),
     %% Set subject
     send(Config, #message{to = Room, type = groupchat,
                           body = [#text{data = Subject}]}),