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

Add option to mod_offline to make it not bounce mucsub/groupchat messages

This commit is contained in:
Paweł Chmielowski 2019-03-14 15:12:39 +01:00
parent 0715e62a41
commit 89db022da4
2 changed files with 59 additions and 12 deletions

View File

@ -38,7 +38,8 @@
compile_exprs/2, join_atoms/2, try_read_file/1, get_descr/2,
css_dir/0, img_dir/0, js_dir/0, msgs_dir/0, sql_dir/0, lua_dir/0,
read_css/1, read_img/1, read_js/1, read_lua/1, try_url/1,
intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0]).
intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0,
is_mucsub_message/1]).
%% Deprecated functions
-export([decode_base64/1, encode_base64/1]).
@ -109,6 +110,26 @@ unwrap_mucsub_message(#message{} = OuterMsg) ->
unwrap_mucsub_message(_Packet) ->
false.
-spec is_mucsub_message(xmpp_element()) -> boolean().
is_mucsub_message(#message{} = OuterMsg) ->
case xmpp:get_subtag(OuterMsg, #ps_event{}) of
#ps_event{
items = #ps_items{
node = Node}}
when Node == ?NS_MUCSUB_NODES_MESSAGES;
Node == ?NS_MUCSUB_NODES_SUBJECT;
Node == ?NS_MUCSUB_NODES_AFFILIATIONS;
Node == ?NS_MUCSUB_NODES_CONFIG;
Node == ?NS_MUCSUB_NODES_PARTICIPANTS;
Node == ?NS_MUCSUB_NODES_PRESENCE;
Node == ?NS_MUCSUB_NODES_SUBSCRIBERS ->
true;
_ ->
false
end;
is_mucsub_message(_Packet) ->
false.
-spec is_standalone_chat_state(stanza()) -> boolean().
is_standalone_chat_state(Stanza) ->
case unwrap_carbon(Stanza) of

View File

@ -576,19 +576,42 @@ remove_user(User, Server) ->
%% Helper functions:
-spec check_if_message_should_be_bounced(message()) -> boolean().
check_if_message_should_be_bounced(Packet) ->
case Packet of
#message{type = groupchat, to = #jid{lserver = LServer}} ->
gen_mod:get_module_opt(LServer, ?MODULE, bounce_groupchat);
#message{to = #jid{lserver = LServer}} ->
case misc:is_mucsub_message(Packet) of
true ->
gen_mod:get_module_opt(LServer, ?MODULE, bounce_groupchat);
_ ->
true
end;
_ ->
true
end.
%% Warn senders that their messages have been discarded:
-spec discard_warn_sender(message(), full | any()) -> ok.
discard_warn_sender(Packet, full) ->
ErrText = <<"Your contact offline message queue is "
"full. The message has been discarded.">>,
Lang = xmpp:get_lang(Packet),
Err = xmpp:err_resource_constraint(ErrText, Lang),
ejabberd_router:route_error(Packet, Err);
discard_warn_sender(Packet, _) ->
ErrText = <<"Database failure">>,
Lang = xmpp:get_lang(Packet),
Err = xmpp:err_internal_server_error(ErrText, Lang),
ejabberd_router:route_error(Packet, Err).
discard_warn_sender(Packet, Reason) ->
case check_if_message_should_be_bounced(Packet) of
true ->
Lang = xmpp:get_lang(Packet),
Err = case Reason of
full ->
ErrText = <<"Your contact offline message queue is "
"full. The message has been discarded.">>,
xmpp:err_resource_constraint(ErrText, Lang);
_ ->
ErrText = <<"Database failure">>,
xmpp:err_internal_server_error(ErrText, Lang)
end,
ejabberd_router:route_error(Packet, Err);
_ ->
ok
end.
webadmin_page(_, Host,
#request{us = _US, path = [<<"user">>, U, <<"queue">>],
@ -855,6 +878,8 @@ mod_opt_type(access_max_user_messages) ->
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(store_groupchat) ->
fun(V) when is_boolean(V) -> V end;
mod_opt_type(bounce_groupchat) ->
fun(V) when is_boolean(V) -> V end;
mod_opt_type(store_empty_body) ->
fun (V) when is_boolean(V) -> V;
(unless_chat_state) -> unless_chat_state
@ -864,4 +889,5 @@ mod_options(Host) ->
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{access_max_user_messages, max_user_offline_messages},
{store_empty_body, unless_chat_state},
{bounce_groupchat, true},
{store_groupchat, false}].