From 55767a72cd2b3e9043bdc74c88805ff7e66035b2 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jun 2024 10:56:55 -0500 Subject: [PATCH 1/8] activity: add feed endpoint --- desk/app/activity.hoon | 124 ++++++++++++++++++++++++++++++++++++ desk/lib/activity-json.hoon | 13 +++- desk/mar/activity/feed.hoon | 14 ++++ desk/sur/activity.hoon | 8 +++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 desk/mar/activity/feed.hoon diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 93894d5225..009e93196b 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -312,6 +312,21 @@ [%x %all start=@ count=@ ~] =- ``activity-stream+!>((gas:on-event:a *stream:a -)) (tab:on-event:a stream:base `(slav %da start.pole) (slav %ud count.pole)) + :: + [%x %feed type=@ start=@ count=@ ~] + =/ start (slav %ud start.pole) + =/ count (slav %ud count.pole) + =- ``activity-feed+!>(-) + ?+ type.pole ~|(bad-feed-type+type.pole !!) + %all + (all-feed start count) + :: + %mentions + (mentions-feed start count) + :: + %replies + (replies-feed start count) + == :: :: /each: unified feed (equality of outcome) ::TODO want to be able to filter for specific events kind too, but that will @@ -374,6 +389,115 @@ ``activity-settings+!>(volume-settings) == :: +++ all-feed + |= [start=time-id:a count=@ud] + |^ + ^- (list activity-bundle:a) + =- happenings.-.- + %^ (dop:ex-event:a out) + (lot:on-event:a stream:base `*@da `+(start)) [count ~] + |= [acc=out =time =event:a] + ^- [(unit event:a) ? out] + ?: =(limit.acc 0) [~ & acc] + :- ~ :- | + ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) acc + =/ =source:a (determine-source -.event) + =- acc(limit (sub limit.acc 1), happenings (snoc happenings.acc -)) + =/ is-mention + ?- -<.event + %post mention.event + %reply mention.event + %dm-post mention.event + %dm-reply mention.event + == + ?: is-mention [source time ~[[time event]]] + [source time (top-messages source stream:(get-index source))] + +$ out + $: limit=@ud + happenings=(list activity-bundle:a) + == + -- +++ mentions-feed + |= [start=time-id:a count=@ud] + |^ + ^- (list activity-bundle:a) + =- happenings.-.- + %^ (dop:ex-event:a out) + (lot:on-event:a stream:base `*@da `+(start)) [count ~] + |= [acc=out =time =event:a] + ^- [(unit event:a) ? out] + ?: =(limit.acc 0) [~ & acc] + :- ~ :- | + ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) acc + =/ is-mention + ?- -<.event + %post mention.event + %reply mention.event + %dm-post mention.event + %dm-reply mention.event + == + ?. is-mention acc + =/ =source:a (determine-source -.event) + =/ bundle [source time ~[[time event]]] + [(sub limit.acc 1) (snoc happenings.acc bundle)] + +$ out + $: limit=@ud + happenings=(list activity-bundle:a) + == + -- +:: +++ replies-feed + |= [start=time-id:a count=@ud] + |^ + ^- (list activity-bundle:a) + =- happenings.-.- + %^ (dop:ex-event:a out) + (lot:on-event:a stream:base `*@da `+(start)) [count ~] + |= [acc=out =time =event:a] + ^- [(unit event:a) ? out] + ?: =(limit.acc 0) [~ & acc] + :- ~ :- | + ?. ?=(?(%reply %dm-reply) -<.event) acc + =/ is-mention + ?- -<.event + %reply mention.event + %dm-reply mention.event + == + ?: is-mention acc + =/ =source:a (determine-source -.event) + =/ bundle [source time (top-messages source stream:(get-index source))] + [(sub limit.acc 1) (snoc happenings.acc bundle)] + +$ out + $: limit=@ud + happenings=(list activity-bundle:a) + == + -- +:: +++ top-messages + |= [=source:a =stream:a] + |^ + ^- (list time-event:a) + =- msgs.-.- + %^ (dop:ex-event:a out) stream [6 ~] + |= [acc=out [=time =event:a]] + ?: =(limit.acc 0) [~ & acc] + ?: child.event [~ | acc] + ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) [~ | acc] + =/ is-mention + ?- -<.event + %post mention.event + %reply mention.event + %dm-post mention.event + %dm-reply mention.event + == + ?: is-mention [~ | acc] + [~ | [(sub limit.acc 1) (snoc msgs.acc [time event])]] + +$ out + $: limit=@ud + msgs=(list time-event:a) + == + -- +:: ++ base ^- index:a (~(got by indices) [%base ~]) diff --git a/desk/lib/activity-json.hoon b/desk/lib/activity-json.hoon index bb0b59d038..bd4ad38b5c 100644 --- a/desk/lib/activity-json.hoon +++ b/desk/lib/activity-json.hoon @@ -144,6 +144,13 @@ children+?~(children.sum ~ (activity u.children.sum)) == :: + ++ activity-bundle + |= ab=activity-bundle:a + %- pairs + :~ source+(source source.ab) + latest+s+(scot %ud latest.ab) + events+a+(turn events.ab time-event) + == ++ event |= e=event:a %- pairs @@ -226,7 +233,7 @@ ++ time-event |= te=time-event:a %- pairs - :~ time+(time time.te) + :~ time+s+(scot %ud time.te) event+(event event.te) == +| %collections @@ -276,6 +283,10 @@ %+ turn ~(tap by vm) |= [e=event-type:a v=volume:a] [e (volume v)] + ++ feed + |= f=feed:a + a+(turn f activity-bundle) + :: +| %updates ++ update |= u=update:a diff --git a/desk/mar/activity/feed.hoon b/desk/mar/activity/feed.hoon new file mode 100644 index 0000000000..e8e414e588 --- /dev/null +++ b/desk/mar/activity/feed.hoon @@ -0,0 +1,14 @@ +/- a=activity +/+ aj=activity-json +|_ =feed:a +++ grad %noun +++ grow + |% + ++ noun feed + ++ json (feed:enjs:aj feed) + -- +++ grab + |% + ++ noun feed:a + -- +-- diff --git a/desk/sur/activity.hoon b/desk/sur/activity.hoon index e3bb42ab9e..0332e9a92c 100644 --- a/desk/sur/activity.hoon +++ b/desk/sur/activity.hoon @@ -16,6 +16,8 @@ +$ volume-map $~ default-volumes (map event-type volume) +:: $feed: a set of grouped events ++$ feed (list activity-bundle) +| %actions :: $action: how to interact with our activity stream :: @@ -163,6 +165,12 @@ == +$ unread-point [message-key count=@ud notify=_|] +$ volume [unreads=? notify=?] ++$ activity-bundle + $: =source + latest=time + events=(list time-event) + == +:: +| %primitives +$ whom $% [%ship p=ship] From 72a9a5d128955c5e14b7ed92e45adca12301433b Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jun 2024 12:47:03 -0500 Subject: [PATCH 2/8] activity: correctly limit feed --- desk/app/activity.hoon | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 009e93196b..3259cdecb0 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -400,8 +400,23 @@ ^- [(unit event:a) ? out] ?: =(limit.acc 0) [~ & acc] :- ~ :- | - ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) acc =/ =source:a (determine-source -.event) + ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) acc + :: if it's a channel we don't host, we don't care + ?: ?& ?=(%channel -.source) + !=(ship.nest.source our.bowl) + == + acc + :: if it's a thread make sure it's one we care about + ?: ?& ?=(?(%reply %dm-reply) -<.event) + !notified.event + == + acc + :: if it's a DM make sure we haven't muted it + ?: ?& ?=(%dm-post -<.event) + !notified.event + == + acc =- acc(limit (sub limit.acc 1), happenings (snoc happenings.acc -)) =/ is-mention ?- -<.event @@ -457,7 +472,7 @@ ^- [(unit event:a) ? out] ?: =(limit.acc 0) [~ & acc] :- ~ :- | - ?. ?=(?(%reply %dm-reply) -<.event) acc + ?. &(?=(?(%reply %dm-reply) -<.event) notified.event) acc =/ is-mention ?- -<.event %reply mention.event From 90f913c0858be5dcff7baeb94d9901ebc67aac15 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jun 2024 15:54:12 -0500 Subject: [PATCH 3/8] activity: update types and refine feed --- desk/app/activity.hoon | 55 ++++++++++++--------------- desk/lib/activity-json.hoon | 9 +++-- desk/sur/activity.hoon | 2 +- packages/shared/src/urbit/activity.ts | 11 ++++++ 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 3259cdecb0..896f53f119 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -313,19 +313,17 @@ =- ``activity-stream+!>((gas:on-event:a *stream:a -)) (tab:on-event:a stream:base `(slav %da start.pole) (slav %ud count.pole)) :: - [%x %feed type=@ start=@ count=@ ~] - =/ start (slav %ud start.pole) + [%x %feed type=@ count=@ start=?(~ [u=@ ~])] + =/ start + ?~ start.pole now.bowl + ?^ tim=(slaw %ud u.start.pole) u.tim + (slav %da u.start.pole) =/ count (slav %ud count.pole) =- ``activity-feed+!>(-) ?+ type.pole ~|(bad-feed-type+type.pole !!) - %all - (all-feed start count) - :: - %mentions - (mentions-feed start count) - :: - %replies - (replies-feed start count) + %all (all-feed start count) + %replies (replies-feed start count) + %mentions (mentions-feed start count) == :: :: /each: unified feed (equality of outcome) @@ -395,29 +393,16 @@ ^- (list activity-bundle:a) =- happenings.-.- %^ (dop:ex-event:a out) - (lot:on-event:a stream:base `*@da `+(start)) [count ~] + (lot:on-event:a stream:base `*@da `+(start)) [count ~ ~] |= [acc=out =time =event:a] ^- [(unit event:a) ? out] ?: =(limit.acc 0) [~ & acc] :- ~ :- | =/ =source:a (determine-source -.event) - ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) acc - :: if it's a channel we don't host, we don't care - ?: ?& ?=(%channel -.source) - !=(ship.nest.source our.bowl) - == - acc - :: if it's a thread make sure it's one we care about - ?: ?& ?=(?(%reply %dm-reply) -<.event) - !notified.event - == - acc - :: if it's a DM make sure we haven't muted it - ?: ?& ?=(%dm-post -<.event) - !notified.event + ?. ?& notified.event + ?=(?(%post %reply %dm-post %dm-reply) -<.event) == acc - =- acc(limit (sub limit.acc 1), happenings (snoc happenings.acc -)) =/ is-mention ?- -<.event %post mention.event @@ -425,11 +410,21 @@ %dm-post mention.event %dm-reply mention.event == - ?: is-mention [source time ~[[time event]]] - [source time (top-messages source stream:(get-index source))] + :: make sure we haven't collapsed this event already, but elevate + :: mentions either way + ?. |(!(~(has in collapsed.acc) time) is-mention) acc + :- (sub limit.acc 1) + ?: is-mention + =/ bundle=activity-bundle:a [source time ~[[time event]]] + [(snoc happenings.acc bundle) collapsed.acc] + =/ top (top-messages source stream:(get-index source)) + =/ collapsed + (~(gas in collapsed.acc) (turn top |=([=time-id:a *] time-id))) + [(snoc happenings.acc [source time top]) collapsed] +$ out $: limit=@ud happenings=(list activity-bundle:a) + collapsed=(set time-id:a) == -- ++ mentions-feed @@ -527,14 +522,14 @@ $(t +(t)) =/ notify notify:(get-volume inc) =/ =event:a [inc notify |] + =/ =source:a (determine-source inc) =? cor !importing - (give %fact ~[/] activity-update+!>([%add time-id event])) + (give %fact ~[/] activity-update+!>([%add source time-id event])) =? cor &(!importing notify) (give %fact ~[/notifications] activity-event+!>([time-id event])) =. indices =/ =stream:a (put:on-event:a stream:base time-id event) (~(put by indices) [%base ~] [stream reads:base]) - =/ =source:a (determine-source inc) ?+ -<.event (add-to-index source time-id event) %chan-init =/ group-src [%group group.event] diff --git a/desk/lib/activity-json.hoon b/desk/lib/activity-json.hoon index bd4ad38b5c..c642a3f135 100644 --- a/desk/lib/activity-json.hoon +++ b/desk/lib/activity-json.hoon @@ -148,6 +148,7 @@ |= ab=activity-bundle:a %- pairs :~ source+(source source.ab) + source-key+s+(string-source source.ab) latest+s+(scot %ud latest.ab) events+a+(turn events.ab time-event) == @@ -299,10 +300,12 @@ == :: ++ added - |= ad=time-event:a + |= [src=source:a te=time-event:a] %- pairs - :~ time+(time time.ad) - event+(event event.ad) + :~ source+(source src) + source-key+s+(string-source src) + time+(time time.te) + event+(event event.te) == :: ++ read diff --git a/desk/sur/activity.hoon b/desk/sur/activity.hoon index 0332e9a92c..9c8d03cf04 100644 --- a/desk/sur/activity.hoon +++ b/desk/sur/activity.hoon @@ -57,7 +57,7 @@ :: $adjust: the volume of a source was adjusted :: +$ update - $% [%add time-event] + $% [%add =source time-event] [%del =source] [%read =source =activity-summary] [%adjust =source volume-map=(unit volume-map)] diff --git a/packages/shared/src/urbit/activity.ts b/packages/shared/src/urbit/activity.ts index 7ca0ff459a..7f28edbd42 100644 --- a/packages/shared/src/urbit/activity.ts +++ b/packages/shared/src/urbit/activity.ts @@ -173,6 +173,13 @@ export interface ActivitySummary { children: Activity | null; } +export interface ActivityBundle { + source: Source; + latest: string; + events: ActivityEvent[]; + 'source-key': string; +} + export type Activity = Record; export type Indices = Record; @@ -181,6 +188,8 @@ export type Stream = Record; export type VolumeMap = Partial>; +export type ActivityFeed = ActivityBundle[]; + export type ReadAction = | { event: ActivityIncomingEvent } | { item: string } @@ -218,8 +227,10 @@ export interface ActivityVolumeUpdate { export interface ActivityAddUpdate { add: { + source: Source; time: string; event: ActivityEvent; + 'source-key': string; }; } From 0c29689f3568abc91e5ab7b23ab5d3904103ad38 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jun 2024 16:41:01 -0500 Subject: [PATCH 4/8] activity: add init scry and refactor feed collection --- desk/app/activity.hoon | 111 ++++++++++--------------------- desk/lib/mark-warmer.hoon | 3 + desk/mar/activity/feed-init.hoon | 20 ++++++ 3 files changed, 59 insertions(+), 75 deletions(-) create mode 100644 desk/mar/activity/feed-init.hoon diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 896f53f119..47973c16af 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -312,6 +312,15 @@ [%x %all start=@ count=@ ~] =- ``activity-stream+!>((gas:on-event:a *stream:a -)) (tab:on-event:a stream:base `(slav %da start.pole) (slav %ud count.pole)) + :: + [%x %feed %init count=@ ~] + =- ``activity-feed-init+!>(-) + =/ start now.bowl + =/ count (slav %ud count.pole) + :* (feed %all start count) + (feed %mentions start count) + (feed %replies start count) + == :: [%x %feed type=@ count=@ start=?(~ [u=@ ~])] =/ start @@ -320,11 +329,9 @@ (slav %da u.start.pole) =/ count (slav %ud count.pole) =- ``activity-feed+!>(-) - ?+ type.pole ~|(bad-feed-type+type.pole !!) - %all (all-feed start count) - %replies (replies-feed start count) - %mentions (mentions-feed start count) - == + ~| bad-feed-type+type.pole + ?> ?=(?(%all %mentions %replies) type.pole) + (feed type.pole start count) :: :: /each: unified feed (equality of outcome) ::TODO want to be able to filter for specific events kind too, but that will @@ -387,8 +394,8 @@ ``activity-settings+!>(volume-settings) == :: -++ all-feed - |= [start=time-id:a count=@ud] +++ feed + |= [type=?(%all %mentions %replies) start=time-id:a count=@ud] |^ ^- (list activity-bundle:a) =- happenings.-.- @@ -403,20 +410,29 @@ ?=(?(%post %reply %dm-post %dm-reply) -<.event) == acc - =/ is-mention - ?- -<.event - %post mention.event - %reply mention.event - %dm-post mention.event - %dm-reply mention.event - == - :: make sure we haven't collapsed this event already, but elevate - :: mentions either way - ?. |(!(~(has in collapsed.acc) time) is-mention) acc :- (sub limit.acc 1) - ?: is-mention - =/ bundle=activity-bundle:a [source time ~[[time event]]] - [(snoc happenings.acc bundle) collapsed.acc] + =/ mention=(unit activity-bundle:a) + ?. |(?=(%all type) ?=(%mentions type)) ~ + =/ is-mention + ?- -<.event + %post mention.event + %reply mention.event + %dm-post mention.event + %dm-reply mention.event + == + ?. is-mention ~ + `[source time ~[[time event]]] + ?^ mention + [(snoc happenings.acc u.mention) collapsed.acc] + =/ care + ?| ?=(%all type) + &(?=(%replies type) ?=(?(%reply %dm-reply) -<.event)) + == + :: make sure we care and haven't collapsed this event already + ?. ?& care + !(~(has in collapsed.acc) time) + == + [happenings collapsed]:acc =/ top (top-messages source stream:(get-index source)) =/ collapsed (~(gas in collapsed.acc) (turn top |=([=time-id:a *] time-id))) @@ -427,61 +443,6 @@ collapsed=(set time-id:a) == -- -++ mentions-feed - |= [start=time-id:a count=@ud] - |^ - ^- (list activity-bundle:a) - =- happenings.-.- - %^ (dop:ex-event:a out) - (lot:on-event:a stream:base `*@da `+(start)) [count ~] - |= [acc=out =time =event:a] - ^- [(unit event:a) ? out] - ?: =(limit.acc 0) [~ & acc] - :- ~ :- | - ?. ?=(?(%post %reply %dm-post %dm-reply) -<.event) acc - =/ is-mention - ?- -<.event - %post mention.event - %reply mention.event - %dm-post mention.event - %dm-reply mention.event - == - ?. is-mention acc - =/ =source:a (determine-source -.event) - =/ bundle [source time ~[[time event]]] - [(sub limit.acc 1) (snoc happenings.acc bundle)] - +$ out - $: limit=@ud - happenings=(list activity-bundle:a) - == - -- -:: -++ replies-feed - |= [start=time-id:a count=@ud] - |^ - ^- (list activity-bundle:a) - =- happenings.-.- - %^ (dop:ex-event:a out) - (lot:on-event:a stream:base `*@da `+(start)) [count ~] - |= [acc=out =time =event:a] - ^- [(unit event:a) ? out] - ?: =(limit.acc 0) [~ & acc] - :- ~ :- | - ?. &(?=(?(%reply %dm-reply) -<.event) notified.event) acc - =/ is-mention - ?- -<.event - %reply mention.event - %dm-reply mention.event - == - ?: is-mention acc - =/ =source:a (determine-source -.event) - =/ bundle [source time (top-messages source stream:(get-index source))] - [(sub limit.acc 1) (snoc happenings.acc bundle)] - +$ out - $: limit=@ud - happenings=(list activity-bundle:a) - == - -- :: ++ top-messages |= [=source:a =stream:a] diff --git a/desk/lib/mark-warmer.hoon b/desk/lib/mark-warmer.hoon index b0e51e8eca..c346a93806 100644 --- a/desk/lib/mark-warmer.hoon +++ b/desk/lib/mark-warmer.hoon @@ -35,4 +35,7 @@ /$ act-sum %activity-summary %json /$ act-vol %activity-settings %json /$ act-evt %activity-event %json +/$ act-stream %activity-stream %json +/$ act-feed %activity-feed %json +/$ act-fe-it %activity-feed-init %json ~ diff --git a/desk/mar/activity/feed-init.hoon b/desk/mar/activity/feed-init.hoon new file mode 100644 index 0000000000..15cef1ade3 --- /dev/null +++ b/desk/mar/activity/feed-init.hoon @@ -0,0 +1,20 @@ +/- a=activity +/+ aj=activity-json +|_ [all=feed:a mentions=feed:a replies=feed:a] +++ grad %noun +++ grow + |% + ++ noun [all mentions replies] + ++ json + =, enjs:format + %- pairs + :~ all+(feed:enjs:aj all) + mentions+(feed:enjs:aj mentions) + replies+(feed:enjs:aj replies) + == + -- +++ grab + |% + ++ noun [all=feed:a mentions=feed:a replies=feed:a] + -- +-- From 33c6633a6520f359d3c67b8dcd0820be4e6c10cb Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jun 2024 16:49:47 -0500 Subject: [PATCH 5/8] activity: switch all scry to latest first and make start optional --- desk/app/activity.hoon | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 47973c16af..3ba4605678 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -309,9 +309,14 @@ [%x %all ~] ``activity-stream+!>(stream:base) :: - [%x %all start=@ count=@ ~] + [%x %all count=@ start=?(~ [u=@ ~])] + =/ start + ?~ start.pole now.bowl + ?^ tim=(slaw %ud u.start.pole) u.tim + (slav %da u.start.pole) + =/ count (slav %ud count.pole) =- ``activity-stream+!>((gas:on-event:a *stream:a -)) - (tab:on-event:a stream:base `(slav %da start.pole) (slav %ud count.pole)) + (bat:ex-event:a stream:base `start count) :: [%x %feed %init count=@ ~] =- ``activity-feed-init+!>(-) From 7d8f40ae105aa279f839b17cfeccf956266e7a51 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jun 2024 18:03:40 -0500 Subject: [PATCH 6/8] activity: make sure we don't aggregate events whose sources have newer activity than start --- desk/app/activity.hoon | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 3ba4605678..90d9828d8a 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -404,17 +404,32 @@ |^ ^- (list activity-bundle:a) =- happenings.-.- + :: if start is now, need to increment to make sure we include latest + :: event if that event somehow has now as its time + =/ real-start ?:(=(start now.bowl) +(start) start) %^ (dop:ex-event:a out) - (lot:on-event:a stream:base `*@da `+(start)) [count ~ ~] + (lot:on-event:a stream:base `*@da `real-start) [~ count ~ ~] |= [acc=out =time =event:a] ^- [(unit event:a) ? out] ?: =(limit.acc 0) [~ & acc] :- ~ :- | =/ =source:a (determine-source -.event) + =/ latest + ?^ stored=(~(get by times.acc) source) u.stored + ?~ new=(ram:on-event:a stream:(get-index source)) + :: should never happen but -\_(ツ)_/- + (sub start 1) + -.u.new + =/ new-times (~(put by times.acc) source latest) + :: we only care about posts/replies events that are notified, and we + :: don't want to include events from sources whose latest event is + :: after the start so we always get "new" sources when paging ?. ?& notified.event + (lth latest start) ?=(?(%post %reply %dm-post %dm-reply) -<.event) == - acc + acc(times new-times) + :- new-times :- (sub limit.acc 1) =/ mention=(unit activity-bundle:a) ?. |(?=(%all type) ?=(%mentions type)) ~ @@ -443,7 +458,8 @@ (~(gas in collapsed.acc) (turn top |=([=time-id:a *] time-id))) [(snoc happenings.acc [source time top]) collapsed] +$ out - $: limit=@ud + $: times=(map source:a time-id:a) + limit=@ud happenings=(list activity-bundle:a) collapsed=(set time-id:a) == From 314c3988895449cfb52e92e0555cb43ae7455593 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Wed, 12 Jun 2024 11:10:40 -0500 Subject: [PATCH 7/8] activity: make sure we correctly account for limit --- desk/app/activity.hoon | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 90d9828d8a..5e499c3828 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -430,7 +430,6 @@ == acc(times new-times) :- new-times - :- (sub limit.acc 1) =/ mention=(unit activity-bundle:a) ?. |(?=(%all type) ?=(%mentions type)) ~ =/ is-mention @@ -443,7 +442,7 @@ ?. is-mention ~ `[source time ~[[time event]]] ?^ mention - [(snoc happenings.acc u.mention) collapsed.acc] + [(sub limit.acc 1) (snoc happenings.acc u.mention) collapsed.acc] =/ care ?| ?=(%all type) &(?=(%replies type) ?=(?(%reply %dm-reply) -<.event)) @@ -452,11 +451,11 @@ ?. ?& care !(~(has in collapsed.acc) time) == - [happenings collapsed]:acc + [limit happenings collapsed]:acc =/ top (top-messages source stream:(get-index source)) =/ collapsed (~(gas in collapsed.acc) (turn top |=([=time-id:a *] time-id))) - [(snoc happenings.acc [source time top]) collapsed] + [(sub limit.acc 1) (snoc happenings.acc [source time top]) collapsed] +$ out $: times=(map source:a time-id:a) limit=@ud From 8ebe939499b6b0de797cd8a790493baa1f73fbd8 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Wed, 12 Jun 2024 14:27:47 -0500 Subject: [PATCH 8/8] activity: cleanup code and style --- desk/app/activity.hoon | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/desk/app/activity.hoon b/desk/app/activity.hoon index 5e499c3828..371f0450e9 100644 --- a/desk/app/activity.hoon +++ b/desk/app/activity.hoon @@ -319,23 +319,23 @@ (bat:ex-event:a stream:base `start count) :: [%x %feed %init count=@ ~] - =- ``activity-feed-init+!>(-) =/ start now.bowl =/ count (slav %ud count.pole) + =; init=[all=feed:a mentions=feed:a replies=feed:a] + ``activity-feed-init+!>(init) :* (feed %all start count) (feed %mentions start count) (feed %replies start count) == :: - [%x %feed type=@ count=@ start=?(~ [u=@ ~])] + [%x %feed type=?(%all %mentions %replies) count=@ start=?(~ [u=@ ~])] =/ start ?~ start.pole now.bowl ?^ tim=(slaw %ud u.start.pole) u.tim (slav %da u.start.pole) =/ count (slav %ud count.pole) - =- ``activity-feed+!>(-) - ~| bad-feed-type+type.pole - ?> ?=(?(%all %mentions %replies) type.pole) + =; =feed:a + ``activity-feed+!>(feed) (feed type.pole start count) :: :: /each: unified feed (equality of outcome) @@ -403,24 +403,24 @@ |= [type=?(%all %mentions %replies) start=time-id:a count=@ud] |^ ^- (list activity-bundle:a) - =- happenings.-.- + =- happenings :: if start is now, need to increment to make sure we include latest :: event if that event somehow has now as its time =/ real-start ?:(=(start now.bowl) +(start) start) %^ (dop:ex-event:a out) - (lot:on-event:a stream:base `*@da `real-start) [~ count ~ ~] + stream:base + [~ count ~ ~] |= [acc=out =time =event:a] ^- [(unit event:a) ? out] ?: =(limit.acc 0) [~ & acc] + :: we only care about events older than start + ?: (gth time real-start) [~ | acc] :- ~ :- | =/ =source:a (determine-source -.event) =/ latest ?^ stored=(~(get by times.acc) source) u.stored - ?~ new=(ram:on-event:a stream:(get-index source)) - :: should never happen but -\_(ツ)_/- - (sub start 1) - -.u.new - =/ new-times (~(put by times.acc) source latest) + -:(need (ram:on-event:a stream:(get-index source))) + =. times.acc (~(put by times.acc) source latest) :: we only care about posts/replies events that are notified, and we :: don't want to include events from sources whose latest event is :: after the start so we always get "new" sources when paging @@ -428,8 +428,8 @@ (lth latest start) ?=(?(%post %reply %dm-post %dm-reply) -<.event) == - acc(times new-times) - :- new-times + acc + :- times.acc =/ mention=(unit activity-bundle:a) ?. |(?=(%all type) ?=(%mentions type)) ~ =/ is-mention @@ -453,8 +453,10 @@ == [limit happenings collapsed]:acc =/ top (top-messages source stream:(get-index source)) + :: collapsed is a set of event ids that we've already included in the feed + :: and so should be ignored =/ collapsed - (~(gas in collapsed.acc) (turn top |=([=time-id:a *] time-id))) + (~(gas in collapsed.acc) (turn top head)) [(sub limit.acc 1) (snoc happenings.acc [source time top]) collapsed] +$ out $: times=(map source:a time-id:a) @@ -463,13 +465,13 @@ collapsed=(set time-id:a) == -- -:: +++ recent-messages-amount 6 ++ top-messages |= [=source:a =stream:a] |^ ^- (list time-event:a) - =- msgs.-.- - %^ (dop:ex-event:a out) stream [6 ~] + =- msgs + %^ (dop:ex-event:a out) stream [recent-messages-amount ~] |= [acc=out [=time =event:a]] ?: =(limit.acc 0) [~ & acc] ?: child.event [~ | acc]