This commit is contained in:
@@ -6,9 +6,9 @@ from services.auth import login_required
|
||||
from services.core import get_my_followings, get_all_authors
|
||||
from services.rediscache import redis
|
||||
from services.schema import query
|
||||
from validators.chat import Message, ChatPayload
|
||||
from validators.member import ChatMember
|
||||
from .chats import create_chat
|
||||
from models.chat import Message, ChatPayload
|
||||
from models.member import ChatMember
|
||||
from resolvers.chats import create_chat
|
||||
|
||||
|
||||
async def get_unread_counter(chat_id: str, author_id: int) -> int:
|
||||
@@ -19,13 +19,11 @@ async def get_unread_counter(chat_id: str, author_id: int) -> int:
|
||||
# NOTE: not an API handler
|
||||
async def load_messages(
|
||||
chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None
|
||||
) -> List[Message]:
|
||||
) -> List[Message|None]:
|
||||
"""load :limit messages for :chat_id with :offset"""
|
||||
if ids is None:
|
||||
ids = []
|
||||
messages = []
|
||||
try:
|
||||
message_ids = [] + ids
|
||||
message_ids = [] + (ids or [])
|
||||
if limit:
|
||||
mids = (await redis.lrange(f"chats/{chat_id}/message_ids", offset, offset + limit)) or []
|
||||
message_ids += mids
|
||||
@@ -119,15 +117,16 @@ async def load_recipients(_, _info, limit=50, offset=0):
|
||||
onliners = (await redis.execute("SMEMBERS", "authors-online")) or []
|
||||
r = []
|
||||
all_authors: List[ChatMember] = await get_all_authors()
|
||||
my_followings = await get_my_followings()
|
||||
if len(my_followings) < limit:
|
||||
my_followings = my_followings + all_authors[0 : limit - len(my_followings)]
|
||||
for a in my_followings:
|
||||
a["online"] = a["id"] in onliners
|
||||
r.append(a)
|
||||
my_followings: List[ChatMember] = await get_my_followings()
|
||||
if all_authors:
|
||||
if len(my_followings) < limit:
|
||||
my_followings = my_followings + all_authors[0 : limit - len(my_followings)]
|
||||
for a in my_followings:
|
||||
a["online"] = a["id"] in onliners
|
||||
r.append(a)
|
||||
|
||||
# NOTE: maybe sort members here
|
||||
# NOTE: maybe sort members here
|
||||
|
||||
print(f"[resolvers.load] loadRecipients found {len(r)} members")
|
||||
print(f"[resolvers.load] loadRecipients found {len(r)} members")
|
||||
|
||||
return {"members": r, "error": None}
|
||||
return {"members": r, "error": None}
|
||||
|
Reference in New Issue
Block a user