diff --git a/src/services/juxt-web/routes/console/communities.js b/src/services/juxt-web/routes/console/communities.js index 08665d9..9dc8075 100644 --- a/src/services/juxt-web/routes/console/communities.js +++ b/src/services/juxt-web/routes/console/communities.js @@ -231,17 +231,30 @@ router.get('/:communityID/:type/more', async function (req, res) { router.post('/follow', upload.none(), async function (req, res) { const community = await database.getCommunityByID(req.body.id); const userContent = await database.getUserContent(req.pid); + const popularCommunities = JSON.parse(await redis.getValue('popularCommunities')); + let updated = false; + if (userContent !== null && userContent.followed_communities.indexOf(community.olive_community_id) === -1) { community.upFollower(); userContent.addToCommunities(community.olive_community_id); res.send({ status: 200, id: community.olive_community_id, count: community.followers }); + updated = true; } else if (userContent !== null && userContent.followed_communities.indexOf(community.olive_community_id) !== -1) { community.downFollower(); userContent.removeFromCommunities(community.olive_community_id); res.send({ status: 200, id: community.olive_community_id, count: community.followers }); + updated = true; } else { res.send({ status: 423, id: community.olive_community_id, count: community.followers }); } + + if (popularCommunities && updated) { + const index = popularCommunities.findIndex((element) => element.olive_community_id === community.olive_community_id); + if (index !== -1) { + popularCommunities[index].followers = community.followers; + redis.setValue('popularCommunities', JSON.stringify(popularCommunities), 60 * 60); + } + } }); async function calculateMostPopularCommunities() { diff --git a/src/services/juxt-web/routes/console/posts.js b/src/services/juxt-web/routes/console/posts.js index b3e03ce..344aadc 100644 --- a/src/services/juxt-web/routes/console/posts.js +++ b/src/services/juxt-web/routes/console/posts.js @@ -100,7 +100,7 @@ router.post('/empathy', yeahLimit, async function (req, res) { } else { res.send({status: 423, id: post.id, count: post.empathy_count}); } - await redis.removeValue(`${post.pid}-user_page_posts`); + await redis.removeValue(`${post.pid}_user_page_posts`); }); router.post('/new', postLimit, upload.none(), async function (req, res) { @@ -163,7 +163,7 @@ router.delete('/:post_id', async function (req, res) { } else { res.send('/users/me'); } - await redis.removeValue(`${post.pid}-user_page_posts`); + await redis.removeValue(`${post.pid}_user_page_posts`); }); router.post('/:post_id/new', postLimit, upload.none(), async function (req, res) { @@ -295,12 +295,11 @@ async function newPost(req, res) { if (duplicatePost && req.params.post_id) { return res.redirect('/posts/' + req.params.post_id.toString()); } - if (document.body === '' && document.painting === '' && document.screenshot === '') { + if (document.body === '' && document.painting === '' && document.screenshot === '' || duplicatePost) { return res.redirect('/titles/' + community.olive_community_id + '/new'); } const newPost = new POST(document); newPost.save(); - await redis.removeValue(`${newPost.pid}-user_page_posts`); if (parentPost) { parentPost.reply_count = parentPost.reply_count + 1; parentPost.save(); @@ -312,12 +311,13 @@ async function newPost(req, res) { user: req.pid, link: `/posts/${parentPost.id}` }); - await redis.removeValue(`${parentPost.pid}-user_page_posts`); } if (parentPost) { res.redirect('/posts/' + req.params.post_id.toString()); + await redis.removeValue(`${parentPost.pid}_user_page_posts`); } else { res.redirect('/titles/' + community.olive_community_id + '/new'); + await redis.removeValue(`${req.pid}_user_page_posts`); } } diff --git a/src/services/juxt-web/routes/console/userpage.js b/src/services/juxt-web/routes/console/userpage.js index d94dc85..af9fafc 100644 --- a/src/services/juxt-web/routes/console/userpage.js +++ b/src/services/juxt-web/routes/console/userpage.js @@ -153,7 +153,7 @@ async function userPage(req, res, userID) { let posts = JSON.parse(await redis.getValue(`${userID}-user_page_posts`)); if (!posts) { posts = await database.getNumberUserPostsByID(userID, config.post_limit); - await redis.setValue(`${userID}-user_page_posts`, JSON.stringify(posts), 60 * 60 * 1); + await redis.setValue(`${userID}_user_page_posts`, JSON.stringify(posts), 60 * 60 * 1); } diff --git a/src/webfiles/portal/user_page.ejs b/src/webfiles/portal/user_page.ejs index 0909dd0..cbbea25 100644 --- a/src/webfiles/portal/user_page.ejs +++ b/src/webfiles/portal/user_page.ejs @@ -45,7 +45,7 @@ <%if(userSettings.birthday_visibility){%> | - <%=moment.utc(pnid.birthday).format("MMM Do")%> + <%=moment.utc(pnid.birthdate || pnid.birthday).format("MMM Do")%> <%}%> <%if(userSettings.game_skill_visibility){%> diff --git a/src/webfiles/web/user_page.ejs b/src/webfiles/web/user_page.ejs index 068d0a7..5cd2a08 100644 --- a/src/webfiles/web/user_page.ejs +++ b/src/webfiles/web/user_page.ejs @@ -94,7 +94,7 @@