Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions realm/app/realm-chat.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -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=?
Expand All @@ -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) ~
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions realm/lib/realm-chat.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -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]
^- ?
Expand Down Expand Up @@ -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
Expand Down