25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Fix pending nodes retrieval for SQL backend

Thanks to Christophe Romain
This commit is contained in:
Evgeny Khramtsov 2019-07-17 12:34:09 +03:00
parent 2171abf5ae
commit 38b2e099d5

View File

@ -546,41 +546,26 @@ unsub_with_subid(Nidx, SubId, SubState) ->
end. end.
get_pending_nodes(Host, Owner) -> get_pending_nodes(Host, Owner) ->
GenKey = jid:remove_resource(jid:tolower(Owner)), GenKey = encode_jid(jid:remove_resource(jid:tolower(Owner))),
States = mnesia:match_object(#pubsub_state{stateid = {GenKey, '_'}, PendingIdxs = case ejabberd_sql:sql_query_t(
affiliation = owner, _ = '_'}), ?SQL("select @(nodeid)d from pubsub_state "
Nidxxs = [Nidx || #pubsub_state{stateid = {_, Nidx}} <- States], "where subscriptions like '%p%' and affiliation='o'"
"and jid=%(GenKey)s")) of
{selected, RItems} ->
[Nidx || {Nidx} <- RItems];
_ ->
[]
end,
NodeTree = mod_pubsub:tree(Host), NodeTree = mod_pubsub:tree(Host),
Reply = mnesia:foldl(fun (#pubsub_state{stateid = {_, Nidx}} = S, Acc) -> Reply = lists:foldl(fun(Nidx, Acc) ->
case lists:member(Nidx, Nidxxs) of case NodeTree:get_node(Nidx) of
true -> #pubsub_node{nodeid = {_, Node}} -> [Node | Acc];
case get_nodes_helper(NodeTree, S) of _ -> Acc
{value, Node} -> [Node | Acc]; end
false -> Acc end,
end; [], PendingIdxs),
false ->
Acc
end
end,
[], pubsub_state),
{result, Reply}. {result, Reply}.
get_nodes_helper(NodeTree, #pubsub_state{stateid = {_, N}, subscriptions = Subs}) ->
HasPending = fun
({pending, _}) -> true;
(pending) -> true;
(_) -> false
end,
case lists:any(HasPending, Subs) of
true ->
case NodeTree:get_node(N) of
#pubsub_node{nodeid = {_, Node}} -> {value, Node};
_ -> false
end;
false ->
false
end.
get_states(Nidx) -> get_states(Nidx) ->
case ejabberd_sql:sql_query_t( case ejabberd_sql:sql_query_t(
?SQL("select @(jid)s, @(affiliation)s, @(subscriptions)s " ?SQL("select @(jid)s, @(affiliation)s, @(subscriptions)s "