mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Room option to ignore private messages from visitors (thanks to Maxim Ignatenko)
This commit is contained in:
parent
49ee637a5c
commit
1e88c3f180
@ -3224,6 +3224,7 @@ Module options:
|
||||
\begin{description}
|
||||
\titem{\{allow\_change\_subj, true|false\}} Allow occupants to change the subject.
|
||||
\titem{\{allow\_private\_messages, true|false\}} Occupants can send private messages to other occupants.
|
||||
\titem{\{allow\_private\_messages\_from\_visitors, anyone|moderators|nobody\}} Visitors can send private messages to other occupants.
|
||||
\titem{\{allow\_query\_users, true|false\}} Occupants can send IQ queries to other occupants.
|
||||
\titem{\{allow\_user\_invites, false|true\}} Allow occupants to send invitations.
|
||||
\titem{\{allow\_visitor\_nickchange, true|false\}} Allow visitors to
|
||||
|
@ -884,6 +884,7 @@ get_roomconfig_text(moderated) -> "Make room moderated";
|
||||
get_roomconfig_text(members_by_default) -> "Default users as participants";
|
||||
get_roomconfig_text(allow_change_subj) -> "Allow users to change the subject";
|
||||
get_roomconfig_text(allow_private_messages) -> "Allow users to send private messages";
|
||||
get_roomconfig_text(allow_private_messages_from_visitors) -> "Allow visitors to send private messages";
|
||||
get_roomconfig_text(allow_query_users) -> "Allow users to query other users";
|
||||
get_roomconfig_text(allow_user_invites) -> "Allow users to send invites";
|
||||
get_roomconfig_text(logging) -> "Enable logging";
|
||||
|
@ -426,25 +426,42 @@ normal_state({route, From, ToNick,
|
||||
ToNick),
|
||||
From, Err);
|
||||
_ ->
|
||||
case find_jid_by_nick(ToNick, StateData) of
|
||||
false ->
|
||||
ErrText = "Recipient is not in the conference room",
|
||||
ToJID = find_jid_by_nick(ToNick, StateData),
|
||||
SrcIsVisitor = is_visitor(From, StateData),
|
||||
DstIsModerator = is_moderator(ToJID, StateData),
|
||||
PmFromVisitors = (StateData#state.config)#config.allow_private_messages_from_visitors,
|
||||
if SrcIsVisitor == false;
|
||||
PmFromVisitors == anyone;
|
||||
(PmFromVisitors == moderators) and (DstIsModerator) ->
|
||||
case ToJID of
|
||||
false ->
|
||||
ErrText = "Recipient is not in the conference room",
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_ITEM_NOT_FOUND(Lang, ErrText)),
|
||||
ejabberd_router:route(
|
||||
jlib:jid_replace_resource(
|
||||
StateData#state.jid,
|
||||
ToNick),
|
||||
From, Err);
|
||||
_ ->
|
||||
{ok, #user{nick = FromNick}} =
|
||||
?DICT:find(jlib:jid_tolower(From),
|
||||
StateData#state.users),
|
||||
ejabberd_router:route(
|
||||
jlib:jid_replace_resource(
|
||||
StateData#state.jid,
|
||||
FromNick),
|
||||
ToJID, Packet)
|
||||
end;
|
||||
true ->
|
||||
ErrText = "It is not allowed to send private messages",
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_ITEM_NOT_FOUND(Lang, ErrText)),
|
||||
Packet, ?ERRT_FORBIDDEN(Lang, ErrText)),
|
||||
ejabberd_router:route(
|
||||
jlib:jid_replace_resource(
|
||||
StateData#state.jid,
|
||||
ToNick),
|
||||
From, Err);
|
||||
ToJID ->
|
||||
{ok, #user{nick = FromNick}} =
|
||||
?DICT:find(jlib:jid_tolower(From),
|
||||
StateData#state.users),
|
||||
ejabberd_router:route(
|
||||
jlib:jid_replace_resource(
|
||||
StateData#state.jid,
|
||||
FromNick),
|
||||
ToJID, Packet)
|
||||
From, Err)
|
||||
end
|
||||
end;
|
||||
{true, false} ->
|
||||
@ -1284,6 +1301,9 @@ get_default_role(Affiliation, StateData) ->
|
||||
is_visitor(Jid, StateData) ->
|
||||
get_role(Jid, StateData) =:= visitor.
|
||||
|
||||
is_moderator(Jid, StateData) ->
|
||||
get_role(Jid, StateData) =:= moderator.
|
||||
|
||||
get_max_users(StateData) ->
|
||||
MaxUsers = (StateData#state.config)#config.max_users,
|
||||
ServiceMaxUsers = get_service_max_users(StateData),
|
||||
@ -3020,6 +3040,25 @@ get_config(Lang, StateData, From) ->
|
||||
?BOOLXFIELD("Allow users to send private messages",
|
||||
"allow_private_messages",
|
||||
Config#config.allow_private_messages),
|
||||
{xmlelement, "field",
|
||||
[{"type", "list-single"},
|
||||
{"label", translate:translate(Lang, "Allow visitors to send private messages to")},
|
||||
{"var", "allow_private_messages_from_visitors"}],
|
||||
[{xmlelement, "value", [], [{xmlcdata,
|
||||
case Config#config.allow_private_messages_from_visitors of
|
||||
anyone ->
|
||||
"anyone";
|
||||
moderators ->
|
||||
"moderators";
|
||||
nobody ->
|
||||
"nobody"
|
||||
end}]},
|
||||
{xmlelement, "option", [{"label", translate:translate(Lang, "nobody")}],
|
||||
[{xmlelement, "value", [], [{xmlcdata, "nobody"}]}]},
|
||||
{xmlelement, "option", [{"label", translate:translate(Lang, "moderators only")}],
|
||||
[{xmlelement, "value", [], [{xmlcdata, "moderators"}]}]},
|
||||
{xmlelement, "option", [{"label", translate:translate(Lang, "anyone")}],
|
||||
[{xmlelement, "value", [], [{xmlcdata, "anyone"}]}]}]},
|
||||
?BOOLXFIELD("Allow users to query other users",
|
||||
"allow_query_users",
|
||||
Config#config.allow_query_users),
|
||||
@ -3137,6 +3176,17 @@ set_xoption([{"allow_query_users", [Val]} | Opts], Config) ->
|
||||
?SET_BOOL_XOPT(allow_query_users, Val);
|
||||
set_xoption([{"allow_private_messages", [Val]} | Opts], Config) ->
|
||||
?SET_BOOL_XOPT(allow_private_messages, Val);
|
||||
set_xoption([{"allow_private_messages_from_visitors", [Val]} | Opts], Config) ->
|
||||
case Val of
|
||||
"anyone" ->
|
||||
?SET_STRING_XOPT(allow_private_messages_from_visitors, anyone);
|
||||
"moderators" ->
|
||||
?SET_STRING_XOPT(allow_private_messages_from_visitors, moderators);
|
||||
"nobody" ->
|
||||
?SET_STRING_XOPT(allow_private_messages_from_visitors, nobody);
|
||||
_ ->
|
||||
{error, ?ERR_BAD_REQUEST}
|
||||
end;
|
||||
set_xoption([{"muc#roomconfig_allowvisitorstatus", [Val]} | Opts], Config) ->
|
||||
?SET_BOOL_XOPT(allow_visitor_status, Val);
|
||||
set_xoption([{"muc#roomconfig_allowvisitornickchange", [Val]} | Opts], Config) ->
|
||||
@ -3239,6 +3289,7 @@ set_opts([{Opt, Val} | Opts], StateData) ->
|
||||
allow_change_subj -> StateData#state{config = (StateData#state.config)#config{allow_change_subj = Val}};
|
||||
allow_query_users -> StateData#state{config = (StateData#state.config)#config{allow_query_users = Val}};
|
||||
allow_private_messages -> StateData#state{config = (StateData#state.config)#config{allow_private_messages = Val}};
|
||||
allow_private_messages_from_visitors -> StateData#state{config = (StateData#state.config)#config{allow_private_messages_from_visitors = Val}};
|
||||
allow_visitor_nickchange -> StateData#state{config = (StateData#state.config)#config{allow_visitor_nickchange = Val}};
|
||||
allow_visitor_status -> StateData#state{config = (StateData#state.config)#config{allow_visitor_status = Val}};
|
||||
public -> StateData#state{config = (StateData#state.config)#config{public = Val}};
|
||||
@ -3283,6 +3334,7 @@ make_opts(StateData) ->
|
||||
?MAKE_CONFIG_OPT(allow_change_subj),
|
||||
?MAKE_CONFIG_OPT(allow_query_users),
|
||||
?MAKE_CONFIG_OPT(allow_private_messages),
|
||||
?MAKE_CONFIG_OPT(allow_private_messages_from_visitors),
|
||||
?MAKE_CONFIG_OPT(allow_visitor_status),
|
||||
?MAKE_CONFIG_OPT(allow_visitor_nickchange),
|
||||
?MAKE_CONFIG_OPT(public),
|
||||
|
@ -31,6 +31,7 @@
|
||||
allow_change_subj = true,
|
||||
allow_query_users = true,
|
||||
allow_private_messages = true,
|
||||
allow_private_messages_from_visitors = anyone,
|
||||
allow_visitor_status = true,
|
||||
allow_visitor_nickchange = true,
|
||||
public = true,
|
||||
|
Loading…
Reference in New Issue
Block a user