Settings / General: Show sensitive content toggle (#1195)
This commit is contained in:
parent
731c0330ad
commit
d854db7ca2
@ -47,7 +47,7 @@ export {
|
|||||||
fetchAuthorizations, terminateAuthorization, terminateAllAuthorizations,
|
fetchAuthorizations, terminateAuthorization, terminateAllAuthorizations,
|
||||||
fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings,
|
fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings,
|
||||||
fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice,
|
fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice,
|
||||||
updateIsOnline,
|
updateIsOnline, fetchContentSettings, updateContentSettings,
|
||||||
} from './settings';
|
} from './settings';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@ -375,6 +375,24 @@ export async function updateIsOnline(isOnline: boolean) {
|
|||||||
await invokeRequest(new GramJs.account.UpdateStatus({ offline: !isOnline }));
|
await invokeRequest(new GramJs.account.UpdateStatus({ offline: !isOnline }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchContentSettings() {
|
||||||
|
const result = await invokeRequest(new GramJs.account.GetContentSettings());
|
||||||
|
if (!result) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isSensitiveEnabled: Boolean(result.sensitiveEnabled),
|
||||||
|
canChangeSensitive: Boolean(result.sensitiveCanChange),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateContentSettings(isEnabled: boolean) {
|
||||||
|
return invokeRequest(new GramJs.account.SetContentSettings({
|
||||||
|
sensitiveEnabled: isEnabled || undefined,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function updateLocalDb(
|
function updateLocalDb(
|
||||||
result: (
|
result: (
|
||||||
GramJs.account.PrivacyRules | GramJs.contacts.Blocked | GramJs.contacts.BlockedSlice |
|
GramJs.account.PrivacyRules | GramJs.contacts.Blocked | GramJs.contacts.BlockedSlice |
|
||||||
|
|||||||
@ -24,12 +24,28 @@ type OwnProps = {
|
|||||||
onScreenSelect: (screen: SettingsScreens) => void;
|
onScreenSelect: (screen: SettingsScreens) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type StateProps = ISettings['byKey'] & {
|
type StateProps = Pick<ISettings, (
|
||||||
|
'messageTextSize' |
|
||||||
|
'animationLevel' |
|
||||||
|
'messageSendKeyCombo' |
|
||||||
|
'shouldAutoDownloadMediaFromContacts' |
|
||||||
|
'shouldAutoDownloadMediaInPrivateChats' |
|
||||||
|
'shouldAutoDownloadMediaInGroups' |
|
||||||
|
'shouldAutoDownloadMediaInChannels' |
|
||||||
|
'shouldAutoPlayGifs' |
|
||||||
|
'shouldAutoPlayVideos' |
|
||||||
|
'shouldSuggestStickers' |
|
||||||
|
'shouldLoopStickers' |
|
||||||
|
'isSensitiveEnabled' |
|
||||||
|
'canChangeSensitive'
|
||||||
|
)> & {
|
||||||
stickerSetIds?: string[];
|
stickerSetIds?: string[];
|
||||||
stickerSetsById?: Record<string, ApiStickerSet>;
|
stickerSetsById?: Record<string, ApiStickerSet>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type DispatchProps = Pick<GlobalActions, 'setSettingOption' | 'loadStickerSets' | 'loadAddedStickers'>;
|
type DispatchProps = Pick<GlobalActions, (
|
||||||
|
'setSettingOption' | 'loadStickerSets' | 'loadAddedStickers' | 'loadContentSettings' | 'updateContentSettings'
|
||||||
|
)>;
|
||||||
|
|
||||||
const ANIMATION_LEVEL_OPTIONS = [
|
const ANIMATION_LEVEL_OPTIONS = [
|
||||||
'Solid and Steady',
|
'Solid and Steady',
|
||||||
@ -52,9 +68,13 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
shouldAutoPlayVideos,
|
shouldAutoPlayVideos,
|
||||||
shouldSuggestStickers,
|
shouldSuggestStickers,
|
||||||
shouldLoopStickers,
|
shouldLoopStickers,
|
||||||
|
isSensitiveEnabled,
|
||||||
|
canChangeSensitive,
|
||||||
setSettingOption,
|
setSettingOption,
|
||||||
loadStickerSets,
|
loadStickerSets,
|
||||||
loadAddedStickers,
|
loadAddedStickers,
|
||||||
|
loadContentSettings,
|
||||||
|
updateContentSettings,
|
||||||
}) => {
|
}) => {
|
||||||
// eslint-disable-next-line no-null/no-null
|
// eslint-disable-next-line no-null/no-null
|
||||||
const stickerSettingsRef = useRef<HTMLDivElement>(null);
|
const stickerSettingsRef = useRef<HTMLDivElement>(null);
|
||||||
@ -75,7 +95,8 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadStickerSets();
|
loadStickerSets();
|
||||||
}, [loadStickerSets]);
|
loadContentSettings();
|
||||||
|
}, [loadContentSettings, loadStickerSets]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (stickerSetIds && stickerSetIds.length) {
|
if (stickerSetIds && stickerSetIds.length) {
|
||||||
@ -104,7 +125,7 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
const stickerSets = stickerSetIds && stickerSetIds.map((id: string) => {
|
const stickerSets = stickerSetIds && stickerSetIds.map((id: string) => {
|
||||||
return stickerSetsById && stickerSetsById[id] && stickerSetsById[id].installedDate ? stickerSetsById[id] : false;
|
return stickerSetsById && stickerSetsById[id] && stickerSetsById[id].installedDate ? stickerSetsById[id] : false;
|
||||||
}).filter(Boolean);
|
}).filter<ApiStickerSet>(Boolean as any);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="settings-content custom-scroll">
|
<div className="settings-content custom-scroll">
|
||||||
@ -155,6 +176,19 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="settings-item">
|
||||||
|
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
|
||||||
|
{lang('lng_settings_sensitive_title')}
|
||||||
|
</h4>
|
||||||
|
<Checkbox
|
||||||
|
label={lang('lng_settings_sensitive_disable_filtering')}
|
||||||
|
subLabel={lang('lng_settings_sensitive_about')}
|
||||||
|
checked={Boolean(isSensitiveEnabled)}
|
||||||
|
disabled={!canChangeSensitive}
|
||||||
|
onCheck={updateContentSettings}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="settings-item">
|
<div className="settings-item">
|
||||||
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>{lang('AutoDownloadMedia')}</h4>
|
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>{lang('AutoDownloadMedia')}</h4>
|
||||||
|
|
||||||
@ -234,25 +268,26 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
export default memo(withGlobal<OwnProps>(
|
export default memo(withGlobal<OwnProps>(
|
||||||
(global): StateProps => {
|
(global): StateProps => {
|
||||||
return {
|
return {
|
||||||
...pick(global.settings.byKey,
|
...pick(global.settings.byKey, [
|
||||||
[
|
'messageTextSize',
|
||||||
'messageTextSize',
|
'animationLevel',
|
||||||
'animationLevel',
|
'messageSendKeyCombo',
|
||||||
'messageSendKeyCombo',
|
'shouldAutoDownloadMediaFromContacts',
|
||||||
'shouldAutoDownloadMediaFromContacts',
|
'shouldAutoDownloadMediaInPrivateChats',
|
||||||
'shouldAutoDownloadMediaInPrivateChats',
|
'shouldAutoDownloadMediaInGroups',
|
||||||
'shouldAutoDownloadMediaInGroups',
|
'shouldAutoDownloadMediaInChannels',
|
||||||
'shouldAutoDownloadMediaInChannels',
|
'shouldAutoPlayGifs',
|
||||||
'shouldAutoPlayGifs',
|
'shouldAutoPlayVideos',
|
||||||
'shouldAutoPlayVideos',
|
'shouldSuggestStickers',
|
||||||
'shouldSuggestStickers',
|
'shouldLoopStickers',
|
||||||
'shouldLoopStickers',
|
'isSensitiveEnabled',
|
||||||
]),
|
'canChangeSensitive',
|
||||||
|
]),
|
||||||
stickerSetIds: global.stickers.added.setIds,
|
stickerSetIds: global.stickers.added.setIds,
|
||||||
stickerSetsById: global.stickers.setsById,
|
stickerSetsById: global.stickers.setsById,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
(setGlobal, actions): DispatchProps => pick(actions, [
|
(setGlobal, actions): DispatchProps => pick(actions, [
|
||||||
'setSettingOption', 'loadStickerSets', 'loadAddedStickers',
|
'setSettingOption', 'loadStickerSets', 'loadAddedStickers', 'loadContentSettings', 'updateContentSettings',
|
||||||
]),
|
]),
|
||||||
)(SettingsGeneral));
|
)(SettingsGeneral));
|
||||||
|
|||||||
@ -450,7 +450,8 @@ export type ActionTypes = (
|
|||||||
'loadAuthorizations' | 'terminateAuthorization' | 'terminateAllAuthorizations' |
|
'loadAuthorizations' | 'terminateAuthorization' | 'terminateAllAuthorizations' |
|
||||||
'loadNotificationSettings' | 'updateContactSignUpNotification' | 'updateNotificationSettings' |
|
'loadNotificationSettings' | 'updateContactSignUpNotification' | 'updateNotificationSettings' |
|
||||||
'loadLanguages' | 'loadPrivacySettings' | 'setPrivacyVisibility' | 'setPrivacySettings' |
|
'loadLanguages' | 'loadPrivacySettings' | 'setPrivacyVisibility' | 'setPrivacySettings' |
|
||||||
'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' |
|
'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' | 'loadContentSettings' |
|
||||||
|
'updateContentSettings' |
|
||||||
// Stickers & GIFs
|
// Stickers & GIFs
|
||||||
'loadStickerSets' | 'loadAddedStickers' | 'loadRecentStickers' | 'loadFavoriteStickers' | 'loadFeaturedStickers' |
|
'loadStickerSets' | 'loadAddedStickers' | 'loadRecentStickers' | 'loadFavoriteStickers' | 'loadFeaturedStickers' |
|
||||||
'loadStickers' | 'setStickerSearchQuery' | 'loadSavedGifs' | 'setGifSearchQuery' | 'searchMoreGifs' |
|
'loadStickers' | 'setStickerSearchQuery' | 'loadSavedGifs' | 'setGifSearchQuery' | 'searchMoreGifs' |
|
||||||
|
|||||||
@ -942,6 +942,8 @@ account.getContactSignUpNotification#9f07c728 = Bool;
|
|||||||
account.setContactSignUpNotification#cff43f61 silent:Bool = Bool;
|
account.setContactSignUpNotification#cff43f61 silent:Bool = Bool;
|
||||||
account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates;
|
account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates;
|
||||||
account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper;
|
account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper;
|
||||||
|
account.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool;
|
||||||
|
account.getContentSettings#8b9b4dae = account.ContentSettings;
|
||||||
users.getUsers#d91a548 id:Vector<InputUser> = Vector<User>;
|
users.getUsers#d91a548 id:Vector<InputUser> = Vector<User>;
|
||||||
users.getFullUser#ca30a5b1 id:InputUser = UserFull;
|
users.getFullUser#ca30a5b1 id:InputUser = UserFull;
|
||||||
contacts.getContacts#c023849f hash:int = contacts.Contacts;
|
contacts.getContacts#c023849f hash:int = contacts.Contacts;
|
||||||
|
|||||||
@ -942,6 +942,8 @@ account.getContactSignUpNotification#9f07c728 = Bool;
|
|||||||
account.setContactSignUpNotification#cff43f61 silent:Bool = Bool;
|
account.setContactSignUpNotification#cff43f61 silent:Bool = Bool;
|
||||||
account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates;
|
account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates;
|
||||||
account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper;
|
account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper;
|
||||||
|
account.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool;
|
||||||
|
account.getContentSettings#8b9b4dae = account.ContentSettings;
|
||||||
users.getUsers#d91a548 id:Vector<InputUser> = Vector<User>;
|
users.getUsers#d91a548 id:Vector<InputUser> = Vector<User>;
|
||||||
users.getFullUser#ca30a5b1 id:InputUser = UserFull;
|
users.getFullUser#ca30a5b1 id:InputUser = UserFull;
|
||||||
contacts.getContacts#c023849f hash:int = contacts.Contacts;
|
contacts.getContacts#c023849f hash:int = contacts.Contacts;
|
||||||
|
|||||||
@ -520,3 +520,23 @@ function buildInputPrivacyRules(global: GlobalState, {
|
|||||||
addReducer('updateIsOnline', (global, actions, payload) => {
|
addReducer('updateIsOnline', (global, actions, payload) => {
|
||||||
callApi('updateIsOnline', payload);
|
callApi('updateIsOnline', payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addReducer('loadContentSettings', () => {
|
||||||
|
(async () => {
|
||||||
|
const result = await callApi('fetchContentSettings');
|
||||||
|
if (!result) return;
|
||||||
|
|
||||||
|
setGlobal(replaceSettings(getGlobal(), result));
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
|
||||||
|
addReducer('updateContentSettings', (global, actions, payload) => {
|
||||||
|
(async () => {
|
||||||
|
setGlobal(replaceSettings(getGlobal(), { isSensitiveEnabled: payload }));
|
||||||
|
|
||||||
|
const result = await callApi('updateContentSettings', payload);
|
||||||
|
if (!result) {
|
||||||
|
setGlobal(replaceSettings(getGlobal(), { isSensitiveEnabled: !payload }));
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
|||||||
@ -60,6 +60,8 @@ export interface ISettings extends NotifySettings, Record<string, any> {
|
|||||||
hasPassword?: boolean;
|
hasPassword?: boolean;
|
||||||
languages?: ApiLanguage[];
|
languages?: ApiLanguage[];
|
||||||
language: LangCode;
|
language: LangCode;
|
||||||
|
isSensitiveEnabled?: boolean;
|
||||||
|
canChangeSensitive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiPrivacySettings {
|
export interface ApiPrivacySettings {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user