Merge pull request #148 from christianbundy/add-topics-page

Add topics page
This commit is contained in:
Cinnamon 2020-02-04 09:45:33 -08:00 committed by GitHub
commit ebdee55d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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")),