From e0557b9e26ba0b2fbaf23a5fa38277193dd045df Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 26 Apr 2015 17:16:52 +0200 Subject: [PATCH] Advertise feature in disco info for account JID As per XEP-0313 >= 0.2, advertise the MAM feature in the service discovery information for the bare account JID. Some clients check the server's discovery information instead, so we'll continue to advertise the feature there as well (at least for the moment). --- mod_mam/src/mod_mam.erl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mod_mam/src/mod_mam.erl b/mod_mam/src/mod_mam.erl index 371a712..0ab0dd7 100644 --- a/mod_mam/src/mod_mam.erl +++ b/mod_mam/src/mod_mam.erl @@ -50,7 +50,8 @@ code_change/3]). %% ejabberd_hooks callbacks. --export([receive_stanza/4, +-export([disco_features/5, + receive_stanza/4, send_stanza/3, remove_user/2]). @@ -157,7 +158,9 @@ start(Host, Opts) -> parallel), gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM, ?MODULE, handle_iq, IQDisc), + %% Set up MAM feature announcement. mod_disco:register_feature(Host, ?NS_MAM), + ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, disco_features, 50), %% Set up message storage process. Proc = gen_mod:get_module_proc(Host, ?PROCNAME), Spec = {Proc, {?MODULE, start_link, [Host, Opts]}, permanent, 3000, worker, @@ -167,6 +170,8 @@ start(Host, Opts) -> -spec stop(binary()) -> ok. stop(Host) -> + ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, disco_features, 50), + %% Stop message storage process. Proc = gen_mod:get_module_proc(Host, ?PROCNAME), ok = supervisor:terminate_child(ejabberd_sup, Proc), ok = supervisor:delete_child(ejabberd_sup, Proc). @@ -258,6 +263,17 @@ code_change(_OldVsn, #state{host = Host} = State, _Extra) -> %% ejabberd_hooks callbacks. %%-------------------------------------------------------------------- +-spec disco_features(empty | {result, [binary()]}, jid(), jid(), binary(), + binary()) -> {result, [binary()]}. + +disco_features(empty, From, To, Node, Lang) -> + disco_features({result, []}, From, To, Node, Lang); +disco_features({result, OtherFeatures}, + #jid{luser = U, lserver = S}, + #jid{luser = U, lserver = S}, <<"">>, _Lang) -> + {result, OtherFeatures ++ [?NS_MAM]}; +disco_features(Acc, _From, _To, _Node, _Lang) -> Acc. + -spec receive_stanza(jid(), jid(), jid(), xmlel()) -> ok. receive_stanza(#jid{luser = U, lserver = S} = JID, From, To,