add effortpost notifications toggle

pull/222/head
Aevann 2024-02-11 16:16:09 +02:00
parent 64a72ea752
commit 301226497f
5 changed files with 28 additions and 16 deletions

View File

@ -149,6 +149,7 @@ class User(Base):
blacklisted_by = Column(Integer, ForeignKey("users.id"))
grinch = Column(Boolean, default=SITE_NAME != 'rDrama') #don't put in an if condition, it will cause an error bc it has a not-null constraint
group_creation_notifs = Column(Boolean, default=False)
effortpost_notifs = Column(Boolean, default=False)
if SITE_NAME == 'WPD':
nitter = False
@ -827,22 +828,26 @@ class User(Base):
@property
@lazy
def post_notifications_count(self):
or_criteria = [
Post.hole.in_(self.followed_holes),
and_(
Post.author_id.in_(self.followed_users),
Post.notify == True,
Post.ghost == False,
)]
if self.effortpost_notifs:
or_criteria.append(Post.effortpost == True)
return g.db.query(Post).filter(
Post.created_utc > self.last_viewed_post_notifs,
or_(
Post.hole.in_(self.followed_holes),
and_(
Post.author_id.in_(self.followed_users),
Post.notify == True,
Post.ghost == False,
),
),
Post.deleted_utc == 0,
Post.is_banned == False,
Post.private == False,
Post.author_id != self.id,
Post.author_id.notin_(self.userblocks),
or_(Post.hole == None, Post.hole.notin_(self.hole_blocks)),
or_(*or_criteria),
).count()
@property

View File

@ -174,15 +174,18 @@ def notifications_modmail(v):
def notifications_posts(v):
page = get_page()
or_criteria = [
Post.hole.in_(v.followed_holes),
and_(
Post.author_id.in_(v.followed_users),
Post.notify == True,
Post.ghost == False,
)]
if v.effortpost_notifs:
or_criteria.append(Post.effortpost == True)
listing = g.db.query(Post).filter(
or_(
Post.hole.in_(v.followed_holes),
and_(
Post.author_id.in_(v.followed_users),
Post.notify == True,
Post.ghost == False,
),
),
Post.deleted_utc == 0,
Post.is_banned == False,
Post.private == False,

View File

@ -177,6 +177,7 @@ def settings_personal_post(v):
updated = updated or update_flag("lifetimedonated_visible", "lifetimedonated_visible")
updated = updated or update_flag("hole_creation_notifs", "hole_creation_notifs")
updated = updated or update_flag("group_creation_notifs", "group_creation_notifs")
updated = updated or update_flag("effortpost_notifs", "effortpost_notifs")
if not updated and request.values.get("spider", v.spider) != v.spider and v.spider <= 1:
updated = True

View File

@ -160,6 +160,7 @@
<section id="site-settings-notifications" class="settings-section-section">
<h5>Notifications</h5>
<div class="settings-section rounded">
{{common.toggle_section('Effortpost Notifications', 'effortpost_notifs', 'effortpost_notifs', v.effortpost_notifs, 'Get a notification when a new effortpost is made.', false)}}
{% if SITE_NAME != 'WPD' %}
{{common.toggle_section('Hole Creation and Deletion Notifications', 'hole_creation_notifs', 'hole_creation_notifs', v.hole_creation_notifs, 'Get a notification when a hole is made or deleted.', false)}}
{% endif %}

View File

@ -0,0 +1,2 @@
alter table users add column effortpost_notifs bool default false not null;
alter table users alter effortpost_notifs drop default;