1 |
|
%% Just a proxy interface module between the main mod_inbox module and |
2 |
|
%% the backend modules (i.e. mod_inbox_rdbms). |
3 |
|
-module(mod_inbox_backend). |
4 |
|
|
5 |
|
-include("mod_inbox.hrl"). |
6 |
|
|
7 |
|
-export([init/2, |
8 |
|
get_inbox/4, |
9 |
|
clear_inbox/3, |
10 |
|
remove_domain/2, |
11 |
|
set_inbox/6, |
12 |
|
remove_inbox_row/2, |
13 |
|
empty_user_bin/4, |
14 |
|
empty_domain_bin/3, |
15 |
|
empty_global_bin/2, |
16 |
|
set_inbox_incr_unread/5, |
17 |
|
get_inbox_unread/2, |
18 |
|
get_full_entry/2, |
19 |
|
get_entry_properties/2, |
20 |
|
set_entry_properties/3, |
21 |
|
reset_unread/4]). |
22 |
|
|
23 |
|
-define(MAIN_MODULE, mod_inbox). |
24 |
|
|
25 |
|
-callback init(HostType, Opts) -> ok when |
26 |
|
HostType :: mongooseim:host_type(), |
27 |
|
Opts :: gen_mod:module_opts(). |
28 |
|
|
29 |
|
-callback get_inbox(HostType, LUser, LServer, Params) -> [mod_inbox:inbox_res()] when |
30 |
|
HostType :: mongooseim:host_type(), |
31 |
|
LUser :: jid:luser(), |
32 |
|
LServer :: jid:lserver(), |
33 |
|
Params :: mod_inbox:get_inbox_params(). |
34 |
|
|
35 |
|
-callback clear_inbox(HostType, LUser, LServer) -> mod_inbox:write_res() when |
36 |
|
HostType :: mongooseim:host_type(), |
37 |
|
LUser :: jid:luser(), |
38 |
|
LServer :: jid:lserver(). |
39 |
|
|
40 |
|
-callback remove_domain(HostType, LServer) -> term() when |
41 |
|
HostType :: mongooseim:host_type(), |
42 |
|
LServer :: jid:lserver(). |
43 |
|
|
44 |
|
-callback set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) -> |
45 |
|
mod_inbox:write_res() when |
46 |
|
HostType :: mongooseim:host_type(), |
47 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
48 |
|
Content :: exml:element(), |
49 |
|
Count :: integer(), |
50 |
|
MsgId :: binary(), |
51 |
|
Timestamp :: integer(). |
52 |
|
|
53 |
|
-callback remove_inbox_row(HostType, InboxEntryKey) -> mod_inbox:write_res() when |
54 |
|
HostType :: mongooseim:host_type(), |
55 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
56 |
|
|
57 |
|
-callback empty_user_bin(HostType, LServer, LUser, TS) -> non_neg_integer() when |
58 |
|
HostType :: mongooseim:host_type(), |
59 |
|
LServer :: jid:lserver(), |
60 |
|
LUser :: jid:luser(), |
61 |
|
TS :: integer(). |
62 |
|
|
63 |
|
-callback empty_domain_bin(HostType, LServer, TS) -> non_neg_integer() when |
64 |
|
HostType :: mongooseim:host_type(), |
65 |
|
LServer :: jid:lserver(), |
66 |
|
TS :: integer(). |
67 |
|
|
68 |
|
-callback empty_global_bin(HostType, TS) -> non_neg_integer() when |
69 |
|
HostType :: mongooseim:host_type(), |
70 |
|
TS :: integer(). |
71 |
|
|
72 |
|
-callback set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) -> |
73 |
|
mod_inbox:count_res() when |
74 |
|
HostType :: mongooseim:host_type(), |
75 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
76 |
|
Content :: exml:element(), |
77 |
|
MsgId :: binary(), |
78 |
|
Timestamp :: integer(). |
79 |
|
|
80 |
|
-callback reset_unread(HostType, InboxEntryKey, MsgId, TS) -> mod_inbox:write_res() when |
81 |
|
HostType :: mongooseim:host_type(), |
82 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
83 |
|
MsgId :: binary() | undefined, |
84 |
|
TS :: integer(). |
85 |
|
|
86 |
|
-callback get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when |
87 |
|
HostType :: mongooseim:host_type(), |
88 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
89 |
|
|
90 |
|
-callback get_full_entry(HostType, InboxEntryKey) -> Ret when |
91 |
|
HostType :: mongooseim:host_type(), |
92 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
93 |
|
Ret :: inbox_res() | nil(). |
94 |
|
|
95 |
|
-callback get_entry_properties(HostType, InboxEntryKey) -> Ret when |
96 |
|
HostType :: mongooseim:host_type(), |
97 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
98 |
|
Ret :: mod_inbox:entry_properties() | nil(). |
99 |
|
|
100 |
|
-callback set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when |
101 |
|
HostType :: mongooseim:host_type(), |
102 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
103 |
|
Params :: mod_inbox:entry_properties(), |
104 |
|
Ret :: mod_inbox:entry_properties() | {error, binary()}. |
105 |
|
|
106 |
|
-spec init(HostType, Opts) -> ok when |
107 |
|
HostType :: mongooseim:host_type(), |
108 |
|
Opts :: gen_mod:module_opts(). |
109 |
|
init(HostType, Opts) -> |
110 |
56 |
mongoose_backend:init(HostType, ?MAIN_MODULE, callback_funs(), Opts), |
111 |
56 |
Args = [HostType, Opts], |
112 |
56 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
113 |
|
|
114 |
|
-spec get_inbox(HostType, LUser, LServer, Params) -> [mod_inbox:inbox_res()] when |
115 |
|
HostType :: mongooseim:host_type(), |
116 |
|
LUser :: jid:luser(), |
117 |
|
LServer :: jid:lserver(), |
118 |
|
Params :: mod_inbox:get_inbox_params(). |
119 |
|
get_inbox(HostType, LUser, LServer, Params) -> |
120 |
1158 |
Args = [HostType, LUser, LServer, Params], |
121 |
1158 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
122 |
|
|
123 |
|
-spec clear_inbox(HostType, LUser, LServer) -> mod_inbox:write_res() when |
124 |
|
HostType :: mongooseim:host_type(), |
125 |
|
LUser :: jid:luser(), |
126 |
|
LServer :: jid:lserver(). |
127 |
|
clear_inbox(HostType, LUser, LServer) -> |
128 |
740 |
Args = [HostType, LUser, LServer], |
129 |
740 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
130 |
|
|
131 |
|
-spec remove_domain(HostType, LServer) -> term() when |
132 |
|
HostType :: mongooseim:host_type(), |
133 |
|
LServer :: jid:lserver(). |
134 |
|
remove_domain(HostType, LServer) -> |
135 |
2 |
Args = [HostType, LServer], |
136 |
2 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
137 |
|
|
138 |
|
-spec set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) -> |
139 |
|
mod_inbox:write_res() when |
140 |
|
HostType :: mongooseim:host_type(), |
141 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
142 |
|
Content :: exml:element(), |
143 |
|
Count :: integer(), |
144 |
|
MsgId :: binary(), |
145 |
|
Timestamp :: integer(). |
146 |
|
set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) -> |
147 |
342 |
Args = [HostType, InboxEntryKey, Content, Count, MsgId, Timestamp], |
148 |
342 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
149 |
|
|
150 |
|
-spec remove_inbox_row(HostType, InboxEntryKey) -> mod_inbox:write_res() when |
151 |
|
HostType :: mongooseim:host_type(), |
152 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
153 |
|
remove_inbox_row(HostType, InboxEntryKey) -> |
154 |
57 |
Args = [HostType, InboxEntryKey], |
155 |
57 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
156 |
|
|
157 |
|
-spec empty_user_bin(HostType, LServer, LUser, TS) -> non_neg_integer() when |
158 |
|
HostType :: mongooseim:host_type(), |
159 |
|
LServer :: jid:lserver(), |
160 |
|
LUser :: jid:luser(), |
161 |
|
TS :: integer(). |
162 |
|
empty_user_bin(HostType, LServer, LUser, TS) -> |
163 |
8 |
Args = [HostType, LServer, LUser, TS], |
164 |
8 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
165 |
|
|
166 |
|
-spec empty_domain_bin(HostType, LServer, TS) -> non_neg_integer() when |
167 |
|
HostType :: mongooseim:host_type(), |
168 |
|
LServer :: jid:lserver(), |
169 |
|
TS :: integer(). |
170 |
|
empty_domain_bin(HostType, LServer, TS) -> |
171 |
7 |
Args = [HostType, LServer, TS], |
172 |
7 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
173 |
|
|
174 |
|
-spec empty_global_bin(HostType, TS) -> non_neg_integer() when |
175 |
|
HostType :: mongooseim:host_type(), |
176 |
|
TS :: integer(). |
177 |
|
empty_global_bin(HostType, TS) -> |
178 |
25 |
Args = [HostType, TS], |
179 |
25 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
180 |
|
|
181 |
|
-spec set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) -> |
182 |
|
mod_inbox:count_res() when |
183 |
|
HostType :: mongooseim:host_type(), |
184 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
185 |
|
Content :: exml:element(), |
186 |
|
MsgId :: binary(), |
187 |
|
Timestamp :: integer(). |
188 |
|
set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) -> |
189 |
605 |
Args = [HostType, InboxEntryKey, Content, MsgId, Timestamp], |
190 |
605 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
191 |
|
|
192 |
|
-spec reset_unread(HostType, InboxEntryKey, MsgId, TS) -> mod_inbox:write_res() when |
193 |
|
HostType :: mongooseim:host_type(), |
194 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
195 |
|
MsgId :: binary() | undefined, |
196 |
|
TS :: integer(). |
197 |
|
reset_unread(HostType, InboxEntryKey, MsgId, TS) -> |
198 |
193 |
Args = [HostType, InboxEntryKey, MsgId, TS], |
199 |
193 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
200 |
|
|
201 |
|
-spec get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when |
202 |
|
HostType :: mongooseim:host_type(), |
203 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
204 |
|
get_inbox_unread(HostType, InboxEntryKey) -> |
205 |
120 |
Args = [HostType, InboxEntryKey], |
206 |
120 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
207 |
|
|
208 |
|
-spec get_full_entry(HostType, InboxEntryKey) -> Ret when |
209 |
|
HostType :: mongooseim:host_type(), |
210 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
211 |
|
Ret :: inbox_res() | nil(). |
212 |
|
get_full_entry(HostType, InboxEntryKey) -> |
213 |
2 |
Args = [HostType, InboxEntryKey], |
214 |
2 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
215 |
|
|
216 |
|
-spec get_entry_properties(HostType, InboxEntryKey) -> Ret when |
217 |
|
HostType :: mongooseim:host_type(), |
218 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
219 |
|
Ret :: mod_inbox:entry_properties() | nil(). |
220 |
|
get_entry_properties(HostType, InboxEntryKey) -> |
221 |
2 |
Args = [HostType, InboxEntryKey], |
222 |
2 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
223 |
|
|
224 |
|
-spec set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when |
225 |
|
HostType :: mongooseim:host_type(), |
226 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
227 |
|
Params :: mod_inbox:entry_properties(), |
228 |
|
Ret :: mod_inbox:entry_properties() | {error, binary()}. |
229 |
|
set_entry_properties(HostType, InboxEntryKey, Params) -> |
230 |
102 |
Args = [HostType, InboxEntryKey, Params], |
231 |
102 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
232 |
|
|
233 |
|
callback_funs() -> |
234 |
56 |
[get_inbox, set_inbox, set_inbox_incr_unread, |
235 |
|
reset_unread, remove_inbox_row, clear_inbox, get_inbox_unread, |
236 |
|
get_full_entry, get_entry_properties, set_entry_properties, remove_domain]. |