return subscribed shout comments in CurrentUserInfo
This commit is contained in:
parent
34aeb95ef3
commit
3f7d9c527b
|
@ -2,7 +2,7 @@ from resolvers.auth import login, sign_out, is_email_used, register, confirm, au
|
|||
from resolvers.zine import get_shout_by_slug, subscribe, unsubscribe, view_shout, rate_shout, \
|
||||
top_month, top_overall, recent_published, recent_all, top_viewed, \
|
||||
shouts_by_authors, shouts_by_topics, shouts_by_communities
|
||||
from resolvers.profile import get_users_by_slugs, get_current_user, shouts_reviewed, shout_comments_subscribed
|
||||
from resolvers.profile import get_users_by_slugs, get_current_user, shouts_reviewed
|
||||
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \
|
||||
topics_by_community, topics_by_slugs
|
||||
from resolvers.comments import create_comment, delete_comment, update_comment, rate_comment
|
||||
|
@ -31,7 +31,6 @@ __all__ = [
|
|||
"shouts_by_topics",
|
||||
"shouts_by_authors",
|
||||
"shouts_by_communities",
|
||||
"shout_comments_subscribed",
|
||||
"shouts_reviewed",
|
||||
"top_month",
|
||||
"top_overall",
|
||||
|
|
|
@ -6,8 +6,6 @@ from auth.authenticate import login_required
|
|||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import and_
|
||||
|
||||
def comments_subscribe(user, slug):
|
||||
ShoutCommentsSubscription.create(
|
||||
subscriber = user.slug,
|
||||
|
@ -103,3 +101,11 @@ async def rate_comment(_, info, id, value):
|
|||
value = value)
|
||||
|
||||
return {}
|
||||
|
||||
def get_subscribed_shout_comments(slug):
|
||||
with local_session() as session:
|
||||
rows = session.query(ShoutCommentsSubscription.shout).\
|
||||
filter(ShoutCommentsSubscription.subscriber == slug and not ShoutCommentsSubscription.deletedAt is None).\
|
||||
all()
|
||||
slugs = [row.shout for row in rows]
|
||||
return slugs
|
||||
|
|
|
@ -5,6 +5,7 @@ from orm.base import local_session
|
|||
from orm.topic import Topic, TopicSubscription
|
||||
from resolvers.base import mutation, query, subscription
|
||||
from resolvers.community import get_subscribed_communities
|
||||
from resolvers.comments import get_subscribed_shout_comments
|
||||
from auth.authenticate import login_required
|
||||
|
||||
from inbox_resolvers.inbox import get_total_unread_messages_for_user
|
||||
|
@ -31,10 +32,11 @@ def _get_user_subscribed_authors(slug):
|
|||
|
||||
async def get_user_info(slug):
|
||||
return {
|
||||
"totalUnreadMessages" : await get_total_unread_messages_for_user(slug),
|
||||
"userSubscribedTopics" : _get_user_subscribed_topic_slugs(slug),
|
||||
"userSubscribedAuthors" : _get_user_subscribed_authors(slug),
|
||||
"userSubscribedCommunities": get_subscribed_communities(slug)
|
||||
"totalUnreadMessages" : await get_total_unread_messages_for_user(slug),
|
||||
"userSubscribedTopics" : _get_user_subscribed_topic_slugs(slug),
|
||||
"userSubscribedAuthors" : _get_user_subscribed_authors(slug),
|
||||
"userSubscribedCommunities" : get_subscribed_communities(slug),
|
||||
"userSubscribedShoutComments": get_subscribed_shout_comments(slug)
|
||||
}
|
||||
|
||||
@query.field("getCurrentUser")
|
||||
|
@ -204,22 +206,6 @@ async def shouts_reviewed(_, info, page, size):
|
|||
|
||||
return shouts
|
||||
|
||||
@query.field("shoutCommentsSubscribed")
|
||||
@login_required
|
||||
async def shout_comments_subscribed(_, info, slug, page, size):
|
||||
user = info.context["request"].user
|
||||
with local_session() as session:
|
||||
comments_by_shout = session.query(Comment).\
|
||||
join(ShoutCommentsSubscription).\
|
||||
join(ShoutCommentsSubscription, ShoutCommentsSubscription.shout == slug).\
|
||||
where(ShoutCommentsSubscription.subscriber == user.slug)
|
||||
comments = comments_by_shout.\
|
||||
order_by(desc(Shout.createdAt)).\
|
||||
limit(size).\
|
||||
offset( (page - 1) * size)
|
||||
|
||||
return shouts
|
||||
|
||||
@query.field("shoutsCommentedByUser")
|
||||
async def shouts_commented_by_user(_, info, slug, page, size):
|
||||
user = await UserStorage.get_user_by_slug(slug)
|
||||
|
|
|
@ -7,10 +7,11 @@ type Result {
|
|||
}
|
||||
|
||||
type CurrentUserInfo {
|
||||
totalUnreadMessages: Int
|
||||
userSubscribedTopics: [String]!
|
||||
userSubscribedAuthors: [String]!
|
||||
userSubscribedCommunities: [String]!
|
||||
totalUnreadMessages: Int
|
||||
userSubscribedTopics: [String]!
|
||||
userSubscribedAuthors: [String]!
|
||||
userSubscribedCommunities: [String]!
|
||||
userSubscribedShoutComments: [String]!
|
||||
}
|
||||
|
||||
type AuthResult {
|
||||
|
@ -206,7 +207,6 @@ type Query {
|
|||
getCommunity(slug: String): Community!
|
||||
getCommunities: [Community]!
|
||||
|
||||
shoutCommentsSubscribed(slug: String!, page: Int!, size: Int!): [Shout]!
|
||||
shoutsReviewed(page: Int!, size: Int!): [Shout]!
|
||||
recentCommented(page: Int!, size: Int!): [Shout]!
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user