Skip to content

Commit

Permalink
add broadcast ability to omnipresence (2600hz#3134)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo authored and k-anderson committed Jan 20, 2017
1 parent a993ca9 commit 053535b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion applications/omnipresence/src/kapi_omnipresence.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
]).

-export([publish_subscribe/1, publish_subscribe/2
,publish_update/2, publish_update/3
,publish_update/1, publish_update/2, publish_update/3
,publish_notify/1, publish_notify/2
,publish_search_req/1, publish_search_req/2
,publish_search_partial_resp/2, publish_search_partial_resp/3
Expand Down Expand Up @@ -157,6 +157,11 @@ update_v(Prop) when is_list(Prop) ->
kz_api:validate(Prop, ?UPDATE_HEADERS, ?UPDATE_VALUES, ?UPDATE_TYPES);
update_v(JObj) -> update_v(kz_json:to_proplist(JObj)).

-spec publish_update(api_terms()) -> 'ok'.
publish_update(Req) ->
{'ok', Payload} = kz_api:prepare_api_payload(Req, ?UPDATE_VALUES, fun update/1),
amqp_util:basic_publish(?OMNIPRESENCE_EXCHANGE, <<"presence.update">>, Payload, ?DEFAULT_CONTENT_TYPE).

-spec publish_update(ne_binary(), api_terms()) -> 'ok'.
-spec publish_update(ne_binary(), api_terms(), binary()) -> 'ok'.
publish_update(Q, JObj) -> publish_update(Q, JObj, ?DEFAULT_CONTENT_TYPE).
Expand Down
14 changes: 13 additions & 1 deletion applications/omnipresence/src/omnip_dialog_amqp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,24 @@ to_uri_cookie(_State, _, From, _, _) ->

-spec maybe_send_update(ne_binary(), kz_proplist()) -> 'ok'.
maybe_send_update(User, Props) ->
State = props:get_value(<<"State">>, Props),
Broadcast = kapps_config:get_is_true(?CONFIG_CAT, [<<"broadcast_presence">>, State]),
maybe_send_update(Broadcast, User, Props).

-spec maybe_send_update(api_boolean(), ne_binary(), kz_proplist()) -> 'ok'.
maybe_send_update('false', User, Props) ->
case omnip_subscriptions:get_stalkers(?DIALOG_EVENT, User) of
{'ok', Stalkers} ->
send_update(Stalkers, Props);
{'error', 'not_found'} ->
lager:debug("no ~s subscriptions for ~s",[?DIALOG_EVENT, User])
end.
end;
maybe_send_update('true', User, Props) ->
_ = log_send_update([<<"BROADCAST">>], Props),
_ = kz_amqp_worker:cast(Props, fun kapi_omnipresence:publish_update/1),
maybe_send_update('false', User, Props);
maybe_send_update('undefined', User, Props) ->
maybe_send_update('false', User, Props).

-spec send_update(binaries(), kz_proplist()) -> 'ok'.
send_update(Stalkers, Props) ->
Expand Down

0 comments on commit 053535b

Please sign in to comment.