mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-03 18:02:28 +01:00
Refactor pubsub's get_last_items
This commit is contained in:
parent
7bcbea2108
commit
c93bf732db
@ -145,6 +145,7 @@
|
|||||||
-record(pubsub_state,
|
-record(pubsub_state,
|
||||||
{
|
{
|
||||||
stateid ,% :: {jlib:ljid(), mod_pubsub:nodeIdx()},
|
stateid ,% :: {jlib:ljid(), mod_pubsub:nodeIdx()},
|
||||||
|
nodeidx ,% :: mod_pubsub:nodeIdx(),
|
||||||
items = [] ,% :: [mod_pubsub:itemId(),...],
|
items = [] ,% :: [mod_pubsub:itemId(),...],
|
||||||
affiliation = 'none',% :: mod_pubsub:affiliation(),
|
affiliation = 'none',% :: mod_pubsub:affiliation(),
|
||||||
subscriptions = [] % :: [{mod_pubsub:subscription(), mod_pubsub:subId()}]
|
subscriptions = [] % :: [{mod_pubsub:subscription(), mod_pubsub:subId()}]
|
||||||
@ -153,6 +154,7 @@
|
|||||||
-record(pubsub_item,
|
-record(pubsub_item,
|
||||||
{
|
{
|
||||||
itemid ,% :: {mod_pubsub:itemId(), mod_pubsub:nodeIdx()},
|
itemid ,% :: {mod_pubsub:itemId(), mod_pubsub:nodeIdx()},
|
||||||
|
nodeidx ,% :: mod_pubsub:nodeIdx(),
|
||||||
creation = {unknown, unknown},% :: {erlang:timestamp(), jlib:ljid()},
|
creation = {unknown, unknown},% :: {erlang:timestamp(), jlib:ljid()},
|
||||||
modification = {unknown, unknown},% :: {erlang:timestamp(), jlib:ljid()},
|
modification = {unknown, unknown},% :: {erlang:timestamp(), jlib:ljid()},
|
||||||
payload = [] % :: mod_pubsub:payload()
|
payload = [] % :: mod_pubsub:payload()
|
||||||
|
@ -183,6 +183,9 @@
|
|||||||
-callback get_items(nodeIdx(), jid(), undefined | rsm_set()) ->
|
-callback get_items(nodeIdx(), jid(), undefined | rsm_set()) ->
|
||||||
{result, {[pubsubItem()], undefined | rsm_set()}}.
|
{result, {[pubsubItem()], undefined | rsm_set()}}.
|
||||||
|
|
||||||
|
-callback get_last_items(nodeIdx(), jid(), undefined | rsm_set()) ->
|
||||||
|
{result, {[pubsubItem()], undefined | rsm_set()}}.
|
||||||
|
|
||||||
-callback get_item(NodeIdx :: nodeIdx(),
|
-callback get_item(NodeIdx :: nodeIdx(),
|
||||||
ItemId :: itemId(),
|
ItemId :: itemId(),
|
||||||
JID :: jid(),
|
JID :: jid(),
|
||||||
|
@ -152,6 +152,7 @@
|
|||||||
-type(pubsubState() ::
|
-type(pubsubState() ::
|
||||||
#pubsub_state{
|
#pubsub_state{
|
||||||
stateid :: {Entity::ljid(), Nidx::mod_pubsub:nodeIdx()},
|
stateid :: {Entity::ljid(), Nidx::mod_pubsub:nodeIdx()},
|
||||||
|
nodeidx :: Nidx::mod_pubsub:nodeIdx(),
|
||||||
items :: [ItemId::mod_pubsub:itemId()],
|
items :: [ItemId::mod_pubsub:itemId()],
|
||||||
affiliation :: Affs::mod_pubsub:affiliation(),
|
affiliation :: Affs::mod_pubsub:affiliation(),
|
||||||
subscriptions :: [{Sub::mod_pubsub:subscription(), SubId::mod_pubsub:subId()}]
|
subscriptions :: [{Sub::mod_pubsub:subscription(), SubId::mod_pubsub:subId()}]
|
||||||
@ -161,6 +162,7 @@
|
|||||||
-type(pubsubItem() ::
|
-type(pubsubItem() ::
|
||||||
#pubsub_item{
|
#pubsub_item{
|
||||||
itemid :: {ItemId::mod_pubsub:itemId(), Nidx::mod_pubsub:nodeIdx()},
|
itemid :: {ItemId::mod_pubsub:itemId(), Nidx::mod_pubsub:nodeIdx()},
|
||||||
|
nodeidx :: Nidx::mod_pubsub:nodeIdx(),
|
||||||
creation :: {erlang:timestamp(), ljid()},
|
creation :: {erlang:timestamp(), ljid()},
|
||||||
modification :: {erlang:timestamp(), ljid()},
|
modification :: {erlang:timestamp(), ljid()},
|
||||||
payload :: mod_pubsub:payload()
|
payload :: mod_pubsub:payload()
|
||||||
@ -2165,48 +2167,21 @@ get_allowed_items_call(Host, Nidx, From, Type, Options, Owners, RSM) ->
|
|||||||
{PS, RG} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
{PS, RG} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
node_call(Host, Type, get_items, [Nidx, From, AccessModel, PS, RG, undefined, RSM]).
|
node_call(Host, Type, get_items, [Nidx, From, AccessModel, PS, RG, undefined, RSM]).
|
||||||
|
|
||||||
get_last_item(Host, Type, Nidx, LJID) ->
|
get_last_items(Host, Type, Nidx, LJID, Count) ->
|
||||||
case get_cached_item(Host, Nidx) of
|
case node_action(Host, Type, get_last_items, [Nidx, LJID, Count]) of
|
||||||
undefined -> get_last_item(Host, Type, Nidx, LJID, gen_mod:db_type(serverhost(Host), ?MODULE));
|
|
||||||
LastItem -> LastItem
|
|
||||||
end.
|
|
||||||
get_last_item(Host, Type, Nidx, LJID, mnesia) ->
|
|
||||||
case node_action(Host, Type, get_items, [Nidx, LJID, undefined]) of
|
|
||||||
{result, {[LastItem|_], _}} -> LastItem;
|
|
||||||
_ -> undefined
|
|
||||||
end;
|
|
||||||
get_last_item(Host, Type, Nidx, LJID, sql) ->
|
|
||||||
case node_action(Host, Type, get_last_items, [Nidx, LJID, 1]) of
|
|
||||||
{result, [LastItem]} -> LastItem;
|
|
||||||
_ -> undefined
|
|
||||||
end;
|
|
||||||
get_last_item(_Host, _Type, _Nidx, _LJID, _) ->
|
|
||||||
undefined.
|
|
||||||
|
|
||||||
get_last_items(Host, Type, Nidx, LJID, Number) ->
|
|
||||||
get_last_items(Host, Type, Nidx, LJID, Number, gen_mod:db_type(serverhost(Host), ?MODULE)).
|
|
||||||
get_last_items(Host, Type, Nidx, LJID, Number, mnesia) ->
|
|
||||||
case node_action(Host, Type, get_items, [Nidx, LJID, undefined]) of
|
|
||||||
{result, {Items, _}} -> lists:sublist(Items, Number);
|
|
||||||
_ -> []
|
|
||||||
end;
|
|
||||||
get_last_items(Host, Type, Nidx, LJID, Number, sql) ->
|
|
||||||
case node_action(Host, Type, get_last_items, [Nidx, LJID, Number]) of
|
|
||||||
{result, Items} -> Items;
|
{result, Items} -> Items;
|
||||||
_ -> []
|
_ -> []
|
||||||
end;
|
end.
|
||||||
get_last_items(_Host, _Type, _Nidx, _LJID, _Number, _) ->
|
|
||||||
[].
|
|
||||||
|
|
||||||
%% @doc <p>Resend the items of a node to the user.</p>
|
%% @doc <p>Resend the items of a node to the user.</p>
|
||||||
%% @todo use cache-last-item feature
|
%% @todo use cache-last-item feature
|
||||||
send_items(Host, Node, Nidx, Type, Options, LJID, last) ->
|
send_items(Host, Node, Nidx, Type, Options, LJID, last) ->
|
||||||
case get_last_item(Host, Type, Nidx, LJID) of
|
case get_last_items(Host, Type, Nidx, LJID, 1) of
|
||||||
undefined ->
|
[LastItem] ->
|
||||||
ok;
|
|
||||||
LastItem ->
|
|
||||||
Stanza = items_event_stanza(Node, Options, [LastItem]),
|
Stanza = items_event_stanza(Node, Options, [LastItem]),
|
||||||
dispatch_items(Host, LJID, Node, Stanza)
|
dispatch_items(Host, LJID, Node, Stanza);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
end;
|
end;
|
||||||
send_items(Host, Node, Nidx, Type, Options, LJID, Number) when Number > 0 ->
|
send_items(Host, Node, Nidx, Type, Options, LJID, Number) when Number > 0 ->
|
||||||
Stanza = items_event_stanza(Node, Options, get_last_items(Host, Type, Nidx, Number, LJID)),
|
Stanza = items_event_stanza(Node, Options, get_last_items(Host, Type, Nidx, Number, LJID)),
|
||||||
@ -2566,28 +2541,21 @@ get_subscriptions(Host, Node, JID) ->
|
|||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_subscriptions_for_send_last(Host, PType, mnesia, JID, LJID, BJID) ->
|
get_subscriptions_for_send_last(Host, PType, sql, JID, LJID, BJID) ->
|
||||||
|
{result, Subs} = node_action(Host, PType,
|
||||||
|
get_entity_subscriptions_for_send_last,
|
||||||
|
[Host, JID]),
|
||||||
|
[{Node, Sub, SubId, SubJID}
|
||||||
|
|| {Node, Sub, SubId, SubJID} <- Subs,
|
||||||
|
Sub =:= subscribed, (SubJID == LJID) or (SubJID == BJID)];
|
||||||
|
get_subscriptions_for_send_last(Host, PType, _, JID, LJID, BJID) ->
|
||||||
{result, Subs} = node_action(Host, PType,
|
{result, Subs} = node_action(Host, PType,
|
||||||
get_entity_subscriptions,
|
get_entity_subscriptions,
|
||||||
[Host, JID]),
|
[Host, JID]),
|
||||||
[{Node, Sub, SubId, SubJID}
|
[{Node, Sub, SubId, SubJID}
|
||||||
|| {Node, Sub, SubId, SubJID} <- Subs,
|
|| {Node, Sub, SubId, SubJID} <- Subs,
|
||||||
Sub =:= subscribed, (SubJID == LJID) or (SubJID == BJID),
|
Sub =:= subscribed, (SubJID == LJID) or (SubJID == BJID),
|
||||||
match_option(Node, send_last_published_item, on_sub_and_presence)];
|
match_option(Node, send_last_published_item, on_sub_and_presence)].
|
||||||
get_subscriptions_for_send_last(Host, PType, sql, JID, LJID, BJID) ->
|
|
||||||
case catch node_action(Host, PType,
|
|
||||||
get_entity_subscriptions_for_send_last,
|
|
||||||
[Host, JID])
|
|
||||||
of
|
|
||||||
{result, Subs} ->
|
|
||||||
[{Node, Sub, SubId, SubJID}
|
|
||||||
|| {Node, Sub, SubId, SubJID} <- Subs,
|
|
||||||
Sub =:= subscribed, (SubJID == LJID) or (SubJID == BJID)];
|
|
||||||
_ ->
|
|
||||||
[]
|
|
||||||
end;
|
|
||||||
get_subscriptions_for_send_last(_Host, _PType, _, _JID, _LJID, _BJID) ->
|
|
||||||
[].
|
|
||||||
|
|
||||||
-spec set_subscriptions(host(), binary(), jid(), [ps_subscription()]) ->
|
-spec set_subscriptions(host(), binary(), jid(), [ps_subscription()]) ->
|
||||||
{result, undefined} | {error, stanza_error()}.
|
{result, undefined} | {error, stanza_error()}.
|
||||||
@ -3202,28 +3170,18 @@ filter_node_options(Options, BaseOptions) ->
|
|||||||
|
|
||||||
-spec node_owners_action(host(), binary(), nodeIdx(), [ljid()]) -> [ljid()].
|
-spec node_owners_action(host(), binary(), nodeIdx(), [ljid()]) -> [ljid()].
|
||||||
node_owners_action(Host, Type, Nidx, []) ->
|
node_owners_action(Host, Type, Nidx, []) ->
|
||||||
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
case node_action(Host, Type, get_node_affiliations, [Nidx]) of
|
||||||
sql ->
|
{result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
|
||||||
case node_action(Host, Type, get_node_affiliations, [Nidx]) of
|
_ -> []
|
||||||
{result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
|
|
||||||
_ -> []
|
|
||||||
end;
|
|
||||||
_ ->
|
|
||||||
[]
|
|
||||||
end;
|
end;
|
||||||
node_owners_action(_Host, _Type, _Nidx, Owners) ->
|
node_owners_action(_Host, _Type, _Nidx, Owners) ->
|
||||||
Owners.
|
Owners.
|
||||||
|
|
||||||
-spec node_owners_call(host(), binary(), nodeIdx(), [ljid()]) -> [ljid()].
|
-spec node_owners_call(host(), binary(), nodeIdx(), [ljid()]) -> [ljid()].
|
||||||
node_owners_call(Host, Type, Nidx, []) ->
|
node_owners_call(Host, Type, Nidx, []) ->
|
||||||
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
case node_call(Host, Type, get_node_affiliations, [Nidx]) of
|
||||||
sql ->
|
{result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
|
||||||
case node_call(Host, Type, get_node_affiliations, [Nidx]) of
|
_ -> []
|
||||||
{result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
|
|
||||||
_ -> []
|
|
||||||
end;
|
|
||||||
_ ->
|
|
||||||
[]
|
|
||||||
end;
|
end;
|
||||||
node_owners_call(_Host, _Type, _Nidx, Owners) ->
|
node_owners_call(_Host, _Type, _Nidx, Owners) ->
|
||||||
Owners.
|
Owners.
|
||||||
@ -3468,23 +3426,15 @@ tree(Host) ->
|
|||||||
Tree -> Tree
|
Tree -> Tree
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec tree(host(), binary() | atom()) -> atom().
|
-spec tree(host(), binary()) -> atom().
|
||||||
tree(_Host, <<"virtual">>) ->
|
tree(_Host, <<"virtual">>) ->
|
||||||
nodetree_virtual; % special case, virtual does not use any backend
|
nodetree_virtual; % special case, virtual does not use any backend
|
||||||
tree(Host, Name) ->
|
tree(Host, Name) ->
|
||||||
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
submodule(Host, <<"nodetree_", Name/binary>>).
|
||||||
mnesia -> aux:binary_to_atom(<<"nodetree_", Name/binary>>);
|
|
||||||
sql -> aux:binary_to_atom(<<"nodetree_", Name/binary, "_sql">>);
|
|
||||||
_ -> Name
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec plugin(host(), binary() | atom()) -> atom().
|
-spec plugin(host(), binary()) -> atom().
|
||||||
plugin(Host, Name) ->
|
plugin(Host, Name) ->
|
||||||
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
submodule(Host, <<"node_", Name/binary>>).
|
||||||
mnesia -> aux:binary_to_atom(<<"node_", Name/binary>>);
|
|
||||||
sql -> aux:binary_to_atom(<<"node_", Name/binary, "_sql">>);
|
|
||||||
_ -> Name
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec plugins(host()) -> [binary()].
|
-spec plugins(host()) -> [binary()].
|
||||||
plugins(Host) ->
|
plugins(Host) ->
|
||||||
@ -3494,14 +3444,16 @@ plugins(Host) ->
|
|||||||
Plugins -> Plugins
|
Plugins -> Plugins
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec subscription_plugin(host()) -> pubsub_subscription |
|
-spec subscription_plugin(host()) -> atom().
|
||||||
pubsub_subscription_sql |
|
|
||||||
none.
|
|
||||||
subscription_plugin(Host) ->
|
subscription_plugin(Host) ->
|
||||||
|
submodule(Host, <<"pubsub_subscription">>).
|
||||||
|
|
||||||
|
-spec submodule(host(), binary()) -> atom().
|
||||||
|
submodule(Host, Name) ->
|
||||||
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
||||||
mnesia -> pubsub_subscription;
|
mnesia -> aux:binary_to_atom(Name);
|
||||||
sql -> pubsub_subscription_sql;
|
Type -> aux:binary_to_atom(<<Name/binary, "_",
|
||||||
_ -> none
|
(jlib:atom_to_binary(Type))/binary>>)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec config(binary(), any()) -> any().
|
-spec config(binary(), any()) -> any().
|
||||||
@ -3614,9 +3566,14 @@ tree_action(Host, Function, Args) ->
|
|||||||
{error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)}
|
{error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)}
|
||||||
end;
|
end;
|
||||||
Other ->
|
Other ->
|
||||||
?ERROR_MSG("unsupported backend: ~p~n", [Other]),
|
case catch Fun() of
|
||||||
ErrTxt = <<"Database failure">>,
|
{'EXIT', _} ->
|
||||||
{error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)}
|
?ERROR_MSG("unsupported backend: ~p~n", [Other]),
|
||||||
|
ErrTxt = <<"Database failure">>,
|
||||||
|
{error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)};
|
||||||
|
Result ->
|
||||||
|
Result
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc <p>node plugin call.</p>
|
%% @doc <p>node plugin call.</p>
|
||||||
@ -3684,7 +3641,7 @@ transaction_retry(Host, ServerHost, Fun, Trans, DBType, Count) ->
|
|||||||
end,
|
end,
|
||||||
catch ejabberd_sql:SqlFun(ServerHost, Fun);
|
catch ejabberd_sql:SqlFun(ServerHost, Fun);
|
||||||
_ ->
|
_ ->
|
||||||
{unsupported, DBType}
|
catch Fun()
|
||||||
end,
|
end,
|
||||||
case Res of
|
case Res of
|
||||||
{result, Result} ->
|
{result, Result} ->
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -157,6 +158,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -156,6 +157,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -144,6 +145,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_hometree:get_items(Nidx, JID, AccessModel,
|
node_hometree:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_hometree:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_hometree:get_item(Nidx, ItemId).
|
node_hometree:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -170,6 +171,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_hometree:get_items(Nidx, JID, AccessModel,
|
node_hometree:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_hometree:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_hometree:get_item(Nidx, ItemId).
|
node_hometree:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -46,17 +46,18 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1, can_fetch_item/2, is_subscribed/1]).
|
path_to_node/1, can_fetch_item/2, is_subscribed/1, transform/1]).
|
||||||
|
|
||||||
init(_Host, _ServerHost, _Opts) ->
|
init(_Host, _ServerHost, _Opts) ->
|
||||||
%pubsub_subscription:init(Host, ServerHost, Opts),
|
%pubsub_subscription:init(Host, ServerHost, Opts),
|
||||||
ejabberd_mnesia:create(?MODULE, pubsub_state,
|
ejabberd_mnesia:create(?MODULE, pubsub_state,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]}, {index, [nodeidx]},
|
||||||
{type, ordered_set},
|
{type, ordered_set},
|
||||||
{attributes, record_info(fields, pubsub_state)}]),
|
{attributes, record_info(fields, pubsub_state)}]),
|
||||||
ejabberd_mnesia:create(?MODULE, pubsub_item,
|
ejabberd_mnesia:create(?MODULE, pubsub_item,
|
||||||
[{disc_only_copies, [node()]},
|
[{disc_only_copies, [node()]}, {index, [nodeidx]},
|
||||||
{attributes, record_info(fields, pubsub_item)}]),
|
{attributes, record_info(fields, pubsub_item)}]),
|
||||||
ejabberd_mnesia:create(?MODULE, pubsub_orphan,
|
ejabberd_mnesia:create(?MODULE, pubsub_orphan,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
@ -131,7 +132,7 @@ create_node_permission(Host, ServerHost, _Node, _ParentNode, Owner, Access) ->
|
|||||||
create_node(Nidx, Owner) ->
|
create_node(Nidx, Owner) ->
|
||||||
OwnerKey = jid:tolower(jid:remove_resource(Owner)),
|
OwnerKey = jid:tolower(jid:remove_resource(Owner)),
|
||||||
set_state(#pubsub_state{stateid = {OwnerKey, Nidx},
|
set_state(#pubsub_state{stateid = {OwnerKey, Nidx},
|
||||||
affiliation = owner}),
|
nodeidx = Nidx, affiliation = owner}),
|
||||||
{result, {default, broadcast}}.
|
{result, {default, broadcast}}.
|
||||||
|
|
||||||
delete_node(Nodes) ->
|
delete_node(Nodes) ->
|
||||||
@ -382,6 +383,7 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload,
|
|||||||
payload = Payload};
|
payload = Payload};
|
||||||
_ ->
|
_ ->
|
||||||
#pubsub_item{itemid = {ItemId, Nidx},
|
#pubsub_item{itemid = {ItemId, Nidx},
|
||||||
|
nodeidx = Nidx,
|
||||||
creation = {Now, GenKey},
|
creation = {Now, GenKey},
|
||||||
modification = PubId,
|
modification = PubId,
|
||||||
payload = Payload}
|
payload = Payload}
|
||||||
@ -681,8 +683,7 @@ get_nodes_helper(NodeTree, #pubsub_state{stateid = {_, N}, subscriptions = Subs}
|
|||||||
%% ```get_states(Nidx) ->
|
%% ```get_states(Nidx) ->
|
||||||
%% node_default:get_states(Nidx).'''</p>
|
%% node_default:get_states(Nidx).'''</p>
|
||||||
get_states(Nidx) ->
|
get_states(Nidx) ->
|
||||||
States = case catch mnesia:match_object(
|
States = case catch mnesia:index_read(pubsub_state, Nidx, #pubsub_state.nodeidx) of
|
||||||
#pubsub_state{stateid = {'_', Nidx}, _ = '_'}) of
|
|
||||||
List when is_list(List) -> List;
|
List when is_list(List) -> List;
|
||||||
_ -> []
|
_ -> []
|
||||||
end,
|
end,
|
||||||
@ -693,7 +694,7 @@ get_state(Nidx, Key) ->
|
|||||||
StateId = {Key, Nidx},
|
StateId = {Key, Nidx},
|
||||||
case catch mnesia:read({pubsub_state, StateId}) of
|
case catch mnesia:read({pubsub_state, StateId}) of
|
||||||
[State] when is_record(State, pubsub_state) -> State;
|
[State] when is_record(State, pubsub_state) -> State;
|
||||||
_ -> #pubsub_state{stateid = StateId}
|
_ -> #pubsub_state{stateid = StateId, nodeidx = Nidx}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc <p>Write a state into database.</p>
|
%% @doc <p>Write a state into database.</p>
|
||||||
@ -725,7 +726,7 @@ del_state(#pubsub_state{stateid = {Key, Nidx}, items = Items}) ->
|
|||||||
%% <p>PubSub plugins can store the items where they wants (for example in a
|
%% <p>PubSub plugins can store the items where they wants (for example in a
|
||||||
%% relational database), or they can even decide not to persist any items.</p>
|
%% relational database), or they can even decide not to persist any items.</p>
|
||||||
get_items(Nidx, _From, _RSM) ->
|
get_items(Nidx, _From, _RSM) ->
|
||||||
Items = mnesia:match_object(#pubsub_item{itemid = {'_', Nidx}, _ = '_'}),
|
Items = mnesia:index_read(pubsub_item, Nidx, #pubsub_item.nodeidx),
|
||||||
{result, {lists:reverse(lists:keysort(#pubsub_item.modification, Items)), undefined}}.
|
{result, {lists:reverse(lists:keysort(#pubsub_item.modification, Items)), undefined}}.
|
||||||
|
|
||||||
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM) ->
|
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM) ->
|
||||||
@ -764,6 +765,12 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM
|
|||||||
get_items(Nidx, JID, RSM)
|
get_items(Nidx, JID, RSM)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) when Count > 0 ->
|
||||||
|
{result, {Items, _}} = get_items(Nidx, From, undefined),
|
||||||
|
{result, lists:sublist(Items, Count)};
|
||||||
|
get_last_items(_Nidx, _From, _Count) ->
|
||||||
|
{result, []}.
|
||||||
|
|
||||||
%% @doc <p>Returns an item (one item list), given its reference.</p>
|
%% @doc <p>Returns an item (one item list), given its reference.</p>
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
@ -868,3 +875,10 @@ first_in_list(Pred, [H | T]) ->
|
|||||||
true -> {value, H};
|
true -> {value, H};
|
||||||
_ -> first_in_list(Pred, T)
|
_ -> first_in_list(Pred, T)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
transform({pubsub_state, {Id, Nidx}, Is, A, Ss}) ->
|
||||||
|
{pubsub_state, {Id, Nidx}, Nidx, Is, A, Ss};
|
||||||
|
transform({pubsub_item, {Id, Nidx}, C, M, P}) ->
|
||||||
|
{pubsub_item, {Id, Nidx}, Nidx, C, M, P};
|
||||||
|
transform(Rec) ->
|
||||||
|
Rec.
|
||||||
|
@ -615,10 +615,11 @@ get_state_without_itemids(Nidx, JID) ->
|
|||||||
"where nodeid=%(Nidx)d and jid=%(J)s")) of
|
"where nodeid=%(Nidx)d and jid=%(J)s")) of
|
||||||
{selected, [{SJID, Aff, Subs}]} ->
|
{selected, [{SJID, Aff, Subs}]} ->
|
||||||
#pubsub_state{stateid = {decode_jid(SJID), Nidx},
|
#pubsub_state{stateid = {decode_jid(SJID), Nidx},
|
||||||
|
nodeidx = Nidx,
|
||||||
affiliation = decode_affiliation(Aff),
|
affiliation = decode_affiliation(Aff),
|
||||||
subscriptions = decode_subscriptions(Subs)};
|
subscriptions = decode_subscriptions(Subs)};
|
||||||
_ ->
|
_ ->
|
||||||
#pubsub_state{stateid = {JID, Nidx}}
|
#pubsub_state{stateid = {JID, Nidx}, nodeidx = Nidx}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_state(State) ->
|
set_state(State) ->
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -154,6 +155,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -171,6 +172,9 @@ get_items(Nidx, From, RSM) ->
|
|||||||
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
|
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
|
||||||
node_pep:get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM).
|
node_pep:get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_pep:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_pep:get_item(Nidx, ItemId).
|
node_pep:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -161,6 +162,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1, get_entity_subscriptions_for_send_last/2]).
|
path_to_node/1, get_entity_subscriptions_for_send_last/2]).
|
||||||
|
|
||||||
@ -161,6 +162,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat_sql:get_items(Nidx, JID, AccessModel,
|
node_flat_sql:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat_sql:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat_sql:get_item(Nidx, ItemId).
|
node_flat_sql:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -156,6 +157,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1, depends/3]).
|
path_to_node/1, depends/3]).
|
||||||
|
|
||||||
@ -228,6 +229,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -156,6 +157,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
|
get_last_items/3,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1]).
|
path_to_node/1]).
|
||||||
|
|
||||||
@ -156,6 +157,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
node_flat:get_items(Nidx, JID, AccessModel,
|
node_flat:get_items(Nidx, JID, AccessModel,
|
||||||
PresenceSubscription, RosterGroup, SubId, RSM).
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
||||||
|
|
||||||
|
get_last_items(Nidx, From, Count) ->
|
||||||
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user