From 96adf84c6f103f1281ec8e19dd0bc31a22381106 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 1 Sep 2015 00:01:25 +0200 Subject: [PATCH] mod_mam_mnesia: Check for hint Respect the and hints. Both tell the server to store a message even if it would otherwise not be stored (e.g., because it doesn't have a body). These hints are not (yet) part of XEP-0334, though. --- mod_mam_mnesia/src/mod_mam_mnesia.erl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mod_mam_mnesia/src/mod_mam_mnesia.erl b/mod_mam_mnesia/src/mod_mam_mnesia.erl index 23c6d71..79365e1 100644 --- a/mod_mam_mnesia/src/mod_mam_mnesia.erl +++ b/mod_mam_mnesia/src/mod_mam_mnesia.erl @@ -319,12 +319,17 @@ send_stanza(Stanza, _C2SState, _From, _To) -> Stanza. -spec is_desired(route(), jid(), jid(), xmlel()) -> boolean(). is_desired(Route, JID, To, Message) -> - is_chat_or_normal_message(Message) andalso - has_non_empty_body(Message) andalso + looks_interesting(Message) andalso not has_no_store_hint(Message) andalso not is_bare_copy(Route, JID, To) andalso not is_resent(Message). +-spec looks_interesting(xmlel()) -> boolean(). + +looks_interesting(Message) -> + (is_chat_or_normal_message(Message) andalso has_non_empty_body(Message)) + orelse has_store_hint(Message). + -spec is_chat_or_normal_message(xmlel()) -> boolean(). is_chat_or_normal_message(#xmlel{name = <<"message">>} = Message) -> @@ -354,6 +359,14 @@ has_non_empty_body(Message) -> xml:get_subtag_cdata(Message, <<"body">>) =/= <<"">> orelse xml:get_subtag(Message, <<"encrypted">>) =/= false. +-spec has_store_hint(xmlel()) -> boolean(). + +has_store_hint(Message) -> + xml:get_subtag_with_xmlns(Message, <<"store">>, ?NS_HINTS) + =/= false orelse + xml:get_subtag_with_xmlns(Message, <<"pretty-please-store">>, ?NS_HINTS) + =/= false. + -spec has_no_store_hint(xmlel()) -> boolean(). has_no_store_hint(Message) ->