From 4045c848c4732add9bd1ef716719523511cdb8e3 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Thu, 2 Jul 2015 00:36:16 +0200 Subject: [PATCH] Send notifications on MUC configuration changes Notify clients when the room configuration changes, as mandated by XEP-0045, #10.2.1. Closes #623. --- src/mod_muc_room.erl | 34 ++++++++++++++++++++++++++++++++++ test/ejabberd_SUITE.erl | 9 +++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index ff2ab5653..7b4cfbf6d 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -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), diff --git a/test/ejabberd_SUITE.erl b/test/ejabberd_SUITE.erl index 4d1a1fc7b..dc528d79a 100644 --- a/test/ejabberd_SUITE.erl +++ b/test/ejabberd_SUITE.erl @@ -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}]}),