@sendbird/uikit-react-native
Version:
Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
148 lines (147 loc) • 6.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _chat = require("@sendbird/chat");
var _uikitReactNativeFoundation = require("@sendbird/uikit-react-native-foundation");
var _uikitUtils = require("@sendbird/uikit-utils");
var _useContext = require("../../../hooks/useContext");
var _moduleContext = require("../module/moduleContext");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
let WARN_onPressMenuNotification = false;
let WARN_onPressMenuSearchInChannel = false;
const GroupChannelSettingsMenu = ({
onPressMenuModeration,
onPressMenuMembers,
onPressMenuSearchInChannel,
onPressMenuLeaveChannel,
onPressMenuNotification,
menuItemsCreator = menu => menu
}) => {
const {
sdk,
sbOptions
} = (0, _useContext.useSendbirdChat)();
const {
channel
} = (0, _react.useContext)(_moduleContext.GroupChannelSettingsContexts.Fragment);
const {
STRINGS
} = (0, _useContext.useLocalization)();
const {
colors
} = (0, _uikitReactNativeFoundation.useUIKitTheme)();
if (__DEV__ && !WARN_onPressMenuNotification && !onPressMenuNotification && sbOptions.uikit.groupChannel.channel.enableMention) {
_uikitUtils.Logger.warn('If you are using mention, make sure to pass the `onPressMenuNotification` prop');
WARN_onPressMenuNotification = true;
}
if (__DEV__ && !WARN_onPressMenuSearchInChannel && !onPressMenuSearchInChannel && sbOptions.uikitWithAppInfo.groupChannel.setting.enableMessageSearch) {
_uikitUtils.Logger.warn('If you are using message search, make sure to pass the `onPressMenuSearchInChannel` prop');
WARN_onPressMenuSearchInChannel = true;
}
const toggleNotification = async () => {
try {
if (channel.myPushTriggerOption === 'off') {
await channel.setMyPushTriggerOption(_chat.PushTriggerOption.DEFAULT);
} else {
await channel.setMyPushTriggerOption(_chat.PushTriggerOption.OFF);
}
} catch (error) {
_uikitUtils.Logger.warn('Failed to toggle notification', error);
}
};
const {
onPressNotificationMenu,
actionLabelNotificationMenu,
actionItemNotificationMenu
} = (0, _uikitUtils.useIIFE)(() => {
const getNotificationsLabel = () => {
switch (channel.myPushTriggerOption) {
case _chat.PushTriggerOption.ALL:
case _chat.PushTriggerOption.DEFAULT:
return STRINGS.GROUP_CHANNEL_SETTINGS.MENU_NOTIFICATION_LABEL_ON;
case _chat.PushTriggerOption.OFF:
return STRINGS.GROUP_CHANNEL_SETTINGS.MENU_NOTIFICATION_LABEL_OFF;
case _chat.PushTriggerOption.MENTION_ONLY:
return STRINGS.GROUP_CHANNEL_SETTINGS.MENU_NOTIFICATION_LABEL_MENTION_ONLY;
}
};
return {
actionLabelNotificationMenu: getNotificationsLabel(),
actionItemNotificationMenu: (0, _uikitUtils.conditionChaining)([sbOptions.uikit.groupChannel.channel.enableMention], [/*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Icon, {
icon: 'chevron-right',
color: colors.onBackground01
}), /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Switch, {
value: channel.myPushTriggerOption !== 'off',
onChangeValue: toggleNotification
})]),
onPressNotificationMenu: () => {
if (sbOptions.uikit.groupChannel.channel.enableMention) onPressMenuNotification === null || onPressMenuNotification === void 0 || onPressMenuNotification();else toggleNotification();
}
};
});
const defaultMenuItems = [{
icon: 'moderation',
visible: channel.myRole === 'operator',
name: STRINGS.GROUP_CHANNEL_SETTINGS.MENU_MODERATION,
onPress: () => onPressMenuModeration(),
actionItem: /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Icon, {
icon: 'chevron-right',
color: colors.onBackground01
})
}, {
icon: 'notifications',
name: STRINGS.GROUP_CHANNEL_SETTINGS.MENU_NOTIFICATION,
onPress: onPressNotificationMenu,
actionLabel: actionLabelNotificationMenu,
actionItem: actionItemNotificationMenu
}, {
icon: 'members',
name: STRINGS.GROUP_CHANNEL_SETTINGS.MENU_MEMBERS,
onPress: () => onPressMenuMembers(),
actionLabel: String(channel.memberCount),
actionItem: /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Icon, {
icon: 'chevron-right',
color: colors.onBackground01
})
}];
if (sbOptions.uikitWithAppInfo.groupChannel.setting.enableMessageSearch && !channel.isEphemeral) {
defaultMenuItems.push({
icon: 'search',
name: STRINGS.GROUP_CHANNEL_SETTINGS.MENU_SEARCH,
onPress: () => onPressMenuSearchInChannel === null || onPressMenuSearchInChannel === void 0 ? void 0 : onPressMenuSearchInChannel()
});
}
defaultMenuItems.push({
icon: 'leave',
iconColor: colors.error,
name: STRINGS.GROUP_CHANNEL_SETTINGS.MENU_LEAVE_CHANNEL,
onPress: () => {
channel.leave().then(() => {
onPressMenuLeaveChannel();
sdk.clearCachedMessages([channel.url]).catch();
});
}
});
const menuItems = menuItemsCreator(defaultMenuItems);
return /*#__PURE__*/_react.default.createElement(_reactNative.View, null, menuItems.map(menu => {
return /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.MenuBar, {
key: menu.name,
onPress: menu.onPress,
name: menu.name,
disabled: menu.disabled,
visible: menu.visible,
icon: menu.icon,
iconColor: menu.iconColor,
iconBackgroundColor: menu.iconBackgroundColor,
actionLabel: menu.actionLabel,
actionItem: menu.actionItem
});
}));
};
var _default = exports.default = GroupChannelSettingsMenu;
//# sourceMappingURL=GroupChannelSettingsMenu.js.map
;