gql-format-fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
|
||||
from services.core import get_author
|
||||
from services.core import get_author, get_network
|
||||
from services.redis import redis
|
||||
from services.auth import login_required
|
||||
from services.schema import query
|
||||
@@ -9,8 +9,10 @@ from .unread import get_unread_counter
|
||||
|
||||
|
||||
# NOTE: not an API handler
|
||||
async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids=[]):
|
||||
async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids=None):
|
||||
"""load :limit messages for :chat_id with :offset"""
|
||||
if ids is None:
|
||||
ids = []
|
||||
messages = []
|
||||
try:
|
||||
message_ids = [] + ids
|
||||
@@ -32,7 +34,7 @@ async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids=[]):
|
||||
if rt not in message_ids:
|
||||
replies.append(rt)
|
||||
if replies:
|
||||
messages += await load_messages(redis, chat_id, limit=0, ids=replies)
|
||||
messages += await load_messages(chat_id, offset, limit, replies)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return messages
|
||||
@@ -105,26 +107,19 @@ async def load_recipients(_, _info, limit=50, offset=0):
|
||||
"""load possible chat participants"""
|
||||
onliners = (await redis.execute("SMEMBERS", "authors-online")) or []
|
||||
members = []
|
||||
with local_session() as session:
|
||||
all_authors = session.query(Author).limit(limit).offset(offset)
|
||||
for a in all_authors:
|
||||
members.append(
|
||||
{
|
||||
"id": a.id,
|
||||
"slug": a.slug,
|
||||
"userpic": a.userpic,
|
||||
"name": a.name,
|
||||
"lastSeen": a.lastSeen,
|
||||
"online": a.id in onliners,
|
||||
}
|
||||
)
|
||||
all_authors = await get_network(limit, offset)
|
||||
for a in all_authors:
|
||||
members.append(
|
||||
{
|
||||
"id": a.id,
|
||||
"slug": a.slug,
|
||||
"userpic": a.userpic,
|
||||
"name": a.name,
|
||||
"lastSeen": a.lastSeen,
|
||||
"online": a.id in onliners,
|
||||
}
|
||||
)
|
||||
|
||||
# NOTE: maybe sort members here
|
||||
|
||||
return {"members": members, "error": None}
|
||||
|
||||
|
||||
load_resolvers = {
|
||||
"Query": {
|
||||
"loadRecipients": load_recipients,
|
||||
"loadMessagesBy": load_messages_by,
|
||||
"loadChats": load_chats,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user