aboutsummaryrefslogtreecommitdiff
path: root/src/mod_pubsub/nodetree_tree.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mod_pubsub/nodetree_tree.erl')
-rw-r--r--src/mod_pubsub/nodetree_tree.erl60
1 files changed, 35 insertions, 25 deletions
diff --git a/src/mod_pubsub/nodetree_tree.erl b/src/mod_pubsub/nodetree_tree.erl
index ba8168f52..39160e7b5 100644
--- a/src/mod_pubsub/nodetree_tree.erl
+++ b/src/mod_pubsub/nodetree_tree.erl
@@ -56,7 +56,7 @@
get_parentnodes_tree/3,
get_subnodes/3,
get_subnodes_tree/3,
- create_node/5,
+ create_node/6,
delete_node/2
]).
@@ -160,13 +160,13 @@ get_parentnodes_tree(Host, Node, From) ->
%% From = mod_pubsub:jid()
get_subnodes(Host, Node, _From) ->
get_subnodes(Host, Node).
+get_subnodes(Host, <<>>) ->
+ Q = qlc:q([N || #pubsub_node{nodeid = {NHost, _},
+ parents = Parents} = N <- mnesia:table(pubsub_node),
+ Host == NHost,
+ Parents == []]),
+ qlc:e(Q);
get_subnodes(Host, Node) ->
-% mnesia:foldl(fun(#pubsub_node{nodeid = {H, _}, parents = Parents} = N, Acc) ->
-% case lists:member(Node, Parents) and (Host == H) of
-% true -> [N | Acc];
-% false -> Acc
-% end
-% end, [], pubsub_node).
Q = qlc:q([N || #pubsub_node{nodeid = {NHost, _},
parents = Parents} = N <- mnesia:table(pubsub_node),
Host == NHost,
@@ -181,12 +181,21 @@ get_subnodes_tree(Host, Node, _From) ->
%% Node = mod_pubsub:pubsubNode()
%% From = mod_pubsub:jid()
get_subnodes_tree(Host, Node) ->
- mnesia:foldl(fun(#pubsub_node{nodeid = {H, N}} = R, Acc) ->
- case lists:prefix(Node, N) and (H == Host) of
- true -> [R | Acc];
- false -> Acc
- end
- end, [], pubsub_node).
+ case get_node(Host, Node) of
+ {error, _} ->
+ [];
+ Rec ->
+ BasePlugin = list_to_atom("node_"++Rec#pubsub_node.type),
+ BasePath = BasePlugin:node_to_path(Node),
+ mnesia:foldl(fun(#pubsub_node{nodeid = {H, N}} = R, Acc) ->
+ Plugin = list_to_atom("node_"++R#pubsub_node.type),
+ Path = Plugin:node_to_path(N),
+ case lists:prefix(BasePath, Path) and (H == Host) of
+ true -> [R | Acc];
+ false -> Acc
+ end
+ end, [], pubsub_node)
+ end.
%% @spec (Host, Node, Type, Owner, Options) -> ok | {error, Reason}
%% Host = mod_pubsub:host() | mod_pubsub:jid()
@@ -194,26 +203,27 @@ get_subnodes_tree(Host, Node) ->
%% NodeType = mod_pubsub:nodeType()
%% Owner = mod_pubsub:jid()
%% Options = list()
-create_node(Host, Node, Type, Owner, Options) ->
+create_node(Host, Node, Type, Owner, Options, Parents) ->
BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
case catch mnesia:read({pubsub_node, {Host, Node}}) of
[] ->
- {ParentNode, ParentExists} =
+ ParentExists =
case Host of
{_U, _S, _R} ->
%% This is special case for PEP handling
%% PEP does not uses hierarchy
- {[], true};
+ true;
_ ->
- case lists:sublist(Node, length(Node) - 1) of
- [] ->
- {[], true};
- Parent ->
+ case Parents of
+ [] -> true;
+ [Parent|_] ->
case catch mnesia:read({pubsub_node, {Host, Parent}}) of
- [#pubsub_node{owners = [{[], Host, []}]}] -> {Parent, true};
- [#pubsub_node{owners = Owners}] -> {Parent, lists:member(BJID, Owners)};
- _ -> {Parent, false}
- end
+ [#pubsub_node{owners = [{[], Host, []}]}] -> true;
+ [#pubsub_node{owners = Owners}] -> lists:member(BJID, Owners);
+ _ -> false
+ end;
+ _ ->
+ false
end
end,
case ParentExists of
@@ -221,7 +231,7 @@ create_node(Host, Node, Type, Owner, Options) ->
NodeId = pubsub_index:new(node),
mnesia:write(#pubsub_node{nodeid = {Host, Node},
id = NodeId,
- parents = [ParentNode],
+ parents = Parents,
type = Type,
owners = [BJID],
options = Options}),