@progress/kendo-react-conversational-ui
Version:
React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components
59 lines (58 loc) • 1.92 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import { isAuthor as i } from "./utils.mjs";
const o = (s) => s[s.length - 1], p = (s, e) => s && e && (e.getDate() !== s.getDate() || e.getMonth() !== s.getMonth() || e.getFullYear() !== s.getFullYear()), r = (s, e) => {
const t = e.timestamp, a = o(s);
if (t && (!a || p(t, a.timestamp))) {
const n = {
type: "date-marker",
timestamp: t,
trackBy: t.getTime()
};
s.push(n);
}
}, u = (s, e, t) => {
const a = o(s);
let n;
e.typing && !t || (a && a.type === "message-group" && (n = a.messages), n && i(e.author, o(n)) ? n.push(e) : s.push({
type: "message-group",
messages: [e],
author: e.author,
timestamp: e.timestamp,
trackBy: e
}));
}, c = (s) => (e, t, a) => {
const n = a === s - 1;
return r(e, t), u(e, t, n), t.attachments && t.attachments.length > 1 && e.push({
type: "attachment-group",
attachments: t.attachments,
attachmentLayout: t.attachmentLayout,
timestamp: t.timestamp,
trackBy: t
}), t.suggestedActions && n && e.push({
type: "action-group",
actions: t.suggestedActions,
timestamp: t.timestamp,
trackBy: t
}), e;
};
function h(s) {
let e = 0;
s.forEach((t) => {
t.type === "message-group" ? t.messages.forEach((a) => {
a.selectionIndex = e++;
}) : (t.type === "attachment-group" || t.type === "action-group") && (t.selectionIndex = e++);
}), s.lastSelectionIndex = e - 1;
}
const m = (s) => {
const t = s.slice().reduce(c(s.length), []);
return h(t), t;
};
export {
m as convertMsgsToViewItems
};