From 5fd1aa0d046aedc4d3b61a150899085ad863ca0f Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Wed, 16 Dec 2015 00:08:23 +0100 Subject: [PATCH] Advertise MAM in disco info for account/room JID As per XEP-0313 version 0.2 and newer, advertise the MAM feature in the service discovery information for the bare account (or MUC room) JID. Some clients check the server's discovery information instead, so we'll continue to advertise the feature there as well. --- src/mod_mam.erl | 17 +++++++++++++++-- src/mod_muc_room.erl | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/mod_mam.erl b/src/mod_mam.erl index 54572fb09..dba8b1cbf 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -34,8 +34,8 @@ -export([start/2, stop/1]). -export([user_send_packet/4, user_receive_packet/5, - process_iq_v0_2/3, process_iq_v0_3/3, remove_user/2, - remove_user/3, mod_opt_type/1, muc_process_iq/4, + process_iq_v0_2/3, process_iq_v0_3/3, disco_sm_features/5, + remove_user/2, remove_user/3, mod_opt_type/1, muc_process_iq/4, muc_filter_message/5]). -include_lib("stdlib/include/ms_transform.hrl"). @@ -88,6 +88,8 @@ start(Host, Opts) -> muc_filter_message, 50), ejabberd_hooks:add(muc_process_iq, Host, ?MODULE, muc_process_iq, 50), + ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, + disco_sm_features, 50), ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50), ejabberd_hooks:add(anonymous_purge_hook, Host, ?MODULE, @@ -130,6 +132,8 @@ stop(Host) -> gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_0), gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MAM_1), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_1), + ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, + disco_sm_features, 50), ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50), ejabberd_hooks:delete(anonymous_purge_hook, Host, @@ -276,6 +280,15 @@ get_xdata_fields(SubEl) -> [] end. +disco_sm_features(empty, From, To, Node, Lang) -> + disco_sm_features({result, []}, From, To, Node, Lang); +disco_sm_features({result, OtherFeatures}, + #jid{luser = U, lserver = S}, + #jid{luser = U, lserver = S}, <<>>, _Lang) -> + {result, [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1 | OtherFeatures]}; +disco_sm_features(Acc, _From, _To, _Node, _Lang) -> + Acc. + %%%=================================================================== %%% Internal functions %%%=================================================================== diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index dd7f78163..1606b593a 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -4144,6 +4144,13 @@ process_iq_disco_info(_From, get, Lang, StateData) -> <<"muc_moderated">>, <<"muc_unmoderated">>), ?CONFIG_OPT_TO_FEATURE((Config#config.password_protected), <<"muc_passwordprotected">>, <<"muc_unsecured">>)] + ++ case {gen_mod:is_loaded(StateData#state.server_host, mod_mam), + Config#config.mam} of + {true, true} -> + [?FEATURE(?NS_MAM_0)]; + _ -> + [] + end ++ iq_disco_info_extras(Lang, StateData), StateData}.