This commit is contained in:
Untone 2023-11-16 18:53:24 +03:00
parent 4f7702a77f
commit de097240e3
9 changed files with 96 additions and 8 deletions

View File

@ -0,0 +1,10 @@
import { ChatInput } from './../types.gen'
import { gql } from '@urql/core'
export default gql`
mutation DeleteChat($chat_id: String!) {
deleteChat(chat_id: $chat_id) {
error
}
}
`

View File

@ -0,0 +1,17 @@
import { gql } from '@urql/core'
export default gql`
mutation createMessage($chat: String!, $body: String!, $reply_to: Int) {
createMessage(chat: $chat, body: $body, reply_to: $reply_to) {
error
message {
id
body
author
created_at
reply_to
updated_at
}
}
}
`

View File

@ -0,0 +1,9 @@
import { gql } from '@urql/core'
export default gql`
mutation DeleteMessage($chat_id: String!) {
deleteMessage(chat_id: $chat_id) {
error
}
}
`

View File

@ -1,8 +1,9 @@
import { ChatInput } from './../types.gen'
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
mutation createMessage($chat: String!, $body: String!, $replyTo: Int) { mutation UpdateMessage($message: MessageInput!) {
createMessage(chat: $chat, body: $body, replyTo: $replyTo) { createMessage(message: $message) {
error error
message { message {
id id

View File

@ -0,0 +1,17 @@
import { ChatInput } from './../types.gen'
import { gql } from '@urql/core'
export default gql`
mutation UpdateChat($chat: ChatInput!) {
updateChat(chat: $chat) {
error
chat {
id
members {
id
slug
}
}
}
}
`

View File

@ -8,7 +8,6 @@ export default gql`
id id
title title
admins admins
users
members { members {
id id
slug slug
@ -17,7 +16,7 @@ export default gql`
} }
unread unread
description description
updatedAt updated_at
private private
messages { messages {
id id

View File

@ -18,7 +18,12 @@ import type {
Shout, Shout,
NotificationsQueryParams, NotificationsQueryParams,
NotificationsQueryResult, NotificationsQueryResult,
MySubscriptionsQueryResult MySubscriptionsQueryResult,
MutationUpdateMessageArgs,
MutationDeleteMessageArgs,
MutationMarkAsReadArgs,
MutationDeleteChatArgs,
MutationUpdateChatArgs
} from '../graphql/types.gen' } from '../graphql/types.gen'
import { publicGraphQLClient } from '../graphql/publicGraphQLClient' import { publicGraphQLClient } from '../graphql/publicGraphQLClient'
import { getToken, privateGraphQLClient, privateInboxGraphQLClient } from '../graphql/privateGraphQLClient' import { getToken, privateGraphQLClient, privateInboxGraphQLClient } from '../graphql/privateGraphQLClient'
@ -45,7 +50,6 @@ import userSubscribers from '../graphql/query/author-followers'
import userFollowedAuthors from '../graphql/query/author-following-users' import userFollowedAuthors from '../graphql/query/author-following-users'
import userFollowedTopics from '../graphql/query/author-following-topics' import userFollowedTopics from '../graphql/query/author-following-topics'
import topicBySlug from '../graphql/query/topic-by-slug' import topicBySlug from '../graphql/query/topic-by-slug'
import createChat from '../graphql/mutation/create-chat'
import reactionsLoadBy from '../graphql/query/reactions-load-by' import reactionsLoadBy from '../graphql/query/reactions-load-by'
import authorsLoadBy from '../graphql/query/authors-load-by' import authorsLoadBy from '../graphql/query/authors-load-by'
import shoutsLoadBy from '../graphql/query/articles-load-by' import shoutsLoadBy from '../graphql/query/articles-load-by'
@ -53,13 +57,19 @@ import draftsLoad from '../graphql/query/drafts-load'
import shoutLoad from '../graphql/query/article-load' import shoutLoad from '../graphql/query/article-load'
import myFeed from '../graphql/query/my-feed' import myFeed from '../graphql/query/my-feed'
import loadRecipients from '../graphql/query/chat-recipients' import loadRecipients from '../graphql/query/chat-recipients'
import createMessage from '../graphql/mutation/create-chat-message'
import updateProfile from '../graphql/mutation/update-profile' import updateProfile from '../graphql/mutation/update-profile'
import updateArticle from '../graphql/mutation/article-update' import updateArticle from '../graphql/mutation/article-update'
import deleteShout from '../graphql/mutation/article-delete' import deleteShout from '../graphql/mutation/article-delete'
// import notifications from '../graphql/query/notifications' // import notifications from '../graphql/query/notifications'
// import markNotificationAsRead from '../graphql/mutation/mark-notification-as-read' // import markNotificationAsRead from '../graphql/mutation/mark-notification-as-read'
import markAllNotificationsAsRead from '../graphql/mutation/mark-all-notifications-as-read' import markAllNotificationsAsRead from '../graphql/mutation/mark-all-notifications-as-read'
import markAsRead from '../graphql/mutation/chat-mark-as-read'
import createChat from '../graphql/mutation/chat-create'
import updateChat from '../graphql/mutation/chat-update'
import deleteChat from '../graphql/mutation/chat-delete'
import createChatMessage from '../graphql/mutation/chat-message-create'
import updateChatMessage from '../graphql/mutation/chat-message-update'
import deleteChatMessage from '../graphql/mutation/chat-message-delete'
import mySubscriptions from '../graphql/query/my-subscriptions' import mySubscriptions from '../graphql/query/my-subscriptions'
type ApiErrorCode = type ApiErrorCode =
@ -391,11 +401,36 @@ export const inboxClient = {
return resp.data.createChat return resp.data.createChat
}, },
markAsRead: async (options: MutationMarkAsReadArgs) => {
const resp = await privateInboxGraphQLClient.mutation(markAsRead, options).toPromise()
return resp.data.markAsRead
},
updateChat: async (options: MutationUpdateChatArgs) => {
const resp = await privateInboxGraphQLClient.mutation(updateChat, options).toPromise()
return resp.data.updateChat
},
deleteChat: async (options: MutationDeleteChatArgs) => {
const resp = await privateInboxGraphQLClient.mutation(deleteChat, options).toPromise()
return resp.data.deleteChat
},
createMessage: async (options: MutationCreateMessageArgs) => { createMessage: async (options: MutationCreateMessageArgs) => {
const resp = await privateInboxGraphQLClient.mutation(createMessage, options).toPromise() const resp = await privateInboxGraphQLClient.mutation(createChatMessage, options).toPromise()
return resp.data.createMessage.message return resp.data.createMessage.message
}, },
updateMessage: async (options: MutationUpdateMessageArgs) => {
const resp = await privateInboxGraphQLClient.mutation(updateChatMessage, options).toPromise()
return resp.data.updateMessage.message
},
deleteMessage: async (options: MutationDeleteMessageArgs) => {
const resp = await privateInboxGraphQLClient.mutation(deleteChatMessage, options).toPromise()
return resp.data.deleteMessage
},
loadChatMessages: async (options: QueryLoadMessagesByArgs) => { loadChatMessages: async (options: QueryLoadMessagesByArgs) => {
const resp = await privateInboxGraphQLClient.query(chatMessagesLoadBy, options).toPromise() const resp = await privateInboxGraphQLClient.query(chatMessagesLoadBy, options).toPromise()
return resp.data.loadMessagesBy.messages return resp.data.loadMessagesBy.messages