2022-11-21 08:13:57 +00:00
|
|
|
from auth.authenticate import login_required
|
2022-12-01 14:45:19 +00:00
|
|
|
from auth.credentials import AuthCredentials
|
2023-01-31 16:51:48 +00:00
|
|
|
from base.resolvers import mutation, subscription
|
2022-11-21 08:13:57 +00:00
|
|
|
# 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
|
2023-01-31 16:51:48 +00:00
|
|
|
import asyncio
|
|
|
|
from graphql.type import GraphQLResolveInfo
|
2022-11-21 08:13:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mutation.field("follow")
|
|
|
|
@login_required
|
|
|
|
async def follow(_, info, what, slug):
|
2022-12-01 14:45:19 +00:00
|
|
|
auth: AuthCredentials = info.context["request"].auth
|
|
|
|
|
2022-11-21 08:13:57 +00:00
|
|
|
try:
|
|
|
|
if what == "AUTHOR":
|
2022-12-01 14:45:19 +00:00
|
|
|
author_follow(auth.user_id, slug)
|
2022-11-21 08:13:57 +00:00
|
|
|
elif what == "TOPIC":
|
2022-12-01 14:45:19 +00:00
|
|
|
topic_follow(auth.user_id, slug)
|
2022-11-21 08:13:57 +00:00
|
|
|
elif what == "COMMUNITY":
|
|
|
|
# community_follow(user, slug)
|
|
|
|
pass
|
|
|
|
elif what == "REACTIONS":
|
2022-12-01 14:45:19 +00:00
|
|
|
reactions_follow(auth.user_id, slug)
|
2022-11-21 08:13:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
return {"error": str(e)}
|
|
|
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
@mutation.field("unfollow")
|
|
|
|
@login_required
|
|
|
|
async def unfollow(_, info, what, slug):
|
2022-12-01 14:45:19 +00:00
|
|
|
auth: AuthCredentials = info.context["request"].auth
|
2022-11-21 08:13:57 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
if what == "AUTHOR":
|
2022-12-01 14:45:19 +00:00
|
|
|
author_unfollow(auth.user_id, slug)
|
2022-11-21 08:13:57 +00:00
|
|
|
elif what == "TOPIC":
|
2022-12-01 14:45:19 +00:00
|
|
|
topic_unfollow(auth.user_id, slug)
|
2022-11-21 08:13:57 +00:00
|
|
|
elif what == "COMMUNITY":
|
|
|
|
# community_unfollow(user, slug)
|
|
|
|
pass
|
|
|
|
elif what == "REACTIONS":
|
2022-12-01 14:45:19 +00:00
|
|
|
reactions_unfollow(auth.user_id, slug)
|
2022-11-21 08:13:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
return {"error": str(e)}
|
|
|
|
|
|
|
|
return {}
|
2023-01-31 16:51:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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
|