diff --git a/realm/app/realm-chat.hoon b/realm/app/realm-chat.hoon index 2d79d1c..234a272 100644 --- a/realm/app/realm-chat.hoon +++ b/realm/app/realm-chat.hoon @@ -222,6 +222,27 @@ ?: =(sender.id our.bowl) ~ :: if it's our message, don't do anything =/ thepath path.first-msg-part + =/ prow (scry-path-row:lib thepath bowl) + + :: VoIP push logic + =/ should-voip-push=? + ?+ -.content.first-msg-part %.n + %status + =/ ucall (find "started a call with you" (trip p.content.first-msg-part)) + ?~ ucall %.n + %.y + == + =/ voip-cards=(list card) + ?. should-voip-push ~ + ?> ?=(%status -.content.first-msg-part) + :_ ~ + %: voip-push-notification-card:lib + bowl + state + prow + p.content.first-msg-part + == + :: if it's a %react AND it's not reacting to our :: message, don't do anything =/ not-replying-to-us=? @@ -230,13 +251,12 @@ ?: &(=(-.content.first-msg-part %react) not-replying-to-us) ~ ?: (~(has in mutes.state) thepath) :: if it's a muted path, send a pre-dismissed notif to notif-db =/ notif-db-card (notif-new-msg:core parts our.bowl %.y bowl) - [notif-db-card ~] + [notif-db-card voip-cards] =/ notif-db-card (notif-new-msg:core parts our.bowl %.n bowl) ?: :: if we should do a push notification also, ?& push-enabled.state :: push is enabled (gth (lent ~(tap by devices.state)) 0) :: there is at least one device == - =/ prow (scry-path-row:lib thepath bowl) =/ mess (scry-message:lib id bowl) =/ space-scry=(unit view:spc) ?. =(%space type.prow) ~ @@ -279,9 +299,9 @@ avatar mess == - [push-card notif-db-card ~] + [push-card notif-db-card voip-cards] :: otherwise, just send to notif-db - [notif-db-card ~] + [notif-db-card voip-cards] =/ cards=(list card) %- zing diff --git a/realm/lib/realm-chat.hoon b/realm/lib/realm-chat.hoon index 6445219..0a9b345 100644 --- a/realm/lib/realm-chat.hoon +++ b/realm/lib/realm-chat.hoon @@ -308,6 +308,33 @@ [%pass /push-notification/(scot %da now.bowl) %arvo %i %request request *outbound-config:iris] :: +++ voip-push-notification-card + |= [=bowl:gall state=state-1 =path-row:db message=@t] + ^- card + =/ details + :* app-id.state + path-row + message + == + :: send http request + :: + =/ =header-list:http ['Content-Type' 'application/json']~ + =| =request:http + =: method.request %'POST' + url.request 'https://onesignal.com/api/v1/notifications' + header-list.request header-list + body.request + :- ~ + %- as-octt:mimes:html + %- trip + %- en:json:html + %+ voip-request:encode + details + devices.state + == + + [%pass /push-notification/(scot %da now.bowl) %arvo %i %request request *outbound-config:iris] +:: ++ dm-already-exists |= [typ=@tas peers=(list ship) =bowl:gall] ^- ? @@ -870,6 +897,22 @@ msg-preview-notif+b+msg-preview-notif.s == :: + ++ voip-request :: encodes for iris outbound + |= [details=[app-id=@t =path-row:db msg=@t] =devices] + ^- json + =/ player-ids ~(val by devices) + %- pairs + :~ + ['app_id' s+app-id.details] + ['include_player_ids' a+(turn player-ids |=([id=@t] s+id))] + ['contents' (pairs ~[en+s+msg.details])] + ['apns_push_type_override' s+'voip'] + :- 'data' + %- pairs + :_ ~ + ['path-row' (path-row:encode:chat-db path-row.details)] + == + :: ++ notify-request :: encodes for iris outbound |= [notif=push-notif =devices] ^- json