follow-fix

This commit is contained in:
Untone 2024-05-01 04:00:54 +03:00
parent 88de00706d
commit c68322e550

View File

@ -49,10 +49,10 @@ async def follow(_, info, what, slug):
[author] = result [author] = result
if author: if author:
author_dict = author.dict() author_dict = author.dict()
follows_ids = [a.id for a in follows]
if author.id not in follows_ids:
await cache_follower(follower_dict, author_dict) await cache_follower(follower_dict, author_dict)
await notify_follower(follower_dict, author.id, "follow") await notify_follower(follower_dict, author.id, "follow")
if not any(a["id"] == author.id for a in follows):
if author_dict not in follows:
follows.append(author_dict) follows.append(author_dict)
elif what == "TOPIC": elif what == "TOPIC":
@ -93,10 +93,10 @@ async def unfollow(_, info, what, slug):
author = local_session().query(Author).where(Author.slug == slug).first() author = local_session().query(Author).where(Author.slug == slug).first()
if isinstance(author, Author): if isinstance(author, Author):
author_dict = author.dict() author_dict = author.dict()
await cache_follower(follower_dict, author_dict, False)
await notify_follower(follower_dict, author.id, "unfollow")
for idx, item in enumerate(follows): for idx, item in enumerate(follows):
if item["id"] == author.id: if item["id"] == author.id:
await cache_follower(follower_dict, author_dict, False)
await notify_follower(follower_dict, author.id, "unfollow")
follows.pop(idx) # Remove the author_dict from the follows list follows.pop(idx) # Remove the author_dict from the follows list
break break