diff --git a/modules/discussion.js b/modules/discussion.js index 9ec6014..c700de3 100644 --- a/modules/discussion.js +++ b/modules/discussion.js @@ -38,7 +38,7 @@ app.get('/discussion/:type?', async (req, res) => { where = { problem_id: { $eq: null } }; } let paginate = syzoj.utils.paginate(await Article.count(where), req.query.page, syzoj.config.page.discussion); - let articles = await Article.query(paginate, where, [['public_time', 'desc']]); + let articles = await Article.query(paginate, where, [['sort_time', 'desc']]); for (let article of articles) { await article.loadRelationships(); @@ -72,7 +72,7 @@ app.get('/discussion/problem/:pid', async (req, res) => { let where = { problem_id: pid }; let paginate = syzoj.utils.paginate(await Article.count(where), req.query.page, syzoj.config.page.discussion); - let articles = await Article.query(paginate, where, [['public_time', 'desc']]); + let articles = await Article.query(paginate, where, [['sort_time', 'desc']]); for (let article of articles) await article.loadRelationships(); @@ -249,6 +249,10 @@ app.post('/article/:id/comment', async (req, res) => { await comment.save(); + article.sort_time = syzoj.utils.getCurrentDate(); + article.comments_num += 1; + await article.save(); + res.redirect(syzoj.utils.makeUrl(['article', article.id])); } catch (e) { syzoj.log(e); @@ -273,6 +277,11 @@ app.post('/article/:article_id/comment/:id/delete', async (req, res) => { await comment.destroy(); + let article = comment.article; + article.comments_num -= 1; + + await article.save(); + res.redirect(syzoj.utils.makeUrl(['article', comment.article_id])); } catch (e) { syzoj.log(e); diff --git a/views/discussion.ejs b/views/discussion.ejs index b31037f..4b795d9 100644 --- a/views/discussion.ejs +++ b/views/discussion.ejs @@ -47,12 +47,13 @@
标题 | +标题 | <% if (in_problems) { %>所属题目 | <% } %>作者 | -发表时间 | +回复数 | +最新回复 | <%= article.problem.title %> | <% } %><%= article.user.username %><% if (article.user.nameplate) { %><%- article.user.nameplate %><% } %> | -<%= syzoj.utils.formatDate(article.public_time) %> | +<%= article.comments_num %> | +<%= syzoj.utils.formatDate(article.sort_time) %> | <% } %>
---|