diff --git a/files/classes/private_chats.py b/files/classes/private_chats.py index 9d55b5328..19b0b5652 100644 --- a/files/classes/private_chats.py +++ b/files/classes/private_chats.py @@ -29,7 +29,6 @@ class ChatMembership(Base): user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) chat_id = Column(Integer, ForeignKey("chats.id"), primary_key=True) notification = Column(Boolean, default=False) - last_notified = Column(Integer, default=0) created_utc = Column(Integer) user = relationship("User") diff --git a/files/routes/chat.py b/files/routes/chat.py index 8ba5d5720..a64443567 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -183,7 +183,6 @@ def speak(data, v): ) for membership in memberships: membership.notification = True - membership.last_notified = time.time() g.db.add(membership) data = { diff --git a/files/routes/notifications.py b/files/routes/notifications.py index ac303b3c3..dd1484eb2 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -141,7 +141,13 @@ def notifications_messages(v): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required def notifications_chats(v): - chats = g.db.query(Chat, ChatMembership.notification).join(ChatMembership, and_(Chat.id == ChatMembership.chat_id, ChatMembership.user_id == v.id)).order_by(ChatMembership.last_notified.desc()).all() + sq = g.db.query(ChatMessage.created_utc, ChatMessage.chat_id).distinct(ChatMessage.chat_id).order_by(ChatMessage.chat_id, ChatMessage.created_utc.desc()).subquery() + + chats = g.db.query(Chat, ChatMembership.notification) \ + .join(ChatMembership, and_(Chat.id == ChatMembership.chat_id, ChatMembership.user_id == v.id)) \ + .join(sq, Chat.id == sq.c.chat_id) \ + .order_by(sq.c.created_utc.desc()).all() + return render_template("notifications.html", v=v, notifications=chats) @app.get("/notifications/modmail")