Skip to content

Commit

Permalink
Send notifications on MUC configuration changes
Browse files Browse the repository at this point in the history
Notify clients when the room configuration changes, as mandated by
XEP-0045, processone#10.2.1.

Closes processone#623.
  • Loading branch information
weiss committed Jul 1, 2015
1 parent 3267d4c commit 4045c84
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions test/ejabberd_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}]}),
Expand Down

0 comments on commit 4045c84

Please sign in to comment.