diff --git a/drama/helpers/alerts.py b/drama/helpers/alerts.py index 40678a310..8bc0c53d4 100644 --- a/drama/helpers/alerts.py +++ b/drama/helpers/alerts.py @@ -37,8 +37,6 @@ def send_notification(vid, user, text): def send_pm(vid, user, text): - text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n") - with CustomRenderer() as renderer: text_html = renderer.render(mistletoe.Document(text)) text_html = sanitize(text_html, linkgen=True) diff --git a/drama/routes/users.py b/drama/routes/users.py index a77e4da28..51e965e78 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -73,6 +73,14 @@ def messagereply(v, username, id): message = request.form.get("message", "")[:1000].strip() user = get_user(username) message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n") + + # check existing + existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id, + Comment.sentto == user.id, + CommentAux.body == message, + ).options(contains_eager(Comment.comment_aux)).first() + if existing: return redirect('/notifications?all=true') + with CustomRenderer() as renderer: text_html = renderer.render(mistletoe.Document(message)) text_html = sanitize(text_html, linkgen=True) parent = get_comment(int(id), v=v) @@ -122,12 +130,13 @@ def message2(v, username): if user.is_blocked: return jsonify({"error": "This user is blocking you."}), 403 message = request.form.get("message", "")[:1000].strip() + message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n") + # check existing existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id, - Comment.deleted_utc == 0, - Comment.parent_submission == None, - CommentAux.body == message, - ).options(contains_eager(Comment.comment_aux)).first() + Comment.sentto == user.id, + CommentAux.body == message, + ).options(contains_eager(Comment.comment_aux)).first() if existing: return redirect('/notifications?all=true') send_pm(v.id, user, message)