Postpone notifications to users until comment has been approved by moderator
This commit is contained in:
parent
3e45ccb7e5
commit
171fcfab72
@ -25,6 +25,9 @@ class Threads(object):
|
||||
def __getitem__(self, uri):
|
||||
return Thread(*self.db.execute("SELECT * FROM threads WHERE uri=?", (uri, )).fetchone())
|
||||
|
||||
def get(self, id):
|
||||
return Thread(*self.db.execute("SELECT * FROM threads WHERE id=?", (id, )).fetchone())
|
||||
|
||||
def new(self, uri, title):
|
||||
self.db.execute(
|
||||
"INSERT INTO threads (uri, title) VALUES (?, ?)", (uri, title))
|
||||
|
@ -97,7 +97,8 @@ class SMTP(object):
|
||||
uwsgi.spooler = spooler
|
||||
|
||||
def __iter__(self):
|
||||
yield "comments.new:after-save", self.notify
|
||||
yield "comments.new:after-save", self.notify_new
|
||||
yield "comments.activate", self.notify_activated
|
||||
|
||||
def format(self, thread, comment, parent_comment, recipient=None, admin=False):
|
||||
|
||||
@ -141,7 +142,17 @@ class SMTP(object):
|
||||
rv.seek(0)
|
||||
return rv.read()
|
||||
|
||||
def notify(self, thread, comment):
|
||||
def notify_new(self, thread, comment):
|
||||
body = self.format(thread, comment, None, admin=True)
|
||||
self.sendmail(thread["title"], body, thread, comment)
|
||||
|
||||
if comment["mode"] == 1:
|
||||
self.notify_users(thread, comment)
|
||||
|
||||
def notify_activated(self, thread, comment):
|
||||
self.notify_users(thread, comment)
|
||||
|
||||
def notify_users(self, thread, comment):
|
||||
if "parent" in comment and comment["parent"] is not None:
|
||||
# Notify interested authors that a new comment is posted
|
||||
notified = []
|
||||
@ -157,9 +168,6 @@ class SMTP(object):
|
||||
self.sendmail(subject, body, thread, comment, to=email)
|
||||
notified.append(email)
|
||||
|
||||
body = self.format(thread, comment, None, admin=True)
|
||||
self.sendmail(thread["title"], body, thread, comment)
|
||||
|
||||
def sendmail(self, subject, body, thread, comment, to=None):
|
||||
if uwsgi:
|
||||
uwsgi.spool({b"subject": subject.encode("utf-8"),
|
||||
|
@ -623,9 +623,12 @@ class API(object):
|
||||
return Response(modal, 200, content_type="text/html")
|
||||
|
||||
if action == "activate":
|
||||
if item['mode'] == 1:
|
||||
return Response("Already activated", 200)
|
||||
with self.isso.lock:
|
||||
self.comments.activate(id)
|
||||
self.signal("comments.activate", id)
|
||||
thread = self.threads.get(item['tid'])
|
||||
self.signal("comments.activate", thread, item)
|
||||
return Response("Yo", 200)
|
||||
elif action == "edit":
|
||||
data = request.get_json()
|
||||
|
Loading…
Reference in New Issue
Block a user