mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Store role, and use it when joining a moderated room (#3330)
This commit is contained in:
parent
add55e1947
commit
4d3875f4ff
@ -122,6 +122,7 @@
|
|||||||
robots = #{} :: robots(),
|
robots = #{} :: robots(),
|
||||||
nicks = #{} :: nicks(),
|
nicks = #{} :: nicks(),
|
||||||
affiliations = #{} :: affiliations(),
|
affiliations = #{} :: affiliations(),
|
||||||
|
roles = #{} :: roles(),
|
||||||
history = #lqueue{} :: lqueue(),
|
history = #lqueue{} :: lqueue(),
|
||||||
subject = [] :: [text()],
|
subject = [] :: [text()],
|
||||||
subject_author = <<"">> :: binary(),
|
subject_author = <<"">> :: binary(),
|
||||||
@ -137,3 +138,4 @@
|
|||||||
-type robots() :: #{jid() => {binary(), stanza()}}.
|
-type robots() :: #{jid() => {binary(), stanza()}}.
|
||||||
-type nicks() :: #{binary() => [ljid()]}.
|
-type nicks() :: #{binary() => [ljid()]}.
|
||||||
-type affiliations() :: #{ljid() => affiliation() | {affiliation(), binary()}}.
|
-type affiliations() :: #{ljid() => affiliation() | {affiliation(), binary()}}.
|
||||||
|
-type roles() :: #{ljid() => role() | {role(), binary()}}.
|
||||||
|
@ -1177,7 +1177,7 @@ opts_to_binary(Opts) ->
|
|||||||
{subject, iolist_to_binary(Subj)};
|
{subject, iolist_to_binary(Subj)};
|
||||||
({subject_author, Author}) ->
|
({subject_author, Author}) ->
|
||||||
{subject_author, iolist_to_binary(Author)};
|
{subject_author, iolist_to_binary(Author)};
|
||||||
({affiliations, Affs}) ->
|
({AffOrRole, Affs}) when (AffOrRole == affiliation) or (AffOrRole == role) ->
|
||||||
{affiliations, lists:map(
|
{affiliations, lists:map(
|
||||||
fun({{U, S, R}, Aff}) ->
|
fun({{U, S, R}, Aff}) ->
|
||||||
NewAff =
|
NewAff =
|
||||||
|
@ -1732,7 +1732,8 @@ set_role(JID, Role, StateData) ->
|
|||||||
end, StateData#state.users, LJIDs),
|
end, StateData#state.users, LJIDs),
|
||||||
StateData#state.nicks}
|
StateData#state.nicks}
|
||||||
end,
|
end,
|
||||||
StateData#state{users = Users, nicks = Nicks}.
|
Roles = maps:put(jid:remove_resource(LJID), Role, StateData#state.roles),
|
||||||
|
StateData#state{users = Users, nicks = Nicks, roles = Roles}.
|
||||||
|
|
||||||
-spec get_role(jid(), state()) -> role().
|
-spec get_role(jid(), state()) -> role().
|
||||||
get_role(JID, StateData) ->
|
get_role(JID, StateData) ->
|
||||||
@ -2144,7 +2145,7 @@ add_new_user(From, Nick, Packet, StateData) ->
|
|||||||
Collision,
|
Collision,
|
||||||
mod_muc:can_use_nick(StateData#state.server_host,
|
mod_muc:can_use_nick(StateData#state.server_host,
|
||||||
StateData#state.host, From, Nick),
|
StateData#state.host, From, Nick),
|
||||||
get_default_role(Affiliation, StateData)}
|
get_occupant_initial_role(From, Affiliation, StateData)}
|
||||||
of
|
of
|
||||||
{false, _, _, _} when NUsers >= MaxUsers orelse NUsers >= MaxAdminUsers ->
|
{false, _, _, _} when NUsers >= MaxUsers orelse NUsers >= MaxAdminUsers ->
|
||||||
Txt = ?T("Too many users in this conference"),
|
Txt = ?T("Too many users in this conference"),
|
||||||
@ -4010,6 +4011,8 @@ set_opts([{Opt, Val} | Opts], StateData) ->
|
|||||||
StateData#state{muc_subscribers = MUCSubscribers};
|
StateData#state{muc_subscribers = MUCSubscribers};
|
||||||
affiliations ->
|
affiliations ->
|
||||||
StateData#state{affiliations = maps:from_list(Val)};
|
StateData#state{affiliations = maps:from_list(Val)};
|
||||||
|
roles ->
|
||||||
|
StateData#state{roles = maps:from_list(Val)};
|
||||||
subject ->
|
subject ->
|
||||||
Subj = if Val == <<"">> -> [];
|
Subj = if Val == <<"">> -> [];
|
||||||
is_binary(Val) -> [#text{data = Val}];
|
is_binary(Val) -> [#text{data = Val}];
|
||||||
@ -4022,7 +4025,9 @@ set_opts([{Opt, Val} | Opts], StateData) ->
|
|||||||
lists:map(fun({U, H}) -> {U, maps:from_list(H)} end,
|
lists:map(fun({U, H}) -> {U, maps:from_list(H)} end,
|
||||||
Val)),
|
Val)),
|
||||||
StateData#state{hats_users = Hats};
|
StateData#state{hats_users = Hats};
|
||||||
_ -> StateData
|
Other ->
|
||||||
|
?INFO_MSG("Unknown MUC room option, will be discarded: ~p", [Other]),
|
||||||
|
StateData
|
||||||
end,
|
end,
|
||||||
set_opts(Opts, NSD).
|
set_opts(Opts, NSD).
|
||||||
|
|
||||||
@ -4041,6 +4046,18 @@ set_vcard_xupdate(#state{config =
|
|||||||
set_vcard_xupdate(State) ->
|
set_vcard_xupdate(State) ->
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
get_occupant_initial_role(Jid, Affiliation, #state{roles = Roles} = StateData) ->
|
||||||
|
DefaultRole = get_default_role(Affiliation, StateData),
|
||||||
|
case (StateData#state.config)#config.moderated of
|
||||||
|
true ->
|
||||||
|
get_occupant_stored_role(Jid, Roles, DefaultRole);
|
||||||
|
false ->
|
||||||
|
DefaultRole
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_occupant_stored_role(Jid, Roles, DefaultRole) ->
|
||||||
|
maps:get(jid:split(jid:remove_resource(Jid)), Roles, DefaultRole).
|
||||||
|
|
||||||
-define(MAKE_CONFIG_OPT(Opt),
|
-define(MAKE_CONFIG_OPT(Opt),
|
||||||
{get_config_opt_name(Opt), element(Opt, Config)}).
|
{get_config_opt_name(Opt), element(Opt, Config)}).
|
||||||
|
|
||||||
@ -4084,6 +4101,7 @@ make_opts(StateData, Hibernation) ->
|
|||||||
(?SETS):to_list((StateData#state.config)#config.captcha_whitelist)},
|
(?SETS):to_list((StateData#state.config)#config.captcha_whitelist)},
|
||||||
{affiliations,
|
{affiliations,
|
||||||
maps:to_list(StateData#state.affiliations)},
|
maps:to_list(StateData#state.affiliations)},
|
||||||
|
{roles, maps:to_list(StateData#state.roles)},
|
||||||
{subject, StateData#state.subject},
|
{subject, StateData#state.subject},
|
||||||
{subject_author, StateData#state.subject_author},
|
{subject_author, StateData#state.subject_author},
|
||||||
{hats_users,
|
{hats_users,
|
||||||
|
Loading…
Reference in New Issue
Block a user