mirror of
https://github.com/processone/ejabberd.git
synced 2024-10-19 15:32:08 +02:00
Merge pull request #849 from weiss/discard-chat-states
mod_offline: Support discarding chat state notifications
This commit is contained in:
commit
3397a9be5e
21
src/jlib.erl
21
src/jlib.erl
@ -43,6 +43,7 @@
|
|||||||
get_iq_namespace/1, iq_query_info/1,
|
get_iq_namespace/1, iq_query_info/1,
|
||||||
iq_query_or_response_info/1, is_iq_request_type/1,
|
iq_query_or_response_info/1, is_iq_request_type/1,
|
||||||
iq_to_xml/1, parse_xdata_submit/1,
|
iq_to_xml/1, parse_xdata_submit/1,
|
||||||
|
is_standalone_chat_state/1,
|
||||||
add_delay_info/3, add_delay_info/4,
|
add_delay_info/3, add_delay_info/4,
|
||||||
timestamp_to_iso/1, timestamp_to_iso/2,
|
timestamp_to_iso/1, timestamp_to_iso/2,
|
||||||
now_to_utc_string/1, now_to_local_string/1,
|
now_to_utc_string/1, now_to_local_string/1,
|
||||||
@ -527,6 +528,26 @@ rsm_encode_count(Count, Arr) ->
|
|||||||
children = [{xmlcdata, i2l(Count)}]}
|
children = [{xmlcdata, i2l(Count)}]}
|
||||||
| Arr].
|
| Arr].
|
||||||
|
|
||||||
|
-spec is_standalone_chat_state(xmlel()) -> boolean().
|
||||||
|
|
||||||
|
is_standalone_chat_state(#xmlel{name = <<"message">>} = El) ->
|
||||||
|
ChatStates = [<<"active">>, <<"inactive">>, <<"gone">>, <<"composing">>,
|
||||||
|
<<"paused">>],
|
||||||
|
Stripped =
|
||||||
|
lists:foldl(fun(ChatState, AccEl) ->
|
||||||
|
xml:remove_subtags(AccEl, ChatState,
|
||||||
|
{<<"xmlns">>, ?NS_CHATSTATES})
|
||||||
|
end, El, ChatStates),
|
||||||
|
case Stripped of
|
||||||
|
#xmlel{children = [#xmlel{name = <<"thread">>}]} ->
|
||||||
|
true;
|
||||||
|
#xmlel{children = []} ->
|
||||||
|
true;
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end;
|
||||||
|
is_standalone_chat_state(_El) -> false.
|
||||||
|
|
||||||
-spec add_delay_info(xmlel(), jid() | ljid() | binary(), erlang:timestamp())
|
-spec add_delay_info(xmlel(), jid() | ljid() | binary(), erlang:timestamp())
|
||||||
-> xmlel().
|
-> xmlel().
|
||||||
|
|
||||||
|
@ -91,22 +91,12 @@ filter_presence(_Action, #xmlel{name = <<"presence">>, attrs = Attrs}) ->
|
|||||||
filter_presence(Action, _Stanza) -> Action.
|
filter_presence(Action, _Stanza) -> Action.
|
||||||
|
|
||||||
filter_chat_states(_Action, #xmlel{name = <<"message">>} = Stanza) ->
|
filter_chat_states(_Action, #xmlel{name = <<"message">>} = Stanza) ->
|
||||||
%% All XEP-0085 chat states except for <gone/>:
|
case jlib:is_standalone_chat_state(Stanza) of
|
||||||
ChatStates = [<<"active">>, <<"inactive">>, <<"composing">>, <<"paused">>],
|
true ->
|
||||||
Stripped =
|
|
||||||
lists:foldl(fun(ChatState, AccStanza) ->
|
|
||||||
xml:remove_subtags(AccStanza, ChatState,
|
|
||||||
{<<"xmlns">>, ?NS_CHATSTATES})
|
|
||||||
end, Stanza, ChatStates),
|
|
||||||
case Stripped of
|
|
||||||
#xmlel{children = [#xmlel{name = <<"thread">>}]} ->
|
|
||||||
?DEBUG("Got standalone chat state notification", []),
|
?DEBUG("Got standalone chat state notification", []),
|
||||||
{stop, drop};
|
{stop, drop};
|
||||||
#xmlel{children = []} ->
|
false ->
|
||||||
?DEBUG("Got standalone chat state notification", []),
|
?DEBUG("Got message stanza", []),
|
||||||
{stop, drop};
|
|
||||||
_ ->
|
|
||||||
?DEBUG("Got message with chat state notification", []),
|
|
||||||
{stop, send}
|
{stop, send}
|
||||||
end;
|
end;
|
||||||
filter_chat_states(Action, _Stanza) -> Action.
|
filter_chat_states(Action, _Stanza) -> Action.
|
||||||
|
@ -286,10 +286,14 @@ need_to_store(LServer, Packet) ->
|
|||||||
and (Type /= <<"headline">>) ->
|
and (Type /= <<"headline">>) ->
|
||||||
case gen_mod:get_module_opt(
|
case gen_mod:get_module_opt(
|
||||||
LServer, ?MODULE, store_empty_body,
|
LServer, ?MODULE, store_empty_body,
|
||||||
fun(V) when is_boolean(V) -> V end,
|
fun(V) when is_boolean(V) -> V;
|
||||||
true) of
|
(unless_chat_state) -> unless_chat_state
|
||||||
|
end,
|
||||||
|
unless_chat_state) of
|
||||||
false ->
|
false ->
|
||||||
xml:get_subtag(Packet, <<"body">>) /= false;
|
xml:get_subtag(Packet, <<"body">>) /= false;
|
||||||
|
unless_chat_state ->
|
||||||
|
not jlib:is_standalone_chat_state(Packet);
|
||||||
true ->
|
true ->
|
||||||
true
|
true
|
||||||
end;
|
end;
|
||||||
@ -1129,6 +1133,8 @@ mod_opt_type(access_max_user_messages) ->
|
|||||||
fun (A) -> A end;
|
fun (A) -> A end;
|
||||||
mod_opt_type(db_type) -> fun gen_mod:v_db/1;
|
mod_opt_type(db_type) -> fun gen_mod:v_db/1;
|
||||||
mod_opt_type(store_empty_body) ->
|
mod_opt_type(store_empty_body) ->
|
||||||
fun (V) when is_boolean(V) -> V end;
|
fun (V) when is_boolean(V) -> V;
|
||||||
|
(unless_chat_state) -> unless_chat_state
|
||||||
|
end;
|
||||||
mod_opt_type(_) ->
|
mod_opt_type(_) ->
|
||||||
[access_max_user_messages, db_type, store_empty_body].
|
[access_max_user_messages, db_type, store_empty_body].
|
||||||
|
Loading…
Reference in New Issue
Block a user