mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
use communities_banned_from() more often
This commit is contained in:
parent
e1204bc267
commit
cede0163fd
2 changed files with 3 additions and 2 deletions
|
@ -1177,7 +1177,7 @@ def community_notification(community_id: int):
|
|||
db.session.delete(existing_notification)
|
||||
db.session.commit()
|
||||
else: # no subscription yet, so make one
|
||||
if not community.user_is_banned(current_user):
|
||||
if community.id not in communities_banned_from(current_user.id):
|
||||
new_notification = NotificationSubscription(name=community.title, user_id=current_user.id, entity_id=community.id,
|
||||
type=NOTIF_COMMUNITY)
|
||||
db.session.add(new_notification)
|
||||
|
@ -1190,7 +1190,7 @@ def community_notification(community_id: int):
|
|||
member_info.notify_new_posts = not member_info.notify_new_posts
|
||||
db.session.commit()
|
||||
else: # people who are not yet members become members, with notify on.
|
||||
if not community.user_is_banned(current_user):
|
||||
if community.id not in communities_banned_from(current_user.id):
|
||||
new_member = CommunityMember(community_id=community.id, user_id=current_user.id, notify_new_posts=True)
|
||||
db.session.add(new_member)
|
||||
db.session.commit()
|
||||
|
|
|
@ -485,6 +485,7 @@ class Community(db.Model):
|
|||
|
||||
def user_is_banned(self, user):
|
||||
# use communities_banned_from() instead of this method, where possible. Redis caches the result of communities_banned_from()
|
||||
# we cannot use communities_banned_from() in models.py because it causes a circular import
|
||||
community_bans = CommunityBan.query.filter(CommunityBan.user_id == user.id).all()
|
||||
return self.id in [cb.community_id for cb in community_bans]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue