From f671cdfd4ee4b3fea4206ce98277f07f59ef0222 Mon Sep 17 00:00:00 2001 From: zPlus Date: Sat, 28 Jul 2018 07:53:07 +0200 Subject: [PATCH] Fix #75 Missing replies to comments --- freepost/__init__.py | 19 ++++++++++++++----- freepost/database.py | 6 +++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/freepost/__init__.py b/freepost/__init__.py index d30ca8ea..23d9b2a0 100755 --- a/freepost/__init__.py +++ b/freepost/__init__.py @@ -506,16 +506,23 @@ def post_thread (hash_id): @requires_login @post ('/post/') def new_comment (hash_id): - user = session.user () - # The comment text comment = request.forms.getunicode ('new_comment').strip () - # Empty comment + # Empty comment? if len (comment) == 0: redirect (application.get_url ('post', hash_id=hash_id)) - comment_hash_id = database.new_comment (comment, hash_id, user['id']) + # Retrieve the post + post = database.get_post (hash_id) + + # Does post exist? + if not post: + redirect (application.get_url ('homepage')) + + user = session.user () + + comment_hash_id = database.new_comment (comment, hash_id, user['id'], post['userId']) # Retrieve new comment comment = database.get_comment (comment_hash_id) @@ -679,7 +686,9 @@ def reply_check (hash_id): redirect (application.get_url ('post', hash_id=comment['postHashId'])) # We have a text, add the reply and redirect to the new reply - reply_hash_id = database.new_comment (text, comment['postHashId'], user['id'], comment['id']) + reply_hash_id = database.new_comment ( + text, comment['postHashId'], user['id'], + comment['userId'], comment['id']) # Retrieve new comment comment = database.get_comment (reply_hash_id) diff --git a/freepost/database.py b/freepost/database.py index 64aeb1a3..b5ecd1ab 100644 --- a/freepost/database.py +++ b/freepost/database.py @@ -440,7 +440,7 @@ def get_post_comments (post_id, session_user_id = None): return cursor.fetchall () # Submit a new comment to a post -def new_comment (comment_text, post_hash_id, user_id, parent_comment_id = None): +def new_comment (comment_text, post_hash_id, user_id, parent_user_id = None, parent_comment_id = None): # Create a hash_id for the new comment hash_id = random.alphanumeric_string (10) @@ -451,7 +451,7 @@ def new_comment (comment_text, post_hash_id, user_id, parent_comment_id = None): cursor.execute ( """ - INSERT INTO comment (hashId, created, dateCreated, `read`, `text`, `vote`, + INSERT INTO comment (hashId, created, dateCreated, `read`, text, vote, parentId, parentUserId, postId, userId) VALUES (%(hash_id)s, NOW(), CURDATE(), 0, %(text)s, 0, %(parent_id)s, %(parent_user_id)s, %(post_id)s, %(user)s) @@ -460,7 +460,7 @@ def new_comment (comment_text, post_hash_id, user_id, parent_comment_id = None): 'hash_id': hash_id, 'text': comment_text, 'parent_id': parent_comment_id, - 'parent_user_id': post['userId'], + 'parent_user_id': parent_user_id, 'post_id': post['id'], 'user': user_id }