formatted

This commit is contained in:
2023-10-14 15:59:43 +03:00
parent 4ddc424f29
commit 154633c114
15 changed files with 63 additions and 48 deletions

View File

@@ -1,13 +1,15 @@
import asyncio
import json
from typing import Any, Dict, List, Optional, Union
from services.auth import login_required
from services.core import get_author, get_network
from services.redis import redis
from services.auth import login_required
from services.schema import query
from validators.inbox import Message, Chat, ChatMember
from .chats import create_chat
from .unread import get_unread_counter
import asyncio
# NOTE: not an API handler
async def load_messages(
@@ -21,10 +23,10 @@ async def load_messages(
message_ids = [] + ids
if limit:
mids = (
await redis.lrange(
f"chats/{chat_id}/message_ids", offset, offset + limit
)
) or []
await redis.lrange(
f"chats/{chat_id}/message_ids", offset, offset + limit
)
) or []
mids = [mid for mid in mids]
message_ids += mids
if message_ids:
@@ -54,7 +56,7 @@ async def load_chats(
author_id = info.context["author_id"]
cids = (await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or []
members_online = (await redis.execute("SMEMBERS", "authors-online")) or []
cids = list(cids)[offset : (offset + limit)]
cids = list(cids)[offset: (offset + limit)]
chats = []
lock = asyncio.Lock()
if len(cids) == 0:
@@ -87,8 +89,8 @@ async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
"""load :limit messages of :chat_id with :offset"""
author_id = info.context["author_id"]
user_chats = (
await redis.execute("SMEMBERS", "chats_by_author/" + str(author_id))
) or []
await redis.execute("SMEMBERS", "chats_by_author/" + str(author_id))
) or []
user_chats = [c for c in user_chats]
if user_chats:
messages = []