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 |
|
-export([init/2, |
6 |
|
get_inbox/4, |
7 |
|
clear_inbox/3, |
8 |
|
remove_domain/2, |
9 |
|
set_inbox/6, |
10 |
|
remove_inbox_row/2, |
11 |
|
set_inbox_incr_unread/5, |
12 |
|
get_inbox_unread/2, |
13 |
|
get_entry_properties/2, |
14 |
|
set_entry_properties/3, |
15 |
|
reset_unread/3]). |
16 |
|
|
17 |
|
-define(MAIN_MODULE, mod_inbox). |
18 |
|
|
19 |
|
-callback init(HostType, Opts) -> ok when |
20 |
|
HostType :: mongooseim:host_type(), |
21 |
|
Opts :: list(). |
22 |
|
|
23 |
|
-callback get_inbox(HostType, LUser, LServer, Params) -> mod_inbox:get_inbox_res() when |
24 |
|
HostType :: mongooseim:host_type(), |
25 |
|
LUser :: jid:luser(), |
26 |
|
LServer :: jid:lserver(), |
27 |
|
Params :: mod_inbox:get_inbox_params(). |
28 |
|
|
29 |
|
-callback clear_inbox(HostType, LUser, LServer) -> mod_inbox:write_res() when |
30 |
|
HostType :: mongooseim:host_type(), |
31 |
|
LUser :: jid:luser(), |
32 |
|
LServer :: jid:lserver(). |
33 |
|
|
34 |
|
-callback remove_domain(HostType, LServer) -> ok when |
35 |
|
HostType :: mongooseim:host_type(), |
36 |
|
LServer :: jid:lserver(). |
37 |
|
|
38 |
|
-callback set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) -> |
39 |
|
mod_inbox:write_res() when |
40 |
|
HostType :: mongooseim:host_type(), |
41 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
42 |
|
Content :: binary(), |
43 |
|
Count :: integer(), |
44 |
|
MsgId :: binary(), |
45 |
|
Timestamp :: integer(). |
46 |
|
|
47 |
|
-callback remove_inbox_row(HostType, InboxEntryKey) -> mod_inbox:write_res() when |
48 |
|
HostType :: mongooseim:host_type(), |
49 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
50 |
|
|
51 |
|
-callback set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) -> |
52 |
|
mod_inbox:count_res() when |
53 |
|
HostType :: mongooseim:host_type(), |
54 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
55 |
|
Content :: binary(), |
56 |
|
MsgId :: binary(), |
57 |
|
Timestamp :: integer(). |
58 |
|
|
59 |
|
-callback reset_unread(HostType, InboxEntryKey, MsgId) -> mod_inbox:write_res() when |
60 |
|
HostType :: mongooseim:host_type(), |
61 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
62 |
|
MsgId :: binary(). |
63 |
|
|
64 |
|
-callback get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when |
65 |
|
HostType :: mongooseim:host_type(), |
66 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
67 |
|
|
68 |
|
-callback get_entry_properties(HostType, InboxEntryKey) -> Ret when |
69 |
|
HostType :: mongooseim:host_type(), |
70 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
71 |
|
Ret :: mod_inbox:entry_properties() | nil(). |
72 |
|
|
73 |
|
-callback set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when |
74 |
|
HostType :: mongooseim:host_type(), |
75 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
76 |
|
Params :: mod_inbox:entry_properties(), |
77 |
|
Ret :: mod_inbox:entry_properties() | {error, binary()}. |
78 |
|
|
79 |
|
-spec init(HostType, Opts) -> ok when |
80 |
|
HostType :: mongooseim:host_type(), |
81 |
|
Opts :: list(). |
82 |
|
init(HostType, Opts) -> |
83 |
25 |
mongoose_backend:init(HostType, ?MAIN_MODULE, callback_funs(), Opts), |
84 |
25 |
Args = [HostType, Opts], |
85 |
25 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
86 |
|
|
87 |
|
-spec get_inbox(HostType, LUser, LServer, Params) -> mod_inbox:get_inbox_res() when |
88 |
|
HostType :: mongooseim:host_type(), |
89 |
|
LUser :: jid:luser(), |
90 |
|
LServer :: jid:lserver(), |
91 |
|
Params :: mod_inbox:get_inbox_params(). |
92 |
|
get_inbox(HostType, LUser, LServer, Params) -> |
93 |
282 |
Args = [HostType, LUser, LServer, Params], |
94 |
282 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
95 |
|
|
96 |
|
-spec clear_inbox(HostType, LUser, LServer) -> mod_inbox:write_res() when |
97 |
|
HostType :: mongooseim:host_type(), |
98 |
|
LUser :: jid:luser(), |
99 |
|
LServer :: jid:lserver(). |
100 |
|
clear_inbox(HostType, LUser, LServer) -> |
101 |
219 |
Args = [HostType, LUser, LServer], |
102 |
219 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
103 |
|
|
104 |
|
-spec remove_domain(HostType, LServer) -> ok when |
105 |
|
HostType :: mongooseim:host_type(), |
106 |
|
LServer :: jid:lserver(). |
107 |
|
remove_domain(HostType, LServer) -> |
108 |
1 |
Args = [HostType, LServer], |
109 |
1 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
110 |
|
|
111 |
|
-spec set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) -> |
112 |
|
mod_inbox:write_res() when |
113 |
|
HostType :: mongooseim:host_type(), |
114 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
115 |
|
Content :: binary(), |
116 |
|
Count :: integer(), |
117 |
|
MsgId :: binary(), |
118 |
|
Timestamp :: integer(). |
119 |
|
set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) -> |
120 |
113 |
Args = [HostType, InboxEntryKey, Content, Count, MsgId, Timestamp], |
121 |
113 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
122 |
|
|
123 |
|
-spec remove_inbox_row(HostType, InboxEntryKey) -> mod_inbox:write_res() when |
124 |
|
HostType :: mongooseim:host_type(), |
125 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
126 |
|
remove_inbox_row(HostType, InboxEntryKey) -> |
127 |
5 |
Args = [HostType, InboxEntryKey], |
128 |
5 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
129 |
|
|
130 |
|
-spec set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) -> |
131 |
|
mod_inbox:count_res() when |
132 |
|
HostType :: mongooseim:host_type(), |
133 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
134 |
|
Content :: binary(), |
135 |
|
MsgId :: binary(), |
136 |
|
Timestamp :: integer(). |
137 |
|
set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) -> |
138 |
180 |
Args = [HostType, InboxEntryKey, Content, MsgId, Timestamp], |
139 |
180 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
140 |
|
|
141 |
|
-spec reset_unread(HostType, InboxEntryKey, MsgId) -> mod_inbox:write_res() when |
142 |
|
HostType :: mongooseim:host_type(), |
143 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
144 |
|
MsgId :: binary() | undefined. |
145 |
|
reset_unread(HostType, InboxEntryKey, MsgId) -> |
146 |
54 |
Args = [HostType, InboxEntryKey, MsgId], |
147 |
54 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
148 |
|
|
149 |
|
-spec get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when |
150 |
|
HostType :: mongooseim:host_type(), |
151 |
|
InboxEntryKey :: mod_inbox:entry_key(). |
152 |
|
get_inbox_unread(HostType, InboxEntryKey) -> |
153 |
:-( |
Args = [HostType, InboxEntryKey], |
154 |
:-( |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
155 |
|
|
156 |
|
-spec get_entry_properties(HostType, InboxEntryKey) -> Ret when |
157 |
|
HostType :: mongooseim:host_type(), |
158 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
159 |
|
Ret :: mod_inbox:entry_properties() | nil(). |
160 |
|
get_entry_properties(HostType, InboxEntryKey) -> |
161 |
1 |
Args = [HostType, InboxEntryKey], |
162 |
1 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
163 |
|
|
164 |
|
-spec set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when |
165 |
|
HostType :: mongooseim:host_type(), |
166 |
|
InboxEntryKey :: mod_inbox:entry_key(), |
167 |
|
Params :: mod_inbox:entry_properties(), |
168 |
|
Ret :: mod_inbox:entry_properties() | {error, binary()}. |
169 |
|
set_entry_properties(HostType, InboxEntryKey, Params) -> |
170 |
32 |
Args = [HostType, InboxEntryKey, Params], |
171 |
32 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
172 |
|
|
173 |
|
callback_funs() -> |
174 |
25 |
[get_inbox, set_inbox, set_inbox_incr_unread, |
175 |
|
reset_unread, remove_inbox_row, clear_inbox, get_inbox_unread, |
176 |
|
get_entry_properties, set_entry_properties, remove_domain]. |