1 |
|
-module(mongoose_stanza_api). |
2 |
|
-export([lookup_recent_messages/4]). |
3 |
|
|
4 |
|
-include("jlib.hrl"). |
5 |
|
-include("mongoose_rsm.hrl"). |
6 |
|
|
7 |
|
%% Before is in microseconds |
8 |
|
-spec lookup_recent_messages( |
9 |
|
ArcJID :: jid:jid(), |
10 |
|
With :: jid:jid() | undefined, |
11 |
|
Before :: mod_mam:unix_timestamp() | undefined, |
12 |
|
Limit :: non_neg_integer()) -> |
13 |
|
[mod_mam:message_row()]. |
14 |
|
lookup_recent_messages(_, _, _, Limit) when Limit > 500 -> |
15 |
:-( |
throw({error, message_limit_too_high}); |
16 |
|
lookup_recent_messages(ArcJID, With, Before, Limit) when is_binary(ArcJID) -> |
17 |
7 |
lookup_recent_messages(jid:from_binary(ArcJID), With, Before, Limit); |
18 |
|
lookup_recent_messages(ArcJID, With, Before, Limit) when is_binary(With) -> |
19 |
6 |
lookup_recent_messages(ArcJID, jid:from_binary(With), Before, Limit); |
20 |
|
lookup_recent_messages(ArcJID, WithJID, Before, Limit) -> |
21 |
16 |
#jid{luser = LUser, lserver = LServer} = ArcJID, |
22 |
16 |
{ok, HostType} = mongoose_domain_api:get_domain_host_type(LServer), |
23 |
16 |
EndTS = case Before of |
24 |
5 |
0 -> undefined; |
25 |
11 |
_ -> Before |
26 |
|
end, |
27 |
16 |
Params = #{archive_id => mod_mam:archive_id(LServer, LUser), |
28 |
|
owner_jid => ArcJID, |
29 |
|
borders => undefined, |
30 |
|
rsm => #rsm_in{direction = before, id = undefined}, % last msgs |
31 |
|
start_ts => undefined, |
32 |
|
end_ts => EndTS, |
33 |
|
now => os:system_time(microsecond), |
34 |
|
with_jid => WithJID, |
35 |
|
search_text => undefined, |
36 |
|
page_size => Limit, |
37 |
|
limit_passed => false, |
38 |
|
max_result_limit => 1, |
39 |
|
is_simple => true}, |
40 |
16 |
R = mod_mam:lookup_messages(HostType, Params), |
41 |
16 |
{ok, {_, _, L}} = R, |
42 |
16 |
L. |