@sendbird/uikit-utils
Version:
A collection of utility functions and constants for building chat UI components with Sendbird UIKit.
29 lines (28 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getGroupChannelTitle = exports.getGroupChannelPreviewTime = exports.getGroupChannelLastMessage = void 0;
var _common = require("./common");
const getGroupChannelTitle = (currentUserId, channel, EMPTY_USERNAME = '(No name)', NO_MEMBERS = '(No members)', DEFAULT_CHANNEL_NAME = 'Group Channel') => {
if (channel.name !== DEFAULT_CHANNEL_NAME && channel.name !== '') return channel.name;
if (channel.memberCount === 1) return NO_MEMBERS;
return channel.members.filter(({
userId
}) => userId !== currentUserId).map(({
nickname
}) => nickname || EMPTY_USERNAME).join(', ');
};
exports.getGroupChannelTitle = getGroupChannelTitle;
const getGroupChannelPreviewTime = (channel, locale) => {
var _channel$lastMessage;
return (0, _common.getMessagePreviewTime)(((_channel$lastMessage = channel.lastMessage) === null || _channel$lastMessage === void 0 ? void 0 : _channel$lastMessage.createdAt) || channel.joinedAt * 1000 || channel.createdAt, locale);
};
exports.getGroupChannelPreviewTime = getGroupChannelPreviewTime;
const getGroupChannelLastMessage = (channel, EMPTY_MESSAGE = '') => {
const message = channel.lastMessage;
if (!message) return EMPTY_MESSAGE;
return (0, _common.getMessagePreviewBody)(message, EMPTY_MESSAGE);
};
exports.getGroupChannelLastMessage = getGroupChannelLastMessage;
//# sourceMappingURL=groupChannel.js.map