diff --git a/files/classes/comment.py b/files/classes/comment.py index 9cfb40ba7..2e84a0213 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -4,11 +4,10 @@ from urllib.parse import parse_qs, urlencode, urlparse, urlunparse, ParseResult from flask import g from sqlalchemy import Column, ForeignKey -from sqlalchemy.dialects.postgresql import TSVECTOR, ARRAY +from sqlalchemy.dialects.postgresql import TSVECTOR from sqlalchemy.orm import relationship from sqlalchemy.schema import FetchedValue from sqlalchemy.sql.sqltypes import * -from sqlalchemy.ext.mutable import MutableList from files.classes import Base from files.helpers.config.const import * @@ -200,7 +199,6 @@ class Comment(Base): pinned_utc = Column(Integer) num_of_pinned_children = Column(Integer, default=0) sentto = Column(Integer, ForeignKey("users.id")) - group_dm_ids = Column(MutableList.as_mutable(ARRAY(Integer))) app_id = Column(Integer, ForeignKey("oauth_apps.id")) upvotes = Column(Integer, default=1) downvotes = Column(Integer, default=0) @@ -228,8 +226,7 @@ class Comment(Base): post = relationship("Post", back_populates="comments") author = relationship("User", primaryjoin="User.id==Comment.author_id") senttouser = relationship("User", primaryjoin="User.id==Comment.sentto") - parent_comment = relationship("Comment", remote_side=[id], back_populates="child_comments") - child_comments = relationship("Comment", remote_side=[parent_comment_id], back_populates="parent_comment") + parent_comment = relationship("Comment", remote_side=[id]) awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment") reports = relationship("CommentReport", order_by="CommentReport.created_utc") options = relationship("CommentOption", order_by="CommentOption.id") @@ -240,10 +237,6 @@ class Comment(Base): def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) - - if "sentto" in kwargs and "group_dm_ids" not in kwargs: - kwargs["group_dm_ids"] = [kwargs["author_id"], kwargs["sentto"]] - super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/classes/user.py b/files/classes/user.py index 5621b4689..5ef53171b 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -832,7 +832,7 @@ class User(Base): Notification.user_id == self.id, Notification.read == False, Comment.sentto != None, - Comment.group_dm_ids.any(self.id), + or_(Comment.author_id==self.id, Comment.sentto==self.id), Comment.parent_post == None, ) diff --git a/files/helpers/can_see.py b/files/helpers/can_see.py index d55a74d69..4914501d2 100644 --- a/files/helpers/can_see.py +++ b/files/helpers/can_see.py @@ -42,7 +42,7 @@ def can_see(user, obj): if obj.sentto == MODMAIL_ID: if obj.top_comment.author_id == user.id: return True return user.admin_level >= PERMS['VIEW_MODMAIL'] - if obj.group_dm_ids and user.id not in obj.group_dm_ids: + if obj.sentto != user.id: return user.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'] elif isinstance(obj, Hole): if obj.name == 'chudrama': return bool(user) and user.can_see_chudrama diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 77f078d01..da1646f46 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -9,7 +9,6 @@ valid_username_regex = re.compile("^[\w-]{3,25}$", flags=re.A) valid_username_patron_regex = re.compile("^[\w-]{1,25}$", flags=re.A) mention_regex = re.compile('(?)!(everyone)' + NOT_IN_CODE_OR_LINKS, flags=re.A) diff --git a/files/routes/chat.py b/files/routes/chat.py index f261e41f3..f7e07f594 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -313,7 +313,6 @@ def messagereply(v): top_comment_id=parent.top_comment_id, level=parent.level + 1, sentto=sentto, - group_dm_ids=parent.group_dm_ids, body=body, body_html=body_html, ) @@ -322,22 +321,12 @@ def messagereply(v): execute_blackjack(v, c, c.body_html, 'chat') execute_under_siege(v, c, c.body_html, 'chat') - if dm_adding_regex.fullmatch(c.body): - uid = get_user(c.body[2:], attributes=[User.id]).id - if uid not in parent.group_dm_ids: - parent.group_dm_ids.append(uid) - g.db.add(parent) - for child in parent.child_comments: - child.group_dm_ids = parent.group_dm_ids - if user_id and user_id not in {v.id, MODMAIL_ID} | BOT_IDs: if can_see(user, v): - for user_id in c.group_dm_ids: - if user_id == v.id: continue - notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user_id).one_or_none() - if not notif: - notif = Notification(comment_id=c.id, user_id=user_id) - g.db.add(notif) + notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user_id).one_or_none() + if not notif: + notif = Notification(comment_id=c.id, user_id=user_id) + g.db.add(notif) title = f'New message from @{c.author_name}' url = f'{SITE_FULL}/notifications/messages' @@ -351,9 +340,7 @@ def messagereply(v): g.db.add(notif) elif user_id and user_id not in {v.id, MODMAIL_ID} | BOT_IDs: c.unread = True - for user_id in c.group_dm_ids: - if user_id == v.id: continue - rendered = render_template("comments.html", v=get_account(user_id), comments=[c]) - emit('insert_reply', [parent.id, rendered], namespace='/', to=user_id) + rendered = render_template("comments.html", v=get_account(user_id), comments=[c]) + emit('insert_reply', [parent.id, rendered], namespace='/', to=user_id) return {"comment": render_template("comments.html", v=v, comments=[c])} diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 3730e97df..674d49eac 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -68,7 +68,7 @@ def notifications_messages(v): # Notifications & Comments. It's worth it. Save yourself. message_threads = g.db.query(Comment).filter( Comment.sentto != None, - Comment.group_dm_ids.any(v.id), + or_(Comment.author_id == v.id, Comment.sentto == v.id), Comment.parent_post == None, Comment.level == 1, ) @@ -78,7 +78,7 @@ def notifications_messages(v): .distinct(Comment.top_comment_id) \ .filter( Comment.sentto != None, - Comment.group_dm_ids.any(v.id), + or_(Comment.author_id == v.id, Comment.sentto == v.id), ).order_by( Comment.top_comment_id.desc(), Comment.created_utc.desc() @@ -93,8 +93,7 @@ def notifications_messages(v): notifs_unread_row = g.db.query(Notification.comment_id).join(Comment).filter( Notification.user_id == v.id, Notification.read == False, - Comment.sentto != None, - Comment.group_dm_ids.any(v.id), + or_(Comment.author_id == v.id, Comment.sentto == v.id), ).all() notifs_unread = [n.comment_id for n in notifs_unread_row] @@ -332,7 +331,7 @@ def notifications(v): comments = g.db.query(Comment, Notification).options(load_only(Comment.id)).join(Notification.comment).filter( Notification.user_id == v.id, - or_(Comment.sentto == None, Comment.sentto == MODMAIL_ID), + or_(Comment.sentto == None, Comment.sentto != v.id), ) if v.admin_level < PERMS['USER_SHADOWBAN']: diff --git a/migrations/20240307-add-group-dms.sql b/migrations/20240307-add-group-dms.sql deleted file mode 100644 index 8714ed4d1..000000000 --- a/migrations/20240307-add-group-dms.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE comments add COLUMN group_dm_ids int[]; -update comments set group_dm_ids=ARRAY[author_id, sentto] where sentto is not null;