remove group dms temporarily

pull/225/head
Aevann 2024-03-08 10:10:23 +02:00
parent 0529a3d1bd
commit 6e1a423226
7 changed files with 14 additions and 38 deletions

View File

@ -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):

View File

@ -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,
)

View File

@ -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

View File

@ -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('(?<![:/\w])@([\w-]{1,30})' + NOT_IN_CODE_OR_LINKS, flags=re.A)
dm_adding_regex = re.compile('\+@[\w-]{1,30}' + NOT_IN_CODE_OR_LINKS, flags=re.A)
group_mention_regex = re.compile('(?<![:/\w])!([\w-]{3,25})' + NOT_IN_CODE_OR_LINKS, flags=re.A|re.I)
everyone_regex = re.compile('(^|\s|>)!(everyone)' + NOT_IN_CODE_OR_LINKS, flags=re.A)

View File

@ -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])}

View File

@ -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']:

View File

@ -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;