diff --git a/resolvers/collab.py b/resolvers/collab.py index 8271b478..7db4620e 100644 --- a/resolvers/collab.py +++ b/resolvers/collab.py @@ -32,16 +32,16 @@ async def invite_author(_, info, author, shout): authors = [a.id for a in shout.authors] if user_id not in authors: return {"error": "access denied"} - author = session.query(User).filter(User.slug == author).first() - if author.id in authors: - return {"error": "already added"} - shout.authors.append(author) + author = session.query(User).filter(User.id == author.id).first() + if author: + if author.id in authors: + return {"error": "already added"} + shout.authors.append(author) shout.updated_at = datetime.now() session.add(shout) session.commit() # TODO: email notify - return {} @@ -59,9 +59,10 @@ async def remove_author(_, info, author, shout): if user_id not in authors: return {"error": "access denied"} author = session.query(User).filter(User.slug == author).first() - if author.id not in authors: - return {"error": "not in authors"} - shout.authors.remove(author) + if author: + if author.id not in authors: + return {"error": "not in authors"} + shout.authors.remove(author) shout.updated_at = datetime.now() session.add(shout) session.commit() diff --git a/resolvers/inbox/load.py b/resolvers/inbox/load.py index 05431c68..5d7927b7 100644 --- a/resolvers/inbox/load.py +++ b/resolvers/inbox/load.py @@ -1,13 +1,16 @@ import json from datetime import datetime, timedelta + +from auth.authenticate import login_required from base.redis import redis from base.resolvers import query -from auth.authenticate import login_required async def get_unread_counter(chat_id: str, user_slug: str): try: - return int(await redis.execute("LLEN", f"chats/{chat_id}/unread/{user_slug}")) + unread = await redis.execute("LLEN", f"chats/{chat_id}/unread/{user_slug}") + if unread: + return unread except Exception: return 0 @@ -55,7 +58,7 @@ async def load_chats(_, info, offset: int, amount: int): if not chats: chats = [] for c in chats: - c['messages'] = await load_messages(c['id']) + c['messages'] = await load_messages(c['id'], offset, amount) c['unread'] = await get_unread_counter(c['id'], user.slug) return { "chats": chats, diff --git a/resolvers/reactions.py b/resolvers/reactions.py index 267d40ba..abdbb46b 100644 --- a/resolvers/reactions.py +++ b/resolvers/reactions.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta + from sqlalchemy import and_, desc, select, text from sqlalchemy.orm import selectinload diff --git a/schema.graphql b/schema.graphql index 73e8762b..7e43d280 100644 --- a/schema.graphql +++ b/schema.graphql @@ -255,8 +255,6 @@ type Query { userFollowers(slug: String!): [Author]! userFollowedAuthors(slug: String!): [Author]! userFollowedTopics(slug: String!): [Topic]! - - authorsAll: [Author]! getAuthor(slug: String!): User! diff --git a/services/stat/views.py b/services/stat/views.py index 74434753..32c08cbf 100644 --- a/services/stat/views.py +++ b/services/stat/views.py @@ -1,7 +1,9 @@ -from gql import gql, Client -from gql.transport.aiohttp import AIOHTTPTransport import asyncio import json + +from gql import Client, gql +from gql.transport.aiohttp import AIOHTTPTransport + from base.redis import redis from services.zine.topics import TopicStorage