25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

fix pubsub#title option (EJAB-1190) (thanks karim)

This commit is contained in:
Christophe Romain 2010-03-05 15:45:31 +01:00
parent 7d97830ad7
commit 3c36cd64e3
3 changed files with 72 additions and 54 deletions

View File

@ -1116,11 +1116,15 @@ iq_disco_items(Host, [], From) ->
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, type = Type}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]),
[Name | _] = lists:reverse(Path),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host),
?XMLATTR('name', Name) | nodeAttr(SubNode)]}
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
Attrs =
case get_option(Options, title) of
false ->
[?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, Nodes)};
Other ->
Other
@ -1151,10 +1155,15 @@ iq_disco_items(Host, Item, From) ->
_ -> []
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]),
[Name|_] = lists:reverse(Path),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name) | nodeAttr(SubNode)]}
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
Attrs =
case get_option(Options, title) of
false ->
[?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, tree_call(Host, get_subnodes, [Host, Node, From])),
Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) ->

View File

@ -924,11 +924,15 @@ iq_disco_items(Host, [], From, _RSM) ->
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, type = Type}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]),
[Name | _] = lists:reverse(Path),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host),
?XMLATTR('name', Name) | nodeAttr(SubNode)]}
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
Attrs =
case get_option(Options, title) of
false ->
[?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, Nodes)};
Other ->
Other
@ -959,10 +963,15 @@ iq_disco_items(Host, Item, From, RSM) ->
_ -> {[], none}
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]),
[Name|_] = lists:reverse(Path),
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name) | nodeAttr(SubNode)]}
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
Attrs =
case get_option(Options, title) of
false ->
[?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, tree_call(Host, get_subnodes, [Host, Node, From])),
Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) ->

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-03-05 15:35:25.000000000 +0100
+++ mod_pubsub_odbc.erl 2010-03-05 15:37:52.000000000 +0100
--- mod_pubsub.erl 2010-03-05 15:44:11.000000000 +0100
+++ mod_pubsub_odbc.erl 2010-03-05 15:45:00.000000000 +0100
@@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18.
@ -371,7 +371,7 @@
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
@@ -1125,7 +933,7 @@
@@ -1129,7 +937,7 @@
Other ->
Other
end;
@ -380,7 +380,7 @@
%% TODO: support localization of this string
CommandItems = [
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
@@ -1134,10 +942,10 @@
@@ -1138,10 +946,10 @@
?XMLATTR('name', "Get Pending")
]}],
{result, CommandItems};
@ -393,7 +393,7 @@
case string:tokens(Item, "!") of
[_SNode, _ItemID] ->
{result, []};
@@ -1145,10 +953,10 @@
@@ -1149,10 +957,10 @@
Node = string_to_node(SNode),
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -406,8 +406,8 @@
+ _ -> {[], none}
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
@@ -1159,9 +967,10 @@
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
@@ -1168,9 +976,10 @@
Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
@ -420,7 +420,7 @@
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result};
@@ -1292,7 +1101,8 @@
@@ -1301,7 +1110,8 @@
(_, Acc) ->
Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -430,7 +430,7 @@
{get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} ->
@@ -1314,8 +1124,9 @@
@@ -1323,8 +1133,9 @@
end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
@ -442,7 +442,7 @@
case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
@@ -1449,7 +1260,8 @@
@@ -1458,7 +1269,8 @@
_ -> []
end
end,
@ -452,7 +452,7 @@
sync_dirty) of
{result, Res} -> Res;
Err -> Err
@@ -1493,7 +1305,7 @@
@@ -1502,7 +1314,7 @@
%%% authorization handling
@ -461,7 +461,7 @@
Lang = "en", %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
@@ -1523,7 +1335,7 @@
@@ -1532,7 +1344,7 @@
lists:foreach(fun(Owner) ->
{U, S, R} = Owner,
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
@ -470,7 +470,7 @@
find_authorization_response(Packet) ->
Els = Packet#xmlel.children,
@@ -1565,7 +1377,7 @@
@@ -1574,7 +1386,7 @@
end,
Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
@ -479,7 +479,7 @@
}]),
ejabberd_router:route(service_jid(Host), JID, Stanza).
@@ -1576,14 +1388,14 @@
@@ -1585,14 +1397,14 @@
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
{value, {_, [SAllow]}}} ->
Node = string_to_node(SNode),
@ -497,7 +497,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if
not IsApprover ->
@@ -1778,7 +1590,7 @@
@@ -1787,7 +1599,7 @@
end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
@ -506,7 +506,7 @@
{result, {Result, broadcast}} ->
%%Lang = "en", %% TODO: fix
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
@@ -1887,7 +1699,7 @@
@@ -1896,7 +1708,7 @@
%%<li>The node does not exist.</li>
%%</ul>
subscribe_node(Host, Node, From, JID, Configuration) ->
@ -515,7 +515,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -1897,7 +1709,7 @@
@@ -1906,7 +1718,7 @@
_:_ ->
{undefined, undefined, undefined}
end,
@ -524,7 +524,7 @@
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@@ -1916,9 +1728,13 @@
@@ -1925,9 +1737,13 @@
{"", "", ""} ->
{false, false};
_ ->
@ -541,7 +541,7 @@
end
end,
if
@@ -2251,7 +2067,7 @@
@@ -2260,7 +2076,7 @@
%% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right
%% to read the items.
@ -550,7 +550,7 @@
MaxItems =
if
SMaxItems == "" -> get_max_items_node(Host);
@@ -2290,11 +2106,11 @@
@@ -2299,11 +2115,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
@ -564,7 +564,7 @@
SendItems = case ItemIDs of
[] ->
Items;
@@ -2307,7 +2123,7 @@
@@ -2316,7 +2132,7 @@
%% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -573,7 +573,7 @@
Error ->
Error
end
@@ -2339,17 +2155,29 @@
@@ -2348,17 +2164,29 @@
%% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -610,7 +610,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2479,29 +2307,12 @@
@@ -2488,29 +2316,12 @@
error ->
{error, 'bad-request'};
_ ->
@ -643,7 +643,7 @@
end, Entities),
{result, []};
_ ->
@@ -2556,11 +2367,11 @@
@@ -2565,11 +2376,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -657,7 +657,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('Subid', SubID) | nodeAttr(Node)],
@@ -2587,7 +2398,7 @@
@@ -2596,7 +2407,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -666,7 +666,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2617,7 +2428,7 @@
@@ -2626,7 +2437,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
@ -675,7 +675,7 @@
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@@ -2790,8 +2601,8 @@
@@ -2799,8 +2610,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router:route(service_jid(Host), JID, Stanza)
end,
@ -686,7 +686,7 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3080,7 +2891,7 @@
@@ -3089,7 +2900,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
@ -695,7 +695,7 @@
{result, CollSubs} -> CollSubs;
_ -> []
end.
@@ -3094,9 +2905,9 @@
@@ -3103,9 +2914,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -707,7 +707,7 @@
_ -> Acc
end;
(_, Acc) ->
@@ -3104,7 +2915,7 @@
@@ -3113,7 +2924,7 @@
end, [], Subs).
% TODO: merge broadcast code that way
@ -716,7 +716,7 @@
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
% case (get_option(NodeOptions, Feature) or Force) of
% true ->
@@ -3303,6 +3114,30 @@
@@ -3312,6 +3123,30 @@
Result
end.
@ -747,7 +747,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3698,7 +3533,13 @@
@@ -3707,7 +3542,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -762,7 +762,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3718,13 +3559,13 @@
@@ -3727,13 +3568,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -778,7 +778,7 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3737,8 +3578,15 @@
@@ -3746,8 +3587,15 @@
end
end, Trans).
@ -796,7 +796,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3746,6 +3594,15 @@
@@ -3755,6 +3603,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'};
@ -812,7 +812,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'};
@@ -3754,6 +3611,16 @@
@@ -3763,6 +3620,16 @@
{error, 'internal-server-error'}
end.