lint wip
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
import asyncio
|
||||
import json
|
||||
from typing import Any
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
from graphql.type import GraphQLResolveInfo
|
||||
|
||||
from auth.authenticate import login_required
|
||||
from auth.credentials import AuthCredentials
|
||||
from base.redis import redis
|
||||
from base.resolvers import mutation
|
||||
from services.following import FollowingManager, FollowingResult, Following
|
||||
from services.following import Following, FollowingManager, FollowingResult
|
||||
from validations.inbox import Message
|
||||
|
||||
|
||||
@mutation.field("createMessage")
|
||||
@login_required
|
||||
async def create_message(_, info, chat: str, body: str, replyTo=None):
|
||||
""" create message with :body for :chat_id replying to :replyTo optionally """
|
||||
"""create message with :body for :chat_id replying to :replyTo optionally"""
|
||||
auth: AuthCredentials = info.context["request"].auth
|
||||
|
||||
chat = await redis.execute("GET", f"chats/{chat}")
|
||||
if not chat:
|
||||
return {
|
||||
"error": "chat is not exist"
|
||||
}
|
||||
return {"error": "chat is not exist"}
|
||||
else:
|
||||
chat = dict(json.loads(chat))
|
||||
message_id = await redis.execute("GET", f"chats/{chat['id']}/next_message_id")
|
||||
@@ -31,7 +31,7 @@ async def create_message(_, info, chat: str, body: str, replyTo=None):
|
||||
"id": message_id,
|
||||
"author": auth.user_id,
|
||||
"body": body,
|
||||
"createdAt": int(datetime.now(tz=timezone.utc).timestamp())
|
||||
"createdAt": int(datetime.now(tz=timezone.utc).timestamp()),
|
||||
}
|
||||
if replyTo:
|
||||
new_message['replyTo'] = replyTo
|
||||
@@ -46,17 +46,12 @@ async def create_message(_, info, chat: str, body: str, replyTo=None):
|
||||
|
||||
users = chat["users"]
|
||||
for user_slug in users:
|
||||
await redis.execute(
|
||||
"LPUSH", f"chats/{chat['id']}/unread/{user_slug}", str(message_id)
|
||||
)
|
||||
await redis.execute("LPUSH", f"chats/{chat['id']}/unread/{user_slug}", str(message_id))
|
||||
|
||||
result = FollowingResult("NEW", 'chat', new_message)
|
||||
await FollowingManager.push('chat', result)
|
||||
|
||||
return {
|
||||
"message": new_message,
|
||||
"error": None
|
||||
}
|
||||
return {"message": new_message, "error": None}
|
||||
|
||||
|
||||
@mutation.field("updateMessage")
|
||||
@@ -84,10 +79,7 @@ async def update_message(_, info, chat_id: str, message_id: int, body: str):
|
||||
result = FollowingResult("UPDATED", 'chat', message)
|
||||
await FollowingManager.push('chat', result)
|
||||
|
||||
return {
|
||||
"message": message,
|
||||
"error": None
|
||||
}
|
||||
return {"message": message, "error": None}
|
||||
|
||||
|
||||
@mutation.field("deleteMessage")
|
||||
@@ -137,6 +129,4 @@ async def mark_as_read(_, info, chat_id: str, messages: [int]):
|
||||
for message_id in messages:
|
||||
await redis.execute("LREM", f"chats/{chat_id}/unread/{auth.user_id}", 0, str(message_id))
|
||||
|
||||
return {
|
||||
"error": None
|
||||
}
|
||||
return {"error": None}
|
||||
|
Reference in New Issue
Block a user