forked from MarseyWorld/MarseyWorld
rework reddit notifs - testing on pcm lol
parent
d160a1686f
commit
e1ed46fa36
|
@ -129,6 +129,7 @@ class User(Base):
|
|||
total_lottery_winnings = Column(Integer, default=0)
|
||||
last_viewed_post_notifs = Column(Integer, default=0)
|
||||
last_viewed_log_notifs = Column(Integer, default=0)
|
||||
last_viewed_reddit_notifs = Column(Integer, default=0)
|
||||
pronouns = Column(String, default='they/them')
|
||||
bite = Column(Integer)
|
||||
earlylife = Column(Integer)
|
||||
|
@ -701,9 +702,9 @@ class User(Base):
|
|||
@property
|
||||
@lazy
|
||||
def reddit_notifications_count(self):
|
||||
if not self.can_view_offsitementions: return 0
|
||||
return g.db.query(Notification).join(Comment).filter(
|
||||
Notification.user_id == self.id, Notification.read == False,
|
||||
if not self.can_view_offsitementions or self.id == AEVANN_ID: return 0
|
||||
return g.db.query(Comment).filter(
|
||||
Comment.created_utc > self.last_viewed_reddit_notifs,
|
||||
Comment.is_banned == False, Comment.deleted_utc == 0,
|
||||
Comment.body_html.like('%<p>New site mention%<a href="https://old.reddit.com/r/%'),
|
||||
Comment.parent_submission == None, Comment.author_id == AUTOJANNY_ID).count()
|
||||
|
|
|
@ -10,7 +10,6 @@ from sqlalchemy import or_
|
|||
import files.helpers.const as const
|
||||
from files.classes.badges import Badge
|
||||
from files.classes.comment import Comment
|
||||
from files.classes.notifications import Notification
|
||||
from files.classes.user import User
|
||||
from files.helpers.sanitize import sanitize
|
||||
|
||||
|
@ -21,18 +20,8 @@ from files.helpers.sanitize import sanitize
|
|||
# value from /meta (or just guessing) and doing a random selection of keywords.
|
||||
|
||||
def offsite_mentions_task(cache:Cache):
|
||||
if const.REDDIT_NOTIFS_SITE:
|
||||
row_send_to = g.db.query(Badge.user_id).filter_by(badge_id=140).all()
|
||||
row_send_to += g.db.query(User.id).filter(
|
||||
User.admin_level >= const.PERMS['NOTIFICATIONS_REDDIT'],
|
||||
User.id != const.AEVANN_ID,
|
||||
).all()
|
||||
|
||||
send_to = [x[0] for x in row_send_to]
|
||||
send_to = set(send_to)
|
||||
|
||||
site_mentions = get_mentions(cache, const.REDDIT_NOTIFS_SITE)
|
||||
notify_mentions(send_to, site_mentions)
|
||||
site_mentions = get_mentions(cache, const.REDDIT_NOTIFS_SITE)
|
||||
notify_mentions(send_to, site_mentions)
|
||||
|
||||
if const.REDDIT_NOTIFS_USERS:
|
||||
for query, send_user in const.REDDIT_NOTIFS_USERS.items():
|
||||
|
@ -119,6 +108,7 @@ def notify_mentions(send_to, mentions, mention_str='site mention'):
|
|||
g.db.flush()
|
||||
new_comment.top_comment_id = new_comment.id
|
||||
|
||||
for user_id in send_to:
|
||||
notif = Notification(comment_id=new_comment.id, user_id=user_id)
|
||||
g.db.add(notif)
|
||||
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)
|
||||
|
|
|
@ -224,28 +224,17 @@ def notifications_reddit(v:User):
|
|||
|
||||
if not v.can_view_offsitementions: abort(403)
|
||||
|
||||
notifications = g.db.query(Notification, Comment).join(Notification.comment).filter(
|
||||
Notification.user_id == v.id,
|
||||
listing = g.db.query(Comment).filter(
|
||||
Comment.created_utc > v.last_viewed_reddit_notifs,
|
||||
Comment.body_html.like('%<p>New site mention%<a href="https://old.reddit.com/r/%'),
|
||||
Comment.parent_submission == None,
|
||||
Comment.author_id == AUTOJANNY_ID
|
||||
).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
|
||||
).order_by(Comment.created_utc.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all()
|
||||
|
||||
listing = []
|
||||
next_exists = len(listing) > PAGE_SIZE
|
||||
|
||||
for index, x in enumerate(notifications[:100]):
|
||||
n, c = x
|
||||
if n.read and index > 24: break
|
||||
elif not n.read:
|
||||
n.read = True
|
||||
c.unread = True
|
||||
g.db.add(n)
|
||||
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
|
||||
listing.append(c)
|
||||
|
||||
next_exists = (len(notifications) > len(listing))
|
||||
|
||||
g.db.commit()
|
||||
v.last_viewed_reddit_notifs = int(time.time())
|
||||
g.db.add(v)
|
||||
|
||||
if v.client: return {"data":[x.json(g.db) for x in listing]}
|
||||
|
||||
|
@ -271,7 +260,6 @@ def notifications(v:User):
|
|||
Notification.user_id == v.id,
|
||||
Comment.is_banned == False,
|
||||
Comment.deleted_utc == 0,
|
||||
Comment.body_html.notlike('%<p>New site mention%<a href="https://old.reddit.com/r/%'),
|
||||
or_(Comment.sentto == None, Comment.sentto == MODMAIL_ID),
|
||||
not_(and_(Comment.sentto != None, Comment.sentto == MODMAIL_ID, User.is_muted)),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue