From 5b6d042de221c3a8f23b73f5eff55c9a16df6698 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Mon, 27 Mar 2017 16:24:24 +0200 Subject: [PATCH] Fix PEP issues (#1636) --- src/mod_caps.erl | 6 +++--- src/mod_pubsub.erl | 35 ++++++++++++----------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/mod_caps.erl b/src/mod_caps.erl index f8c8e3a30..f542e7494 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -92,12 +92,12 @@ get_features(Host, #caps{node = Node, version = Version, -spec list_features(ejabberd_c2s:state()) -> [{ljid(), caps()}]. list_features(C2SState) -> - Rs = maps:get(caps_features, C2SState, gb_trees:empty()), + Rs = maps:get(caps_resources, C2SState, gb_trees:empty()), gb_trees:to_list(Rs). -spec get_user_caps(jid(), ejabberd_c2s:state()) -> {ok, caps()} | error. get_user_caps(JID, C2SState) -> - Rs = maps:get(caps_features, C2SState, gb_trees:empty()), + Rs = maps:get(caps_resources, C2SState, gb_trees:empty()), LJID = jid:tolower(JID), case gb_trees:lookup(LJID, Rs) of {value, Caps} -> @@ -209,7 +209,7 @@ c2s_presence_in(C2SState, Delete = (Type == unavailable) or (Type == error), if Insert or Delete -> LFrom = jid:tolower(From), - Rs = maps:get(caps_resources, C2SState, gb_trees:empty()), + Rs = maps:get(caps_resources, C2SState, gb_trees:empty()), Caps = read_caps(Presence), NewRs = case Caps of nothing when Insert == true -> Rs; diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index a0ac8643e..cc86fd22c 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -1215,7 +1215,7 @@ iq_pubsub(Host, Access, #iq{from = From, type = IQType, lang = Lang, create_node(Host, ServerHost, Node, From, Type, Access, Config) end; {set, #pubsub{publish = #ps_publish{node = Node, items = Items}, - publish_options = XData, _ = undefined}} -> + publish_options = XData, configure = _, _ = undefined}} -> ServerHost = serverhost(Host), case Items of [#ps_item{id = ItemId, xml_els = Payload}] -> @@ -2215,23 +2215,12 @@ send_items(Host, Node, _Nidx, _Type, Options, LJID, _) -> Stanza = items_event_stanza(Node, Options, []), dispatch_items(Host, LJID, Node, Stanza). -dispatch_items({FromU, FromS, FromR} = From, {ToU, ToS, ToR} = To, - Node, Stanza) -> - C2SPid = case ejabberd_sm:get_session_pid(ToU, ToS, ToR) of - ToPid when is_pid(ToPid) -> ToPid; - _ -> - R = user_resource(FromU, FromS, FromR), - case ejabberd_sm:get_session_pid(FromU, FromS, R) of - FromPid when is_pid(FromPid) -> FromPid; - _ -> undefined - end - end, - if C2SPid == undefined -> ok; - true -> - C2SPid ! {send_filtered, {pep_message, <>}, - service_jid(From), jid:make(To), - Stanza} - end; +dispatch_items({FromU, FromS, FromR}, To, Node, Stanza) -> + SenderResource = user_resource(FromU, FromS, FromR), + ejabberd_sm:route(jid:make(FromU, FromS, SenderResource), + {send_filtered, {pep_message, <<((Node))/binary, "+notify">>}, + jid:make(FromU, FromS), jid:make(To), + Stanza}); dispatch_items(From, To, _Node, Stanza) -> ejabberd_router:route( xmpp:set_from_to(Stanza, service_jid(From), jid:make(To))). @@ -3016,11 +3005,11 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, Nidx, Type, NodeO broadcast_stanza({LUser, LServer, <<>>}, Node, Nidx, Type, NodeOptions, SubsByDepth, NotifyType, BaseStanza, SHIM), %% Handles implicit presence subscriptions SenderResource = user_resource(LUser, LServer, LResource), - NotificationType = get_option(NodeOptions, notification_type, headline), - Stanza = add_message_type(BaseStanza, NotificationType), - %% set the from address on the notification to the bare JID of the account owner - %% Also, add "replyto" if entity has presence subscription to the account owner - %% See XEP-0163 1.1 section 4.3.1 + NotificationType = get_option(NodeOptions, notification_type, headline), + Stanza = add_message_type(BaseStanza, NotificationType), + %% set the from address on the notification to the bare JID of the account owner + %% Also, add "replyto" if entity has presence subscription to the account owner + %% See XEP-0163 1.1 section 4.3.1 ejabberd_sm:route(jid:make(LUser, LServer, SenderResource), {pep_message, <<((Node))/binary, "+notify">>, jid:make(LUser, LServer),