25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-30 16:36:29 +01:00

* src/mod_roster.erl: When account is deleted, cancel presence

subscription for all roster items (EJAB-790)
* src/mod_roster_odbc.erl: Likewise

SVN Revision: 1877
This commit is contained in:
Badlop 2009-02-16 14:49:20 +00:00
parent d0f1300a84
commit b0e749eca5
3 changed files with 100 additions and 56 deletions

View File

@ -1,3 +1,9 @@
2009-02-16 Badlop <badlop@process-one.net>
* src/mod_roster.erl: When account is deleted, cancel presence
subscription for all roster items (EJAB-790)
* src/mod_roster_odbc.erl: Likewise
2009-02-14 Badlop <badlop@process-one.net> 2009-02-14 Badlop <badlop@process-one.net>
* src/web/ejabberd_http_poll.erl: Allow configuration of session * src/web/ejabberd_http_poll.erl: Allow configuration of session

View File

@ -233,34 +233,7 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
push_item(User, LServer, To, Item), push_item(User, LServer, To, Item),
case Item#roster.subscription of case Item#roster.subscription of
remove -> remove ->
IsTo = case OldItem#roster.subscription of send_unsubscribing_presence(From, OldItem),
both -> true;
to -> true;
_ -> false
end,
IsFrom = case OldItem#roster.subscription of
both -> true;
from -> true;
_ -> false
end,
if IsTo ->
ejabberd_router:route(
jlib:jid_remove_resource(From),
jlib:make_jid(OldItem#roster.jid),
{xmlelement, "presence",
[{"type", "unsubscribe"}],
[]});
true -> ok
end,
if IsFrom ->
ejabberd_router:route(
jlib:jid_remove_resource(From),
jlib:make_jid(OldItem#roster.jid),
{xmlelement, "presence",
[{"type", "unsubscribed"}],
[]});
true -> ok
end,
ok; ok;
_ -> _ ->
ok ok
@ -570,6 +543,7 @@ remove_user(User, Server) ->
LUser = jlib:nodeprep(User), LUser = jlib:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = jlib:nameprep(Server),
US = {LUser, LServer}, US = {LUser, LServer},
send_unsubscription_to_rosteritems(LUser, LServer),
F = fun() -> F = fun() ->
lists:foreach(fun(R) -> lists:foreach(fun(R) ->
mnesia:delete_object(R) mnesia:delete_object(R)
@ -578,6 +552,51 @@ remove_user(User, Server) ->
end, end,
mnesia:transaction(F). mnesia:transaction(F).
%% For each contact with Subscription:
%% Both or From, send a "unsubscribed" presence stanza;
%% Both or To, send a "unsubscribe" presence stanza.
send_unsubscription_to_rosteritems(LUser, LServer) ->
RosterItems = get_user_roster([], {LUser, LServer}),
From = jlib:make_jid({LUser, LServer, ""}),
lists:foreach(fun(RosterItem) ->
send_unsubscribing_presence(From, RosterItem)
end,
RosterItems).
%% @spec (From::jid(), Item::roster()) -> ok
send_unsubscribing_presence(From, Item) ->
IsTo = case Item#roster.subscription of
both -> true;
to -> true;
_ -> false
end,
IsFrom = case Item#roster.subscription of
both -> true;
from -> true;
_ -> false
end,
if IsTo ->
send_presence_type(
jlib:jid_remove_resource(From),
jlib:make_jid(Item#roster.jid), "unsubscribe");
true -> ok
end,
if IsFrom ->
send_presence_type(
jlib:jid_remove_resource(From),
jlib:make_jid(Item#roster.jid), "unsubscribed");
true -> ok
end,
ok.
send_presence_type(From, To, Type) ->
ejabberd_router:route(
From, To,
{xmlelement, "presence",
[{"type", Type}],
[]}).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_items(User, Server, SubEl) -> set_items(User, Server, SubEl) ->

View File

@ -274,34 +274,7 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
push_item(User, LServer, To, Item), push_item(User, LServer, To, Item),
case Item#roster.subscription of case Item#roster.subscription of
remove -> remove ->
IsTo = case OldItem#roster.subscription of send_unsubscribing_presence(From, OldItem),
both -> true;
to -> true;
_ -> false
end,
IsFrom = case OldItem#roster.subscription of
both -> true;
from -> true;
_ -> false
end,
if IsTo ->
ejabberd_router:route(
jlib:jid_remove_resource(From),
jlib:make_jid(OldItem#roster.jid),
{xmlelement, "presence",
[{"type", "unsubscribe"}],
[]});
true -> ok
end,
if IsFrom ->
ejabberd_router:route(
jlib:jid_remove_resource(From),
jlib:make_jid(OldItem#roster.jid),
{xmlelement, "presence",
[{"type", "unsubscribed"}],
[]});
true -> ok
end,
ok; ok;
_ -> _ ->
ok ok
@ -631,9 +604,55 @@ remove_user(User, Server) ->
LUser = jlib:nodeprep(User), LUser = jlib:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = jlib:nameprep(Server),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
send_unsubscription_to_rosteritems(LUser, LServer),
odbc_queries:del_user_roster_t(LServer, Username), odbc_queries:del_user_roster_t(LServer, Username),
ok. ok.
%% For each contact with Subscription:
%% Both or From, send a "unsubscribed" presence stanza;
%% Both or To, send a "unsubscribe" presence stanza.
send_unsubscription_to_rosteritems(LUser, LServer) ->
RosterItems = get_user_roster([], {LUser, LServer}),
From = jlib:make_jid({LUser, LServer, ""}),
lists:foreach(fun(RosterItem) ->
send_unsubscribing_presence(From, RosterItem)
end,
RosterItems).
%% @spec (From::jid(), Item::roster()) -> ok
send_unsubscribing_presence(From, Item) ->
IsTo = case Item#roster.subscription of
both -> true;
to -> true;
_ -> false
end,
IsFrom = case Item#roster.subscription of
both -> true;
from -> true;
_ -> false
end,
if IsTo ->
send_presence_type(
jlib:jid_remove_resource(From),
jlib:make_jid(Item#roster.jid), "unsubscribe");
true -> ok
end,
if IsFrom ->
send_presence_type(
jlib:jid_remove_resource(From),
jlib:make_jid(Item#roster.jid), "unsubscribed");
true -> ok
end,
ok.
send_presence_type(From, To, Type) ->
ejabberd_router:route(
From, To,
{xmlelement, "presence",
[{"type", Type}],
[]}).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_items(User, Server, SubEl) -> set_items(User, Server, SubEl) ->