session-info
This commit is contained in:
@@ -36,7 +36,7 @@ class MessageResult:
|
||||
self.status = status
|
||||
self.message = message
|
||||
|
||||
async def get_inbox_counter(user_slug):
|
||||
async def get_unread_counter(user_slug):
|
||||
chats = await redis.execute("GET", f"chats_by_user/{user_slug}")
|
||||
if not chats:
|
||||
return 0
|
||||
@@ -250,13 +250,8 @@ async def mark_as_read(_, info, chatId, ids):
|
||||
return {}
|
||||
|
||||
@subscription.source("chatUpdated")
|
||||
@login_required
|
||||
async def message_generator(obj, info, chatId):
|
||||
|
||||
#TODO: send AUTH header
|
||||
#auth = info.context["request"].auth
|
||||
#if not auth.logged_in:
|
||||
# yield {"error" : auth.error_message or "Please login"}
|
||||
|
||||
try:
|
||||
following_chat = ChatFollowing(chatId)
|
||||
await MessagesStorage.register_chat(following_chat)
|
||||
|
@@ -9,7 +9,7 @@ from base.resolvers import mutation, query
|
||||
from resolvers.community import get_followed_communities
|
||||
from resolvers.reactions import get_shout_reactions
|
||||
from auth.authenticate import login_required
|
||||
from resolvers.inbox import get_inbox_counter
|
||||
from resolvers.inbox import get_unread_counter
|
||||
from sqlalchemy import and_, desc
|
||||
from sqlalchemy.orm import selectinload
|
||||
from typing import List
|
||||
@@ -60,10 +60,10 @@ async def user_followers(_, slug) -> List[User]:
|
||||
all()
|
||||
return users
|
||||
|
||||
# for query.field("refreshSession")
|
||||
# for mutation.field("refreshSession")
|
||||
async def get_user_info(slug):
|
||||
return {
|
||||
"inbox": await get_inbox_counter(slug),
|
||||
"unread": await get_unread_counter(slug),
|
||||
"topics": [t.slug for t in get_followed_topics(0, slug)],
|
||||
"authors": [a.slug for a in get_followed_authors(0, slug)],
|
||||
"reactions": [r.shout for r in get_shout_reactions(0, slug)],
|
||||
@@ -71,7 +71,7 @@ async def get_user_info(slug):
|
||||
}
|
||||
|
||||
|
||||
@query.field("refreshSession")
|
||||
@mutation.field("refreshSession")
|
||||
@login_required
|
||||
async def get_current_user(_, info):
|
||||
user = info.context["request"].user
|
||||
@@ -80,6 +80,7 @@ async def get_current_user(_, info):
|
||||
user.save()
|
||||
session.commit()
|
||||
return {
|
||||
"token": "", # same token?
|
||||
"user": user,
|
||||
"info": await get_user_info(user.slug)
|
||||
}
|
||||
|
@@ -11,19 +11,15 @@ from sqlalchemy import and_
|
||||
@query.field("topicsAll")
|
||||
async def topics_by_slugs(_, info, page = 1, size = 50):
|
||||
topics = await TopicStorage.get_topics_all(page, size)
|
||||
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
||||
if "stat" in all_fields:
|
||||
for topic in topics:
|
||||
topic.stat = await TopicStat.get_stat(topic.slug)
|
||||
for topic in topics:
|
||||
topic.stat = await TopicStat.get_stat(topic.slug)
|
||||
return topics
|
||||
|
||||
@query.field("topicsByCommunity")
|
||||
async def topics_by_community(_, info, community):
|
||||
topics = await TopicStorage.get_topics_by_community(community)
|
||||
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
||||
if "stat" in all_fields:
|
||||
for topic in topics:
|
||||
topic.stat = await TopicStat.get_stat(topic.slug)
|
||||
for topic in topics:
|
||||
topic.stat = await TopicStat.get_stat(topic.slug)
|
||||
return topics
|
||||
|
||||
@query.field("topicsByAuthor")
|
||||
|
Reference in New Issue
Block a user