inbox fixes
This commit is contained in:
parent
5af72afe40
commit
5c056525ed
|
@ -74,13 +74,22 @@ async def add_user_to_chat(user_slug, chat_id, chat=None):
|
|||
await redis.execute("SET", f"chats/{chat_id}", json.dumps(chat))
|
||||
|
||||
|
||||
@mutation.query("inviteChat")
|
||||
async def invite_to_chat(_, info, invited, chat_id):
|
||||
user = info.context["request"].user
|
||||
chat = await redis.execute("GET", f"chats/{chat_id}")
|
||||
if user.slug in chat['users']:
|
||||
add_user_to_chat(invited, chat_id, chat)
|
||||
|
||||
|
||||
@mutation.field("createChat")
|
||||
@login_required
|
||||
async def create_chat(_, info, description):
|
||||
async def create_chat(_, info, description, title=""):
|
||||
user = info.context["request"].user
|
||||
|
||||
chat_id = uuid.uuid4()
|
||||
chat = {
|
||||
"title": title,
|
||||
"description": description,
|
||||
"createdAt": str(datetime.now),
|
||||
"createdBy": user.slug,
|
||||
|
@ -110,7 +119,7 @@ async def load_messages(chatId, size, page):
|
|||
return messages
|
||||
|
||||
|
||||
@query.field("userChats")
|
||||
@query.field("myChats")
|
||||
@login_required
|
||||
async def user_chats(_, info):
|
||||
user = info.context["request"].user
|
||||
|
@ -120,25 +129,23 @@ async def user_chats(_, info):
|
|||
chats = list()
|
||||
else:
|
||||
chats = list(json.loads(chats))
|
||||
|
||||
return {"chats": chats}
|
||||
for c in chats:
|
||||
c['messages'] = await load_messages(c['id'], 50, 1)
|
||||
return chats
|
||||
|
||||
|
||||
@query.field("enterChat")
|
||||
@login_required
|
||||
async def enter_chat(_, info, chatId, size):
|
||||
async def enter_chat(_, info, chatId):
|
||||
user = info.context["request"].user
|
||||
|
||||
chat = await redis.execute("GET", f"chats/{chatId}")
|
||||
if not chat:
|
||||
return {"error": "chat not exist"}
|
||||
chat = json.loads(chat)
|
||||
|
||||
messages = await load_messages(chatId, size, 1)
|
||||
|
||||
await add_user_to_chat(user.slug, chatId, chat)
|
||||
|
||||
return {"chat": chat, "messages": messages}
|
||||
chat['messages'] = await load_messages(chatId, 50, 1)
|
||||
return chat
|
||||
|
||||
|
||||
@mutation.field("createMessage")
|
||||
|
@ -181,7 +188,7 @@ async def create_message(_, info, chatId, body, replyTo=None):
|
|||
return {"message": new_message}
|
||||
|
||||
|
||||
@query.field("getMessages")
|
||||
@query.field("loadChat")
|
||||
@login_required
|
||||
async def get_messages(_, info, chatId, size, page):
|
||||
chat = await redis.execute("GET", f"chats/{chatId}")
|
||||
|
|
|
@ -30,9 +30,13 @@ type EnterChatResult {
|
|||
error: String
|
||||
}
|
||||
|
||||
type UserChatsResult {
|
||||
type ChatResult {
|
||||
error: String
|
||||
chats: [String]
|
||||
members: [User]!
|
||||
createdAt: DateTime!
|
||||
createdBy: User
|
||||
messages: [Message]
|
||||
title: String
|
||||
}
|
||||
|
||||
type SessionInfo {
|
||||
|
@ -203,9 +207,10 @@ type Mutation {
|
|||
|
||||
type Query {
|
||||
# inbox
|
||||
userChats: UserChatsResult!
|
||||
enterChat(chatId: String!, size: Int = 50): EnterChatResult!
|
||||
getMessages(chatId: String!, size: Int!, page: Int!): [Message]!
|
||||
myChats: [ChatResult]!
|
||||
enterChat(chatId: String!): ChatResult!
|
||||
loadChat(chatId: String!, size: Int!, page: Int!): [Message]!
|
||||
inviteChat(chatId: String!, userslug: String!): Result!
|
||||
|
||||
# auth
|
||||
isEmailUsed(email: String!): Boolean!
|
||||
|
@ -496,6 +501,10 @@ type Message {
|
|||
type Chat {
|
||||
id: Int!
|
||||
createdAt: DateTime!
|
||||
createdBy: User!
|
||||
updatedAt: DateTime!
|
||||
title: string
|
||||
description: String
|
||||
users: [User]!
|
||||
messages: [Message]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user