From 15ef9765387f1cdff6d0e1903e94c9f2d4e94d19 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 16 Oct 2023 18:18:29 +0300 Subject: [PATCH] using presence service --- resolvers/editor.py | 2 ++ resolvers/following.py | 7 +++++++ resolvers/inbox/messages.py | 0 resolvers/reactions.py | 10 ++++------ resolvers/zine/following.py | 0 5 files changed, 13 insertions(+), 6 deletions(-) delete mode 100644 resolvers/inbox/messages.py delete mode 100644 resolvers/zine/following.py diff --git a/resolvers/editor.py b/resolvers/editor.py index c9cba2da..91faace2 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -10,6 +10,7 @@ from services.schema import mutation from orm.shout import Shout, ShoutAuthor, ShoutTopic from orm.topic import Topic from resolvers.reactions import reactions_follow, reactions_unfollow +from services.presence import notify_shout @mutation.field("createShout") @@ -157,6 +158,7 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False): shout.visibility = "community" shout.publishedAt = datetime.now(tz=timezone.utc) updated = True + notify_shout(shout.dict()) if updated: shout.updatedAt = datetime.now(tz=timezone.utc) diff --git a/resolvers/following.py b/resolvers/following.py index 92fbbf20..389e8285 100644 --- a/resolvers/following.py +++ b/resolvers/following.py @@ -6,6 +6,9 @@ from resolvers.reactions import reactions_follow, reactions_unfollow from resolvers.topics import topic_follow, topic_unfollow from services.following import FollowingManager, FollowingResult from resolvers.community import community_follow, community_unfollow +from services.presence import notify_follower +from orm.user import Author +from services.db import local_session @mutation.field("follow") @@ -18,6 +21,10 @@ async def follow(_, info, what, slug): if author_follow(auth.user_id, slug): result = FollowingResult("NEW", "author", slug) await FollowingManager.push("author", result) + with local_session() as session: + author_id = session.query(Author.id).where(Author.slug == slug).one() + follower = session.query() + notify_follower(follower.dict(), author_id) elif what == "TOPIC": if topic_follow(auth.user_id, slug): result = FollowingResult("NEW", "topic", slug) diff --git a/resolvers/inbox/messages.py b/resolvers/inbox/messages.py deleted file mode 100644 index e69de29b..00000000 diff --git a/resolvers/reactions.py b/resolvers/reactions.py index 55ebef44..22403b8a 100644 --- a/resolvers/reactions.py +++ b/resolvers/reactions.py @@ -10,8 +10,7 @@ from services.schema import mutation, query from orm.reaction import Reaction, ReactionKind from orm.shout import Shout, ShoutReactionsFollower from orm.user import User -# TODO: use presense interface -# from services.notifications.notification_service import notification_service +from services.presence import notify_reaction def add_reaction_stat_columns(q): @@ -65,7 +64,7 @@ def reactions_follow(user_id, shout_id: int, auto=False): session.add(following) session.commit() return True - except: + except Exception: return False @@ -89,7 +88,7 @@ def reactions_unfollow(user_id: int, shout_id: int): session.delete(following) session.commit() return True - except: + except Exception: pass return False @@ -242,8 +241,7 @@ async def create_reaction(_, info, reaction): session.add(r) session.commit() - # FIXME: use presence service interface here - # await notification_service.handle_new_reaction(r.id) + notify_reaction(r.dict()) rdict = r.dict() rdict["shout"] = shout.dict() diff --git a/resolvers/zine/following.py b/resolvers/zine/following.py deleted file mode 100644 index e69de29b..00000000