feature/IO-3000-messaging-sockets-migration2 - Final fixes around sync / archive / receive

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-11-25 11:38:59 -08:00
parent 239c1502f9
commit 62dd3d7e8e
3 changed files with 77 additions and 47 deletions

View File

@@ -42,10 +42,13 @@ export function* openChatByPhone({ payload }) {
} = yield client.query({
query: CONVERSATION_ID_BY_PHONE,
variables: { phone: p.number },
fetchPolicy: "network-only"
// THIS NEEDS TO REMAIN NO CACHE, IT CHECKS FOR NEW MESSAGES FOR SYNC
fetchPolicy: "no-cache"
});
if (conversations.length === 0) {
const existingConversation = conversations?.find((c) => c.phone_num === phone_num);
if (!existingConversation) {
// No conversation exists, create a new one
const {
data: {
@@ -75,18 +78,17 @@ export function* openChatByPhone({ payload }) {
// Set the newly created conversation as selected
yield put(setSelectedConversation(createdConversation.id));
} else if (conversations.length === 1) {
const conversation = conversations[0];
let updatedConversation = conversation;
} else {
let updatedConversation = existingConversation;
if (conversation.archived) {
if (existingConversation.archived) {
// Conversation is archived, unarchive it in the DB
const {
data: { update_conversations_by_pk: unarchivedConversation }
} = yield client.mutate({
mutation: TOGGLE_CONVERSATION_ARCHIVE,
variables: {
id: conversation.id,
id: existingConversation.id,
archived: false
}
});
@@ -115,10 +117,6 @@ export function* openChatByPhone({ payload }) {
}
});
}
} else {
// Multiple conversations found
console.error("ERROR: Multiple conversations found.");
yield put(setSelectedConversation(null));
}
} catch (error) {
console.error("Error in openChatByPhone saga.", error);