session-info
This commit is contained in:
parent
0873304068
commit
9c60318919
|
@ -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,8 +11,6 @@ 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)
|
||||
return topics
|
||||
|
@ -20,8 +18,6 @@ async def topics_by_slugs(_, info, page = 1, size = 50):
|
|||
@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)
|
||||
return topics
|
||||
|
|
|
@ -35,10 +35,19 @@ type UserChatsResult {
|
|||
chats: [String]
|
||||
}
|
||||
|
||||
type SessionInfo {
|
||||
unread: Int
|
||||
topics: [String]
|
||||
authors: [String]
|
||||
reactions: [Int]
|
||||
communities: [String]
|
||||
}
|
||||
|
||||
type AuthResult {
|
||||
error: String
|
||||
token: String
|
||||
user: User
|
||||
info: SessionInfo
|
||||
}
|
||||
|
||||
type Result {
|
||||
|
@ -308,7 +317,7 @@ type User {
|
|||
id: Int!
|
||||
username: String! # to login, ex. email
|
||||
createdAt: DateTime!
|
||||
lastSeen: DataTime
|
||||
lastSeen: DateTime
|
||||
slug: String!
|
||||
name: String # to display
|
||||
email: String
|
||||
|
|
Loading…
Reference in New Issue
Block a user