-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4392 from esl/muc-light-multiple-owners
Multiple owner support in muc_light
- Loading branch information
Showing
10 changed files
with
88 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
-author('[email protected]'). | ||
|
||
%% API | ||
-export([change_aff_users/2]). | ||
-export([change_aff_users/3]). | ||
-export([b2aff/1, aff2b/1]). | ||
-export([light_aff_to_muc_role/1]). | ||
-export([room_limit_reached/2]). | ||
|
@@ -57,21 +57,22 @@ | |
%% API | ||
%%==================================================================== | ||
|
||
-spec change_aff_users(CurrentAffUsers :: aff_users(), AffUsersChangesAssorted :: aff_users()) -> | ||
-spec change_aff_users(HostType :: mongooseim:host_type(), CurrentAffUsers :: aff_users(), AffUsersChangesAssorted :: aff_users()) -> | ||
change_aff_success() | {error, bad_request()}. | ||
change_aff_users(AffUsers, AffUsersChangesAssorted) -> | ||
change_aff_users(HostType, AffUsers, AffUsersChangesAssorted) -> | ||
case {lists:keyfind(owner, 2, AffUsers), lists:keyfind(owner, 2, AffUsersChangesAssorted)} of | ||
{false, false} -> % simple, no special cases | ||
apply_aff_users_change(AffUsers, AffUsersChangesAssorted); | ||
{false, {_, _}} -> % ownerless room! | ||
{error, {bad_request, <<"Ownerless room">>}}; | ||
_ -> | ||
MultipleOwners = allow_multiple_owners(HostType), | ||
lists:foldl(fun(F, Acc) -> F(Acc) end, | ||
apply_aff_users_change(AffUsers, AffUsersChangesAssorted), | ||
[fun maybe_demote_old_owner/1, | ||
fun maybe_select_new_owner/1]) | ||
change_aff_functions(MultipleOwners)) | ||
end. | ||
|
||
|
||
-spec aff2b(Aff :: aff()) -> binary(). | ||
aff2b(owner) -> <<"owner">>; | ||
aff2b(member) -> <<"member">>; | ||
|
@@ -156,6 +157,12 @@ filter_out_loop(_HostType, _FromUS, _MUCServer, _BlockingQuery, _RoomsPerUser, [ | |
|
||
%% ---------------- Affiliations manipulation ---------------- | ||
|
||
-spec change_aff_functions(AllowMultipleOwners :: boolean()) -> [fun(), ...]. | ||
change_aff_functions(_AllowMultipleOwners = false)-> | ||
[fun maybe_demote_old_owner/1, fun maybe_select_new_owner/1]; | ||
change_aff_functions(_AllowMultipleOwners = true)-> | ||
[fun maybe_select_new_owner/1]. | ||
|
||
-spec maybe_select_new_owner(ChangeResult :: change_aff_success() | {error, bad_request()}) -> | ||
change_aff_success() | {error, bad_request()}. | ||
maybe_select_new_owner({ok, AU, AUC, JoiningUsers, LeavingUsers} = _AffRes) -> | ||
|
@@ -317,3 +324,6 @@ run_forget_room_hook({Room, MucHost}) -> | |
?LOG_ERROR(#{what => run_forget_room_hook_skipped, | ||
room => Room, muc_host => MucHost}) | ||
end. | ||
|
||
allow_multiple_owners(HostType) -> | ||
gen_mod:get_module_opt(HostType, mod_muc_light, allow_multiple_owners). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters