Fix offsitementions on localhost testing.

pull/34/head
Snakes 2022-11-30 19:24:21 -05:00
parent f5f660efa9
commit 885601e0ab
Signed by: Snakes
GPG Key ID: E745A82778055C7E
2 changed files with 10 additions and 9 deletions

4
env
View File

@ -2,8 +2,8 @@ export FLASK_APP="/rDrama/files/cli:app"
export SITE="localhost"
export SITE_NAME="rDrama"
export SECRET_KEY="blahblahblah"
export DATABASE_URL="postgresql://postgres@localhost:5432"
export REDIS_URL="redis://localhost:6379"
export DATABASE_URL="postgresql://postgres@postgres:5432"
export REDIS_URL="redis://redis:6379"
export PROXY_URL="http://localhost:18080"
export LOG_DIRECTORY="/var/log/rdrama"
export SETTINGS_FILENAME="/site_settings.json"

View File

@ -21,12 +21,14 @@ from files.helpers.sanitize import sanitize
def offsite_mentions_task(cache:Cache):
site_mentions = get_mentions(cache, const.REDDIT_NOTIFS_SITE)
notify_mentions(send_to, site_mentions)
notify_mentions(site_mentions)
if const.REDDIT_NOTIFS_USERS:
for query, send_user in const.REDDIT_NOTIFS_USERS.items():
user_mentions = get_mentions(cache, [query], reddit_notifs_users=True)
notify_mentions([send_user], user_mentions, mention_str='mention of you')
notify_mentions(user_mentions, send_to=send_user, mention_str='mention of you')
g.db.commit() # commit early otherwise localhost testing fails to commit
def get_mentions(cache:Cache, queries:Iterable[str], reddit_notifs_users=False):
kinds = ['submission', 'comment']
@ -79,7 +81,7 @@ def get_mentions(cache:Cache, queries:Iterable[str], reddit_notifs_users=False):
print("Failed to set cache value; there may be duplication of reddit notifications")
return mentions
def notify_mentions(send_to, mentions, mention_str='site mention'):
def notify_mentions(mentions, send_to=None, mention_str='site mention'):
for m in mentions:
author = m['author']
permalink = m['permalink']
@ -108,7 +110,6 @@ def notify_mentions(send_to, mentions, mention_str='site mention'):
g.db.flush()
new_comment.top_comment_id = new_comment.id
if mention_str == 'mention of you':
for user_id in send_to:
notif = Notification(comment_id=new_comment.id, user_id=user_id)
g.db.add(notif)
if send_to:
notif = Notification(comment_id=new_comment.id, user_id=send_to)
g.db.add(notif)