From 6b6e9a7be2d50bea46ef63fe9a54ce31726a8210 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Thu, 17 Dec 2020 16:10:26 +1000 Subject: [PATCH] hark: cleanup notifications on leave --- pkg/arvo/app/hark-graph-hook.hoon | 41 ++++++++++--- pkg/arvo/app/hark-store.hoon | 57 +++++++++++++++++++ pkg/arvo/lib/graph.hoon | 2 +- pkg/arvo/lib/hark/store.hoon | 1 + pkg/arvo/sur/hark-store.hoon | 2 + .../src/logic/reducers/hark-update.ts | 8 +++ 6 files changed, 101 insertions(+), 10 deletions(-) diff --git a/pkg/arvo/app/hark-graph-hook.hoon b/pkg/arvo/app/hark-graph-hook.hoon index 1fa2ae75a..b9f0d4088 100644 --- a/pkg/arvo/app/hark-graph-hook.hoon +++ b/pkg/arvo/app/hark-graph-hook.hoon @@ -158,6 +158,36 @@ (graph-update !<(update:graph-store q.cage.sign)) [cards this] == + :: + ++ graph-update + |= =update:graph-store + ^- (quip card _state) + ?+ -.q.update `state + %add-graph (add-graph resource.q.update) + :: + ?(%remove-graph %archive-graph) + (remove-graph resource.q.update) + :: + %add-nodes + =* rid resource.q.update + (check-nodes ~(val by nodes.q.update) rid) + == + :: + ++ remove-graph + |= rid=resource + =/ unwatched + %- ~(gas in *_watching) + %+ skim ~(tap in watching) + |= [r=resource idx=index:graph-store] + =(r rid) + :_ state(watching (~(dif in watching) unwatched)) + ^- (list card) + :- (poke-hark:ha %remove-graph rid) + %- zing + %+ turn ~(tap in unwatched) + |= [r=resource =index:graph-store] + (give:ha ~[/updates] %ignore r index) + :: ++ add-graph |= rid=resource ^- (quip card _state) @@ -181,15 +211,6 @@ :_ state(watching (~(put in watching) [rid ~])) (weld cards (give:ha ~[/updates] %listen [rid ~])) :: - ++ graph-update - |= =update:graph-store - ^- (quip card _state) - ?: ?=(%add-graph -.q.update) - (add-graph resource.q.update) - ?. ?=(%add-nodes -.q.update) - [~ state] - =* rid resource.q.update - (check-nodes ~(val by nodes.q.update) rid) :: ++ check-nodes |= $: nodes=(list node:graph-store) @@ -198,8 +219,10 @@ =/ group=(unit resource) (group-from-app-resource:met %graph rid) ?~ group + ~& no-group+rid `state =/ metadata=(unit metadata:metadata-store) + ~& no-metadata+rid (peek-metadata:met %graph u.group rid) ?~ metadata `state abet:check:(abed:handle-update:ha rid nodes u.group module.u.metadata) diff --git a/pkg/arvo/app/hark-store.hoon b/pkg/arvo/app/hark-store.hoon index cadaa8438..031a20284 100644 --- a/pkg/arvo/app/hark-store.hoon +++ b/pkg/arvo/app/hark-store.hoon @@ -326,6 +326,7 @@ %unread-note (unread-note +.in) :: %seen-index (seen-index +.in) + %remove-graph (remove-graph +.in) %set-dnd (set-dnd +.in) %seen seen == @@ -488,6 +489,62 @@ (~(put by last-seen) stats-index new-time) (give %seen-index new-time stats-index) :: + ++ remove-graph + |= rid=resource + |^ + =/ indices get-stats-indices + =. poke-core + (give %remove-graph rid) + =. poke-core + (remove-notifications indices) + =. unreads-count + ((dif-map-by-key ,@ud) unreads-count indices) + =. unreads-each + %+ (dif-map-by-key ,(set index:graph-store)) + unreads-each indices + =. last-seen + ((dif-map-by-key ,@da) last-seen indices) + =. by-index + ((dif-map-by-key ,(set @da)) by-index indices) + poke-core + :: + ++ get-stats-indices + %- ~(gas ^in *(set stats-index:store)) + %+ skim + ;: weld + ~(tap ^in ~(key by unreads-count)) + ~(tap ^in ~(key by last-seen)) + ~(tap ^in ~(key by unreads-each)) + ~(tap ^in ~(key by by-index)) + == + |= =stats-index:store + ?. ?=(%graph -.stats-index) %.n + =(graph.stats-index rid) + :: + ++ dif-map-by-key + |* value=mold + |= [=(map stats-index:store value) =(set stats-index:store)] + =/ to-remove ~(tap ^in set) + |- + ?~ to-remove map + =. map + (~(del by map) i.to-remove) + $(to-remove t.to-remove) + :: + ++ remove-notifications + |= =(set stats-index:store) + ^+ poke-core + =/ indices + ~(tap ^in set) + |- + ?~ indices poke-core + =/ times=(list @da) + ~(tap ^in (~(get ju by-index) i.indices)) + =. poke-core + (read-index i.indices times) + $(indices t.indices) + -- + :: ++ seen => (emit cancel-autoseen) => (emit autoseen-timer) diff --git a/pkg/arvo/lib/graph.hoon b/pkg/arvo/lib/graph.hoon index 9c690a5e8..fc84be6fc 100644 --- a/pkg/arvo/lib/graph.hoon +++ b/pkg/arvo/lib/graph.hoon @@ -22,7 +22,7 @@ ^- graph:store =/ =update:store (get-graph res) - ?> ?=(%0 -.res) + ?> ?=(%0 -.update) ?> ?=(%add-graph -.q.update) graph.q.update :: diff --git a/pkg/arvo/lib/hark/store.hoon b/pkg/arvo/lib/hark/store.hoon index f274fc6b2..c2736724f 100644 --- a/pkg/arvo/lib/hark/store.hoon +++ b/pkg/arvo/lib/hark/store.hoon @@ -97,6 +97,7 @@ %read-count (stats-index +.upd) %unread-each (unread-each +.upd) %unread-count (unread-count +.upd) + %remove-graph s+(enjs-path:resource +.upd) %seen-index (seen-index +.upd) %unreads (unreads +.upd) :: diff --git a/pkg/arvo/sur/hark-store.hoon b/pkg/arvo/sur/hark-store.hoon index 382e07ede..b80f60285 100644 --- a/pkg/arvo/sur/hark-store.hoon +++ b/pkg/arvo/sur/hark-store.hoon @@ -95,6 +95,7 @@ [%unread-note time=@da index] :: [%seen-index time=@da =stats-index] + [%remove-graph =resource] :: [%read-all ~] [%set-dnd dnd=?] @@ -123,6 +124,7 @@ [%added time=@da =index =notification] [%timebox time=@da archived=? =(list [index notification])] [%count count=@ud] + [%clear =stats-index] [%unreads unreads=(list [stats-index stats])] == -- diff --git a/pkg/interface/src/logic/reducers/hark-update.ts b/pkg/interface/src/logic/reducers/hark-update.ts index a706ea16c..64a8cd610 100644 --- a/pkg/interface/src/logic/reducers/hark-update.ts +++ b/pkg/interface/src/logic/reducers/hark-update.ts @@ -142,6 +142,14 @@ function reduce(data: any, state: HarkState) { unreadSince(data, state); unreadEach(data, state); seenIndex(data, state); + removeGraph(data, state); +} + +function removeGraph(json: any, state: HarkState) { + const data = _.get(json, 'remove-graph'); + if(data) { + delete state.unreads.graph[data]; + } } function seenIndex(json: any, state: HarkState) {