From 7606be93d5cfab2ea3219bf4e5b480afe9020da2 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Fri, 13 Jan 2017 14:20:25 +0300 Subject: [PATCH] Decode message before checking for expiration (#1458) --- src/mod_offline.erl | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/mod_offline.erl b/src/mod_offline.erl index ae0915ee4..0c8c3f7a9 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -570,32 +570,34 @@ pop_offline_messages(Ls, User, Server) -> Mod = gen_mod:db_mod(LServer, ?MODULE), case Mod:pop_messages(LUser, LServer) of {ok, Rs} -> - TS = p1_time_compat:timestamp(), Ls ++ lists:flatmap( - fun(R) -> + fun(#offline_msg{expire = Expire} = R) -> case offline_msg_to_route(LServer, R) of - error -> []; - RouteMsg -> [RouteMsg] + error -> + []; + {route, _From, _To, Msg} = RouteMsg -> + case is_expired_message(Expire, Msg) of + true -> []; + false -> [RouteMsg] + end end - end, - lists:filter( - fun(#offline_msg{packet = Pkt} = R) -> - Expire = case R#offline_msg.expire of - undefined -> - find_x_expire(TS, Pkt); - Exp -> - Exp - end, - case Expire of - never -> true; - TimeStamp -> TS < TimeStamp - end - end, Rs)); + end, Rs); _ -> Ls end. +is_expired_message(Expire, Pkt) -> + TS = p1_time_compat:timestamp(), + Exp = case Expire of + undefined -> find_x_expire(TS, Pkt); + _ -> Expire + end, + case Exp of + never -> false; + TimeStamp -> TS >= TimeStamp + end. + remove_expired_messages(Server) -> LServer = jid:nameprep(Server), Mod = gen_mod:db_mod(LServer, ?MODULE), -- 2.40.0