1 |
|
-module(mod_offline_api). |
2 |
|
|
3 |
|
-export([delete_expired_messages/1, delete_old_messages/2]). |
4 |
|
|
5 |
|
-type(api_result()) :: {ok | domain_not_found | server_error, iolist()}. |
6 |
|
|
7 |
|
-spec delete_expired_messages(jid:lserver()) -> api_result(). |
8 |
|
delete_expired_messages(Domain) -> |
9 |
:-( |
call_for_host_type(Domain, fun remove_expired_messages/2, [Domain]). |
10 |
|
|
11 |
|
-spec delete_old_messages(jid:lserver(), Days :: pos_integer()) -> api_result(). |
12 |
|
delete_old_messages(Domain, Days) -> |
13 |
:-( |
call_for_host_type(Domain, fun remove_old_messages/3, [Domain, Days]). |
14 |
|
|
15 |
|
call_for_host_type(Domain, Function, Args) -> |
16 |
:-( |
case mongoose_domain_api:get_domain_host_type(Domain) of |
17 |
|
{ok, HostType} -> |
18 |
:-( |
apply(Function, [HostType | Args]); |
19 |
|
{error, not_found} -> |
20 |
:-( |
{domain_not_found, "Unknown domain"} |
21 |
|
end. |
22 |
|
|
23 |
|
remove_old_messages(HostType, Domain, Days) -> |
24 |
:-( |
case mod_offline:remove_old_messages(HostType, Domain, Days) of |
25 |
|
{ok, C} -> |
26 |
:-( |
{ok, io_lib:format("Removed ~p messages", [C])}; |
27 |
|
{error, Reason} -> |
28 |
:-( |
{server_error, io_lib:format("Can't remove old messages: ~n~p", [Reason])} |
29 |
|
end. |
30 |
|
|
31 |
|
remove_expired_messages(HostType, Domain) -> |
32 |
:-( |
case mod_offline:remove_expired_messages(HostType, Domain) of |
33 |
|
{ok, C} -> |
34 |
:-( |
{ok, io_lib:format("Removed ~p messages", [C])}; |
35 |
|
{error, Reason} -> |
36 |
:-( |
{server_error, io_lib:format("Can't remove old messages: ~n~p", [Reason])} |
37 |
|
end. |