From 8b588d2ff3c83608869c291e7bc07d645470f2c6 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Wed, 25 Oct 2017 10:34:11 +0200 Subject: [PATCH] Add basic PubSub meta-data support (#1421) --- rebar.config | 2 +- src/mod_pubsub.erl | 18 +++++++++++++++--- src/node_flat.erl | 1 - 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/rebar.config b/rebar.config index f24a16777..36f4e96c4 100644 --- a/rebar.config +++ b/rebar.config @@ -25,7 +25,7 @@ {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.16"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.24"}}}, - {xmpp, ".*", {git, "https://github.com/processone/xmpp", "d551ba9"}}, + {xmpp, ".*", {git, "https://github.com/processone/xmpp", "6c8f891"}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.11"}}}, {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_pubsub.erl b/src/mod_pubsub.erl index 780b47491..22e095e7a 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -829,7 +829,8 @@ process_disco_info(#iq{from = From, to = To, lang = Lang, type = get, [ServerHost, ?MODULE, <<>>, <<>>]), case iq_disco_info(Host, Node, From, Lang) of {result, IQRes} -> - xmpp:make_iq_result(IQ, IQRes#disco_info{node = Node, xdata = Info}); + XData = IQRes#disco_info.xdata ++ Info, + xmpp:make_iq_result(IQ, IQRes#disco_info{node = Node, xdata = XData}); {error, Error} -> xmpp:make_error(IQ, Error) end. @@ -938,14 +939,25 @@ node_disco_info(Host, Node, From) -> {result, disco_info()} | {error, stanza_error()}. node_disco_info(Host, Node, _From, _Identity, _Features) -> Action = - fun(#pubsub_node{type = Type, options = Options}) -> + fun(#pubsub_node{id = Nidx, type = Type, options = Options}) -> NodeType = case get_option(Options, node_type) of collection -> <<"collection">>; _ -> <<"leaf">> end, + Affs = case node_call(Host, Type, get_node_affiliations, [Nidx]) of + {result, Result} -> Result; + _ -> [] + end, + Meta = [{title, get_option(Options, title, <<>>)}, + {description, get_option(Options, description, <<>>)}, + {owner, [LJID || {LJID, Aff} <- Affs, Aff =:= owner]}, + {publisher, [LJID || {LJID, Aff} <- Affs, Aff =:= publisher]}, + {num_subscribers, length([LJID || {LJID, Aff} <- Affs, Aff =:= subscriber])}], + XData = #xdata{type = result, + fields = pubsub_meta_data:encode(Meta)}, Is = [#identity{category = <<"pubsub">>, type = NodeType}], Fs = [?NS_PUBSUB | [feature(F) || F <- plugin_features(Host, Type)]], - {result, #disco_info{identities = Is, features = Fs}} + {result, #disco_info{identities = Is, features = Fs, xdata = [XData]}} end, case transaction(Host, Node, Action, sync_dirty) of {result, {_, Result}} -> {result, Result}; diff --git a/src/node_flat.erl b/src/node_flat.erl index 2c11edde7..d63f589ec 100644 --- a/src/node_flat.erl +++ b/src/node_flat.erl @@ -88,7 +88,6 @@ options() -> {max_payload_size, ?MAX_PAYLOAD_SIZE}, {send_last_published_item, on_sub_and_presence}, {deliver_notifications, true}, - {title, <<>>}, {presence_based_delivery, false}, {itemreply, none}].