@botonic/react
Version:
Build Chatbots using React
45 lines • 2.72 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageTimestamp = exports.resolveMessageTimestamps = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const constants_1 = require("../../constants");
const index_types_1 = require("../../index-types");
const util_1 = require("../../util");
const context_1 = require("../../webchat/context");
const styles_1 = require("./styles");
const resolveMessageTimestamps = (getThemeProperty, timestampEnabled) => {
const timestampsFormat = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsFormat);
const timestampStyle = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsStyle);
const timestampsEnabled = Boolean(timestampEnabled !== undefined
? timestampEnabled
: getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.enableMessageTimestamps, Boolean(timestampStyle) || Boolean(timestampsFormat) || false));
const defaultTimestampFormat = {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
};
const getFormattedTimestamp = timestampsFormat
? timestampsFormat()
: // @ts-ignore
new Date().toLocaleString(undefined, defaultTimestampFormat);
return {
timestampsEnabled,
getFormattedTimestamp,
timestampStyle,
};
};
exports.resolveMessageTimestamps = resolveMessageTimestamps;
const MessageTimestamp = ({ timestamp, style, sentBy, }) => {
const { getThemeProperty } = (0, react_1.useContext)(context_1.WebchatContext);
const isSentByUser = sentBy === index_types_1.SENDERS.user;
const isSentByAgent = sentBy === index_types_1.SENDERS.agent;
const BotMessageImage = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.botMessageImage);
const AgentMessageImage = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.agentMessageImage, BotMessageImage);
const timestampsWithImage = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsWithImage);
return ((0, jsx_runtime_1.jsxs)(styles_1.TimestampContainer, Object.assign({ className: `botonic-timestamp-container ${sentBy}`, isSentByUser: isSentByUser }, { children: [timestampsWithImage && BotMessageImage && !isSentByUser && ((0, jsx_runtime_1.jsx)("img", { src: (0, util_1.resolveImage)(isSentByAgent ? AgentMessageImage : BotMessageImage) })), (0, jsx_runtime_1.jsx)(styles_1.TimestampText, Object.assign({ isSentByUser: isSentByUser, style: style }, { children: timestamp }))] })));
};
exports.MessageTimestamp = MessageTimestamp;
//# sourceMappingURL=timestamps.js.map
;