diff --git a/cmd/web.go b/cmd/web.go
index 3f5f60615..dc2bd3d84 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -446,6 +446,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/comment/*", repo.GetCommentForm)
m.Get("/commit/*", repo.Diff)
+ m.Post("/commit/comment/delete/", repo.DeleteCommitComment)
m.Post("/commit/comment/:action/:commitId", repo.CreateCommitComment)
}, middleware.RepoRef())
diff --git a/models/issue.go b/models/issue.go
index 41add8c7e..41f94c346 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1089,3 +1089,9 @@ func DeleteAttachmentsByComment(commentId int64, remove bool) (int, error) {
return DeleteAttachments(attachments, remove)
}
+
+func DeleteComment(commentId, userId int64) error {
+ _, err := x.Delete(&Comment{Id: commentId, PosterId: userId})
+
+ return err
+}
diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js
index 0f87adb49..c8bded524 100644
--- a/public/ng/js/gogs.js
+++ b/public/ng/js/gogs.js
@@ -286,6 +286,25 @@ var Gogs = {};
return false;
});
+ $('.remove-comment').click(function () {
+ var commit = document.location.href.match(/([a-zA-Z0-9:\/\/]+)\/commit\/([a-z0-9]+)/);
+ var url = commit[1] + '/commit/comment/delete/';
+ $.ajax({
+ url: url,
+ data: {comment: $(this).data('id')},
+ dataType: 'json',
+ method: 'post',
+ success: function (json) {
+ if (json.ok) {
+ location.reload();
+ } else {
+ alert(json.error);
+ }
+ }
+ });
+ return false;
+ });
+
$('.code-diff').on('submit', '#commit-add-comment-form', function () {
var url = $(this).attr('action');
$.ajax({
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 54770be4b..fded732a0 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -457,3 +457,20 @@ func CreateCommitComment(ctx *middleware.Context) {
send(200, fmt.Sprintf("%s/commit/%s#comment-%d", ctx.Repo.RepoLink, commitId, comment.Id), nil)
}
+
+func DeleteCommitComment(ctx *middleware.Context) {
+
+ commentId := com.StrTo(ctx.Query("comment")).MustInt64()
+ if err := models.DeleteComment(int64(commentId), ctx.User.Id); err != nil {
+ ctx.JSON(200, map[string]interface{}{
+ "ok": false,
+ "error": err.Error(),
+ })
+ return
+ }
+
+ ctx.JSON(200, map[string]interface{}{
+ "ok": true,
+ "data": "ok",
+ })
+}
diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl
index 740c4f285..2893f9a66 100644
--- a/templates/repo/diff.tmpl
+++ b/templates/repo/diff.tmpl
@@ -140,8 +140,8 @@
{{end}}
{{if $.SignedUser}}
{{if eq $.SignedUser.Id .Poster.Id}}
-
-
+
+
{{end}}
{{end}}