25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Decode message before checking for expiration (#1458)

This commit is contained in:
Evgeniy Khramtsov 2017-01-13 14:20:25 +03:00
parent e2665c5da9
commit 7606be93d5

View File

@ -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),