From 7e811b47fb210a15672bbbe82c132bcdef002d2c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 12 Sep 2022 11:48:01 +0200 Subject: [PATCH] reporting improvement --- files/assets/js/comments_v.js | 3 --- files/assets/js/report_post_modal.js | 2 -- files/routes/reporting.py | 6 ++++-- files/templates/comments.html | 20 +++++++++----------- files/templates/report_post_modal.html | 22 ++++++++++------------ files/templates/util/assetcache.html | 2 +- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/files/assets/js/comments_v.js b/files/assets/js/comments_v.js index 2c4872414..aa7538312 100644 --- a/files/assets/js/comments_v.js +++ b/files/assets/js/comments_v.js @@ -16,8 +16,6 @@ function report_commentModal(id, author) { document.getElementById("comment-author").textContent = author; - document.getElementById("reportCommentFormBefore").classList.remove('d-none'); - reportCommentButton.innerHTML='Report comment'; reportCommentButton.disabled = false; reportCommentButton.classList.remove('disabled'); @@ -43,7 +41,6 @@ function report_commentModal(id, author) { try {data = JSON.parse(xhr.response)} catch(e) {console.log(e)} if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) { - document.getElementById("reportCommentFormBefore").classList.add('d-none'); document.getElementById('toast-post-success-text').innerText = data["message"]; bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show(); } else { diff --git a/files/assets/js/report_post_modal.js b/files/assets/js/report_post_modal.js index 421438d80..555599e74 100644 --- a/files/assets/js/report_post_modal.js +++ b/files/assets/js/report_post_modal.js @@ -13,7 +13,6 @@ reason_post.addEventListener('keydown', (e) => { function report_postModal(id) { - document.getElementById("reportPostFormBefore").classList.remove('d-none'); reportPostButton.disabled = false; reportPostButton.classList.remove('disabled'); reportPostButton.innerHTML='Report post'; @@ -41,7 +40,6 @@ function report_postModal(id) { try {data = JSON.parse(xhr.response)} catch(e) {console.log(e)} if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) { - document.getElementById("reportPostFormBefore").classList.add('d-none'); document.getElementById('toast-post-success-text').innerText = data["message"]; bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show(); } else { diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 84636c175..588a49873 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -77,7 +77,8 @@ def flag_post(pid, v): return {"message": f"Post moved to /h/{post.sub}"} else: existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none() - if existing: return "", 409 + if existing: + return {"error": "You already reported this post!"}, 409 flag = Flag(post_id=post.id, user_id=v.id, reason=reason) g.db.add(flag) @@ -94,7 +95,8 @@ def flag_comment(cid, v): comment = get_comment(cid) existing = g.db.query(CommentFlag.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() - if existing: return "", 409 + if existing: + return {"error": "You already reported this comment!"}, 409 reason = request.values.get("reason", "").strip() diff --git a/files/templates/comments.html b/files/templates/comments.html index c67b0a5ad..0c05ca5d9 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -795,17 +795,15 @@ -
- - + +
diff --git a/files/templates/report_post_modal.html b/files/templates/report_post_modal.html index ee61cccba..7f7329c58 100644 --- a/files/templates/report_post_modal.html +++ b/files/templates/report_post_modal.html @@ -7,20 +7,18 @@ -
- - + +
- \ No newline at end of file + \ No newline at end of file diff --git a/files/templates/util/assetcache.html b/files/templates/util/assetcache.html index 2566f7c4b..7f4fa6772 100644 --- a/files/templates/util/assetcache.html +++ b/files/templates/util/assetcache.html @@ -19,7 +19,7 @@ set CACHE_VER = { 'js/bootstrap.js': 4004, 'js/category_modal.js': 4000, 'js/comments_admin.js': 4000, - 'js/comments_v.js': 4001, + 'js/comments_v.js': 4002, 'js/submission_listing.js': 4000, 'js/emoji_modal.js': 4004, 'js/formatting.js': 4000,