import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import useUpdate from 'react-use/lib/useUpdate'; import { SettingsKey } from '../../../data/settings-key'; import { unblockConvoById } from '../../../interactions/conversationInteractions'; import { getConversationController } from '../../../session/conversations'; import { ToastUtils } from '../../../session/utils'; import { toggleAudioAutoplay } from '../../../state/ducks/userConfig'; import { getBlockedPubkeys } from '../../../state/selectors/conversations'; import { getAudioAutoplay } from '../../../state/selectors/userConfig'; import { SessionButtonColor } from '../../basic/SessionButton'; import { SessionSettingButtonItem, SessionSettingsItemWrapper, SessionToggleWithDescription, } from '../SessionSettingListItem'; async function toggleCommunitiesPruning() { try { const newValue = !(await window.getOpengroupPruning()); // make sure to write it here too, as this is the value used on the UI to mark the toggle as true/false window.setSettingValue(SettingsKey.settingsOpengroupPruning, newValue); await window.setOpengroupPruning(newValue); ToastUtils.pushRestartNeeded(); } catch (e) { window.log.warn('toggleCommunitiesPruning change error:', e); } } const CommunitiesPruningSetting = () => { const forceUpdate = useUpdate(); const isOpengroupPruningEnabled = Boolean( window.getSettingValue(SettingsKey.settingsOpengroupPruning) ); return ( { await toggleCommunitiesPruning(); forceUpdate(); }} title={window.i18n('pruneSettingTitle')} description={window.i18n('pruneSettingDescription')} active={isOpengroupPruningEnabled} /> ); }; const SpellCheckSetting = () => { const forceUpdate = useUpdate(); const isSpellCheckActive = window.getSettingValue(SettingsKey.settingsSpellCheck) === undefined ? true : window.getSettingValue(SettingsKey.settingsSpellCheck); return ( { window.toggleSpellCheck(); forceUpdate(); }} title={window.i18n('spellCheckTitle')} description={window.i18n('spellCheckDescription')} active={isSpellCheckActive} /> ); }; const AudioMessageAutoPlaySetting = () => { const audioAutoPlay = useSelector(getAudioAutoplay); const dispatch = useDispatch(); const forceUpdate = useUpdate(); return ( { dispatch(toggleAudioAutoplay()); forceUpdate(); }} title={window.i18n('audioMessageAutoplayTitle')} description={window.i18n('audioMessageAutoplayDescription')} active={audioAutoPlay} /> ); }; const NoBlockedContacts = () => { return ( ); }; const BlockedEntry = (props: { blockedEntry: string; title: string }) => { return ( { await unblockConvoById(props.blockedEntry); }} /> ); }; const BlockedContactsList = (props: { blockedNumbers: Array }) => { const blockedEntries = props.blockedNumbers.map(blockedEntry => { const currentModel = getConversationController().get(blockedEntry); const title = currentModel?.getNicknameOrRealUsernameOrPlaceholder() || window.i18n('anonymous'); return ; }); return <>{blockedEntries}; }; export const CategoryConversations = () => { const blockedNumbers = useSelector(getBlockedPubkeys); return ( <> {blockedNumbers?.length ? ( ) : ( )} ); };