From 3a8f630c6dbf07c8750cd6f83ac598cbb1b46fab Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Thu, 17 Nov 2022 00:34:24 +0100 Subject: [PATCH] get all chat users --- resolvers/inbox/chats.py | 10 +++++++++- schema.graphql | 9 +++++++++ services/auth/users.py | 8 ++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/resolvers/inbox/chats.py b/resolvers/inbox/chats.py index 1b80c2ea..04fd691d 100644 --- a/resolvers/inbox/chats.py +++ b/resolvers/inbox/chats.py @@ -4,7 +4,8 @@ from datetime import datetime from auth.authenticate import login_required from base.redis import redis -from base.resolvers import mutation +from base.resolvers import mutation, query +from services.auth.users import UserStorage async def add_user_to_chat(user_slug: str, chat_id: str, chat=None): @@ -121,3 +122,10 @@ async def delete_chat(_, info, chat_id: str): return { "error": "chat not exist" } + + +@query.field("chatUsersAll") +@login_required +async def get_chat_users_all(_, info): + chat_users = await UserStorage.get_all_chat_users() + return chat_users diff --git a/schema.graphql b/schema.graphql index 0fd3cc06..3dace2c9 100644 --- a/schema.graphql +++ b/schema.graphql @@ -243,6 +243,7 @@ type Query { loadChats( limit: Int, offset: Int): Result! # your chats loadMessagesBy(by: MessagesBy!, limit: Int, offset: Int): Result! searchUsers(query: String!, limit: Int, offset: Int): Result! + chatUsersAll: [ChatUser]! # auth isEmailUsed(email: String!): Boolean! @@ -348,6 +349,14 @@ type User { oid: String } +type ChatUser { + id: Int! + slug: String! + name: String! + userpic: String + lastSeen: DateTime +} + type Collab { authors: [String]! invites: [String] diff --git a/services/auth/users.py b/services/auth/users.py index 489155ce..7d4d6c0b 100644 --- a/services/auth/users.py +++ b/services/auth/users.py @@ -1,7 +1,6 @@ import asyncio - from sqlalchemy.orm import selectinload - +from base.orm import local_session from orm.user import User @@ -34,6 +33,11 @@ class UserStorage: aaa.sort(key=lambda user: user.createdAt) return aaa + @staticmethod + async def get_all_chat_users(): + with local_session() as session: + return session.query(User).where(User.emailConfirmed).all() + @staticmethod async def get_top_users(): self = UserStorage