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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user