From fad040817513053abf35aec56eb9a2737c6a571c Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 13 Dec 2016 18:55:37 +0000 Subject: [PATCH] set mwi expires large value (#2971) * set mwi expires large value * expires value is in seconds --- .../omnipresence/src/omnip_dialog_amqp.erl | 2 +- .../src/omnip_message_summary_amqp.erl | 2 ++ .../omnipresence/src/omnip_presence_amqp.erl | 25 +++++++++++++++++++ .../omnipresence/src/omnipresence.hrl | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/applications/omnipresence/src/omnip_dialog_amqp.erl b/applications/omnipresence/src/omnip_dialog_amqp.erl index 5d8c7a6fa8e..53b320f17a3 100644 --- a/applications/omnipresence/src/omnip_dialog_amqp.erl +++ b/applications/omnipresence/src/omnip_dialog_amqp.erl @@ -427,4 +427,4 @@ mwi_event(JObj) -> ,{<<"Flush-Level">>, 1} ,{<<"Call-Direction">>, <<"inbound">>} ]), - handle_update(kz_json:from_list(Props), State, 0). + handle_update(kz_json:from_list(Props), State, 60 * ?SECONDS_IN_DAY). diff --git a/applications/omnipresence/src/omnip_message_summary_amqp.erl b/applications/omnipresence/src/omnip_message_summary_amqp.erl index 84d957d5a44..8e5515ab0f3 100644 --- a/applications/omnipresence/src/omnip_message_summary_amqp.erl +++ b/applications/omnipresence/src/omnip_message_summary_amqp.erl @@ -192,6 +192,7 @@ handle_update(JObj, To) -> MessagesUrgent = kz_json:get_integer_value(<<"Messages-Urgent">>, JObj, 0), MessagesUrgentSaved = kz_json:get_integer_value(<<"Messages-Urgent-Saved">>, JObj, 0), MessagesWaiting = case MessagesNew of 0 -> <<"no">>; _ -> <<"yes">> end, + Expires = 60 * ?SECONDS_IN_DAY, Update = props:filter_undefined( [{<<"To">>, <<"sip:", To/binary>>} ,{<<"To-User">>, ToUsername} @@ -200,6 +201,7 @@ handle_update(JObj, To) -> ,{<<"From-User">>, ToUsername} ,{<<"From-Realm">>, ToRealm} ,{<<"Call-ID">>, ?FAKE_CALLID(To)} + ,{<<"Expires">>, Expires} ,{<<"Message-Account">>, <<"sip:", To/binary>>} ,{<<"Messages-Waiting">>, MessagesWaiting} ,{<<"Messages-New">>, MessagesNew} diff --git a/applications/omnipresence/src/omnip_presence_amqp.erl b/applications/omnipresence/src/omnip_presence_amqp.erl index 1f4ce0519e3..d0415412e34 100644 --- a/applications/omnipresence/src/omnip_presence_amqp.erl +++ b/applications/omnipresence/src/omnip_presence_amqp.erl @@ -24,6 +24,10 @@ -define(SERVER, ?MODULE). +-define(DEFAULT_VM_NUMBER, <<"*98">>). +-define(VM_NUMBER_KEY, <<"presence_subscribed_mwi_prefix">>). +-define(VM_NUMBER(A), kapps_account_config:get_global(A, ?CONFIG_CAT, ?VM_NUMBER_KEY, ?DEFAULT_VM_NUMBER)). + -record(state, {}). -type state() :: #state{}. @@ -111,6 +115,10 @@ handle_cast({'omnipresence',{'channel_event', JObj}}, State) -> EventType = kz_json:get_value(<<"Event-Name">>, JObj), _ = kz_util:spawn(fun channel_event/2, [EventType, JObj]), {'noreply', State}; +handle_cast({'omnipresence',{'mwi_update', JObj}}, State) -> + kz_util:put_callid(JObj), + _ = kz_util:spawn(fun mwi_event/1, [JObj]), + {'noreply', State}; handle_cast({'omnipresence', _}, State) -> {'noreply', State}; handle_cast(_Msg, State) -> @@ -331,3 +339,20 @@ presence_reset(JObj) -> set_presence_state(PresenceId, State) -> Headers = [{<<"Presence-ID">>, PresenceId }], handle_update(kz_json:from_list(Headers), State, 0). + +-spec mwi_event(kz_json:object()) -> 'ok'. +mwi_event(JObj) -> + To = kz_json:get_value(<<"To">>, JObj), + [_, ToRealm] = binary:split(To, <<"@">>), + {ok, AccountDb} = kapps_util:get_account_by_realm(ToRealm), + AccountId = kz_util:format_account_id(AccountDb), + State = case kz_json:get_integer_value(<<"Messages-New">>, JObj, 0) of + 0 -> ?PRESENCE_HANGUP; + _ -> ?PRESENCE_ANSWERED + end, + Props = props:filter_undefined( + [{<<"Presence-ID">>, <<(?VM_NUMBER(AccountId))/binary, To/binary>>} + ,{<<"Flush-Level">>, 1} + ,{<<"Call-Direction">>, <<"inbound">>} + ]), + handle_update(kz_json:from_list(Props), State, 60 * ?SECONDS_IN_DAY). diff --git a/applications/omnipresence/src/omnipresence.hrl b/applications/omnipresence/src/omnipresence.hrl index b142fa6bcd4..772a9328ee2 100644 --- a/applications/omnipresence/src/omnipresence.hrl +++ b/applications/omnipresence/src/omnipresence.hrl @@ -24,7 +24,7 @@ -define(RINGING_TIME, 24 * ?SECONDS_IN_HOUR). -define(ANSWERED_TIME, 24 * ?SECONDS_IN_HOUR). -define(HANGUP_TIME, 10). --define(OTHER_TIME, 36000). +-define(OTHER_TIME, 24 * ?SECONDS_IN_HOUR). -define(FAKE_CALLID(C), kz_util:to_hex_binary(crypto:hash(md5, C))).