Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved functions to helper file #3033

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 0 additions & 104 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dayjs from 'dayjs';
import * as Yup from 'yup';
import { getDisplayName, getDisplayNameForSearch } from './utils';

export const OLD_DOMAIN = 'tides.coloredcow.com';
export const NEW_DOMAIN = 'glific.com';
Expand Down Expand Up @@ -263,106 +262,3 @@ export const getVariables = (
...variables,
};
};

export const getConversationForSearchMulti = (
conversation: any,
selectedContactId: any,
groups: boolean
) => {
const chatType: string = groups ? 'waGroup' : 'contact';

let entity = conversation;
let selectedRecord = false;
let timer;
if (selectedContactId == entity.id) {
selectedRecord = true;
}
let entityId: any;
let displayName: string;
let contactIsOrgRead: boolean = false;

if (groups) {
entityId = entity.waGroup?.id || entity.id;
} else {
entityId = entity.contact?.id || entity.id;
}

if (conversation[chatType]) {
entity = conversation[chatType];
if (selectedContactId == conversation[chatType]?.id) {
selectedRecord = true;
}
} else if (conversation.bspStatus && conversation.lastMessageAt) {
contactIsOrgRead = conversation.isOrgRead;
timer = {
time: conversation.lastMessageAt,
contactStatus: conversation.status,
contactBspStatus: conversation.bspStatus,
};
}

displayName = getDisplayNameForSearch(entity);

return {
displayName,
contactIsOrgRead,
selectedRecord,
entityId,
entity,
timer,
};
};

export const getConversation = (
conversation: any,
selectedContactId: any,
selectedCollectionId: any
) => {
let lastMessage = [];
if (conversation.messages && conversation.messages.length > 0) {
[lastMessage] = conversation.messages;
}
let entityId: any;
let displayName = '';
let contactIsOrgRead = false;
let selectedRecord = false;
let timer;
if (conversation.waGroup) {
if (selectedContactId === conversation.waGroup?.id) {
selectedRecord = true;
}
entityId = conversation.waGroup?.id;
displayName = conversation.waGroup?.label;
contactIsOrgRead = false;
} else if (conversation.contact) {
if (selectedContactId === conversation.contact.id) {
selectedRecord = true;
}
entityId = conversation.contact.id;
displayName = getDisplayName(conversation.contact);
contactIsOrgRead = conversation.contact.isOrgRead;
timer = {
contactStatus: conversation.contact.status,
contactBspStatus: conversation.contact.bspStatus,
time: conversation.contact.lastMessageAt,
};
}

if (conversation.group) {
if (selectedCollectionId === conversation.group.id) {
selectedRecord = true;
}
entityId = conversation.group.id;
displayName = conversation.group.label;
contactIsOrgRead = conversation.group.isOrgRead;
}

return {
lastMessage,
entityId,
displayName,
contactIsOrgRead,
selectedRecord,
timer,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { getDisplayName, getDisplayNameForSearch } from 'common/utils';

export const getConversationForSearchMulti = (
conversation: any,
selectedContactId: any,
groups: boolean
) => {
const chatType: string = groups ? 'waGroup' : 'contact';

let entity = conversation;
let selectedRecord = false;
let timer;
if (selectedContactId === entity.id) {
selectedRecord = true;

Check warning on line 14 in src/containers/Chat/ChatConversations/ConversationList/ConversationList.helper.ts

View check run for this annotation

Codecov / codecov/patch

src/containers/Chat/ChatConversations/ConversationList/ConversationList.helper.ts#L14

Added line #L14 was not covered by tests
}
let entityId: any;
let displayName: string;
let contactIsOrgRead: boolean = false;

if (groups) {
entityId = entity.waGroup?.id || entity.id;
} else {
entityId = entity.contact?.id || entity.id;
}

if (conversation[chatType]) {
entity = conversation[chatType];
if (selectedContactId === conversation[chatType]?.id) {
selectedRecord = true;

Check warning on line 29 in src/containers/Chat/ChatConversations/ConversationList/ConversationList.helper.ts

View check run for this annotation

Codecov / codecov/patch

src/containers/Chat/ChatConversations/ConversationList/ConversationList.helper.ts#L29

Added line #L29 was not covered by tests
}
} else if (conversation.bspStatus && conversation.lastMessageAt) {
contactIsOrgRead = conversation.isOrgRead;
timer = {
time: conversation.lastMessageAt,
contactStatus: conversation.status,
contactBspStatus: conversation.bspStatus,
};
}

displayName = getDisplayNameForSearch(entity);

return {
displayName,
contactIsOrgRead,
selectedRecord,
entityId,
entity,
timer,
};
};

export const getConversation = (
conversation: any,
selectedContactId: any,
selectedCollectionId: any
) => {
let lastMessage = [];
if (conversation.messages && conversation.messages.length > 0) {
[lastMessage] = conversation.messages;
}
let entityId: any;
let displayName = '';
let contactIsOrgRead = false;
let selectedRecord = false;
let timer;
if (conversation.waGroup) {
if (selectedContactId === conversation.waGroup?.id) {
selectedRecord = true;
}
entityId = conversation.waGroup?.id;
displayName = conversation.waGroup?.label;
contactIsOrgRead = false;
} else if (conversation.contact) {
if (selectedContactId === conversation.contact.id) {
selectedRecord = true;
}
entityId = conversation.contact.id;
displayName = getDisplayName(conversation.contact);
contactIsOrgRead = conversation.contact.isOrgRead;
timer = {
contactStatus: conversation.contact.status,
contactBspStatus: conversation.contact.bspStatus,
time: conversation.contact.lastMessageAt,
};
}

if (conversation.group) {
if (selectedCollectionId === conversation.group.id) {
selectedRecord = true;
}
entityId = conversation.group.id;
displayName = conversation.group.label;
contactIsOrgRead = conversation.group.isOrgRead;
}

return {
lastMessage,
entityId,
displayName,
contactIsOrgRead,
selectedRecord,
timer,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ import {
GROUP_QUERY_VARIABLES,
GROUP_COLLECTION_SEARCH_QUERY_VARIABLES,
getVariables,
getConversationForSearchMulti,
getConversation,
} from 'common/constants';
import { updateConversations } from 'services/ChatService';
import { updateGroupConversations } from 'services/GroupMessageService';
import { showMessages } from 'common/responsive';
import { addLogs } from 'common/utils';
import ChatConversation from '../ChatConversation/ChatConversation';
import { getConversationForSearchMulti, getConversation } from './ConversationList.helper';
import styles from './ConversationList.module.css';
import { GROUP_SEARCH_MULTI_QUERY, GROUP_SEARCH_QUERY } from 'graphql/queries/WaGroups';
import { useLocation } from 'react-router-dom';
Expand Down
Loading