* Add draft support * Fixes issue with draft loading * Adds draft for private notes * Use localstorage helper * .remove instead of .clear * Remove timestamp * clearLocalStorageOnLogout * Fix draft save on refresh * Remove usage of delete operator * Adds autosave for draft messages * Remove setinterval and add debounce * Removes draft redundancy check * Adds test cases for debouncer * Update app/javascript/shared/helpers/specs/TimeHelpers.spec.js Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Update app/javascript/shared/helpers/specs/TimeHelpers.spec.js Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Review fixes * Fixes issue with debouncer * FIxes debouncer issue * Fixes issue with draft empty message * Removes empty keys from local storage drafts * Fixes error with empty draft Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
export const findPendingMessageIndex = (chat, message) => {
|
|
const { echo_id: tempMessageId } = message;
|
|
return chat.messages.findIndex(
|
|
m => m.id === message.id || m.id === tempMessageId
|
|
);
|
|
};
|
|
|
|
const filterByStatus = (chatStatus, filterStatus) =>
|
|
filterStatus === 'all' ? true : chatStatus === filterStatus;
|
|
|
|
export const applyPageFilters = (conversation, filters) => {
|
|
const { inboxId, status, labels = [], teamId } = filters;
|
|
const {
|
|
status: chatStatus,
|
|
inbox_id: chatInboxId,
|
|
labels: chatLabels = [],
|
|
meta = {},
|
|
} = conversation;
|
|
const team = meta.team || {};
|
|
const { id: chatTeamId } = team;
|
|
|
|
let shouldFilter = filterByStatus(chatStatus, status);
|
|
if (inboxId) {
|
|
const filterByInbox = Number(inboxId) === chatInboxId;
|
|
shouldFilter = shouldFilter && filterByInbox;
|
|
}
|
|
if (teamId) {
|
|
const filterByTeam = Number(teamId) === chatTeamId;
|
|
shouldFilter = shouldFilter && filterByTeam;
|
|
}
|
|
if (labels.length) {
|
|
const filterByLabels = labels.every(label => chatLabels.includes(label));
|
|
shouldFilter = shouldFilter && filterByLabels;
|
|
}
|
|
|
|
return shouldFilter;
|
|
};
|
|
|
|
export const trimMessage = (content = '', maxLength = 1024) => {
|
|
if (content.length > maxLength) {
|
|
return content.substring(0, maxLength);
|
|
}
|
|
return content;
|
|
};
|