diff --git a/app/lib/express.js b/app/lib/express.js index b24ac57..b96f549 100644 --- a/app/lib/express.js +++ b/app/lib/express.js @@ -492,10 +492,13 @@ router.post("/about", async (req, res) => { router.get( "/communities", { mobileVersion: "/mobile/communities" }, - async (_req, res) => { - const communities = await queries.getCommunities(); + async (req, res) => { + const [communities, participating] = await Promise.all([ + queries.getCommunities(), + queries.getProfileCommunities(req.context.profile.id), + ]); - res.render("communities/list", { communities }); + res.render("communities/list", { communities, participating }); } ); diff --git a/app/lib/mobile-routes.js b/app/lib/mobile-routes.js index f910148..6732121 100644 --- a/app/lib/mobile-routes.js +++ b/app/lib/mobile-routes.js @@ -78,11 +78,15 @@ module.exports.setupRoutes = (router) => { router.get( "/mobile/communities", { desktopVersion: "/communities" }, - async (_req, res) => { - const communities = await queries.getCommunities(); + async (req, res) => { + const [communities, participating] = await Promise.all([ + queries.getCommunities(), + queries.getProfileCommunities(req.context.profile.id), + ]); res.render("mobile/communities/list", { communities, + participating, layout: "mobile/_layout", }); } diff --git a/app/lib/queries.js b/app/lib/queries.js index a36b4f1..1eb9147 100644 --- a/app/lib/queries.js +++ b/app/lib/queries.js @@ -9,7 +9,10 @@ const debugPosts = require("debug")("queries:posts"), debugCommunities = require("debug")("queries:communities"), debugCommunityMembers = require("debug")("queries:communityMembers"), debugCommunityPosts = require("debug")("queries:communityPosts"), - debugCommunityIsMember = require("debug")("queries:communityIsMember"); + debugCommunityIsMember = require("debug")("queries:communityIsMember"), + debugCommunityProfileCommunities = require("debug")( + "queries:communityProfileCommunities" + ); const paramap = require("pull-paramap"); const { promisePull, mapValues } = require("./utils"); const ssb = require("./ssb-client"); @@ -517,6 +520,42 @@ const getCommunityMembers = async (name) => { return memberProfiles; }; +const getProfileCommunities = async (id) => { + debugCommunityProfileCommunities("Fetching"); + const subscriptions = await promisePull( + ssb.client().query.read({ + reverse: true, + query: [ + { + $filter: { + value: { + author: id, + content: { + type: "channel", + }, + }, + }, + }, + ], + }) + ); + const dedupSubscriptions = {}; + for (const subscription of subscriptions) { + const channel = subscription.value.content.channel; + if (dedupSubscriptions[channel]) continue; + dedupSubscriptions[channel] = subscription; + } + const onlyActiveSubscriptions = Object.values(dedupSubscriptions).filter( + (x) => x.value.content.subscribed + ); + const channelNames = onlyActiveSubscriptions.map( + (x) => x.value.content.channel + ); + debugCommunityProfileCommunities("Done"); + + return channelNames; +}; + const getPostWithReplies = async (channel, key) => { debugCommunityPosts("Fetching"); @@ -651,4 +690,5 @@ module.exports = { progress, autofollow, isMember, + getProfileCommunities, }; diff --git a/app/views/_header.ejs b/app/views/_header.ejs index 49c145e..b1c24dd 100644 --- a/app/views/_header.ejs +++ b/app/views/_header.ejs @@ -37,7 +37,7 @@ <% } %>
🔎
- +
<% } %> diff --git a/app/views/communities/list.ejs b/app/views/communities/list.ejs index 7eb97f1..93de425 100644 --- a/app/views/communities/list.ejs +++ b/app/views/communities/list.ejs @@ -1,13 +1,22 @@ <%- include('../_header') %> -

Communities

+

My communities

-
- <% communities.map(community => { %> - - #<%= community %> - - <% }) %> -
+<% if (participating.length == 0) { %> +

You haven't joined any communities yet, explore some below to join

+<% } %> +<% participating.map(community => { %> + + #<%= community %> + +<% }) %> + +

Explore

+ +<% communities.map(community => { %> + + #<%= community %> + +<% }) %> <%- include('../_footer') %> \ No newline at end of file diff --git a/app/views/mobile/communities/list.ejs b/app/views/mobile/communities/list.ejs index 2bafcec..c49e4ce 100644 --- a/app/views/mobile/communities/list.ejs +++ b/app/views/mobile/communities/list.ejs @@ -1,11 +1,20 @@
-

Communities

+

My communities

-
- <% communities.map(community => { %> - - #<%= community %> - - <% }) %> -
+ <% if (participating.length == 0) { %> +

You haven't joined any communities yet, explore some below to join

+ <% } %> + <% participating.map(community => { %> + + #<%= community %> + + <% }) %> + +

Explore

+ + <% communities.map(community => { %> + + #<%= community %> + + <% }) %>
\ No newline at end of file diff --git a/app/views/mobile/search.ejs b/app/views/mobile/search.ejs index 104fd50..b8ca097 100644 --- a/app/views/mobile/search.ejs +++ b/app/views/mobile/search.ejs @@ -1,7 +1,7 @@
🔎
- +
<% if (query.length < 3) { %>

You need to search for 3 or more characters

@@ -24,7 +24,7 @@

No results found

<% } %> <% communities.map(community => { %> - + #<%= community %> <% }) %> diff --git a/app/views/search.ejs b/app/views/search.ejs index a67e6d1..16068ea 100644 --- a/app/views/search.ejs +++ b/app/views/search.ejs @@ -23,7 +23,7 @@

No results found

<% } %> <% communities.map(community => { %> - + #<%= community %> <% }) %>