From f87139ea243ffaa393dedf0eb7198b481671e8b9 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Tue, 31 Jan 2023 19:51:48 +0300 Subject: [PATCH] place dummy notification --- resolvers/inbox/messages.py | 1 - resolvers/zine/following.py | 40 ++++++++++++++++++++++++++++++++++++- resolvers/zine/reactions.py | 2 +- schema.graphql | 4 ++-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/resolvers/inbox/messages.py b/resolvers/inbox/messages.py index 1200c322..3a6936d0 100644 --- a/resolvers/inbox/messages.py +++ b/resolvers/inbox/messages.py @@ -169,7 +169,6 @@ async def message_generator(_, info: GraphQLResolveInfo): while True: msg = await asyncio.gather(*tasks) - print('[inbox] %d new messages' % len(tasks)) yield msg finally: await MessagesStorage.remove_chat(following_chat) diff --git a/resolvers/zine/following.py b/resolvers/zine/following.py index 753d5e67..f6acff43 100644 --- a/resolvers/zine/following.py +++ b/resolvers/zine/following.py @@ -1,10 +1,12 @@ from auth.authenticate import login_required from auth.credentials import AuthCredentials -from base.resolvers import mutation +from base.resolvers import mutation, subscription # from resolvers.community import community_follow, community_unfollow from resolvers.zine.profile import author_follow, author_unfollow from resolvers.zine.reactions import reactions_follow, reactions_unfollow from resolvers.zine.topics import topic_follow, topic_unfollow +import asyncio +from graphql.type import GraphQLResolveInfo @mutation.field("follow") @@ -47,3 +49,39 @@ async def unfollow(_, info, what, slug): return {"error": str(e)} return {} + + +@subscription.source("newShout") +@login_required +async def shout_generator(_, info: GraphQLResolveInfo): + print(f"[resolvers.zine] shouts generator {info}") + auth: AuthCredentials = info.context["request"].auth + user_id = auth.user_id + try: + tasks = [] + + # TODO: implement when noticing new shout + + while True: + shout = await asyncio.gather(*tasks) + yield shout + finally: + pass + + +@subscription.source("newReaction") +@login_required +async def reaction_generator(_, info): + print(f"[resolvers.zine] reactions generator {info}") + auth: AuthCredentials = info.context["request"].auth + user_id = auth.user_id + try: + tasks = [] + + # TODO: implement when noticing new reaction + + while True: + reaction = await asyncio.gather(*tasks) + yield reaction + finally: + pass diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index 94ead0ca..071e5b38 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -162,7 +162,7 @@ async def create_reaction(_, info, reaction={}): # Proposal accepting logix if r.replyTo is not None and \ r.kind == ReactionKind.ACCEPT and \ - user_id in shout.dict()['authors']: + auth.user_id in shout.dict()['authors']: replied_reaction = session.query(Reaction).when(Reaction.id == r.replyTo).first() if replied_reaction and replied_reaction.kind == ReactionKind.PROPOSE: if replied_reaction.range: diff --git a/schema.graphql b/schema.graphql index cf66d24d..7f30b8ae 100644 --- a/schema.graphql +++ b/schema.graphql @@ -321,8 +321,8 @@ type Query { type Subscription { newMessage: Message # new messages in inbox - collabUpdate(collab: Int!): Reaction # new reactions in collaborative editor - + newShout: Shout # personal feed new shout + newReaction: Reaction # new reactions to notify } ############################################ Entities