New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reply notification #50
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,5 +214,11 @@ a { | |
} | ||
} | ||
} | ||
|
||
> .notification-section { | ||
display: none; | ||
padding-bottom: 10px; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ class Comments: | |
""" | ||
|
||
fields = ['tid', 'id', 'parent', 'created', 'modified', 'mode', 'remote_addr', | ||
'text', 'author', 'email', 'website', 'likes', 'dislikes', 'voters'] | ||
'text', 'author', 'email', 'website', 'likes', 'dislikes', 'voters', 'notification'] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the name "notification", better the plural "notifications" or the verb "notify" to apply for (multiple) notifications. |
||
def __init__(self, db): | ||
|
||
|
@@ -30,7 +30,8 @@ def __init__(self, db): | |
' tid REFERENCES threads(id), id INTEGER PRIMARY KEY, parent INTEGER,', | ||
' created FLOAT NOT NULL, modified FLOAT, mode INTEGER, remote_addr VARCHAR,', | ||
' text VARCHAR, author VARCHAR, email VARCHAR, website VARCHAR,', | ||
' likes INTEGER DEFAULT 0, dislikes INTEGER DEFAULT 0, voters BLOB NOT NULL);']) | ||
' likes INTEGER DEFAULT 0, dislikes INTEGER DEFAULT 0, voters BLOB NOT NULL,', | ||
' notification INTEGER);']) | ||
|
||
def add(self, uri, c): | ||
""" | ||
|
@@ -41,16 +42,16 @@ def add(self, uri, c): | |
'INSERT INTO comments (', | ||
' tid, parent,' | ||
' created, modified, mode, remote_addr,', | ||
' text, author, email, website, voters )', | ||
' text, author, email, website, voters, notification)', | ||
'SELECT', | ||
' threads.id, ?,', | ||
' ?, ?, ?, ?,', | ||
' ?, ?, ?, ?, ?', | ||
' ?, ?, ?, ?, ?, ?', | ||
'FROM threads WHERE threads.uri = ?;'], ( | ||
c.get('parent'), | ||
c.get('created') or time.time(), None, c["mode"], c['remote_addr'], | ||
c['text'], c.get('author'), c.get('email'), c.get('website'), buffer( | ||
Bloomfilter(iterable=[c['remote_addr']]).array), | ||
Bloomfilter(iterable=[c['remote_addr']]).array), c.get('notification', 0), | ||
uri) | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,8 @@ def spooler(args): | |
def __enter__(self): | ||
klass = (smtplib.SMTP_SSL if self.conf.get('security') == 'ssl' else smtplib.SMTP) | ||
self.client = klass(host=self.conf.get('host'), port=self.conf.getint('port')) | ||
|
||
if self.conf.get('security') == 'starttls': | ||
self.client.starttls(); | ||
self.client.starttls() | ||
|
||
if self.conf.get('username') and self.conf.get('password'): | ||
self.client.login(self.conf.get('username'), | ||
|
@@ -75,7 +74,7 @@ def __exit__(self, exc_type, exc_value, traceback): | |
def __iter__(self): | ||
yield "comments.new:after-save", self.notify | ||
|
||
def format(self, thread, comment): | ||
def format(self, thread, comment, admin=False): | ||
|
||
rv = io.StringIO() | ||
|
||
|
@@ -88,39 +87,50 @@ def format(self, thread, comment): | |
rv.write(comment["text"] + "\n") | ||
rv.write("\n") | ||
|
||
if comment["website"]: | ||
rv.write("User's URL: %s\n" % comment["website"]) | ||
if admin: | ||
if comment["website"]: | ||
rv.write("User's URL: %s\n" % comment["website"]) | ||
|
||
rv.write("IP address: %s\n" % comment["remote_addr"]) | ||
rv.write("Link to comment: %s\n" % (local("origin") + thread["uri"] + "#isso-%i" % comment["id"])) | ||
rv.write("\n") | ||
rv.write("IP address: %s\n" % comment["remote_addr"]) | ||
rv.write("Link to comment: %s\n" % (local("origin") + thread["uri"] + "#isso-%i" % comment["id"])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A link to the comment in the reply notification would be useful. |
||
rv.write("\n") | ||
|
||
uri = local("host") + "/id/%i" % comment["id"] | ||
key = self.isso.sign(comment["id"]) | ||
uri = local("host") + "/id/%i" % comment["id"] | ||
key = self.isso.sign(comment["id"]) | ||
|
||
rv.write("---\n") | ||
rv.write("Delete comment: %s\n" % (uri + "/delete/" + key)) | ||
rv.write("---\n") | ||
rv.write("Delete comment: %s\n" % (uri + "/delete/" + key)) | ||
|
||
if comment["mode"] == 2: | ||
rv.write("Activate comment: %s\n" % (uri + "/activate/" + key)) | ||
if comment["mode"] == 2: | ||
rv.write("Activate comment: %s\n" % (uri + "/activate/" + key)) | ||
|
||
rv.seek(0) | ||
return rv.read() | ||
|
||
def notify(self, thread, comment): | ||
|
||
body = self.format(thread, comment) | ||
|
||
if "parent" in comment: | ||
comment_parent = self.isso.db.comments.get(comment["parent"]) | ||
# Notify the author that a new comment is posted if requested | ||
if comment_parent and "email" in comment_parent and comment_parent["notification"]: | ||
body = self.format(thread, comment, admin=False) | ||
subject = "Re: New comment posted on %s" % thread["title"] | ||
self.sendmail(subject, body, thread, comment, to=comment_parent["email"]) | ||
|
||
body = self.format(thread, comment, admin=True) | ||
self.sendmail(thread["title"], body, thread, comment) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a thing for later: the email value is not actually verified to contain a valid email address. Hence it should be checked what kind of errors can appear when an invalid email address is used (e.g. the while loop for the uWSGI implementation). |
||
def sendmail(self, subject, body, thread, comment, to=None): | ||
if uwsgi: | ||
uwsgi.spool({b"subject": thread["title"].encode("utf-8"), | ||
b"body": body.encode("utf-8")}) | ||
uwsgi.spool({b"subject": subject.encode("utf-8"), | ||
b"body": body.encode("utf-8"), | ||
b"to": to}) | ||
else: | ||
start_new_thread(self._retry, (thread["title"], body)) | ||
start_new_thread(self._retry, (subject, body, to)) | ||
|
||
def _sendmail(self, subject, body): | ||
def _sendmail(self, subject, body, to=None): | ||
|
||
from_addr = self.conf.get("from") | ||
to_addr = self.conf.get("to") | ||
to_addr = to or self.conf.get("to") | ||
|
||
msg = MIMEText(body, 'plain', 'utf-8') | ||
msg['From'] = "Ich schrei sonst! <%s>" % from_addr | ||
|
@@ -131,10 +141,10 @@ def _sendmail(self, subject, body): | |
with self as con: | ||
con.sendmail(from_addr, to_addr, msg.as_string()) | ||
|
||
def _retry(self, subject, body): | ||
def _retry(self, subject, body, to): | ||
for x in range(5): | ||
try: | ||
self._sendmail(subject, body) | ||
self._sendmail(subject, body, to) | ||
except smtplib.SMTPConnectError: | ||
time.sleep(60) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invisible by default? Why?