Skip to content

Commit

Permalink
Merge e6fb03e into 524ae59
Browse files Browse the repository at this point in the history
  • Loading branch information
fenek committed Mar 23, 2017
2 parents 524ae59 + e6fb03e commit 3e023c0
Show file tree
Hide file tree
Showing 10 changed files with 1,098 additions and 1,210 deletions.
4 changes: 4 additions & 0 deletions apps/ejabberd/include/mod_muc_light.hrl
Expand Up @@ -75,13 +75,17 @@
raw_config = [] :: raw_config()
}).

-type op_config() :: #config{}.

-record(affiliations, {
id = <<>> :: binary(),
prev_version = <<>> :: binary(),
version = <<>> :: binary(),
aff_users = [] :: aff_users()
}).

-type op_affiliations() :: #affiliations{}.

-record(info, {
id = <<>> :: binary(),
prev_version = <<>> :: binary(),
Expand Down
2 changes: 2 additions & 0 deletions apps/ejabberd/include/mod_muc_room.hrl
Expand Up @@ -59,6 +59,8 @@
last_presence
}).

-type mod_muc_room_user() :: #user{}.

-record(activity, {message_time = 0,
presence_time = 0,
message_shaper :: shaper:shaper(),
Expand Down
309 changes: 109 additions & 200 deletions apps/ejabberd/src/mod_muc.erl

Large diffs are not rendered by default.

19 changes: 3 additions & 16 deletions apps/ejabberd/src/mod_muc_iq.erl
@@ -1,8 +1,8 @@
%% @doc Stores a table of custom IQ-handlers for mod_muc_room.
-module(mod_muc_iq).

-export([start_link/0,
process_iq/4,
register_iq_handler/4,
register_iq_handler/5,
unregister_iq_handler/2]).

Expand Down Expand Up @@ -39,9 +39,6 @@ start_link() ->
ejabberd:iq()) -> error | ignore | any().
process_iq(Host, From, RoomJID, IQ = #iq{xmlns = XMLNS}) ->
case ets:lookup(tbl_name(), {XMLNS, Host}) of
[{_, Module, Function}] ->
%% TODO: Introduce some stricter type checking here
Module:Function(From, RoomJID, IQ);
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts, From,
RoomJID, IQ),
Expand All @@ -50,20 +47,13 @@ process_iq(Host, From, RoomJID, IQ = #iq{xmlns = XMLNS}) ->
end.


-spec register_iq_handler(ejabberd:server(), binary(), module(), atom()) -> 'ok'.
register_iq_handler(Host, XMLNS, Module, Fun) ->
gen_server:cast(srv_name(),
{register_iq_handler, Host, XMLNS, Module, Fun}).


-spec register_iq_handler(ejabberd:server(), binary(), module(), atom(), any())
-> 'ok'.
-spec register_iq_handler(ejabberd:server(), binary(), module(), atom(), any()) -> ok.
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
gen_server:cast(srv_name(),
{register_iq_handler, Host, XMLNS, Module, Fun, Opts}).


-spec unregister_iq_handler(ejabberd:server(), binary()) -> 'ok'.
-spec unregister_iq_handler(ejabberd:server(), binary()) -> ok.
unregister_iq_handler(Host, XMLNS) ->
gen_server:cast(srv_name(),
{unregister_iq_handler, Host, XMLNS}).
Expand Down Expand Up @@ -103,9 +93,6 @@ handle_call(_Request, _From, State) ->
%% Description: Handling cast messages
%%--------------------------------------------------------------------

handle_cast({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
ets:insert(tbl_name(), {{XMLNS, Host}, Module, Function}),
{noreply, State};
handle_cast({register_iq_handler, Host, XMLNS, Module, Function, Opts}, State) ->
ets:insert(tbl_name(), {{XMLNS, Host}, Module, Function, Opts}),
{noreply, State};
Expand Down
2 changes: 1 addition & 1 deletion apps/ejabberd/src/mod_muc_light_db.erl
Expand Up @@ -15,7 +15,7 @@
| {error, any()}.

-type remove_user_return() :: [{RoomUS :: ejabberd:simple_bare_jid(),
modify_aff_users_return()}].
modify_aff_users_return()}].

-export_type([modify_aff_users_return/0, remove_user_return/0]).

Expand Down
7 changes: 5 additions & 2 deletions apps/ejabberd/src/mod_muc_light_db_mnesia.erl
Expand Up @@ -64,6 +64,9 @@
-define(USER_ROOM_TAB, muc_light_user_room).
-define(BLOCKING_TAB, muc_light_blocking).

-type muc_light_room() :: ?ROOM_TAB.
-type muc_light_blocking() :: ?BLOCKING_TAB.

-record(?ROOM_TAB, {
room :: ejabberd:simple_bare_jid(),
config :: [{atom(), term()}],
Expand Down Expand Up @@ -359,7 +362,7 @@ set_config_transaction(RoomUS, ConfigChanges, Version) ->

%% ------------------------ Blocking manipulation ------------------------

-spec dirty_get_blocking_raw(UserUS :: ejabberd:simple_bare_jid()) -> [#?BLOCKING_TAB{}].
-spec dirty_get_blocking_raw(UserUS :: ejabberd:simple_bare_jid()) -> [muc_light_blocking()].
dirty_get_blocking_raw(UserUS) ->
mnesia:dirty_read(?BLOCKING_TAB, UserUS).

Expand All @@ -385,7 +388,7 @@ modify_aff_users_transaction(RoomUS, AffUsersChanges, ExternalCheck, Version) ->
end.

-spec verify_externally_and_submit(RoomUS :: ejabberd:simple_bare_jid(),
RoomRec :: #?ROOM_TAB{},
RoomRec :: muc_light_room(),
ChangeResult :: mod_muc_light_utils:change_aff_success(),
CheckResult :: ok | {error, any()},
Version :: binary()) ->
Expand Down
8 changes: 4 additions & 4 deletions apps/ejabberd/src/mod_muc_light_room.erl
Expand Up @@ -146,10 +146,10 @@ process_request(_UnknownReq, _From, _UserUS, _RoomUS, _Auth, _AffUsers) ->

%% --------- Config set ---------

-spec process_config_set(ConfigReq :: #config{}, RoomUS :: ejabberd:simple_bare_jid(),
-spec process_config_set(ConfigReq :: op_config(), RoomUS :: ejabberd:simple_bare_jid(),
UserAff :: member | owner, AffUsers :: aff_users(),
UserAllowedToConfigure :: boolean()) ->
{set, #config{}} | {error, not_allowed} | validation_error().
{set, op_config()} | {error, not_allowed} | validation_error().
process_config_set(#config{ raw_config = [{<<"subject">>, _}] } = ConfigReq, RoomUS, UserAff,
AffUsers, false) ->
% Everyone is allowed to change subject
Expand Down Expand Up @@ -193,10 +193,10 @@ validate_aff_changes_by_member([{_, member} = AffUserChange | RAffUsersChanges],
validate_aff_changes_by_member(_AffUsersChanges, _Acc, _UserUS, _OwnerUS, _RoomUS, _AllCanInvite) ->
{error, not_allowed}.

-spec process_aff_set(AffReq :: #affiliations{},
-spec process_aff_set(AffReq :: op_affiliations(),
RoomUS :: ejabberd:simple_bare_jid(),
ValidateResult :: {ok, aff_users()} | {error, not_allowed}) ->
{set, #affiliations{}, OldAffUsers :: aff_users(), NewAffUsers :: aff_users()}
{set, op_affiliations(), OldAffUsers :: aff_users(), NewAffUsers :: aff_users()}
| {error, not_allowed}.
process_aff_set(AffReq, _RoomUS, {ok, []}) -> % It seems that all users blocked this request
{set, AffReq, [], []}; % Just return result to the user, don't change or broadcast anything
Expand Down
2 changes: 1 addition & 1 deletion apps/ejabberd/src/mod_muc_light_utils.erl
Expand Up @@ -315,7 +315,7 @@ apply_aff_users_change([{User1, _} | _] = AU, NAU, [{User2, member} | RAUC], CD,
apply_aff_users_change([{User1, _} | _] = _AU, _NAU, [{User2, none} | _RAUC], _CD, _NO, _JA, _LA)
when User1 > User2 ->
% Meaningless change - user not in the room
{error, bad_request};
{error, bad_request};
apply_aff_users_change([{User1, _} | _] = AU, NAU, [{User2, _} = NewAffUser | RAUC], CD, NO, JA, LA)
when User1 > User2 ->
%% Adding new member to a room - owner or member
Expand Down

0 comments on commit 3e023c0

Please sign in to comment.