Adds subscribed channels to Topics
Any subscribed channels now appear at the top of Topics. This gives you easy access to view subscribed channels using the existing hashtags view.
This commit is contained in:
parent
e8bb3e3fe8
commit
398ebe9271
|
@ -471,7 +471,12 @@ router
|
|||
})
|
||||
.get("/public/latest/topics", async (ctx) => {
|
||||
const messages = await post.latestTopics();
|
||||
ctx.body = await topicsView({ messages });
|
||||
const channels = await post.channels();
|
||||
const list = channels.map((c) => {
|
||||
return li(a({ href: `/hashtag/${c}` }, `#${c}`));
|
||||
});
|
||||
const prefix = nav(ul(list));
|
||||
ctx.body = await topicsView({ messages, prefix });
|
||||
})
|
||||
.get("/public/latest/summaries", async (ctx) => {
|
||||
const messages = await post.latestSummaries();
|
||||
|
|
|
@ -1795,6 +1795,49 @@ module.exports = ({ cooler, isPublic }) => {
|
|||
|
||||
return keys;
|
||||
},
|
||||
channels: async () => {
|
||||
const ssb = await cooler.open();
|
||||
|
||||
const source = ssb.createUserStream({ id: ssb.id });
|
||||
|
||||
const messages = await new Promise((resolve, reject) => {
|
||||
pull(
|
||||
source,
|
||||
pull.filter((message) => {
|
||||
return lodash.get(message, "value.content.type") === "channel"
|
||||
? true
|
||||
: false;
|
||||
}),
|
||||
pull.collect((err, collectedMessages) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(transform(ssb, collectedMessages, ssb.id));
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
const channels = messages.map((msg) => {
|
||||
return {
|
||||
channel: msg.value.content.channel,
|
||||
subscribed: msg.value.content.subscribed,
|
||||
};
|
||||
});
|
||||
|
||||
let subbedChannels = [];
|
||||
|
||||
channels.forEach((ch) => {
|
||||
if (ch.subscribed && !subbedChannels.includes(ch.channel)) {
|
||||
subbedChannels.push(ch.channel);
|
||||
}
|
||||
if (ch.subscribed === false && subbedChannels.includes(ch.channel)) {
|
||||
subbedChannels = lodash.pull(subbedChannels, ch.channel);
|
||||
}
|
||||
});
|
||||
|
||||
return subbedChannels;
|
||||
},
|
||||
inbox: async (customOptions = {}) => {
|
||||
const ssb = await cooler.open();
|
||||
|
||||
|
|
|
@ -1225,11 +1225,12 @@ exports.latestView = ({ messages }) => {
|
|||
});
|
||||
};
|
||||
|
||||
exports.topicsView = ({ messages }) => {
|
||||
exports.topicsView = ({ messages, prefix }) => {
|
||||
return messageListView({
|
||||
messages,
|
||||
viewTitle: i18n.topics,
|
||||
viewDescription: i18n.topicsDescription,
|
||||
viewElements: prefix,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue