fix: ban duplicate reply (#490)

This commit is contained in:
Nekotoxin 2022-04-14 21:39:05 +08:00 committed by GitHub
parent d216ed92f0
commit e16d8dbc37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -152,6 +152,12 @@ func (c *ApiController) AddReply() {
panic(err)
}
previousReply := object.GetReplyByContentAndAuthor(reply.Content, reply.Author)
if previousReply != nil {
c.ResponseError("You have same reply before.")
return
}
if object.ContainsSensitiveWord(reply.Content) {
c.ResponseError("Reply contains sensitive word.")
return

View File

@ -203,6 +203,16 @@ func GetTopicReplyNum(topicId int) int {
return int(total)
}
// GetReplyByContentAndAuthor returns reply by content and author.
func GetReplyByContentAndAuthor(content string, author string) []*Reply {
var ret []*Reply
err := adapter.Engine.Where("content = ?", content).And("author = ?", author).Find(&ret)
if err != nil {
panic(err)
}
return ret
}
// GetLatestReplyInfo returns topic's latest reply information.
func GetLatestReplyInfo(topicId int) *Reply {
var reply Reply

View File

@ -54,6 +54,7 @@ class NewReplyBox extends React.Component {
},
],
placeholder: "",
publishClicked: false,
};
this.handleChange = this.handleChange.bind(this);
this.synonyms = this.synonyms.bind(this);
@ -133,6 +134,12 @@ class NewReplyBox extends React.Component {
if (!this.isOkToSubmit()) {
return;
}
if (this.state.publishClicked) {
return;
}
this.setState({
publishClicked: true,
});
this.updateFormField("parentId", this.props.parent.id);
this.updateFormField("topicId", this.props.topic?.id);
@ -143,12 +150,14 @@ class NewReplyBox extends React.Component {
this.props.cancelReply();
this.setState({
form: {},
publishClicked: false,
});
Setting.scrollToBottom();
this.props.refreshAccount();
} else {
this.setState({
message: res.msg,
publishClicked: false,
});
}
});
@ -156,7 +165,6 @@ class NewReplyBox extends React.Component {
if (this.props.topic) {
FavoritesBackend.addFavorites(this.props.topic.id, "subscribe_topic").then((res) => {
if (res.status === "ok") {
this.getTopic("refresh");
this.props.refreshAccount();
} else {
Setting.showMessage("error", res.msg);
@ -414,7 +422,10 @@ class NewReplyBox extends React.Component {
justifyContent: "space-between",
}}
>
<input style={blurStyle} onClick={this.publishReply.bind(this)} type="submit" value={i18next.t("reply:Reply")} className="super normal button" />
<button type="button" style={blurStyle} onClick={this.publishReply.bind(this)} type="submit" className="super normal button">
<li className={this.state.publishClicked ? "fa fa-circle-o-notch fa-spin" : "fa fa-paper-plane"} />
&nbsp;{this.state.publishClicked ? i18next.t("new:Publishing...") : i18next.t("reply:Reply")}
</button>
{this.renderEditorSelect(blurStyle)}
</div>