Add 'Topics' page to show latest root posts

Problem: @masukomi pointed out that the 'latest' view doesn't show the
awesome slice of content that you'll see if you just look at root posts.

Solution: Let's experiment with them! This commit adds a 'Topics' page
that has the latest root posts from people you're following.
This commit is contained in:
Christian Bundy 2020-02-02 16:54:37 -08:00
parent c2ea8f7cb5
commit 7f40a99799
3 changed files with 45 additions and 6 deletions

View File

@ -121,15 +121,15 @@ router
ctx.body = await publicPopular({ period });
})
.get("/public/latest", async ctx => {
const publicLatest = async () => {
const messages = await post.latest();
return publicView({ messages });
};
ctx.body = await publicLatest();
const messages = await post.latest();
ctx.body = await publicView({ messages });
})
.get("/public/latest/extended", async ctx => {
const messages = await post.latestExtended();
ctx.body = await publicView({ messages });
})
.get("/public/latest/topics", async ctx => {
const messages = await post.latestTopics();
ctx.body = await publicView({ messages });
})
.get("/author/:feed", async ctx => {

View File

@ -679,6 +679,44 @@ module.exports = cooler => {
return messages;
},
latestTopics: async () => {
const ssb = await cooler.connect();
const myFeedId = ssb.id;
const options = configure({
type: "post",
private: false
});
const source = await cooler.read(ssb.messagesByType, options);
const extendedFilter = await socialFilter({
following: true
});
const messages = await new Promise((resolve, reject) => {
pull(
source,
pull.filter(
message =>
typeof message.value.content !== "string" &&
message.value.content.root == null
),
extendedFilter,
pull.take(maxMessages),
pull.collect((err, collectedMessages) => {
if (err) {
reject(err);
} else {
resolve(transform(ssb, collectedMessages, myFeedId));
}
})
);
});
return messages;
},
popular: async ({ period }) => {
const ssb = await cooler.connect();

View File

@ -46,6 +46,7 @@ module.exports = (...elements) => {
li(a({ href: "/public/latest/extended" }, "🗺️ Extended")),
li(a({ href: "/" }, "📣 Popular")),
li(a({ href: "/public/latest" }, "🐇 Latest")),
li(a({ href: "/public/latest/topics" }, "📖 Topics")),
li(a({ href: "/profile" }, "🐱 Profile")),
li(a({ href: "/mentions" }, "💬 Mentions")),
li(a({ href: "/inbox" }, "✉️ Private")),