aboutsummaryrefslogtreecommitdiff
path: root/src/nodetree_virtual.erl
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2015-12-17 10:16:17 +0100
committerChristophe Romain <christophe.romain@process-one.net>2015-12-17 10:16:17 +0100
commitbb5a8a42c31048bc1004b54528699dae51f5a418 (patch)
tree8ab1394fda1b43cd1438beeba7b1cad4f3f0f481 /src/nodetree_virtual.erl
parentFix last item message type as message attribute (diff)
Fix pubsub virtual nodetree plugin
Diffstat (limited to 'src/nodetree_virtual.erl')
-rw-r--r--src/nodetree_virtual.erl43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/nodetree_virtual.erl b/src/nodetree_virtual.erl
index f9c7d4eb4..9fc9b53c5 100644
--- a/src/nodetree_virtual.erl
+++ b/src/nodetree_virtual.erl
@@ -59,15 +59,12 @@ get_node(Host, Node, _From) ->
get_node(Host, Node).
get_node(Host, Node) ->
- get_node(nodeidx(Host, Node)).
+ Nidx = nodeidx(Host, Node),
+ node_record(Host, Node, Nidx).
get_node(Nidx) ->
{Host, Node} = nodeid(Nidx),
- [Type|_] = mod_pubsub:plugins(Host),
- Module = mod_pubsub:plugin(Host, Type),
- #pubsub_node{nodeid = Node, id = Nidx, type = Type,
- owners = [{<<"">>, Host, <<"">>}],
- options = Module:options()}.
+ node_record(Host, Node, Nidx).
get_nodes(Host, _From) ->
get_nodes(Host).
@@ -79,10 +76,7 @@ get_parentnodes(_Host, _Node, _From) ->
[].
get_parentnodes_tree(Host, Node, From) ->
- case get_node(Host, Node, From) of
- Node when is_record(Node, pubsub_node) -> [{0, [Node]}];
- _Error -> []
- end.
+ [{0, [get_node(Host, Node, From)]}].
get_subnodes(Host, Node, _From) ->
get_subnodes(Host, Node).
@@ -97,12 +91,35 @@ get_subnodes_tree(_Host, _Node) ->
[].
create_node(Host, Node, _Type, _Owner, _Options, _Parents) ->
- {error, {virtual, {Host, Node}}}.
+ {error, {virtual, nodeidx(Host, Node)}}.
delete_node(Host, Node) ->
[get_node(Host, Node)].
%% internal helper
-nodeidx(Host, Node) -> term_to_binary({Host, Node}).
-nodeid(Nidx) -> binary_to_term(Nidx).
+node_record({U,S,R}, Node, Nidx) ->
+ Host = mod_pubsub:host(S),
+ Type = <<"pep">>,
+ Module = mod_pubsub:plugin(Host, Type),
+ #pubsub_node{nodeid = {{U,S,R},Node}, id = Nidx, type = Type,
+ owners = [{U,S,R}],
+ options = Module:options()};
+node_record(Host, Node, Nidx) ->
+ [Type|_] = mod_pubsub:plugins(Host),
+ Module = mod_pubsub:plugin(Host, Type),
+ #pubsub_node{nodeid = {Host, Node}, id = Nidx, type = Type,
+ owners = [{<<"">>, Host, <<"">>}],
+ options = Module:options()}.
+
+nodeidx({U,S,R}, Node) ->
+ JID = jid:to_string(jid:make(U,S,R)),
+ <<JID/binary, ":", Node/binary>>;
+nodeidx(Host, Node) ->
+ <<Host/binary, ":", Node/binary>>.
+nodeid(Nidx) ->
+ [Head, Node] = binary:split(Nidx, <<":">>),
+ case jid:from_string(Head) of
+ {jid,<<>>,Host,<<>>,_,_,_} -> {Host, Node};
+ {jid,U,S,R,_,_,_} -> {{U,S,R}, Node}
+ end.