This commit is contained in:
parent
d01e1f2313
commit
90923c40e6
|
@ -2,7 +2,7 @@ from sqlalchemy import and_
|
||||||
from orm.notification import NotificationSeen
|
from orm.notification import NotificationSeen
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from resolvers.model import Notification, NotificationSeenResult, NotificationReaction
|
from resolvers.model import Notification, NotificationSeenResult, NotificationReaction
|
||||||
from typing import List
|
|
||||||
import strawberry
|
import strawberry
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
@ -61,15 +61,35 @@ class Mutation:
|
||||||
[shout_id, reply_to_id] = thread.split("::")
|
[shout_id, reply_to_id] = thread.split("::")
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
# TODO: handle new follower and new shout notifications
|
# TODO: handle new follower and new shout notifications
|
||||||
new_reaction_notifications = session.query(Notification).filter(Notification.action == "create", Notification.entity == "reaction", Notification.created_at > after).all()
|
new_reaction_notifications = (
|
||||||
removed_reaction_notifications = session.query(Notification).filter(Notification.action == "delete", Notification.entity == "reaction", Notification.created_at > after).all()
|
session.query(Notification)
|
||||||
|
.filter(
|
||||||
|
Notification.action == "create",
|
||||||
|
Notification.entity == "reaction",
|
||||||
|
Notification.created_at > after,
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
removed_reaction_notifications = (
|
||||||
|
session.query(Notification)
|
||||||
|
.filter(
|
||||||
|
Notification.action == "delete",
|
||||||
|
Notification.entity == "reaction",
|
||||||
|
Notification.created_at > after,
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
exclude = set([])
|
exclude = set([])
|
||||||
for nr in removed_reaction_notifications:
|
for nr in removed_reaction_notifications:
|
||||||
reaction: NotificationReaction = json.loads(nr.payload)
|
reaction: NotificationReaction = json.loads(nr.payload)
|
||||||
exclude.add(reaction.id)
|
exclude.add(reaction.id)
|
||||||
for n in new_reaction_notifications:
|
for n in new_reaction_notifications:
|
||||||
reaction: NotificationReaction = json.loads(n.payload)
|
reaction: NotificationReaction = json.loads(n.payload)
|
||||||
if reaction.id not in exclude and str(reaction.shout) == str(shout_id) and str(reaction.reply_to) == str(reply_to_id):
|
if (
|
||||||
|
reaction.id not in exclude
|
||||||
|
and str(reaction.shout) == str(shout_id)
|
||||||
|
and str(reaction.reply_to) == str(reply_to_id)
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
ns = NotificationSeen(notification=n.id, viewer=author_id)
|
ns = NotificationSeen(notification=n.id, viewer=author_id)
|
||||||
session.add(ns)
|
session.add(ns)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user