Show communities you joined on communities page
This commit is contained in:
parent
5282ba0648
commit
d5c3121cb7
|
@ -492,10 +492,13 @@ router.post("/about", async (req, res) => {
|
||||||
router.get(
|
router.get(
|
||||||
"/communities",
|
"/communities",
|
||||||
{ mobileVersion: "/mobile/communities" },
|
{ mobileVersion: "/mobile/communities" },
|
||||||
async (_req, res) => {
|
async (req, res) => {
|
||||||
const communities = await queries.getCommunities();
|
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 });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -78,11 +78,15 @@ module.exports.setupRoutes = (router) => {
|
||||||
router.get(
|
router.get(
|
||||||
"/mobile/communities",
|
"/mobile/communities",
|
||||||
{ desktopVersion: "/communities" },
|
{ desktopVersion: "/communities" },
|
||||||
async (_req, res) => {
|
async (req, res) => {
|
||||||
const communities = await queries.getCommunities();
|
const [communities, participating] = await Promise.all([
|
||||||
|
queries.getCommunities(),
|
||||||
|
queries.getProfileCommunities(req.context.profile.id),
|
||||||
|
]);
|
||||||
|
|
||||||
res.render("mobile/communities/list", {
|
res.render("mobile/communities/list", {
|
||||||
communities,
|
communities,
|
||||||
|
participating,
|
||||||
layout: "mobile/_layout",
|
layout: "mobile/_layout",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,10 @@ const debugPosts = require("debug")("queries:posts"),
|
||||||
debugCommunities = require("debug")("queries:communities"),
|
debugCommunities = require("debug")("queries:communities"),
|
||||||
debugCommunityMembers = require("debug")("queries:communityMembers"),
|
debugCommunityMembers = require("debug")("queries:communityMembers"),
|
||||||
debugCommunityPosts = require("debug")("queries:communityPosts"),
|
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 paramap = require("pull-paramap");
|
||||||
const { promisePull, mapValues } = require("./utils");
|
const { promisePull, mapValues } = require("./utils");
|
||||||
const ssb = require("./ssb-client");
|
const ssb = require("./ssb-client");
|
||||||
|
@ -517,6 +520,42 @@ const getCommunityMembers = async (name) => {
|
||||||
return memberProfiles;
|
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) => {
|
const getPostWithReplies = async (channel, key) => {
|
||||||
debugCommunityPosts("Fetching");
|
debugCommunityPosts("Fetching");
|
||||||
|
|
||||||
|
@ -651,4 +690,5 @@ module.exports = {
|
||||||
progress,
|
progress,
|
||||||
autofollow,
|
autofollow,
|
||||||
isMember,
|
isMember,
|
||||||
|
getProfileCommunities,
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
<form action="/search" method="GET" style="margin-right: 10px">
|
<form action="/search" method="GET" style="margin-right: 10px">
|
||||||
<div class="search-icon">🔎</div>
|
<div class="search-icon">🔎</div>
|
||||||
<input type="search" class="input-search" name="query" placeholder="Search for people...">
|
<input type="search" class="input-search" name="query" placeholder="Search">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
<%- include('../_header') %>
|
<%- include('../_header') %>
|
||||||
|
|
||||||
<h1>Communities</h1>
|
<h1 style="margin-bottom: 10px">My communities</h1>
|
||||||
|
|
||||||
<div style="padding-top: 20px">
|
<% if (participating.length == 0) { %>
|
||||||
<% communities.map(community => { %>
|
<p>You haven't joined any communities yet, explore some below to join</p>
|
||||||
<a href="/communities/<%= community %>" class="link-block" style="display: inline-block">
|
<% } %>
|
||||||
#<%= community %>
|
<% participating.map(community => { %>
|
||||||
</a>
|
<a href="/mobile/communities/<%= community %>" class="link-block">
|
||||||
<% }) %>
|
#<%= community %>
|
||||||
</div>
|
</a>
|
||||||
|
<% }) %>
|
||||||
|
|
||||||
|
<h1 style="margin-top: 40px; margin-bottom: 10px">Explore</h1>
|
||||||
|
|
||||||
|
<% communities.map(community => { %>
|
||||||
|
<a href="/mobile/communities/<%= community %>" class="link-block">
|
||||||
|
#<%= community %>
|
||||||
|
</a>
|
||||||
|
<% }) %>
|
||||||
|
|
||||||
<%- include('../_footer') %>
|
<%- include('../_footer') %>
|
|
@ -1,11 +1,20 @@
|
||||||
<div class="pink-background">
|
<div class="pink-background">
|
||||||
<h1>Communities</h1>
|
<h1 style="margin-bottom: 10px">My communities</h1>
|
||||||
|
|
||||||
<div style="padding-top: 20px">
|
<% if (participating.length == 0) { %>
|
||||||
<% communities.map(community => { %>
|
<p>You haven't joined any communities yet, explore some below to join</p>
|
||||||
<a href="/mobile/communities/<%= community %>" class="link-block" style="display: inline-block">
|
<% } %>
|
||||||
#<%= community %>
|
<% participating.map(community => { %>
|
||||||
</a>
|
<a href="/mobile/communities/<%= community %>" class="link-block">
|
||||||
<% }) %>
|
#<%= community %>
|
||||||
</div>
|
</a>
|
||||||
|
<% }) %>
|
||||||
|
|
||||||
|
<h1 style="margin-top: 40px; margin-bottom: 10px">Explore</h1>
|
||||||
|
|
||||||
|
<% communities.map(community => { %>
|
||||||
|
<a href="/mobile/communities/<%= community %>" class="link-block">
|
||||||
|
#<%= community %>
|
||||||
|
</a>
|
||||||
|
<% }) %>
|
||||||
</div>
|
</div>
|
|
@ -1,7 +1,7 @@
|
||||||
<div style="padding: 14px">
|
<div style="padding: 14px">
|
||||||
<form action="/mobile/search" method="GET" style="padding-bottom: 20px">
|
<form action="/mobile/search" method="GET" style="padding-bottom: 20px">
|
||||||
<div class="search-icon">🔎</div>
|
<div class="search-icon">🔎</div>
|
||||||
<input type="search" class="input-search" name="query" placeholder="Search for people..." value="<%= query %>">
|
<input type="search" class="input-search" name="query" placeholder="Search" value="<%= query %>">
|
||||||
</form>
|
</form>
|
||||||
<% if (query.length < 3) { %>
|
<% if (query.length < 3) { %>
|
||||||
<h2>You need to search for 3 or more characters</h2>
|
<h2>You need to search for 3 or more characters</h2>
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
<p>No results found</p>
|
<p>No results found</p>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% communities.map(community => { %>
|
<% communities.map(community => { %>
|
||||||
<a href="/communities/<%= community %>" class="link-block" style="display: inline-block">
|
<a href="/communities/<%= community %>" class="link-block">
|
||||||
#<%= community %>
|
#<%= community %>
|
||||||
</a>
|
</a>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<p>No results found</p>
|
<p>No results found</p>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% communities.map(community => { %>
|
<% communities.map(community => { %>
|
||||||
<a href="/communities/<%= community %>" class="link-block" style="display: inline-block">
|
<a href="/communities/<%= community %>" class="link-block">
|
||||||
#<%= community %>
|
#<%= community %>
|
||||||
</a>
|
</a>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
|
|
Loading…
Reference in New Issue