diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 472e935c..3bb3717a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,6 +2,7 @@ - schema: Reaction.range -> Reaction.quote - resolvers: queries and mutations revision and renaming - resolvers: delete_topic(slug) implemented +- resolvers: added get_shout_followers [0.2.15] - schema: Shout.created_by removed diff --git a/resolvers/follower.py b/resolvers/follower.py index cff2315f..591238f2 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -1,6 +1,10 @@ +from typing import List + from sqlalchemy import select from orm.community import Community, CommunityAuthor as CommunityFollower +from orm.reaction import Reaction +from orm.shout import Shout from orm.topic import Topic, TopicFollower from services.auth import login_required from resolvers.author import author_follow, author_unfollow @@ -114,3 +118,20 @@ async def get_my_followed(_, info): for [c] in session.execute(communities_query): communities.append(c) return {"topics": topics, "authors": authors, "communities": communities} + + +@query.field("get_shout_followers") +def get_shout_followers(_, _info, slug: str = "", shout_id: int = None) -> List[Author]: + followers = [] + with local_session() as session: + shout = None + if slug: + shout = session.query(Shout).filter(Shout.slug == slug).first() + elif shout_id: + shout = session.query(Shout).filter(Shout.id == shout_id).first() + if shout: + reactions = session.query(Reaction).filter(Reaction.shout == shout.id).all() + for r in reactions: + followers.append(r.created_by) + + return followers diff --git a/schemas/core.graphql b/schemas/core.graphql index f5b41d95..aa0a5a4e 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -304,9 +304,6 @@ type Mutation { follow(what: FollowingEntity!, slug: String!): Result! unfollow(what: FollowingEntity!, slug: String!): Result! - # FIXME! - updateOnlineStatus: Result! - # topic create_topic(input: TopicInput!): Result! update_topic(input: TopicInput!): Result! @@ -338,6 +335,7 @@ type Query { # follower get_my_followed: Result # { authors topics communities } + get_shout_followers(slug: String, shout_id: Int): [Author] # reaction load_reactions_by(by: ReactionBy!, limit: Int, offset: Int): [Reaction]