This commit is contained in:
@@ -16,7 +16,7 @@ from resolvers.topic import topic_unfollow
|
||||
from resolvers.stat import get_with_stat, author_follows_topics, author_follows_authors
|
||||
from services.auth import login_required
|
||||
from services.db import local_session
|
||||
from services.event_listeners import DEFAULT_FOLLOWS, update_follows_for_author
|
||||
from services.cache import DEFAULT_FOLLOWS, update_follows_for_author, update_followers_for_author
|
||||
from services.notify import notify_follower
|
||||
from services.schema import mutation, query
|
||||
from services.logger import root_logger as logger
|
||||
@@ -28,24 +28,27 @@ from services.rediscache import redis
|
||||
async def follow(_, info, what, slug):
|
||||
try:
|
||||
user_id = info.context['user_id']
|
||||
with local_session() as session:
|
||||
follower = session.query(Author).filter(Author.user == user_id).first()
|
||||
if follower:
|
||||
if what == 'AUTHOR':
|
||||
if author_unfollow(follower.id, slug):
|
||||
author = session.query(Author).where(Author.slug == slug).first()
|
||||
if author:
|
||||
await update_follows_for_author(session, follower, 'author', author, True)
|
||||
await notify_follower(follower.dict(), author.id, 'unfollow')
|
||||
elif what == 'TOPIC':
|
||||
topic = session.query(Topic).where(Topic.slug == slug).first()
|
||||
if topic:
|
||||
await update_follows_for_author(session, follower, 'topic', topic, True)
|
||||
topic_unfollow(follower.id, slug)
|
||||
elif what == 'COMMUNITY':
|
||||
community_follow(follower.id, slug)
|
||||
elif what == 'REACTIONS':
|
||||
reactions_follow(follower.id, slug)
|
||||
follower_query = select(Author).select_from(Author).filter(Author.user == user_id)
|
||||
[follower] = get_with_stat(follower_query)
|
||||
if follower:
|
||||
if what == 'AUTHOR':
|
||||
if author_unfollow(follower.id, slug):
|
||||
author_query = select(Author).select_from(Author).where(Author.slug == slug)
|
||||
[author] = get_with_stat(author_query)
|
||||
if author:
|
||||
await update_follows_for_author(follower, 'author', author, True)
|
||||
await update_followers_for_author(follower, author, True)
|
||||
await notify_follower(follower.dict(), author.id, 'unfollow')
|
||||
elif what == 'TOPIC':
|
||||
topic_query = select(Topic).where(Topic.slug == slug)
|
||||
[topic] = get_with_stat(topic_query)
|
||||
if topic:
|
||||
await update_follows_for_author(follower, 'topic', topic, True)
|
||||
topic_unfollow(follower.id, slug)
|
||||
elif what == 'COMMUNITY':
|
||||
community_follow(follower.id, slug)
|
||||
elif what == 'REACTIONS':
|
||||
reactions_follow(follower.id, slug)
|
||||
except Exception as e:
|
||||
logger.debug(info, what, slug)
|
||||
logger.error(e)
|
||||
@@ -59,24 +62,27 @@ async def follow(_, info, what, slug):
|
||||
async def unfollow(_, info, what, slug):
|
||||
user_id = info.context['user_id']
|
||||
try:
|
||||
with local_session() as session:
|
||||
follower = session.query(Author).filter(Author.user == user_id).first()
|
||||
if follower:
|
||||
if what == 'AUTHOR':
|
||||
if author_unfollow(follower.id, slug):
|
||||
author = session.query(Author).where(Author.slug == slug).first()
|
||||
if author:
|
||||
await update_follows_for_author(session, follower, 'author', author, False)
|
||||
await notify_follower(follower.dict(), author.id, 'unfollow')
|
||||
elif what == 'TOPIC':
|
||||
topic = session.query(Topic).where(Topic.slug == slug).first()
|
||||
if topic:
|
||||
await update_follows_for_author(session, follower, 'topic', topic, False)
|
||||
topic_unfollow(follower.id, slug)
|
||||
elif what == 'COMMUNITY':
|
||||
community_unfollow(follower.id, slug)
|
||||
elif what == 'REACTIONS':
|
||||
reactions_unfollow(follower.id, slug)
|
||||
follower_query = select(Author).filter(Author.user == user_id)
|
||||
[follower] = get_with_stat(follower_query)
|
||||
if follower:
|
||||
if what == 'AUTHOR':
|
||||
if author_unfollow(follower.id, slug):
|
||||
author_query = select(Author).where(Author.slug == slug)
|
||||
[author] = get_with_stat(author_query)
|
||||
if author:
|
||||
await update_follows_for_author(follower, 'author', author, False)
|
||||
await update_followers_for_author(follower, author, False)
|
||||
await notify_follower(follower.dict(), author.id, 'unfollow')
|
||||
elif what == 'TOPIC':
|
||||
topic_query = select(Topic).where(Topic.slug == slug)
|
||||
[topic] = get_with_stat(topic_query)
|
||||
if topic:
|
||||
await update_follows_for_author(follower, 'topic', topic, False)
|
||||
topic_unfollow(follower.id, slug)
|
||||
elif what == 'COMMUNITY':
|
||||
community_unfollow(follower.id, slug)
|
||||
elif what == 'REACTIONS':
|
||||
reactions_unfollow(follower.id, slug)
|
||||
except Exception as e:
|
||||
return {'error': str(e)}
|
||||
|
||||
|
Reference in New Issue
Block a user