Skip to content

Commit

Permalink
handle conference controls (#6433)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo authored Apr 1, 2020
1 parent 279aa58 commit 8a8376c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
36 changes: 23 additions & 13 deletions applications/conference/src/conf_config_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
cache_profile(Conference) ->
{ProfileName, Profile} = kapps_conference:profile(Conference),
lager:debug("caching profile ~s: ~p", [ProfileName, Profile]),
kz_cache:store_local(?CACHE_NAME, {'profile', ProfileName}, fix_profile(Conference, Profile)).
FixedProfile = fix_profile(Conference, Profile),
CacheProps = [{'origin', cache_origin(Conference)}],
kz_cache:store_local(?CACHE_NAME, {'profile', ProfileName}, FixedProfile, CacheProps).

cache_origin(Conference) ->
case kapps_conference:id(Conference) of
undefined -> [];
ConferenceId ->
AccountId = kapps_conference:account_id(Conference),
AccountDB = kz_util:format_account_db(AccountId),
[{'db', AccountDB, ConferenceId}]
end.

-spec handle_req(kz_json:object(), kz_term:proplist()) -> 'ok'.
handle_req(JObj, _Props) ->
Expand All @@ -35,6 +46,7 @@ create_conference(JObj) ->
Routines = [{fun kapps_conference:set_account_id/2, AccountId}
,{fun kapps_conference:set_id/2, ConferenceId}
,{fun kapps_conference:set_profile_name/2, Profile}
,fun kapps_conference:reload/1
],
kapps_conference:update(Routines, Conference).

Expand Down Expand Up @@ -151,6 +163,8 @@ add_conference_params(Conference, Profile) ->
Props = props:filter_undefined(
[{<<"max-members">>, max_participants(Conference)}
,{<<"max-members-sound">>, max_members_sound(Conference)}
,{<<"caller-controls">>, kapps_conference:caller_controls(Conference)}
,{<<"moderator-controls">>, kapps_conference:moderator_controls(Conference)}
]),
kz_json:set_values(Props, Profile).

Expand Down Expand Up @@ -214,16 +228,19 @@ max_members_sound(Conference) ->
-spec handle_controls_request(kz_json:object(), kapps_conference:conference()) -> 'ok'.
handle_controls_request(JObj, Conference) ->
ProfileName = requested_profile_name(JObj),
ControlsType = requested_controls_name(JObj),
ControlsName = get_conference_controls_name(ControlsType, Conference),
ControlsName = requested_controls_name(JObj),
Controls = kapps_conference:controls(Conference, ControlsName),
ServerId = kz_api:server_id(JObj),
Resp = [{<<"Caller-Controls">>, controls(ControlsType, Controls)}
Resp = [{<<"Caller-Controls">>, controls(ControlsName, Controls)}
,{<<"Msg-ID">>, kz_api:msg_id(JObj)}
| kz_api:default_headers(?APP_NAME, ?APP_VERSION)
],
lager:debug("returning ~s (~s) controls profile for ~s"
,[ControlsName, ControlsType, ProfileName]
lager:debug("returning ~s controls profile for ~s (~s/~s)"
,[ControlsName
,ProfileName
,kapps_conference:account_id(Conference)
,kapps_conference:id(Conference)
]
),
kapi_conference:publish_config_resp(ServerId, Resp).

Expand All @@ -235,10 +252,3 @@ requested_controls_name(JObj) ->
controls(ControlsName, Controls) ->
kz_json:from_list([{ControlsName, Controls}]).

-spec get_conference_controls_name(kz_term:ne_binary(), kapps_conference:conference()) -> kz_term:ne_binary().
get_conference_controls_name(<<"caller-controls">>, Conference) ->
kapps_conference:caller_controls(Conference);
get_conference_controls_name(<<"moderator-controls">>, Conference) ->
kapps_conference:moderator_controls(Conference);
get_conference_controls_name(_Name, Conference) ->
kapps_conference:caller_controls(Conference).
10 changes: 8 additions & 2 deletions applications/conference/src/conference_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

-export([blocking_refresh/0]).
-export([refresh/0, refresh/1]).
-export([flush/0]).

-include("conference.hrl").

Expand All @@ -27,7 +28,7 @@ blocking_refresh() ->
%% {@link kapps_maintenance:refresh/0} instead.
%% @end
%%------------------------------------------------------------------------------
-spec refresh() -> 'started'.
-spec refresh() -> 'ok'.
refresh() ->
io:format("This function is deprecated, please use kapps_maintenance:refresh() instead.").

Expand All @@ -37,6 +38,11 @@ refresh() ->
%% {@link kapps_maintenance:refresh/1} instead.
%% @end
%%------------------------------------------------------------------------------
-spec refresh(any()) -> 'started'.
-spec refresh(any()) -> 'ok'.
refresh(_Account) ->
io:format("This function is deprecated, please use kapps_maintenance:refresh(~p) instead.", [_Account]).

-spec flush() -> 'ok'.
flush() ->
kz_cache:flush_local(?CACHE_NAME).

29 changes: 28 additions & 1 deletion core/kazoo_call/src/kapps_conference.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-module(kapps_conference).

-export([new/0]).
-export([reload/1]).
-export([from_conference_doc/1, from_conference_doc/2]).
-export([to_json/1, from_json/1, from_json/2]).
-export([to_proplist/1]).
Expand Down Expand Up @@ -287,6 +288,28 @@ to_proplist(#kapps_conference{}=Conference) ->
is_conference(#kapps_conference{}) -> 'true';
is_conference(_) -> 'false'.

-spec reload(conference()) -> conference().
reload(#kapps_conference{account_id=undefined}=Conference) -> Conference;
reload(#kapps_conference{id=undefined}=Conference) -> Conference;
reload(#kapps_conference{account_id=AccountId
,id=ConferenceId
}=Conference) ->
AccountDB = kz_util:format_account_db(AccountId),

case kz_datamgr:open_cache_doc(AccountDB, ConferenceId) of
{ok, Doc} ->
lager:debug("reloading conference from document ~s/~s", [AccountId, ConferenceId]),
from_conference_doc(Doc, Conference);
{error, Error} ->
lager:debug("conference document ~s/~s not found => ~p"
,[AccountId
,ConferenceId
,Error
]
),
Conference
end.

-spec from_conference_doc(kzd_conferences:doc()) -> conference().
from_conference_doc(JObj) ->
from_conference_doc(JObj, #kapps_conference{}).
Expand Down Expand Up @@ -375,7 +398,10 @@ account_id(#kapps_conference{account_id=AccountId}) ->
AccountId.

-spec controls(conference(), kz_term:ne_binary()) -> kz_json:objects().
controls(#kapps_conference{controls=Controls}, _) when Controls =/= 'undefined' -> Controls;
controls(#kapps_conference{controls=Controls}=Conference, ControlsName)
when Controls =/= 'undefined' ->
Default = controls(Conference#kapps_conference{controls=undefined}, ControlsName),
kz_json:get_list_value(ControlsName, Controls, Default);
controls(#kapps_conference{account_id='undefined'}, ?DEFAULT_PROFILE_NAME) ->
kapps_config:get(?CONFERENCE_CONFIG_CAT, [<<"controls">>, ?DEFAULT_PROFILE_NAME], ?DEFAULT_CONTROLS);
controls(#kapps_conference{account_id=AccountId}=Conference, ?DEFAULT_PROFILE_NAME) ->
Expand Down Expand Up @@ -937,3 +963,4 @@ get_tone(Thing) ->
'false' -> 'true'
end
end.

0 comments on commit 8a8376c

Please sign in to comment.