From 89d63538030e42facdb5d9d332a36715ac21bdcb Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 15 Nov 2023 12:51:13 +0300 Subject: [PATCH 1/5] merged --- src/context/notifications.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context/notifications.tsx b/src/context/notifications.tsx index 3c519752..f0476e43 100644 --- a/src/context/notifications.tsx +++ b/src/context/notifications.tsx @@ -96,7 +96,7 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => { if (isAuthenticated()) { loadNotifications() - await fetchEventSource('https://connect.discours.io', { + await fetchEventSource('https://chat.discours.io/connect', { method: 'GET', headers: { 'Content-Type': 'application/json', From 40b77c99e7d2678de98d4339b0d3bd6e32016fa2 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 15 Nov 2023 16:56:34 +0300 Subject: [PATCH 2/5] fix-bearer --- src/graphql/privateGraphQLClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphql/privateGraphQLClient.ts b/src/graphql/privateGraphQLClient.ts index b39305ac..375001e1 100644 --- a/src/graphql/privateGraphQLClient.ts +++ b/src/graphql/privateGraphQLClient.ts @@ -38,7 +38,7 @@ const options: ClientOptions = { if (!token) { console.error('[privateGraphQLClient] fetchOptions: token is null!') } - const headers = { Authorization: 'Bearer ' + token } + const headers = { Authorization: token } return { headers } }, exchanges From 6dcc4f37d307acfb45323d5a10d9cda13e8d9b55 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 16 Nov 2023 18:17:48 +0300 Subject: [PATCH 3/5] gql-updates --- src/graphql/mutation/create-chat-message.ts | 6 +++--- src/graphql/mutation/mark-as-read.ts | 9 +++++++++ src/graphql/query/chat-messages-load-by.ts | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/graphql/mutation/mark-as-read.ts diff --git a/src/graphql/mutation/create-chat-message.ts b/src/graphql/mutation/create-chat-message.ts index ef13221c..f82c0b0c 100644 --- a/src/graphql/mutation/create-chat-message.ts +++ b/src/graphql/mutation/create-chat-message.ts @@ -8,9 +8,9 @@ export default gql` id body author - createdAt - replyTo - updatedAt + created_at + reply_to + updated_at } } } diff --git a/src/graphql/mutation/mark-as-read.ts b/src/graphql/mutation/mark-as-read.ts new file mode 100644 index 00000000..955158c4 --- /dev/null +++ b/src/graphql/mutation/mark-as-read.ts @@ -0,0 +1,9 @@ +import { gql } from '@urql/core' + +export default gql` + mutation MarkAsReadMutation($message_id: Int!, $chat_id: String!) { + markAsRead(message_id: $message_id, chat_id: $chat_id) { + error + } + } +` diff --git a/src/graphql/query/chat-messages-load-by.ts b/src/graphql/query/chat-messages-load-by.ts index ed4ee950..06f5a603 100644 --- a/src/graphql/query/chat-messages-load-by.ts +++ b/src/graphql/query/chat-messages-load-by.ts @@ -8,9 +8,9 @@ export default gql` author body replyTo - createdAt + created_at id - updatedAt + updated_at replyTo } } From 93c4c3d3089c7bc10b7daf494766fa50ef09b4e2 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 16 Nov 2023 18:27:49 +0300 Subject: [PATCH 4/5] fieldsfix --- src/graphql/query/chat-messages-load-by.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/graphql/query/chat-messages-load-by.ts b/src/graphql/query/chat-messages-load-by.ts index 06f5a603..d4567d60 100644 --- a/src/graphql/query/chat-messages-load-by.ts +++ b/src/graphql/query/chat-messages-load-by.ts @@ -5,13 +5,12 @@ export default gql` loadMessagesBy(by: $by, limit: $limit, offset: $offset) { error messages { + id author body - replyTo + reply_to created_at - id updated_at - replyTo } } } From 4f7702a77f9bf9e18ca18487bfbc7634e567f671 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 16 Nov 2023 18:34:37 +0300 Subject: [PATCH 5/5] add-sse-entity --- src/context/inbox.tsx | 8 ++++---- src/context/notifications.tsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/context/inbox.tsx b/src/context/inbox.tsx index 44cf75e2..e90dcbc3 100644 --- a/src/context/inbox.tsx +++ b/src/context/inbox.tsx @@ -32,12 +32,12 @@ export const InboxProvider = (props: { children: JSX.Element }) => { const handleMessage = (sseMessage) => { console.log('[context.inbox]:', sseMessage) // TODO: handle all action types: create update delete join left - if (['create', 'update', 'delete'].includes(sseMessage.action)) { + if (sseMessage.entity == 'message') { const relivedMessage = sseMessage.payload setMessages((prev) => [...prev, relivedMessage]) - } else if (['left', 'join'].includes(sseMessage.action)) { - // TODO: set chat members - console.debug(sseMessage) + } else if (sseMessage.entity == 'chat') { + const relivedChat = sseMessage.payload + setChats((prev) => [...prev, relivedChat]) } } diff --git a/src/context/notifications.tsx b/src/context/notifications.tsx index f0476e43..c7e28da2 100644 --- a/src/context/notifications.tsx +++ b/src/context/notifications.tsx @@ -104,7 +104,7 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => { }, onmessage(event) { const m: SSEMessage = JSON.parse(event.data) - if (m.entity === 'chat') { + if (m.entity === 'chat' || m.entity == 'message') { console.log('[context.notifications] Received message:', m) messageHandler()(m) } else {