From db41643bea919848e3154ea2bd15f920b554da10 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Mon, 18 Sep 2017 14:17:34 +0300 Subject: [PATCH] Also replace vcard-x-update in direct presences --- src/mod_vcard_xupdate.erl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mod_vcard_xupdate.erl b/src/mod_vcard_xupdate.erl index d34cffa83..7643fed4a 100644 --- a/src/mod_vcard_xupdate.erl +++ b/src/mod_vcard_xupdate.erl @@ -31,7 +31,7 @@ -export([start/2, stop/1, reload/3]). -export([update_presence/1, vcard_set/1, remove_user/2, - mod_opt_type/1, depends/2]). + user_send_packet/1, mod_opt_type/1, depends/2]). -include("ejabberd.hrl"). -include("logger.hrl"). @@ -47,6 +47,8 @@ start(Host, Opts) -> init_cache(Host, Opts), ejabberd_hooks:add(c2s_self_presence, Host, ?MODULE, update_presence, 100), + ejabberd_hooks:add(user_send_packet, Host, ?MODULE, + user_send_packet, 50), ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, vcard_set, 90), ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50). @@ -54,6 +56,8 @@ start(Host, Opts) -> stop(Host) -> ejabberd_hooks:delete(c2s_self_presence, Host, ?MODULE, update_presence, 100), + ejabberd_hooks:delete(user_send_packet, Host, ?MODULE, + user_send_packet, 50), ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_set, 90), ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50). @@ -79,6 +83,18 @@ update_presence({#presence{type = available} = Pres, update_presence(Acc) -> Acc. +-spec user_send_packet({presence(), ejabberd_c2s:state()}) + -> {presence(), ejabberd_c2s:state()}. +user_send_packet({#presence{type = available, + to = #jid{luser = U, lserver = S, + lresource = <<"">>}}, + #{jid := #jid{luser = U, lserver = S}}} = Acc) -> + %% This is processed by update_presence/2 explicitly, we don't + %% want to call this multiple times for performance reasons + Acc; +user_send_packet(Acc) -> + update_presence(Acc). + -spec vcard_set(iq()) -> iq(). vcard_set(#iq{from = #jid{luser = LUser, lserver = LServer}} = IQ) -> ets_cache:delete(?VCARD_XUPDATE_CACHE, {LUser, LServer}),