webapp/src/graphql/client/chat.ts

80 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-11-28 13:18:25 +00:00
// inbox
2023-12-03 10:22:42 +00:00
import { createGraphQLClient } from '../createGraphQLClient'
2023-11-28 13:18:25 +00:00
import createChat from '../mutation/chat/chat-create'
import deleteChat from '../mutation/chat/chat-delete'
import markAsRead from '../mutation/chat/chat-mark-as-read'
import createChatMessage from '../mutation/chat/chat-message-create'
import deleteChatMessage from '../mutation/chat/chat-message-delete'
import updateChatMessage from '../mutation/chat/chat-message-update'
import updateChat from '../mutation/chat/chat-update'
import chatMessagesLoadBy from '../query/chat/chat-messages-load-by'
import loadRecipients from '../query/chat/chat-recipients'
import myChats from '../query/chat/chats-load'
import {
Chat,
2023-11-28 15:36:00 +00:00
MutationCreate_ChatArgs,
MutationCreate_MessageArgs,
MutationDelete_ChatArgs,
MutationDelete_MessageArgs,
MutationMark_As_ReadArgs,
MutationUpdate_ChatArgs,
MutationUpdate_MessageArgs,
QueryLoad_ChatsArgs,
QueryLoad_Messages_ByArgs,
QueryLoad_RecipientsArgs,
2023-11-28 13:18:25 +00:00
} from '../schema/chat.gen'
export const inboxClient = {
2023-12-03 10:22:42 +00:00
private: null,
connect: () => (inboxClient.private = createGraphQLClient('chat')),
2023-11-28 15:36:00 +00:00
loadChats: async (options: QueryLoad_ChatsArgs): Promise<Chat[]> => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.query(myChats, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.load_chats.chats
},
2023-11-28 15:36:00 +00:00
createChat: async (options: MutationCreate_ChatArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(createChat, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.create_chat
},
2023-11-28 15:36:00 +00:00
markAsRead: async (options: MutationMark_As_ReadArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(markAsRead, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.mark_as_read
},
2023-11-28 15:36:00 +00:00
updateChat: async (options: MutationUpdate_ChatArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(updateChat, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.update_chat
},
2023-11-28 15:36:00 +00:00
deleteChat: async (options: MutationDelete_ChatArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(deleteChat, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.delete_chat
},
2023-11-28 15:36:00 +00:00
createMessage: async (options: MutationCreate_MessageArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(createChatMessage, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.create_message.message
},
2023-11-28 15:36:00 +00:00
updateMessage: async (options: MutationUpdate_MessageArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(updateChatMessage, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.update_message.message
},
2023-11-28 15:36:00 +00:00
deleteMessage: async (options: MutationDelete_MessageArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.mutation(deleteChatMessage, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.delete_message
},
2023-11-28 15:36:00 +00:00
loadChatMessages: async (options: QueryLoad_Messages_ByArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.query(chatMessagesLoadBy, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.load_messages_by.messages
},
2023-11-28 15:36:00 +00:00
loadRecipients: async (options: QueryLoad_RecipientsArgs) => {
2023-12-03 10:22:42 +00:00
const resp = await inboxClient.private.query(loadRecipients, options).toPromise()
2023-11-28 13:18:25 +00:00
return resp.data.load_recipients.members
},
}