-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MUC Light ODBC #1093
MUC Light ODBC #1093
Changes from 6 commits
9ec02f9
221523b
8718c42
c79f92d
5b1a842
e2861bd
056f10c
0ac907d
6b30fcc
382fa14
0821777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,8 @@ start(Host, Opts) -> | |
ConfigSchema), | ||
set_opt(MyDomain, default_config, DefaultConfig), | ||
|
||
set_opt(MyDomain, main_host, Host), | ||
|
||
ok. | ||
|
||
-spec stop(Host :: ejabberd:server()) -> ok. | ||
|
@@ -203,12 +205,17 @@ route(From, To, Packet) -> | |
DecodedPacket :: mod_muc_light_codec:decode_result(), | ||
OrigPacket :: jlib:xmlel()) -> any(). | ||
process_packet(From, To, {ok, {set, #create{} = Create}}, OrigPacket) -> | ||
RoomsPerUser = get_opt(To#jid.lserver, rooms_per_user, ?DEFAULT_ROOMS_PER_USER), | ||
FromUS = jid:to_lus(From), | ||
case RoomsPerUser == infinity orelse length(?BACKEND:get_user_rooms(FromUS)) < RoomsPerUser of | ||
true -> | ||
MayCreate = case get_opt(To#jid.lserver, rooms_per_user, ?DEFAULT_ROOMS_PER_USER) of | ||
infinity -> | ||
true; | ||
RoomsPerUser -> | ||
length(?BACKEND:get_user_rooms(FromUS, To#jid.lserver)) < RoomsPerUser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How difficult would it be to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not difficult at all and actually I was considering it. Let's do it! |
||
end, | ||
if | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
MayCreate -> | ||
create_room(From, FromUS, To, Create, OrigPacket); | ||
false -> | ||
true -> | ||
?CODEC:encode_error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
{error, bad_request}, From, To, OrigPacket, fun ejabberd_router:route/3) | ||
end; | ||
|
@@ -304,7 +311,7 @@ add_rooms_to_roster(Acc, UserUS) -> | |
children = [#xmlcdata{ content = RoomVersion }] }] | ||
}, | ||
[Item | Acc0] | ||
end, Acc, get_rooms_info(lists:sort(?BACKEND:get_user_rooms(UserUS)))). | ||
end, Acc, get_rooms_info(lists:sort(?BACKEND:get_user_rooms(UserUS, undefined)))). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
|
||
-spec process_iq_get(Acc :: any(), From :: #jid{}, To :: #jid{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Elvis here. |
||
IQ :: #iq{}, ActiveList :: binary()) -> | ||
|
@@ -313,7 +320,7 @@ process_iq_get(_Acc, #jid{ lserver = FromS } = From, To, #iq{} = IQ, _ActiveList | |
MUCHost = gen_mod:get_module_opt_host(FromS, ?MODULE, ?DEFAULT_HOST), | ||
case {?CODEC:decode(From, To, IQ), get_opt(MUCHost, blocking, ?DEFAULT_BLOCKING)} of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
{{ok, {get, #blocking{} = Blocking}}, true} -> | ||
Items = ?BACKEND:get_blocking(jid:to_lus(From)), | ||
Items = ?BACKEND:get_blocking(jid:to_lus(From), MUCHost), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
?CODEC:encode({get, Blocking#blocking{ items = Items }}, From, jid:to_lus(To), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
fun(_, _, Packet) -> put(encode_res, Packet) end), | ||
#xmlel{ children = ResponseChildren } = erase(encode_res), | ||
|
@@ -336,7 +343,7 @@ process_iq_set(_Acc, #jid{ lserver = FromS } = From, To, #iq{} = IQ) -> | |
true -> | ||
{stop, {error, ?ERR_BAD_REQUEST}}; | ||
false -> | ||
ok = ?BACKEND:set_blocking(jid:to_lus(From), Items), | ||
ok = ?BACKEND:set_blocking(jid:to_lus(From), MUCHost, Items), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
?CODEC:encode(Blocking, From, jid:to_lus(To), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
fun(_, _, Packet) -> put(encode_res, Packet) end), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
#xmlel{ children = ResponseChildren } = erase(encode_res), | ||
|
@@ -457,7 +464,7 @@ handle_disco_info_get(From, To, DiscoInfo) -> | |
-spec handle_disco_items_get(From :: jid(), To :: jid(), DiscoItems :: #disco_items{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
OrigPacket :: jlib:xmlel()) -> ok. | ||
handle_disco_items_get(From, To, DiscoItems0, OrigPacket) -> | ||
case catch ?BACKEND:get_user_rooms(jid:to_lus(From)) of | ||
case catch ?BACKEND:get_user_rooms(jid:to_lus(From), To#jid.lserver) of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
{error, Error} -> | ||
?ERROR_MSG("Couldn't get room list for user ~p: ~p", [From, Error]), | ||
?CODEC:encode_error({error, internal_server_error}, From, To, OrigPacket, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
|
@@ -558,14 +565,15 @@ find_room_pos(_, [], _) -> {error, item_not_found}. | |
BlockingReq :: {get | set, #blocking{}}) -> | ||
{error, bad_request} | ok. | ||
handle_blocking(From, To, {get, #blocking{} = Blocking}) -> | ||
?CODEC:encode({get, Blocking#blocking{ items = ?BACKEND:get_blocking(jid:to_lus(From)) }}, | ||
BlockingItems = ?BACKEND:get_blocking(jid:to_lus(From), To#jid.lserver), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
?CODEC:encode({get, Blocking#blocking{ items = BlockingItems }}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
From, jid:to_lus(To), fun ejabberd_router:route/3); | ||
handle_blocking(From, To, {set, #blocking{ items = Items }} = BlockingReq) -> | ||
case lists:any(fun({_, _, {WhoU, WhoS}}) -> WhoU =:= <<>> orelse WhoS =:= <<>> end, Items) of | ||
true -> | ||
{error, bad_request}; | ||
false -> | ||
ok = ?BACKEND:set_blocking(jid:to_lus(From), Items), | ||
ok = ?BACKEND:set_blocking(jid:to_lus(From), To#jid.lserver, Items), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
?CODEC:encode(BlockingReq, From, jid:to_lus(To), fun ejabberd_router:route/3), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
ok | ||
end. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ send_message(Domain, RoomName, Sender, Message) -> | |
children = [ Body ] | ||
}, | ||
S = jid:binary_to_bare(Sender), | ||
case get_user_rooms(S) of | ||
case get_user_rooms(S, Domain) of | ||
[] -> | ||
{error, given_user_does_not_occupy_any_room}; | ||
RoomJIDs when is_list(RoomJIDs) -> | ||
|
@@ -169,7 +169,7 @@ make_room_config(Name, Subject) -> | |
}. | ||
|
||
muc_light_room_name_to_jid(Participant, RoomName, Domain) -> | ||
case get_user_rooms(Participant) of | ||
case get_user_rooms(Participant, Domain) of | ||
[] -> | ||
{error, given_user_does_not_occupy_any_room}; | ||
RoomJIDs when is_list(RoomJIDs) -> | ||
|
@@ -179,8 +179,8 @@ muc_light_room_name_to_jid(Participant, RoomName, Domain) -> | |
jid:make(RU, RS, <<>>) | ||
end. | ||
|
||
get_user_rooms(UserJID) -> | ||
?BACKEND:get_user_rooms(jid:to_lus(UserJID)). | ||
get_user_rooms(UserJID, Domain) -> | ||
?BACKEND:get_user_rooms(jid:to_lus(UserJID), Domain). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
|
||
name_of_room_with_jid(RoomJID) -> | ||
case ?BACKEND:get_info(RoomJID) of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Elvis:
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move the whole
case
to a dedicated function with meaningful name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, why not.