From fcf1255b7d3487c529355c8a79ff81a9f15f0cc8 Mon Sep 17 00:00:00 2001
From: Fang
Date: Mon, 10 Feb 2020 20:18:42 +0100
Subject: [PATCH 1/2] link-store: add scry endpoint for getting unseen urls
---
pkg/arvo/app/link-store.hoon | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/pkg/arvo/app/link-store.hoon b/pkg/arvo/app/link-store.hoon
index 12acf3ac96..44acf5f2af 100644
--- a/pkg/arvo/app/link-store.hoon
+++ b/pkg/arvo/app/link-store.hoon
@@ -40,8 +40,11 @@
::
:: scry-only paths:
::
+:: (set url)
+:: /seen//some-path the ones we've seen here
+::
:: ?
-:: /seen/wood-url/some-path have we seen this here (scry only)
+:: /seen/wood-url/some-path have we seen this here
::
/+ *link, default-agent, verb, dbug
::
@@ -151,6 +154,9 @@
::
[%x %seen @ ^]
``noun+!>((is-seen t.t.path))
+ ::
+ [%x %unseen *]
+ ``noun+!>((get-unseen t.t.path))
==
::
++ on-watch
@@ -372,6 +378,17 @@
%+ ~(put by *(map ^path submissions)) path
submissions:(~(gut by by-group) path *links)
::
+++ get-unseen
+ |= =path
+ ^- (set url)
+ =/ =links
+ (~(gut by by-group) path *links)
+ %- ~(gas in *(set url))
+ %+ murn submissions.links
+ |= submission
+ ?: (~(has in seen.links) url) ~
+ (some url)
+::
++ is-seen
|= =path
^- ?
From 9c9b1fcaec38d4d7515ef5baf0f3700bd9871966 Mon Sep 17 00:00:00 2001
From: Fang
Date: Mon, 10 Feb 2020 20:19:36 +0100
Subject: [PATCH 2/2] link fe: display unseen link counts in sidebar
---
pkg/arvo/app/link-view.hoon | 10 ++++++++++
.../link/src/js/components/lib/channel-sidebar.js | 4 ++++
.../link/src/js/components/lib/channels-item.js | 4 ++++
pkg/interface/link/src/js/reducers/link-update.js | 7 +++++++
4 files changed, 25 insertions(+)
diff --git a/pkg/arvo/app/link-view.hoon b/pkg/arvo/app/link-view.hoon
index e7042fb730..eee487ea38 100644
--- a/pkg/arvo/app/link-view.hoon
+++ b/pkg/arvo/app/link-view.hoon
@@ -248,6 +248,16 @@
|= [=^path =submissions]
^- [@t json]
:- (spat path)
+ =; =json
+ :: add unseen count
+ ::
+ ?> ?=(%o -.json)
+ :- %o
+ %+ ~(put by p.json) 'unseenCount'
+ %- numb:enjs:format
+ %~ wyt in
+ %+ scry-for (set url)
+ [%unseen path]
%^ page-to-json p
%+ get-paginated `p
submissions
diff --git a/pkg/interface/link/src/js/components/lib/channel-sidebar.js b/pkg/interface/link/src/js/components/lib/channel-sidebar.js
index 2b5a1d57e2..a845abd90c 100644
--- a/pkg/interface/link/src/js/components/lib/channel-sidebar.js
+++ b/pkg/interface/link/src/js/components/lib/channel-sidebar.js
@@ -18,6 +18,9 @@ export class ChannelsSidebar extends Component {
let name = "Private"
let selected = (props.selected === path);
let linkCount = !!props.links[path] ? props.links[path].totalItems : 0;
+ const unseenCount = !!props.links[path]
+ ? props.links[path].unseenCount
+ : linkCount
return (
)
})
diff --git a/pkg/interface/link/src/js/components/lib/channels-item.js b/pkg/interface/link/src/js/components/lib/channels-item.js
index 4475dd82fd..4f230b3d42 100644
--- a/pkg/interface/link/src/js/components/lib/channels-item.js
+++ b/pkg/interface/link/src/js/components/lib/channels-item.js
@@ -11,6 +11,9 @@ export class ChannelsItem extends Component {
: "b--transparent";
let memberCount = Object.keys(props.members).length;
+ const unseenCount = props.unseenCount > 0
+ ? {" " + props.unseenCount + " unread"}
+ : null;
return (
@@ -21,6 +24,7 @@ export class ChannelsItem extends Component {
{props.linkCount + " link" + ((props.linkCount === 1) ? "" : "s")}
+ {unseenCount}
diff --git a/pkg/interface/link/src/js/reducers/link-update.js b/pkg/interface/link/src/js/reducers/link-update.js
index 10e38fc412..d183e84578 100644
--- a/pkg/interface/link/src/js/reducers/link-update.js
+++ b/pkg/interface/link/src/js/reducers/link-update.js
@@ -41,6 +41,7 @@ export class LinkUpdateReducer {
state.links[path].local[page] = false;
state.links[path].totalPages = here.totalPages;
state.links[path].totalItems = here.totalItems;
+ state.links[path].unseenCount = here.unseenCount;
// write seen status to a separate structure,
// for easier modification later.
@@ -74,6 +75,8 @@ export class LinkUpdateReducer {
state.links[path] = this._addNewItems(
data.pages, state.links[path]
);
+ state.links[path].unseenCount =
+ state.links[path].unseenCount + data.pages.length;
}
}
@@ -148,6 +151,10 @@ export class LinkUpdateReducer {
data.urls.map(url => {
seen[url] = true;
});
+ if (state.links[path]) {
+ state.links[path].unseenCount =
+ state.links[path].unseenCount - data.urls.length;
+ }
}
}