Skip to content

Commit

Permalink
Complete post data without template
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed May 1, 2021
1 parent 4818192 commit 8f07874
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions isso/ext/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,16 @@ def __iter__(self):

yield "comments.new:after-save", self.new_comment

def new_comment(self, thread: dict, comment: dict):
def new_comment(self, thread: dict, comment: dict) -> bool:
"""Triggered when a new comment is saved.
:param thread: comment thread
:type thread: dict
:param comment: comment object
:type comment: dict
:return: True if eveythring went fine. False if not.
:rtype: bool
"""

try:
Expand All @@ -299,14 +302,22 @@ def new_comment(self, thread: dict, comment: dict):
post_data = self.render_template(thread, comment, moderation_urls)
else:
post_data = {
"author": comment.get("author", "Anonymous"),
"author_name": comment.get("author", "Anonymous"),
"author_email": comment.get("email"),
"text": comment.get("text"),
"author_website": comment.get("website"),
"comment_ip_address": comment.get("remote_addr"),
"comment_text": comment.get("text"),
"comment_url_activate": moderation_urls[0],
"comment_url_delete": moderation_urls[1],
"comment_url_view": moderation_urls[2],
}

self.send(post_data)
except Exception as err:
logger.error(err)
return False

return True

def moderation_urls(self, thread: dict, comment: dict) -> tuple:
"""Helper to build comment related URLs (deletion, activation, etc.).
Expand Down

0 comments on commit 8f07874

Please sign in to comment.