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
22 changes: 14 additions & 8 deletions realm/lib/chat-db.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@
::
:: MUST EXPLICITLY INCLUDE SELF, this function will not add self into peers list
++ create-path
::chat-db &chat-db-action [%create-path [/example ~ %group *@da *@da ~ %host %.y *@dr *@da (some ['0x000386E3F7559d9B6a2F5c46B4aD1A9587D59Dc3' 'eth-mainnet' 'ERC721'])] ~[[~zod %host] [~bus %member]] 100 ~]
|= [[row=path-row:sur peers=ship-roles:sur expected-msg-count=@ud t=(unit @da)] state=state-4 =bowl:gall]
::chat-db &chat-db-action [%create-path [/example ~ %group *@da *@da ~ %host %.y *@dr *@da (some ['0x000386E3F7559d9B6a2F5c46B4aD1A9587D59Dc3' 'eth-mainnet' 'ERC721'])] ~[[~zod %host] [~bus %member]] %.n ~ ~]
|= [[row=path-row:sur peers=ship-roles:sur pnm=? =message:sur t=(unit @da)] state=state-4 =bowl:gall]
^- (quip card state-4)

?> ?!((~(has by paths-table.state) path.row)) :: ensure the path doesn't already exist!!!
Expand All @@ -226,10 +226,13 @@
=/ vent-path=path
?~ t /chat-vent/(scot %da created-at.row)
/chat-vent/(scot %da u.t)
=/ response
?. pnm !>([%path row])
!>([%path-and-messages row message])
=/ gives :~
[%give %fact [/db (weld /db/path path.row) ~] thechange]
:: give vent response
[%give %fact ~[vent-path] chat-vent+!>([%path-and-count row expected-msg-count])]
[%give %fact ~[vent-path] chat-vent+response]
[%give %kick ~[vent-path] ~]
==
[gives state]
Expand Down Expand Up @@ -1062,11 +1065,14 @@
%ack s/%ack
%msg a+(turn message.chat-vent |=(m=msg-part:sur (messages-row [msg-id.m msg-part-id.m] m)))
%path (path-row path-row.chat-vent)
%path-and-count
=/ prj=json (path-row path-row.chat-vent)
?> ?=([%o *] prj)
:- %o
(~(put by p.prj) %msg-count (numb msg-count.chat-vent))
%path-and-messages
%- pairs
:~ path+(path-row path-row.chat-vent)
:- %messages
:- %a
%+ turn message.chat-vent
|=(m=msg-part:sur (messages-row [[msg-id.m msg-part-id.m] m]))
==
==
::
++ time-bunt-null
Expand Down
24 changes: 12 additions & 12 deletions realm/lib/realm-chat.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
++ create-path-db-poke
|= [=ship row=path-row:db peers=ship-roles:db]
^- card
[%pass /dbpoke %agent [ship %chat-db] %poke %chat-db-action !>([%create-path row peers 0 ~])]
[%pass /dbpoke %agent [ship %chat-db] %poke %chat-db-action !>([%create-path row peers %.n ~ ~])]
::
++ create-path-bedrock-poke
|= [=ship row=path-row:db peers=ship-roles:db]
Expand Down Expand Up @@ -468,28 +468,28 @@
(turn pathpeers |=(p=peer-row:db [patp.p role.p]))
[ship.act %member]

=/ expected-msg-count=@ud
?. peers-get-backlog.pathrow 0
(scry-message-count-for-path path.act bowl)
~& > "expected: {<expected-msg-count>}"
=/ initial-messages=message:db
?. peers-get-backlog.pathrow ~
%+ turn
(scag 50 (scry-messages-for-path path.act our.bowl now.bowl))
|=([k=* v=msg-part:db] v)

=/ backlog-poke-cards=(list card)
?. peers-get-backlog.pathrow ~
?. (gth expected-msg-count 200)
(limo [(into-backlog-msg-poke (turn (scry-messages-for-path path.act our.bowl now.bowl) |=([k=uniq-id:db v=msg-part:db] v)) ship.act) ~])
=/ msgs (scag 200 (scry-messages-for-path path.act our.bowl now.bowl))
:- (into-backlog-msg-poke initial-messages ship.act)
?: (lte (scry-message-count-for-path path.act bowl) 50) ~
=/ tid (cat 3 (spat path.act) ship.act)
=/ start-args [~ `tid byk.bowl(r da+now.bowl) %send-backlog !>(`[path.act ship.act])]
:- (into-backlog-msg-poke (turn msgs |=([k=uniq-id:db v=msg-part:db] v)) ship.act)
:- [%pass /thread/(scot %da now.bowl) %agent [our.bowl %spider] %poke %spider-start !>(start-args)]
~
:_ ~
[%pass /thread/(scot %da now.bowl) %agent [our.bowl %spider] %poke %spider-start !>(start-args)]

:: order matters here, for performance
=/ cards=(list card)
:: :- (add-bedrock-peer-poke (scry-bedrock-path-host:db-scry path.act bowl) path.act ship.act nft.act)
%+ weld
:: we poke the newly-added ship's db with a create-path,
:: since that will automatically handle them joining as a member
:- [%pass /dbpoke %agent [ship.act %chat-db] %poke %chat-db-action !>([%create-path pathrow all-peers expected-msg-count `t.act])]
:- [%pass /dbpoke %agent [ship.act %chat-db] %poke %chat-db-action !>([%create-path pathrow all-peers %.y initial-messages `t.act])]
:: we poke all original peers db with add-peer (including ourselves)
%+ turn
pathpeers
Expand Down
4 changes: 2 additions & 2 deletions realm/sur/chat-db.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
+$ ship-roles (list [s=@p role=@tas])
+$ action
$%
[%create-path =path-row peers=ship-roles expected-msg-count=@ud t=(unit @da)]
[%create-path =path-row peers=ship-roles pnm=? =message t=(unit @da)]
[%edit-path =path metadata=(map cord cord) peers-get-backlog=? invites=@tas max-expires-at-duration=@dr]
[%edit-path-pins =path =pins]
[%leave-path =path]
Expand Down Expand Up @@ -157,7 +157,7 @@
+$ chat-vent
$% [%msg =message]
[%path =path-row]
[%path-and-count =path-row msg-count=@ud]
[%path-and-messages =path-row =message]
[%ack ~]
==
::
Expand Down