Skip to content

Commit

Permalink
endpoint id/type accessor (#6206)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo authored and icehess committed Dec 16, 2019
1 parent 773f8fb commit 370bcfb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions applications/doodle/src/tf_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ maybe_do_not_disturb(Endpoint, _Properties, _Im) ->

-spec create_im_endpoints(kz_json:object(), kz_json:object(), kapps_im:im()) -> kz_json:objects().
create_im_endpoints(Endpoint, Properties, Im) ->
create_im_endpoints(kz_doc:type(Endpoint), Endpoint, Properties, Im).
create_im_endpoints(kzd_endpoint:type(Endpoint), Endpoint, Properties, Im).

-spec create_im_endpoints(kz_term:ne_binary(), kz_json:object(), kz_json:object(), kapps_im:im()) -> kz_json:objects().
create_im_endpoints(<<"device">>, Endpoint, Properties, Im) ->
[create_im_endpoint(Endpoint, Properties, Im)];
create_im_endpoints(<<"user">>, Endpoint, Properties, Im) ->
OwnerId = kz_doc:id(Endpoint),
OwnerId = kzd_endpoint:id(Endpoint),
EndpointIds = [kz_doc:id(EP) || EP
<- kz_attributes:owned_by_docs(OwnerId, kapps_im:account_id(Im))
,<<"device">> =:= kz_doc:type(EP)
Expand All @@ -107,7 +107,7 @@ create_im_endpoint(Endpoint, _Properties, Im) ->
[{<<"To-Username">>, kzd_devices:sip_username(Endpoint)}
,{<<"To-Realm">>, kzd_devices:sip_realm(Endpoint, kapps_im:to_realm(Im))}
,{<<"To-DID">>, kapps_im:request_user(Im)}
,{<<"Endpoint-ID">>, kz_doc:id(Endpoint)}
,{<<"Endpoint-ID">>, kzd_endpoint:id(Endpoint)}
,{<<"Invite-Format">>, kzd_devices:sip_invite_format(Endpoint)}
]).

Expand Down
23 changes: 23 additions & 0 deletions core/kazoo_documents/src/kzd_endpoint.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2010-2019, 2600Hz
%%% @doc This Source Code Form is subject to the terms of the Mozilla Public
%%% License, v. 2.0. If a copy of the MPL was not distributed with this
%%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%%
%%% @end
%%%-----------------------------------------------------------------------------
-module(kzd_endpoint).

-export([id/1]).
-export([type/1]).

-type endpoint() :: kz_json:object().
-export_type([endpoint/0]).

-spec id(endpoint()) -> kz_term:ne_binary().
id(Endpoint) ->
kz_json:get_ne_binary_value(<<"Endpoint-ID">>, Endpoint).

-spec type(endpoint()) -> kz_term:ne_binary().
type(Endpoint) ->
kz_json:get_ne_binary_value(<<"Endpoint-Type">>, Endpoint).
5 changes: 4 additions & 1 deletion core/kazoo_endpoint/src/kz_endpoint.erl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ is_endpoint_enabled(JObj, _) ->
-spec cache_store_endpoint(kz_json:object(), kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary()) ->
{'ok', kz_json:object()}.
cache_store_endpoint(JObj, EndpointId, AccountDb, EndpointType) ->
Endpoint = kz_json:set_value(<<"Endpoint-ID">>, EndpointId, merge_attributes(JObj, EndpointType)),
Values = [{<<"Endpoint-ID">>, EndpointId}
,{<<"Endpoint-Type">>, EndpointType}
],
Endpoint = kz_json:set_values(Values, merge_attributes(JObj, EndpointType)),
CacheProps = [{'origin', cache_origin(JObj, EndpointId, AccountDb)}],
catch kz_cache:store_local(?CACHE_NAME, {?MODULE, AccountDb, EndpointId}, Endpoint, CacheProps),
{'ok', Endpoint}.
Expand Down

0 comments on commit 370bcfb

Please sign in to comment.