Skip to content
Browse files

WHISTLE-571: reply to presence probes for BLF

  • Loading branch information...
1 parent 7e1328a commit 5c8a4179df436fc53d7ec7a7b46ac98fd0b6c51a @k-anderson k-anderson committed Feb 14, 2012
View
36 whistle_apps/apps/registrar/src/reg_query.erl
@@ -8,17 +8,41 @@
%%%-------------------------------------------------------------------
-module(reg_query).
--export([init/0, handle_req/2]).
-
-include("reg.hrl").
+-export([init/0]).
+-export([req_query_req/2]).
+-export([presence_probe/2]).
+
init() ->
ok.
--spec handle_req/2 :: (ApiJObj, Props) -> no_return() when
- ApiJObj :: wh_json:json_object(),
- Props :: proplist().
-handle_req(ApiJObj, _Props) ->
+-spec presence_probe/2 :: (wh_json:json_object(), proplist()) -> ok.
+presence_probe(ApiJObj, _Props) ->
+ ToRealm = wh_json:get_ne_value(<<"To-Realm">>, ApiJObj),
+ ToUser = wh_json:get_ne_value(<<"To-User">>, ApiJObj),
+ FromRealm = wh_json:get_ne_value(<<"From-Realm">>, ApiJObj),
+ FromUser = wh_json:get_ne_value(<<"From-User">>, ApiJObj),
+ case reg_util:lookup_registration(ToRealm, ToUser) of
+ {ok, RegJObjs} when is_list(RegJObjs) ->
+ PresenceUpdate = [{<<"Presence-ID">>, list_to_binary([ToUser, "@", ToRealm])}
+ ,{<<"To">>, list_to_binary([FromUser, "@", FromRealm])}
+ | wh_api:default_headers(?APP_NAME, ?APP_VERSION)
+ ],
+ wapi_notifications:publish_presence_update(PresenceUpdate);
+ {ok, _} ->
+ PresenceUpdate = [{<<"Presence-ID">>, list_to_binary([ToUser, "@", ToRealm])}
+ ,{<<"To">>, list_to_binary([FromUser, "@", FromRealm])}
+ | wh_api:default_headers(?APP_NAME, ?APP_VERSION)
+ ],
+ wapi_notifications:publish_presence_update(PresenceUpdate);
+ {error, not_found} ->
+ ok
+ end,
+ ok.
+
+-spec req_query_req/2 :: (wh_json:json_object(), proplist()) -> ok.
+req_query_req(ApiJObj, _Props) ->
true = wapi_registration:query_req_v(ApiJObj),
CallId = wh_json:get_value(<<"Call-ID">>, ApiJObj, <<"000000000000">>),
View
4 whistle_apps/apps/registrar/src/registrar_listener.erl
@@ -23,11 +23,13 @@
-define(RESPONDERS, [{reg_authn_req, [{<<"directory">>, <<"authn_req">>}]}
,{reg_success, [{<<"directory">>, <<"reg_success">>}]}
- ,{reg_query, [{<<"directory">>, <<"reg_query">>}]}
+ ,{{reg_query, req_query_req}, [{<<"directory">>, <<"reg_query">>}]}
,{{?MODULE, reg_query_resp}, [{<<"directory">>, <<"reg_query_resp">>}]}
+ ,{{reg_query, presence_probe}, [{<<"notification">>, <<"presence_probe">>}]}
]).
-define(BINDINGS, [{authn, []}
,{registration, []}
+ ,{notifications, [{restrict_to, [presence_probe]}]}
,{self, []}
]).

0 comments on commit 5c8a417

Please sign in to comment.
Something went wrong with that request. Please try again.