mod_offline: Honor <store/> hint

Ignore the "store_empty_body" option for messages that have a <store/>
hint as described in XEP-0334, version 0.2.
This commit is contained in:
Holger Weiss 2015-12-08 21:46:36 +01:00
parent c2f6bf0343
commit 90fd7f3780
1 changed files with 46 additions and 27 deletions

View File

@ -284,18 +284,25 @@ need_to_store(LServer, Packet) ->
Type = xml:get_tag_attr_s(<<"type">>, Packet), Type = xml:get_tag_attr_s(<<"type">>, Packet),
if (Type /= <<"error">>) and (Type /= <<"groupchat">>) if (Type /= <<"error">>) and (Type /= <<"groupchat">>)
and (Type /= <<"headline">>) -> and (Type /= <<"headline">>) ->
case gen_mod:get_module_opt( case check_store_hint(Packet) of
LServer, ?MODULE, store_empty_body, store ->
fun(V) when is_boolean(V) -> V; true;
(unless_chat_state) -> unless_chat_state no_store ->
end, false;
unless_chat_state) of none ->
false -> case gen_mod:get_module_opt(
xml:get_subtag(Packet, <<"body">>) /= false; LServer, ?MODULE, store_empty_body,
unless_chat_state -> fun(V) when is_boolean(V) -> V;
not jlib:is_standalone_chat_state(Packet); (unless_chat_state) -> unless_chat_state
true -> end,
true unless_chat_state) of
false ->
xml:get_subtag(Packet, <<"body">>) /= false;
unless_chat_state ->
not jlib:is_standalone_chat_state(Packet);
true ->
true
end
end; end;
true -> true ->
false false
@ -304,26 +311,38 @@ need_to_store(LServer, Packet) ->
store_packet(From, To, Packet) -> store_packet(From, To, Packet) ->
case need_to_store(To#jid.lserver, Packet) of case need_to_store(To#jid.lserver, Packet) of
true -> true ->
case has_no_store_hint(Packet) of case check_event(From, To, Packet) of
false -> true ->
case check_event(From, To, Packet) of #jid{luser = LUser, lserver = LServer} = To,
true -> TimeStamp = p1_time_compat:timestamp(),
#jid{luser = LUser, lserver = LServer} = To, #xmlel{children = Els} = Packet,
TimeStamp = p1_time_compat:timestamp(), Expire = find_x_expire(TimeStamp, Els),
#xmlel{children = Els} = Packet, gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
Expire = find_x_expire(TimeStamp, Els), #offline_msg{us = {LUser, LServer},
gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) ! timestamp = TimeStamp, expire = Expire,
#offline_msg{us = {LUser, LServer}, from = From, to = To, packet = Packet},
timestamp = TimeStamp, expire = Expire, stop;
from = From, to = To, packet = Packet},
stop;
_ -> ok
end;
_ -> ok _ -> ok
end; end;
false -> ok false -> ok
end. end.
check_store_hint(Packet) ->
case has_store_hint(Packet) of
true ->
store;
false ->
case has_no_store_hint(Packet) of
true ->
no_store;
false ->
none
end
end.
has_store_hint(Packet) ->
xml:get_subtag_with_xmlns(Packet, <<"store">>, ?NS_HINTS) =/= false.
has_no_store_hint(Packet) -> has_no_store_hint(Packet) ->
xml:get_subtag_with_xmlns(Packet, <<"no-store">>, ?NS_HINTS) =/= false xml:get_subtag_with_xmlns(Packet, <<"no-store">>, ?NS_HINTS) =/= false
orelse orelse