Merge pull request #626 from nickwynja/subscribed-channels
Adds subscribed channels to Topics
This commit is contained in:
commit
4c576a51c5
|
@ -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();
|
||||
|
|
|
@ -1800,6 +1800,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();
|
||||
|
||||
|
|
|
@ -1243,11 +1243,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