1 |
|
%%%---------------------------------------------------------------------- |
2 |
|
%%% File : mod_offline_stub.erl |
3 |
|
%%% Author : Radek Szymczyszyn |
4 |
|
%%% <radoslaw.szymczyszyn@erlang-solutions.com> |
5 |
|
%%% Purpose : Silence <service-unavailable/> when not using mod_offline |
6 |
|
%%% but using mod_mam for message persistence. |
7 |
|
%%% |
8 |
|
%%% RFC 6121 requires a <service-unavailable/> stanza error |
9 |
|
%%% to be sent to a user messaging an unavailable recipient |
10 |
|
%%% if the message is not stored for delayed delivery |
11 |
|
%%% (i.e. as an "offline message"). |
12 |
|
%%% If the recipient exists (i.e. auth module returns `true` |
13 |
|
%%% from `does_user_exist`) mod_mam stores the message, |
14 |
|
%%% but <service-unavailable/> is still returned, |
15 |
|
%%% what is not compliant with the RFC. |
16 |
|
%%% |
17 |
|
%%% This module prevents returning <service-unavailable/>. |
18 |
|
%%% See : RFC 6121 8.5.2.2.1 |
19 |
|
%%% License : GNU GPLv2 or (at your option) any later version |
20 |
|
%%% |
21 |
|
%%% MongooseIM, Copyright (C) 2014 Erlang Solutions |
22 |
|
%%%---------------------------------------------------------------------- |
23 |
|
|
24 |
|
-module(mod_offline_stub). |
25 |
|
-author('mongoose-im@erlang-solutions.com'). |
26 |
|
-behaviour(gen_mod). |
27 |
|
-behaviour(mongoose_module_metrics). |
28 |
|
|
29 |
|
%% gen_mod callbacks |
30 |
|
-export([start/2, |
31 |
|
stop/1, |
32 |
|
hooks/1, |
33 |
|
supported_features/0]). |
34 |
|
|
35 |
|
%% Hook handlers |
36 |
|
-export([stop_hook_processing/3]). |
37 |
|
|
38 |
|
-spec start(any(), any()) -> 'ok'. |
39 |
|
start(_HostType, _Opts) -> |
40 |
2 |
ok. |
41 |
|
|
42 |
|
-spec stop(any()) -> 'ok'. |
43 |
|
stop(_HostType) -> |
44 |
2 |
ok. |
45 |
|
|
46 |
:-( |
supported_features() -> [dynamic_domains]. |
47 |
|
|
48 |
|
-spec hooks(mongooseim:host_type()) -> gen_hook:hook_list(). |
49 |
|
hooks(HostType) -> |
50 |
4 |
[{offline_message_hook, HostType, fun ?MODULE:stop_hook_processing/3, #{}, 75}]. |
51 |
|
|
52 |
|
-spec stop_hook_processing(Acc, Params, Extra) -> {stop, Acc} when |
53 |
|
Acc :: mongoose_acc:t(), |
54 |
|
Params :: map(), |
55 |
|
Extra :: gen_hook:extra(). |
56 |
|
stop_hook_processing(Acc, _Params, _Extra) -> |
57 |
9 |
{stop, Acc}. |