From bf9d6b55342dbb013bba612d4855271b582ae0ff Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 12 Aug 2016 21:13:10 +0200 Subject: [PATCH] Honor hint for any non-"error" message XEP-0334 says: "A message containing the hint that is not of type 'error' SHOULD be stored by the entity." --- src/mod_mam.erl | 42 +++++++++++++++++----------------- src/mod_offline.erl | 55 +++++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/mod_mam.erl b/src/mod_mam.erl index 4ee998793..6ea757223 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -555,31 +555,29 @@ parse_query_v0_2(Query) -> end, Query#xmlel.children). should_archive(#xmlel{name = <<"message">>} = Pkt, LServer) -> - case fxml:get_attr_s(<<"type">>, Pkt#xmlel.attrs) of - <<"error">> -> + case is_resent(Pkt, LServer) of + true -> false; - <<"groupchat">> -> - false; - <<"headline">> -> - false; - _ -> - case is_resent(Pkt, LServer) of - true -> + false -> + case {check_store_hint(Pkt), + fxml:get_attr_s(<<"type">>, Pkt#xmlel.attrs)} of + {_Hint, <<"error">>} -> false; - false -> - case check_store_hint(Pkt) of - store -> - true; - no_store -> + {store, _Type} -> + true; + {no_store, _Type} -> + false; + {none, <<"groupchat">>} -> + false; + {none, <<"headline">>} -> + false; + {none, _Type} -> + case fxml:get_subtag_cdata(Pkt, <<"body">>) of + <<>> -> + %% Empty body false; - none -> - case fxml:get_subtag_cdata(Pkt, <<"body">>) of - <<>> -> - %% Empty body - false; - _ -> - true - end + _ -> + true end end end; diff --git a/src/mod_offline.erl b/src/mod_offline.erl index 799605c69..87a136853 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -437,35 +437,36 @@ remove_msg_by_node(To, Seq) -> end. need_to_store(LServer, Packet) -> - Type = fxml:get_tag_attr_s(<<"type">>, Packet), - if (Type /= <<"error">>) and (Type /= <<"groupchat">>) - and (Type /= <<"headline">>) -> - case has_offline_tag(Packet) of - false -> - case check_store_hint(Packet) of - store -> + case has_offline_tag(Packet) of + false -> + case {check_store_hint(Packet), + fxml:get_tag_attr_s(<<"type">>, Packet)} of + {_Hint, <<"error">>} -> + false; + {store, _Type} -> + true; + {no_store, _Type} -> + false; + {none, <<"groupchat">>} -> + false; + {none, <<"headline">>} -> + false; + {none, _Type} -> + case gen_mod:get_module_opt( + LServer, ?MODULE, store_empty_body, + fun(V) when is_boolean(V) -> V; + (unless_chat_state) -> unless_chat_state + end, + unless_chat_state) of + true -> true; - no_store -> - false; - none -> - case gen_mod:get_module_opt( - LServer, ?MODULE, store_empty_body, - fun(V) when is_boolean(V) -> V; - (unless_chat_state) -> unless_chat_state - end, - unless_chat_state) of - false -> - fxml:get_subtag(Packet, <<"body">>) /= false; - unless_chat_state -> - not jlib:is_standalone_chat_state(Packet); - true -> - true - end - end; - true -> - false + false -> + fxml:get_subtag(Packet, <<"body">>) /= false; + unless_chat_state -> + not jlib:is_standalone_chat_state(Packet) + end end; - true -> + true -> false end.