25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

* src/mod_shared_roster.erl: Support in API to add 'all' as member

of a group (thanks to Martin Langhoff)(EJAB-916)

SVN Revision: 2031
This commit is contained in:
Badlop 2009-04-22 10:40:11 +00:00
parent 8654991333
commit d7223ea6ef
2 changed files with 47 additions and 19 deletions

View File

@ -1,5 +1,8 @@
2009-04-22 Badlop <badlop@process-one.net> 2009-04-22 Badlop <badlop@process-one.net>
* src/mod_shared_roster.erl: Support in API to add 'all' as member
of a group (thanks to Martin Langhoff)(EJAB-916)
* src/ejabberd_captcha.erl: If a problem appears while obtaining * src/ejabberd_captcha.erl: If a problem appears while obtaining
the image, show error message (EJAB-895) the image, show error message (EJAB-895)

View File

@ -542,6 +542,18 @@ is_user_in_group({_U, S} = US, Group, Host) ->
%% @spec (Host::string(), {User::string(), Server::string()}, Group::string()) -> {atomic, ok} %% @spec (Host::string(), {User::string(), Server::string()}, Group::string()) -> {atomic, ok}
add_user_to_group(Host, US, Group) -> add_user_to_group(Host, US, Group) ->
{LUser, LServer} = US, {LUser, LServer} = US,
case regexp:match(LUser, "^@.+@$") of
{match,_,_} ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
AllUsersOpt =
case LUser == "@all@" of
true -> [{all_users, true}];
false -> []
end,
mod_shared_roster:set_group_opts(
Host, Group,
GroupOpts ++ AllUsersOpt);
nomatch ->
%% Push this new user to members of groups where this group is displayed %% Push this new user to members of groups where this group is displayed
push_user_to_displayed(LUser, LServer, Group, both), push_user_to_displayed(LUser, LServer, Group, both),
%% Push members of groups that are displayed to this group %% Push members of groups that are displayed to this group
@ -550,7 +562,8 @@ add_user_to_group(Host, US, Group) ->
F = fun() -> F = fun() ->
mnesia:write(R) mnesia:write(R)
end, end,
mnesia:transaction(F). mnesia:transaction(F)
end.
push_displayed_to_user(LUser, LServer, Group, Host, Subscription) -> push_displayed_to_user(LUser, LServer, Group, Host, Subscription) ->
GroupsOpts = groups_with_opts(LServer), GroupsOpts = groups_with_opts(LServer),
@ -560,17 +573,29 @@ push_displayed_to_user(LUser, LServer, Group, Host, Subscription) ->
remove_user_from_group(Host, US, Group) -> remove_user_from_group(Host, US, Group) ->
GroupHost = {Group, Host}, GroupHost = {Group, Host},
{LUser, LServer} = US,
case regexp:match(LUser, "^@.+@$") of
{match,_,_} ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
NewGroupOpts =
case LUser of
"@all@" ->
lists:filter(fun(X) -> X/={all_users,true} end, GroupOpts)
end,
mod_shared_roster:set_group_opts(Host, Group, NewGroupOpts);
nomatch ->
R = #sr_user{us = US, group_host = GroupHost}, R = #sr_user{us = US, group_host = GroupHost},
F = fun() -> F = fun() ->
mnesia:delete_object(R) mnesia:delete_object(R)
end, end,
Result = mnesia:transaction(F), Result = mnesia:transaction(F),
{LUser, LServer} = US,
%% Push removal of the old user to members of groups where the group that this user was members was displayed %% Push removal of the old user to members of groups where the group that this user was members was displayed
push_user_to_displayed(LUser, LServer, Group, remove), push_user_to_displayed(LUser, LServer, Group, remove),
%% Push removal of members of groups that where displayed to the group which this user has left %% Push removal of members of groups that where displayed to the group which this user has left
push_displayed_to_user(LUser, LServer, Group, Host, remove), push_displayed_to_user(LUser, LServer, Group, Host, remove),
Result. Result
end.
push_members_to_user(LUser, LServer, Group, Host, Subscription) -> push_members_to_user(LUser, LServer, Group, Host, Subscription) ->
GroupsOpts = groups_with_opts(LServer), GroupsOpts = groups_with_opts(LServer),