Skip to content

Commit ec0c46e

Browse files
committed
fix: forbid users to like themselves' comments
1 parent 26d4a59 commit ec0c46e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/components/TopicDetail/index.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ class TopicDetail extends Component {
6767
is_collect: topic.is_collect
6868
})
6969
}
70-
like(id) {
70+
like(id, author) {
7171
const {
7272
accesstoken,
73-
likeComment
73+
likeComment,
74+
self
7475
} = this.props
7576
if (!accesstoken) {
7677
alert('请先登录!')
7778
return
7879
}
80+
if (author === self) {
81+
alert('不能给自己点赞哦!')
82+
return
83+
}
7984

8085
likeComment({
8186
accesstoken,
@@ -132,7 +137,7 @@ class TopicDetail extends Component {
132137
<span className="time_stamp">{format(item.create_at)}</span>
133138
<span className="floor">{index + 1}</span>
134139
</div>
135-
<div className={'user_action ' + (item.is_uped ? 'liked' : '')} onClick={this.like.bind(this, item.id)}>
140+
<div className={'user_action ' + (item.is_uped ? 'liked' : '')} onClick={this.like.bind(this, item.id, item.author.loginname)}>
136141
<span className="iconfont icon-thumbup"></span>
137142
<span className="up_number">{item.ups.length}</span>
138143
</div>
@@ -171,11 +176,13 @@ class TopicDetail extends Component {
171176

172177
function mapStateToProps({
173178
topic,
174-
accesstoken
179+
accesstoken,
180+
self
175181
}) {
176182
return {
177183
topic,
178-
accesstoken
184+
accesstoken,
185+
self: self.loginname
179186
}
180187
}
181188

0 commit comments

Comments
 (0)