From cd592b671c68370c1017ff7f415d031b643944b9 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 21 Nov 2024 15:05:52 -0800 Subject: [PATCH] feature/IO-3000-messaging-sockets-migrations2 - - Checkpoint, Signed-off-by: Dave Richer --- .../registerMessagingSocketHandlers.js | 10 +++++++++- client/src/graphql/conversations.queries.js | 18 +++++++++++++++++- server/sms/receive.js | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/client/src/components/chat-affix/registerMessagingSocketHandlers.js b/client/src/components/chat-affix/registerMessagingSocketHandlers.js index 325770541..b50d02c8a 100644 --- a/client/src/components/chat-affix/registerMessagingSocketHandlers.js +++ b/client/src/components/chat-affix/registerMessagingSocketHandlers.js @@ -22,6 +22,7 @@ export const registerMessagingHandlers = ({ socket, client }) => { query: CONVERSATION_LIST_QUERY, variables: { offset: 0 } }); + client.cache.writeQuery({ query: CONVERSATION_LIST_QUERY, variables: { offset: 0 }, @@ -49,7 +50,14 @@ export const registerMessagingHandlers = ({ socket, client }) => { id: conversationId }), fields: { - updated_at: () => new Date(), + updated_at: () => new Date().toISOString(), + archived(cached) { + // Unarchive the conversation if it was previously marked as archived + if (cached) { + return false; + } + return cached; + }, messages_aggregate(cached) { // Increment unread count only if the message is inbound if (!isoutbound) { diff --git a/client/src/graphql/conversations.queries.js b/client/src/graphql/conversations.queries.js index e05a474ab..03bc0426b 100644 --- a/client/src/graphql/conversations.queries.js +++ b/client/src/graphql/conversations.queries.js @@ -90,9 +90,25 @@ export const CONVERSATION_ID_BY_PHONE = gql` query CONVERSATION_ID_BY_PHONE($phone: String!) { conversations(where: { phone_num: { _eq: $phone } }) { id + phone_num + archived + label + unreadcnt job_conversations { jobid - id + conversationid + job { + id + ownr_fn + ownr_ln + ownr_co_nm + ro_number + } + } + messages_aggregate(where: { read: { _eq: false }, isoutbound: { _eq: false } }) { + aggregate { + count + } } } } diff --git a/server/sms/receive.js b/server/sms/receive.js index 3fb721eec..f7f41652e 100644 --- a/server/sms/receive.js +++ b/server/sms/receive.js @@ -54,7 +54,8 @@ exports.receive = async (req, res) => { newMessage.conversation = { data: { bodyshopid: bodyshop.id, - phone_num: phone(req.body.From).phoneNumber + phone_num: phone(req.body.From).phoneNumber, + archived: false } };