UNPKG

@sendbird/uikit-react

Version:

Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

85 lines (82 loc) 5.25 kB
import { a as __awaiter, b as __generator } from '../chunks/bundle-yl5d1NoZ.js'; import React__default from 'react'; import { L as Label, a as LabelTypography, b as LabelColors } from '../chunks/bundle-viBng0Kh.js'; import Icon, { IconTypes, IconColors } from './Icon.js'; import TextButton from './TextButton.js'; import { z as getClassName, q as getUIKitFileType, t as truncateString } from '../chunks/bundle-vmZ9LoYK.js'; import { C as Colors } from '../chunks/bundle-Bokm7tQ9.js'; import { u as useMediaQueryContext } from '../chunks/bundle-DBhJIxHw.js'; import { o as openURL } from '../chunks/bundle-MlG9piGf.js'; import { u as useSendbird } from '../chunks/bundle-i_3w58Zd.js'; import '../chunks/bundle-C1dqPUnT.js'; import '@sendbird/chat/groupChannel'; import '../utils/message/getOutgoingMessageState.js'; import '../chunks/bundle-DgosLQK9.js'; import '../chunks/bundle-DEuCwnTn.js'; import '../chunks/bundle-fdEQfX2s.js'; import '../chunks/bundle-CqLLOVG5.js'; import '../chunks/bundle-BUYU9H94.js'; import '@sendbird/chat'; import '@sendbird/chat/openChannel'; function FileMessageItemBody(_a) { var _this = this; var _b; var _c = _a.className, className = _c === void 0 ? '' : _c, message = _a.message, _d = _a.isByMe, isByMe = _d === void 0 ? false : _d, _e = _a.mouseHover, mouseHover = _e === void 0 ? false : _e, _f = _a.isReactionEnabled, isReactionEnabled = _f === void 0 ? false : _f, truncateLimit = _a.truncateLimit, onBeforeDownloadFileMessage = _a.onBeforeDownloadFileMessage; var logger = null; try { var globalLogger = useSendbird().state.config.logger; logger = globalLogger; } catch (err) { // TODO: Handle error } var isMobile = useMediaQueryContext().isMobile; var truncateMaxNum = truncateLimit !== null && truncateLimit !== void 0 ? truncateLimit : (isMobile ? 20 : undefined); var downloadFileWithUrl = function () { return openURL(message === null || message === void 0 ? void 0 : message.url); }; var handleOnClickTextButton = onBeforeDownloadFileMessage ? function () { return __awaiter(_this, void 0, void 0, function () { var allowDownload, err_1; var _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); return [4 /*yield*/, onBeforeDownloadFileMessage({ message: message })]; case 1: allowDownload = _c.sent(); if (allowDownload) { downloadFileWithUrl(); } else { (_a = logger === null || logger === void 0 ? void 0 : logger.info) === null || _a === void 0 ? void 0 : _a.call(logger, 'FileMessageItemBody: Not allowed to download.'); } return [3 /*break*/, 3]; case 2: err_1 = _c.sent(); (_b = logger === null || logger === void 0 ? void 0 : logger.error) === null || _b === void 0 ? void 0 : _b.call(logger, 'FileMessageItemBody: Error occurred while determining download continuation:', err_1); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); } : downloadFileWithUrl; return (React__default.createElement("div", { className: getClassName([ className, 'sendbird-file-message-item-body', isByMe ? 'outgoing' : 'incoming', mouseHover ? 'mouse-hover' : '', (isReactionEnabled && ((_b = message === null || message === void 0 ? void 0 : message.reactions) === null || _b === void 0 ? void 0 : _b.length) > 0) ? 'reactions' : '', ]) }, React__default.createElement("div", { className: "sendbird-file-message-item-body__file-icon" }, React__default.createElement(Icon, { className: "sendbird-file-message-item-body__file-icon__icon", type: { IMAGE: IconTypes.PHOTO, VIDEO: IconTypes.PLAY, AUDIO: IconTypes.FILE_AUDIO, GIF: IconTypes.GIF, OTHERS: IconTypes.FILE_DOCUMENT, }[getUIKitFileType(message === null || message === void 0 ? void 0 : message.type)], fillColor: IconColors.PRIMARY, width: "24px", height: "24px" })), React__default.createElement(TextButton, { className: "sendbird-file-message-item-body__file-name", onClick: handleOnClickTextButton, color: isByMe ? Colors.ONCONTENT_1 : Colors.ONBACKGROUND_1 }, React__default.createElement(Label, { className: "sendbird-file-message-item-body__file-name__text", testID: "sendbird-file-message-item-body__file-name__text", type: LabelTypography.BODY_1, color: isByMe ? LabelColors.ONCONTENT_1 : LabelColors.ONBACKGROUND_1 }, truncateString((message === null || message === void 0 ? void 0 : message.name) || (message === null || message === void 0 ? void 0 : message.url), truncateMaxNum))))); } export { FileMessageItemBody as default }; //# sourceMappingURL=FileMessageItemBody.js.map