diff --git a/realm/lib/chat-db.hoon b/realm/lib/chat-db.hoon index 7b2b88a..4908fe0 100644 --- a/realm/lib/chat-db.hoon +++ b/realm/lib/chat-db.hoon @@ -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!!! @@ -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] @@ -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 diff --git a/realm/lib/realm-chat.hoon b/realm/lib/realm-chat.hoon index 9f3d2dd..2118bed 100644 --- a/realm/lib/realm-chat.hoon +++ b/realm/lib/realm-chat.hoon @@ -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] @@ -468,20 +468,20 @@ (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: {}" + =/ 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) @@ -489,7 +489,7 @@ %+ 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 diff --git a/realm/sur/chat-db.hoon b/realm/sur/chat-db.hoon index 55c1e9a..bc92de2 100644 --- a/realm/sur/chat-db.hoon +++ b/realm/sur/chat-db.hoon @@ -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] @@ -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 ~] == ::