diff --git a/rebar.config b/rebar.config index 098b19cff..143de5774 100644 --- a/rebar.config +++ b/rebar.config @@ -25,7 +25,7 @@ {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.20"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "dbf173f"}}}, - {xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "2bb82b29"}}}, + {xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "0a1c76e"}}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.12"}}}, {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}}, {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}}, diff --git a/src/mod_avatar.erl b/src/mod_avatar.erl index 640f5f6b4..45999e885 100644 --- a/src/mod_avatar.erl +++ b/src/mod_avatar.erl @@ -26,7 +26,8 @@ %% gen_mod API -export([start/2, stop/1, reload/3, depends/2, mod_opt_type/1, mod_options/1]). %% Hooks --export([pubsub_publish_item/6, vcard_iq_convert/1, vcard_iq_publish/1]). +-export([pubsub_publish_item/6, vcard_iq_convert/1, vcard_iq_publish/1, + get_sm_features/5]). -include("xmpp.hrl"). -include("logger.hrl"). @@ -43,13 +44,17 @@ start(Host, _Opts) -> ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, vcard_iq_convert, 30), ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, - vcard_iq_publish, 100). + vcard_iq_publish, 100), + ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, + get_sm_features, 50). stop(Host) -> ejabberd_hooks:delete(pubsub_publish_item, Host, ?MODULE, pubsub_publish_item, 50), ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_convert, 30), - ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_publish, 100). + ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_publish, 100), + ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, + get_sm_features, 50). reload(_Host, _NewOpts, _OldOpts) -> ok. @@ -144,6 +149,20 @@ vcard_iq_publish(#iq{sub_els = [#vcard_temp{ vcard_iq_publish(Acc) -> Acc. +-spec get_sm_features({error, stanza_error()} | empty | {result, [binary()]}, + jid(), jid(), binary(), binary()) -> + {error, stanza_error()} | empty | {result, [binary()]}. +get_sm_features({error, _Error} = Acc, _From, _To, _Node, _Lang) -> + Acc; +get_sm_features(Acc, _From, _To, <<"">>, _Lang) -> + {result, [?NS_DISCO_INFO, ?NS_PEP_VCARD_CONVERSION_0 | + case Acc of + {result, Features} -> Features; + empty -> [] + end]}; +get_sm_features(Acc, _From, _To, _Node, _Lang) -> + Acc. + %%%=================================================================== %%% Internal functions %%%=================================================================== diff --git a/src/mod_vcard_xupdate.erl b/src/mod_vcard_xupdate.erl index 597ff41a8..867e5ae25 100644 --- a/src/mod_vcard_xupdate.erl +++ b/src/mod_vcard_xupdate.erl @@ -24,9 +24,10 @@ %%%---------------------------------------------------------------------- -module(mod_vcard_xupdate). - -behaviour(gen_mod). +-protocol({xep, 398, '0.2.0'}). + %% gen_mod callbacks -export([start/2, stop/1, reload/3]). @@ -75,11 +76,18 @@ depends(_Host, _Opts) -> -> {presence(), ejabberd_c2s:state()}. update_presence({#presence{type = available} = Pres, #{jid := #jid{luser = LUser, lserver = LServer}} = State}) -> - Pres1 = case get_xupdate(LUser, LServer) of - undefined -> xmpp:remove_subtag(Pres, #vcard_xupdate{}); - XUpdate -> xmpp:set_subtag(Pres, XUpdate) - end, - {Pres1, State}; + case xmpp:get_subtag(Pres, #vcard_xupdate{}) of + #vcard_xupdate{hash = <<>>} -> + %% XEP-0398 forbids overwriting vcard:x:update + %% tags with empty element + {Pres, State}; + _ -> + Pres1 = case get_xupdate(LUser, LServer) of + undefined -> xmpp:remove_subtag(Pres, #vcard_xupdate{}); + XUpdate -> xmpp:set_subtag(Pres, XUpdate) + end, + {Pres1, State} + end; update_presence(Acc) -> Acc.