inbox-client
This commit is contained in:
parent
82411d1a11
commit
f4336b40f6
|
@ -1,7 +1,7 @@
|
|||
import type { Accessor, JSX } from 'solid-js'
|
||||
import { createContext, createSignal, useContext } from 'solid-js'
|
||||
import type { Chat, Message, MutationCreateMessageArgs } from '../graphql/types.gen'
|
||||
import { apiClient } from '../utils/apiClient'
|
||||
import { inboxClient } from '../utils/apiClient'
|
||||
|
||||
import { loadMessages } from '../stores/inbox'
|
||||
|
||||
|
@ -26,7 +26,7 @@ export function useInbox() {
|
|||
export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||
const [chats, setChats] = createSignal<Chat[]>([])
|
||||
const [messages, setMessages] = createSignal<Message[]>([])
|
||||
const eventSource = new EventSource('testapi.discours.io/connect')
|
||||
const eventSource = new EventSource('chat.discours.io/connect')
|
||||
// TODO: call /disconnect some time
|
||||
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
||||
eventSource.onmessage = function (event) {
|
||||
|
|
|
@ -45,3 +45,8 @@ const options: ClientOptions = {
|
|||
}
|
||||
|
||||
export const privateGraphQLClient = createClient(options)
|
||||
|
||||
export const privateInboxGraphQLClient = createClient({
|
||||
...options,
|
||||
url: 'https://chat.discours.io'
|
||||
})
|
||||
|
|
|
@ -18,7 +18,7 @@ import type {
|
|||
Shout
|
||||
} from '../graphql/types.gen'
|
||||
import { publicGraphQLClient } from '../graphql/publicGraphQLClient'
|
||||
import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient'
|
||||
import { getToken, privateGraphQLClient, privateInboxGraphQLClient } from '../graphql/privateGraphQLClient'
|
||||
import topicsAll from '../graphql/query/topics-all'
|
||||
import mySession from '../graphql/mutation/my-session'
|
||||
import authLogoutQuery from '../graphql/mutation/auth-logout'
|
||||
|
@ -349,30 +349,31 @@ export const apiClient = {
|
|||
.toPromise()
|
||||
// console.debug(resp)
|
||||
return resp.data.loadReactionsBy
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// inbox
|
||||
export const inboxClient = {
|
||||
getChats: async (options: QueryLoadChatsArgs): Promise<Chat[]> => {
|
||||
const resp = await privateGraphQLClient.query(myChats, options).toPromise()
|
||||
const resp = await privateInboxGraphQLClient.query(myChats, options).toPromise()
|
||||
return resp.data.loadChats.chats
|
||||
},
|
||||
|
||||
createChat: async (options: MutationCreateChatArgs) => {
|
||||
const resp = await privateGraphQLClient.mutation(createChat, options).toPromise()
|
||||
const resp = await privateInboxGraphQLClient.mutation(createChat, options).toPromise()
|
||||
return resp.data.createChat
|
||||
},
|
||||
|
||||
createMessage: async (options: MutationCreateMessageArgs) => {
|
||||
const resp = await privateGraphQLClient.mutation(createMessage, options).toPromise()
|
||||
const resp = await privateInboxGraphQLClient.mutation(createMessage, options).toPromise()
|
||||
return resp.data.createMessage.message
|
||||
},
|
||||
|
||||
getChatMessages: async (options: QueryLoadMessagesByArgs) => {
|
||||
const resp = await privateGraphQLClient.query(chatMessagesLoadBy, options).toPromise()
|
||||
const resp = await privateInboxGraphQLClient.query(chatMessagesLoadBy, options).toPromise()
|
||||
return resp.data.loadMessagesBy.messages
|
||||
},
|
||||
getRecipients: async (options: QueryLoadRecipientsArgs) => {
|
||||
const resp = await privateGraphQLClient.query(loadRecipients, options).toPromise()
|
||||
const resp = await privateInboxGraphQLClient.query(loadRecipients, options).toPromise()
|
||||
return resp.data.loadRecipients.members
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user