diff --git a/app/lib/express.js b/app/lib/express.js index 1847040..6d4e1d0 100644 --- a/app/lib/express.js +++ b/app/lib/express.js @@ -518,6 +518,48 @@ router.get( } ); +router.get( + "/communities/new", + { mobileVersion: "/mobile/communities/new" }, + async (_req, res) => { + res.render("desktop/communities/new"); + } +); + +router.post("/communities/new", async (req, res) => { + const name = req.body.name; + if (!name.match(/^[a-z0-9-]+$/)) { + res.send("Invalid community name"); + return; + } + + const title = req.body.title; + const post = req.body.post; + + await ssb.client().identities.publishAs({ + id: req.context.profile.id, + private: false, + content: { + type: "post", + title: title, + text: post, + channel: name, + }, + }); + + await ssb.client().identities.publishAs({ + id: req.context.profile.id, + private: false, + content: { + type: "channel", + channel: name, + subscribed: true, + }, + }); + + res.redirect(`/communities/${name}`); +}); + const communityData = (req) => { const name = req.params.name; return Promise.all([ diff --git a/app/lib/mobile-routes.js b/app/lib/mobile-routes.js index 4e5388a..119234d 100644 --- a/app/lib/mobile-routes.js +++ b/app/lib/mobile-routes.js @@ -100,6 +100,14 @@ module.exports.setupRoutes = (router) => { } ); + router.get( + "/mobile/communities/new", + { desktopVersion: "/communities/new" }, + async (_req, res) => { + res.render("mobile/communities/new", { layout: "mobile/_layout" }); + } + ); + router.get( "/mobile/communities/:name", { desktopVersion: "/communities/:name" }, diff --git a/app/views/desktop/communities/list.ejs b/app/views/desktop/communities/list.ejs index 4606f8d..c9321a0 100644 --- a/app/views/desktop/communities/list.ejs +++ b/app/views/desktop/communities/list.ejs @@ -1,6 +1,9 @@ <%- include('../_header') %> -
You haven't joined any communities yet, explore some below to join
diff --git a/app/views/desktop/communities/new.ejs b/app/views/desktop/communities/new.ejs new file mode 100644 index 0000000..05959f8 --- /dev/null +++ b/app/views/desktop/communities/new.ejs @@ -0,0 +1,28 @@ +<%- include('../_header') %> + +