Initial commit: Add logistics and order_detail message types
Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
94
app/javascript/dashboard/helper/conversationHelper.js
Normal file
94
app/javascript/dashboard/helper/conversationHelper.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Determines the last non-activity message between store and API messages.
|
||||
* @param {Object} messageInStore - The last non-activity message from the store.
|
||||
* @param {Object} messageFromAPI - The last non-activity message from the API.
|
||||
* @returns {Object} The latest non-activity message.
|
||||
*/
|
||||
const getLastNonActivityMessage = (messageInStore, messageFromAPI) => {
|
||||
// If both API value and store value for last non activity message
|
||||
// are available, then return the latest one.
|
||||
if (messageInStore && messageFromAPI) {
|
||||
return messageInStore.created_at >= messageFromAPI.created_at
|
||||
? messageInStore
|
||||
: messageFromAPI;
|
||||
}
|
||||
// Otherwise, return whichever is available
|
||||
return messageInStore || messageFromAPI;
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters out duplicate source messages from an array of messages.
|
||||
* @param {Array} messages - The array of messages to filter.
|
||||
* @returns {Array} An array of messages without duplicates.
|
||||
*/
|
||||
export const filterDuplicateSourceMessages = (messages = []) => {
|
||||
const messagesWithoutDuplicates = [];
|
||||
// We cannot use Map or any short hand method as it returns the last message with the duplicate ID
|
||||
// We should return the message with smaller id when there is a duplicate
|
||||
messages.forEach(m1 => {
|
||||
if (m1.source_id) {
|
||||
const index = messagesWithoutDuplicates.findIndex(
|
||||
m2 => m1.source_id === m2.source_id
|
||||
);
|
||||
|
||||
if (index < 0) {
|
||||
messagesWithoutDuplicates.push(m1);
|
||||
}
|
||||
} else {
|
||||
messagesWithoutDuplicates.push(m1);
|
||||
}
|
||||
});
|
||||
return messagesWithoutDuplicates;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the last message from a conversation, prioritizing non-activity messages.
|
||||
* @param {Object} m - The conversation object containing messages.
|
||||
* @returns {Object} The last message of the conversation.
|
||||
*/
|
||||
export const getLastMessage = m => {
|
||||
const lastMessageIncludingActivity = m.messages[m.messages.length - 1];
|
||||
|
||||
const nonActivityMessages = m.messages.filter(
|
||||
message => message.message_type !== 2
|
||||
);
|
||||
const lastNonActivityMessageInStore =
|
||||
nonActivityMessages[nonActivityMessages.length - 1];
|
||||
|
||||
const lastNonActivityMessageFromAPI = m.last_non_activity_message;
|
||||
|
||||
// If API value and store value for last non activity message
|
||||
// is empty, then return the last activity message
|
||||
if (!lastNonActivityMessageInStore && !lastNonActivityMessageFromAPI) {
|
||||
return lastMessageIncludingActivity;
|
||||
}
|
||||
|
||||
return getLastNonActivityMessage(
|
||||
lastNonActivityMessageInStore,
|
||||
lastNonActivityMessageFromAPI
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters messages that have been read by the agent.
|
||||
* @param {Array} messages - The array of messages to filter.
|
||||
* @param {number} agentLastSeenAt - The timestamp of when the agent last saw the messages.
|
||||
* @returns {Array} An array of read messages.
|
||||
*/
|
||||
export const getReadMessages = (messages, agentLastSeenAt) => {
|
||||
return messages.filter(
|
||||
message => message.created_at * 1000 <= agentLastSeenAt * 1000
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters messages that have not been read by the agent.
|
||||
* @param {Array} messages - The array of messages to filter.
|
||||
* @param {number} agentLastSeenAt - The timestamp of when the agent last saw the messages.
|
||||
* @returns {Array} An array of unread messages.
|
||||
*/
|
||||
export const getUnreadMessages = (messages, agentLastSeenAt) => {
|
||||
return messages.filter(
|
||||
message => message.created_at * 1000 > agentLastSeenAt * 1000
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user