wip-refactoring

This commit is contained in:
tonyrewin 2022-11-16 09:35:51 +03:00
parent db3617c80d
commit 606655ee2c
5 changed files with 20 additions and 15 deletions

View File

@ -32,7 +32,8 @@ 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()
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)
@ -41,7 +42,6 @@ async def invite_author(_, info, author, shout):
session.commit()
# TODO: email notify
return {}
@ -59,6 +59,7 @@ 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:
if author.id not in authors:
return {"error": "not in authors"}
shout.authors.remove(author)

View File

@ -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,

View File

@ -1,4 +1,5 @@
from datetime import datetime, timedelta
from sqlalchemy import and_, desc, select, text
from sqlalchemy.orm import selectinload

View File

@ -255,8 +255,6 @@ type Query {
userFollowers(slug: String!): [Author]!
userFollowedAuthors(slug: String!): [Author]!
userFollowedTopics(slug: String!): [Topic]!
authorsAll: [Author]!
getAuthor(slug: String!): User!

View File

@ -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