mod_mam_sql: Remove duplicated functions

This commit is contained in:
Holger Weiss 2021-08-07 12:57:57 +02:00
parent fdfd202a30
commit 3e942bf4ac
1 changed files with 5 additions and 15 deletions

View File

@ -72,7 +72,7 @@ remove_from_archive(LUser, LServer, WithJid) ->
end. end.
delete_old_messages(ServerHost, TimeStamp, Type) -> delete_old_messages(ServerHost, TimeStamp, Type) ->
TS = now_to_usec(TimeStamp), TS = misc:now_to_usec(TimeStamp),
case Type of case Type of
all -> all ->
ejabberd_sql:sql_query( ejabberd_sql:sql_query(
@ -315,7 +315,7 @@ export(_Server) ->
id = _ID, timestamp = TS, peer = Peer, id = _ID, timestamp = TS, peer = Peer,
type = Type, nick = Nick, packet = Pkt}) type = Type, nick = Nick, packet = Pkt})
when LServer == Host -> when LServer == Host ->
TStmp = now_to_usec(TS), TStmp = misc:now_to_usec(TS),
SUser = case Type of SUser = case Type of
chat -> LUser; chat -> LUser;
groupchat -> jid:encode({LUser, LServer, <<>>}) groupchat -> jid:encode({LUser, LServer, <<>>})
@ -372,16 +372,6 @@ is_empty_for_room(LServer, LName, LHost) ->
%%%=================================================================== %%%===================================================================
%%% Internal functions %%% Internal functions
%%%=================================================================== %%%===================================================================
now_to_usec({MSec, Sec, USec}) ->
(MSec*1000000 + Sec)*1000000 + USec.
usec_to_now(Int) ->
Secs = Int div 1000000,
USec = Int rem 1000000,
MSec = Secs div 1000000,
Sec = Secs rem 1000000,
{MSec, Sec, USec}.
make_sql_query(User, LServer, MAMQuery, RSM, ExtraUsernames) -> make_sql_query(User, LServer, MAMQuery, RSM, ExtraUsernames) ->
Start = proplists:get_value(start, MAMQuery), Start = proplists:get_value(start, MAMQuery),
End = proplists:get_value('end', MAMQuery), End = proplists:get_value('end', MAMQuery),
@ -432,14 +422,14 @@ make_sql_query(User, LServer, MAMQuery, RSM, ExtraUsernames) ->
StartClause = case Start of StartClause = case Start of
{_, _, _} -> {_, _, _} ->
[<<" and timestamp >= ">>, [<<" and timestamp >= ">>,
integer_to_binary(now_to_usec(Start))]; integer_to_binary(misc:now_to_usec(Start))];
_ -> _ ->
[] []
end, end,
EndClause = case End of EndClause = case End of
{_, _, _} -> {_, _, _} ->
[<<" and timestamp <= ">>, [<<" and timestamp <= ">>,
integer_to_binary(now_to_usec(End))]; integer_to_binary(misc:now_to_usec(End))];
_ -> _ ->
[] []
end, end,
@ -526,7 +516,7 @@ make_archive_el(User, TS, XML, Peer, Kind, Nick, MsgType, JidRequestor, JidArchi
TSInt -> TSInt ->
try jid:decode(Peer) of try jid:decode(Peer) of
PeerJID -> PeerJID ->
Now = usec_to_now(TSInt), Now = misc:usec_to_now(TSInt),
PeerLJID = jid:tolower(PeerJID), PeerLJID = jid:tolower(PeerJID),
T = case Kind of T = case Kind of
<<"">> -> chat; <<"">> -> chat;