mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Enforce affiliation removal, remove corresponding items (#1320)
This commit is contained in:
parent
a50247c20d
commit
2976c2d921
@ -137,9 +137,8 @@ delete_node(Nodes) ->
|
|||||||
end,
|
end,
|
||||||
Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
|
Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
|
||||||
{result, States} = get_states(Nidx),
|
{result, States} = get_states(Nidx),
|
||||||
lists:foreach(fun (#pubsub_state{stateid = {LJID, _}, items = Items}) ->
|
lists:foreach(fun (State) ->
|
||||||
del_items(Nidx, Items),
|
del_state(State)
|
||||||
del_state(Nidx, LJID)
|
|
||||||
end, States),
|
end, States),
|
||||||
{PubsubNode, lists:flatmap(Tr, States)}
|
{PubsubNode, lists:flatmap(Tr, States)}
|
||||||
end, Nodes),
|
end, Nodes),
|
||||||
@ -286,7 +285,7 @@ unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
|
|||||||
SubState#pubsub_state.subscriptions),
|
SubState#pubsub_state.subscriptions),
|
||||||
case Sub of
|
case Sub of
|
||||||
{value, S} ->
|
{value, S} ->
|
||||||
delete_subscriptions(SubKey, Nidx, [S], SubState),
|
delete_subscriptions(SubState, [S]),
|
||||||
{result, default};
|
{result, default};
|
||||||
false ->
|
false ->
|
||||||
{error,
|
{error,
|
||||||
@ -294,11 +293,11 @@ unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
|
|||||||
end;
|
end;
|
||||||
%% Asking to remove all subscriptions to the given node
|
%% Asking to remove all subscriptions to the given node
|
||||||
SubId == all ->
|
SubId == all ->
|
||||||
delete_subscriptions(SubKey, Nidx, Subscriptions, SubState),
|
delete_subscriptions(SubState, Subscriptions),
|
||||||
{result, default};
|
{result, default};
|
||||||
%% No subid supplied, but there's only one matching subscription
|
%% No subid supplied, but there's only one matching subscription
|
||||||
length(Subscriptions) == 1 ->
|
length(Subscriptions) == 1 ->
|
||||||
delete_subscriptions(SubKey, Nidx, Subscriptions, SubState),
|
delete_subscriptions(SubState, Subscriptions),
|
||||||
{result, default};
|
{result, default};
|
||||||
%% No subid and more than one possible subscription match.
|
%% No subid and more than one possible subscription match.
|
||||||
true ->
|
true ->
|
||||||
@ -306,13 +305,13 @@ unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
|
|||||||
mod_pubsub:extended_error((xmpp:err_bad_request()), mod_pubsub:err_subid_required())}
|
mod_pubsub:extended_error((xmpp:err_bad_request()), mod_pubsub:err_subid_required())}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
delete_subscriptions(SubKey, Nidx, Subscriptions, SubState) ->
|
delete_subscriptions(SubState, Subscriptions) ->
|
||||||
NewSubs = lists:foldl(fun ({Subscription, SubId}, Acc) ->
|
NewSubs = lists:foldl(fun ({Subscription, SubId}, Acc) ->
|
||||||
%%pubsub_subscription:delete_subscription(SubKey, Nidx, SubId),
|
%%pubsub_subscription:delete_subscription(SubKey, Nidx, SubId),
|
||||||
Acc -- [{Subscription, SubId}]
|
Acc -- [{Subscription, SubId}]
|
||||||
end, SubState#pubsub_state.subscriptions, Subscriptions),
|
end, SubState#pubsub_state.subscriptions, Subscriptions),
|
||||||
case {SubState#pubsub_state.affiliation, NewSubs} of
|
case {SubState#pubsub_state.affiliation, NewSubs} of
|
||||||
{none, []} -> del_state(Nidx, SubKey);
|
{none, []} -> del_state(SubState);
|
||||||
_ -> set_state(SubState#pubsub_state{subscriptions = NewSubs})
|
_ -> set_state(SubState#pubsub_state{subscriptions = NewSubs})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -515,7 +514,7 @@ set_affiliation(Nidx, Owner, Affiliation) ->
|
|||||||
GenKey = jid:remove_resource(SubKey),
|
GenKey = jid:remove_resource(SubKey),
|
||||||
GenState = get_state(Nidx, GenKey),
|
GenState = get_state(Nidx, GenKey),
|
||||||
case {Affiliation, GenState#pubsub_state.subscriptions} of
|
case {Affiliation, GenState#pubsub_state.subscriptions} of
|
||||||
{none, []} -> del_state(Nidx, GenKey);
|
{none, []} -> del_state(GenState);
|
||||||
_ -> set_state(GenState#pubsub_state{affiliation = Affiliation})
|
_ -> set_state(GenState#pubsub_state{affiliation = Affiliation})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -588,7 +587,7 @@ set_subscriptions(Nidx, Owner, Subscription, SubId) ->
|
|||||||
end;
|
end;
|
||||||
{<<>>, [{_, SID}]} ->
|
{<<>>, [{_, SID}]} ->
|
||||||
case Subscription of
|
case Subscription of
|
||||||
none -> unsub_with_subid(Nidx, SID, SubState);
|
none -> unsub_with_subid(SubState, SID);
|
||||||
_ -> replace_subscription({Subscription, SID}, SubState)
|
_ -> replace_subscription({Subscription, SID}, SubState)
|
||||||
end;
|
end;
|
||||||
{<<>>, [_ | _]} ->
|
{<<>>, [_ | _]} ->
|
||||||
@ -596,7 +595,7 @@ set_subscriptions(Nidx, Owner, Subscription, SubId) ->
|
|||||||
mod_pubsub:extended_error((xmpp:err_bad_request()), mod_pubsub:err_subid_required())};
|
mod_pubsub:extended_error((xmpp:err_bad_request()), mod_pubsub:err_subid_required())};
|
||||||
_ ->
|
_ ->
|
||||||
case Subscription of
|
case Subscription of
|
||||||
none -> unsub_with_subid(Nidx, SubId, SubState);
|
none -> unsub_with_subid(SubState, SubId);
|
||||||
_ -> replace_subscription({Subscription, SubId}, SubState)
|
_ -> replace_subscription({Subscription, SubId}, SubState)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
@ -616,13 +615,13 @@ new_subscription(_Nidx, _Owner, Sub, SubState) ->
|
|||||||
set_state(SubState#pubsub_state{subscriptions = [{Sub, SubId} | Subs]}),
|
set_state(SubState#pubsub_state{subscriptions = [{Sub, SubId} | Subs]}),
|
||||||
{Sub, SubId}.
|
{Sub, SubId}.
|
||||||
|
|
||||||
unsub_with_subid(Nidx, SubId, #pubsub_state{stateid = {Entity, _}} = SubState) ->
|
unsub_with_subid(SubState, SubId) ->
|
||||||
%%pubsub_subscription:delete_subscription(SubState#pubsub_state.stateid, Nidx, SubId),
|
%%pubsub_subscription:delete_subscription(SubState#pubsub_state.stateid, Nidx, SubId),
|
||||||
NewSubs = [{S, Sid}
|
NewSubs = [{S, Sid}
|
||||||
|| {S, Sid} <- SubState#pubsub_state.subscriptions,
|
|| {S, Sid} <- SubState#pubsub_state.subscriptions,
|
||||||
SubId =/= Sid],
|
SubId =/= Sid],
|
||||||
case {NewSubs, SubState#pubsub_state.affiliation} of
|
case {NewSubs, SubState#pubsub_state.affiliation} of
|
||||||
{[], none} -> del_state(Nidx, Entity);
|
{[], none} -> del_state(SubState);
|
||||||
_ -> set_state(SubState#pubsub_state{subscriptions = NewSubs})
|
_ -> set_state(SubState#pubsub_state{subscriptions = NewSubs})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -697,8 +696,9 @@ set_state(State) when is_record(State, pubsub_state) ->
|
|||||||
%set_state(_) -> {error, ?ERR_INTERNAL_SERVER_ERROR}.
|
%set_state(_) -> {error, ?ERR_INTERNAL_SERVER_ERROR}.
|
||||||
|
|
||||||
%% @doc <p>Delete a state from database.</p>
|
%% @doc <p>Delete a state from database.</p>
|
||||||
del_state(Nidx, Key) ->
|
del_state(#pubsub_state{stateid = {LJID, Nidx}, items = Items}) ->
|
||||||
mnesia:delete({pubsub_state, {Key, Nidx}}).
|
del_items(Nidx, Items),
|
||||||
|
mnesia:delete({pubsub_state, {LJID, Nidx}}).
|
||||||
|
|
||||||
%% @doc Returns the list of stored items for a given node.
|
%% @doc Returns the list of stored items for a given node.
|
||||||
%% <p>For the default PubSub module, items are stored in Mnesia database.</p>
|
%% <p>For the default PubSub module, items are stored in Mnesia database.</p>
|
||||||
|
@ -641,6 +641,9 @@ set_state(Nidx, State) ->
|
|||||||
|
|
||||||
del_state(Nidx, JID) ->
|
del_state(Nidx, JID) ->
|
||||||
J = encode_jid(JID),
|
J = encode_jid(JID),
|
||||||
|
catch ejabberd_sql:sql_query_t(
|
||||||
|
?SQL("delete from pubsub_item where publisher=%(J)s"
|
||||||
|
" and nodeid=%(Nidx)d")),
|
||||||
catch ejabberd_sql:sql_query_t(
|
catch ejabberd_sql:sql_query_t(
|
||||||
?SQL("delete from pubsub_state"
|
?SQL("delete from pubsub_state"
|
||||||
" where jid=%(J)s and nodeid=%(Nidx)d")),
|
" where jid=%(J)s and nodeid=%(Nidx)d")),
|
||||||
|
Loading…
Reference in New Issue
Block a user