Skip to content

Commit

Permalink
resolve #KAZOO-607: resolve_endpoint_ids accumulator reverses the lis…
Browse files Browse the repository at this point in the history
…t order so we should collect from the builders back-to-front
  • Loading branch information
k-anderson committed Feb 20, 2013
1 parent 64883b7 commit b92ec0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions whistle_apps/apps/callflow/src/module/cf_page_group.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
-spec handle(wh_json:object(), whapps_call:call()) -> ok.
handle(Data, Call) ->
case get_endpoints(wh_json:get_value(<<"endpoints">>, Data, []), Call) of
[] ->
[] ->
lager:notice("page group has no endpoints, moving to next callflow element"),
cf_exe:continue(Call);
Endpoints ->
Endpoints ->
attempt_page(Endpoints, Data, Call)
end.
end.

-spec attempt_page/3 :: (wh_json:objects(), wh_json:object(), whapps_call:call()) -> 'ok'.
attempt_page(Endpoints, Data, Call) ->
Expand All @@ -55,27 +55,27 @@ get_endpoints(Members, Call) ->
|| {EndpointId, Member} <- resolve_endpoint_ids(Members, Call)
],
lists:foldl(fun(Pid, Acc) ->
receive
receive
{Pid, {ok, EP}} when is_list(EP) ->
EP ++ Acc;
{Pid, {ok, EP}} ->
[EP | Acc];
{Pid, _} -> Acc
end
end, [], lists:reverse(Builders)).
end, [], Builders).

-spec resolve_endpoint_ids/2 :: (wh_json:objects(), whapps_call:call()) -> [] | [{ne_binary(), wh_json:object()},...].
resolve_endpoint_ids(Members, Call) ->
[{Id, wh_json:set_value(<<"source">>, ?MODULE, Member)}
[{Id, wh_json:set_value(<<"source">>, ?MODULE, Member)}
|| {Type, Id, Member} <- resolve_endpoint_ids(Members, [], Call)
,Type =:= <<"device">>
,Id =/= whapps_call:authorizing_id(Call)
,Id =/= whapps_call:authorizing_id(Call)
].

-type endpoint_intermediate() :: {ne_binary(), ne_binary(), 'undefined' | wh_json:object()}.
-type endpoint_intermediates() :: [] | [endpoint_intermediate(),...].
-spec resolve_endpoint_ids/3 :: (wh_json:objects(), endpoint_intermediates(), whapps_call:call()) -> endpoint_intermediates().
resolve_endpoint_ids([], EndpointIds, _) ->
resolve_endpoint_ids([], EndpointIds, _) ->
EndpointIds;
resolve_endpoint_ids([Member|Members], EndpointIds, Call) ->
Id = wh_json:get_value(<<"id">>, Member),
Expand All @@ -84,14 +84,14 @@ resolve_endpoint_ids([Member|Members], EndpointIds, Call) ->
orelse lists:keymember(Id, 2, EndpointIds)
orelse Type
of
true ->
true ->
resolve_endpoint_ids(Members, EndpointIds, Call);
<<"group">> ->
lager:info("member ~s is a group, merge the group's members", [Id]),
GroupMembers = get_group_members(Member, Id, Call),
Ids = resolve_endpoint_ids(GroupMembers, EndpointIds, Call),
resolve_endpoint_ids(Members, [{Type, Id, undefined}|Ids], Call);
<<"user">> ->
<<"user">> ->
lager:info("member ~s is a user, get all the user's endpoints", [Id]),
Ids = lists:foldr(fun(EndpointId, Acc) ->
case lists:keymember(EndpointId, 2, Acc) of
Expand Down
20 changes: 10 additions & 10 deletions whistle_apps/apps/callflow/src/module/cf_ring_group.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
-spec handle(wh_json:object(), whapps_call:call()) -> ok.
handle(Data, Call) ->
case get_endpoints(wh_json:get_value(<<"endpoints">>, Data, []), Call) of
[] ->
[] ->
lager:notice("ring group has no endpoints, moving to next callflow element"),
cf_exe:continue(Call);
Endpoints ->
Endpoints ->
attempt_endpoints(Endpoints, Data, Call)
end.
end.

-spec attempt_endpoints/3 :: (wh_json:objects(), wh_json:object(), whapps_call:call()) -> 'ok'.
attempt_endpoints(Endpoints, Data, Call) ->
Expand Down Expand Up @@ -58,27 +58,27 @@ get_endpoints(Members, Call) ->
|| {EndpointId, Member} <- resolve_endpoint_ids(Members, Call)
],
lists:foldl(fun(Pid, Acc) ->
receive
receive
{Pid, {ok, EP}} when is_list(EP) ->
EP ++ Acc;
{Pid, {ok, EP}} ->
[EP | Acc];
{Pid, _} -> Acc
end
end, [], lists:reverse(Builders)).
end, [], Builders).

-spec resolve_endpoint_ids/2 :: (wh_json:objects(), whapps_call:call()) -> [] | [{ne_binary(), wh_json:object()},...].
resolve_endpoint_ids(Members, Call) ->
[{Id, wh_json:set_value(<<"source">>, ?MODULE, Member)}
[{Id, wh_json:set_value(<<"source">>, ?MODULE, Member)}
|| {Type, Id, Member} <- resolve_endpoint_ids(Members, [], Call)
,Type =:= <<"device">>
,Id =/= whapps_call:authorizing_id(Call)
,Id =/= whapps_call:authorizing_id(Call)
].

-type endpoint_intermediate() :: {ne_binary(), ne_binary(), 'undefined' | wh_json:object()}.
-type endpoint_intermediates() :: [] | [endpoint_intermediate(),...].
-spec resolve_endpoint_ids/3 :: (wh_json:objects(), endpoint_intermediates(), whapps_call:call()) -> endpoint_intermediates().
resolve_endpoint_ids([], EndpointIds, _) ->
resolve_endpoint_ids([], EndpointIds, _) ->
EndpointIds;
resolve_endpoint_ids([Member|Members], EndpointIds, Call) ->
Id = wh_json:get_value(<<"id">>, Member),
Expand All @@ -87,14 +87,14 @@ resolve_endpoint_ids([Member|Members], EndpointIds, Call) ->
orelse lists:keymember(Id, 2, EndpointIds)
orelse Type
of
true ->
true ->
resolve_endpoint_ids(Members, EndpointIds, Call);
<<"group">> ->
lager:info("member ~s is a group, merge the group's members", [Id]),
GroupMembers = get_group_members(Member, Id, Call),
Ids = resolve_endpoint_ids(GroupMembers, EndpointIds, Call),
resolve_endpoint_ids(Members, [{Type, Id, undefined}|Ids], Call);
<<"user">> ->
<<"user">> ->
lager:info("member ~s is a user, get all the user's endpoints", [Id]),
Ids = lists:foldr(fun(EndpointId, Acc) ->
case lists:keymember(EndpointId, 2, Acc) of
Expand Down

0 comments on commit b92ec0d

Please sign in to comment.