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

Send notifications on MUC configuration changes

Notify clients when the room configuration changes, as mandated by
XEP-0045, #10.2.1.

Closes #623.
This commit is contained in:
Holger Weiss 2015-07-02 00:36:16 +02:00
parent 3267d4c923
commit 4045c848c4
2 changed files with 39 additions and 4 deletions

View File

@ -3732,6 +3732,7 @@ set_xoption([_ | _Opts], _Config) ->
{error, ?ERR_BAD_REQUEST}. {error, ?ERR_BAD_REQUEST}.
change_config(Config, StateData) -> change_config(Config, StateData) ->
send_config_change_info(Config, StateData),
NSD = StateData#state{config = Config}, NSD = StateData#state{config = Config},
case {(StateData#state.config)#config.persistent, case {(StateData#state.config)#config.persistent,
Config#config.persistent} Config#config.persistent}
@ -3752,6 +3753,39 @@ change_config(Config, StateData) ->
_ -> {result, [], NSD} _ -> {result, [], NSD}
end. 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) -> remove_nonmembers(StateData) ->
lists:foldl(fun ({_LJID, #user{jid = JID}}, SD) -> lists:foldl(fun ({_LJID, #user{jid = JID}}, SD) ->
Affiliation = get_affiliation(JID, SD), Affiliation = get_affiliation(JID, SD),

View File

@ -1122,10 +1122,11 @@ muc_master(Config) ->
end end
end, RoomCfg#xdata.fields), end, RoomCfg#xdata.fields),
NewRoomCfg = #xdata{type = submit, fields = NewFields}, NewRoomCfg = #xdata{type = submit, fields = NewFields},
%% BUG: We should not receive any sub_els! ID = send(Config, #iq{type = set, to = Room,
#iq{type = result, sub_els = [_|_]} = sub_els = [#muc_owner{config = NewRoomCfg}]}),
send_recv(Config, #iq{type = set, to = Room, ?recv2(#iq{type = result, id = ID},
sub_els = [#muc_owner{config = NewRoomCfg}]}), #message{from = Room, type = groupchat,
sub_els = [#muc_user{status_codes = [104]}]}),
%% Set subject %% Set subject
send(Config, #message{to = Room, type = groupchat, send(Config, #message{to = Room, type = groupchat,
body = [#text{data = Subject}]}), body = [#text{data = Subject}]}),