Skip to content

Commit

Permalink
set mwi expires large value (2600hz#2971)
Browse files Browse the repository at this point in the history
* set mwi expires large value

* expires value is in seconds
  • Loading branch information
lazedo authored and k-anderson committed Dec 13, 2016
1 parent 5bb2d7d commit fad0408
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion applications/omnipresence/src/omnip_dialog_amqp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 2 additions & 0 deletions applications/omnipresence/src/omnip_message_summary_amqp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
25 changes: 25 additions & 0 deletions applications/omnipresence/src/omnip_presence_amqp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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{}.

Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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).
2 changes: 1 addition & 1 deletion applications/omnipresence/src/omnipresence.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -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))).

Expand Down

0 comments on commit fad0408

Please sign in to comment.