Skip to content

Commit

Permalink
fix(comment): show correct reply user
Browse files Browse the repository at this point in the history
  • Loading branch information
imaegoo committed Sep 6, 2020
1 parent 39a24ac commit 83f52f1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo",
"version": "0.1.3",
"version": "0.1.4",
"description": "A simple comment system based on Tencent CloudBase (tcb).",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
7 changes: 4 additions & 3 deletions src/function/comment-get/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function toDto (comment, uid, replies = [], comments = []) {
liked: comment.like ? comment.like.findIndex((item) => item === uid) > -1 : false,
replies: replies,
rid: comment.rid,
ruser: ruser(comment.rid, comments),
pid: comment.pid,
ruser: ruser(comment.pid, comments),
created: comment.created,
updated: comment.updated
}
Expand All @@ -75,8 +76,8 @@ function toDto (comment, uid, replies = [], comments = []) {
/**
* Get replied user nick name.
*/
function ruser (rid, comments = []) {
const comment = comments.find((item) => item._id === rid)
function ruser (pid, comments = []) {
const comment = comments.find((item) => item._id === pid)
return comment ? comment.nick : null
}

Expand Down
1 change: 1 addition & 0 deletions src/function/comment-submit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@cloudbase/node-sdk": "^2.3.1",
"axios": "^0.20.0",
"blueimp-md5": "^2.17.0",
"cheerio": "^1.0.0-rc.3",
"nodemailer": "^6.4.11",
"querystring": "^0.2.0"
}
Expand Down
5 changes: 3 additions & 2 deletions src/function/comment-submit/utils/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const nodemailer = require('nodemailer')
const tcb = require('@cloudbase/node-sdk')
const axios = require('axios')
const qs = require('querystring')
const $ = require('cheerio')
const app = tcb.init({ env: tcb.SYMBOL_CURRENT_ENV })
const db = app.database()

Expand Down Expand Up @@ -70,11 +71,11 @@ exports.noticeMaster = async (comment, config) => {
exports.noticeWeChat = async (comment, config) => {
const SITE_NAME = config.SITE_NAME
const NICK = comment.nick
const COMMENT = comment.comment
const COMMENT = $(comment.comment).text()
const SITE_URL = config.SITE_URL
const POST_URL = SITE_URL + comment.url
const emailSubject = config.MAIL_SUBJECT_ADMIN || `${SITE_NAME}上有新评论了`
const emailContent = `您在${SITE_NAME}上的文章有了新的评论\n${NICK}回复说:\n${COMMENT}\n您可以点击 ${POST_URL} 查看回复的完整內容`
const emailContent = `${NICK}回复说:\n${COMMENT}\n您可以点击 ${POST_URL} 查看回复的完整內容`
const sendResult = await axios.post(`https://sctapi.ftqq.com/${config.SC_SENDKEY}.send`, qs.stringify({
title: emailSubject,
desp: emailContent
Expand Down
2 changes: 1 addition & 1 deletion src/view/components/TkComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@reply="onReply" />
</div>
<div class="tk-content">
<span v-if="comment.rid">回复 <a :href="`#${comment.rid}`">@{{ comment.ruser }}</a> :</span>
<span v-if="comment.pid">回复 <a :href="`#${comment.pid}`">@{{ comment.ruser }}</a> :</span>
<span v-html="comment.comment"></span>
</div>
<!-- 回复列表 -->
Expand Down
9 changes: 9 additions & 0 deletions src/view/components/TkComments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<tk-submit @load="initComments" />
<div class="tk-comments-container" v-loading="loading">
<div class="tk-comments-title">{{ comments.length }} 条评论</div>
<div class="tk-comments-no" v-if="!loading && !comments.length">没有评论</div>
<tk-comment v-for="comment in comments"
:key="comment.id"
:comment="comment"
Expand Down Expand Up @@ -59,5 +60,13 @@ export default {
}
.tk-comments-container {
min-height: 10rem;
display: flex;
flex-direction: column;
}
.tk-comments-no {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
</style>
2 changes: 1 addition & 1 deletion src/view/components/TkFooter.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="tk-footer">
Powered by <a href="https://github.com/imaegoo/twikoo" target="_blank">Twikoo</a>
v0.1.3
v0.1.4
</div>
</template>

Expand Down

0 comments on commit 83f52f1

Please sign in to comment.