mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Fulfill all requirements of XEP-0398 v0.2.0
These include:
- Avoid rewriting vcard❌update tags with empty <photo/> element
- Advertise "urn:xmpp:pep-vcard-conversion:0" feature
This commit is contained in:
parent
e15595df64
commit
ddc29d42de
@ -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"}}},
|
||||
|
@ -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
|
||||
%%%===================================================================
|
||||
|
@ -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}) ->
|
||||
case xmpp:get_subtag(Pres, #vcard_xupdate{}) of
|
||||
#vcard_xupdate{hash = <<>>} ->
|
||||
%% XEP-0398 forbids overwriting vcard:x:update
|
||||
%% tags with empty <photo/> 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};
|
||||
{Pres1, State}
|
||||
end;
|
||||
update_presence(Acc) ->
|
||||
Acc.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user