mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-26 20:34:44 +01:00
Settings / General: Show sensitive content toggle (#1195)
This commit is contained in:
parent
731c0330ad
commit
d854db7ca2
@ -47,7 +47,7 @@ export {
|
||||
fetchAuthorizations, terminateAuthorization, terminateAllAuthorizations,
|
||||
fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings,
|
||||
fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice,
|
||||
updateIsOnline,
|
||||
updateIsOnline, fetchContentSettings, updateContentSettings,
|
||||
} from './settings';
|
||||
|
||||
export {
|
||||
|
@ -375,6 +375,24 @@ export async function updateIsOnline(isOnline: boolean) {
|
||||
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(
|
||||
result: (
|
||||
GramJs.account.PrivacyRules | GramJs.contacts.Blocked | GramJs.contacts.BlockedSlice |
|
||||
|
@ -24,12 +24,28 @@ type OwnProps = {
|
||||
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[];
|
||||
stickerSetsById?: Record<string, ApiStickerSet>;
|
||||
};
|
||||
|
||||
type DispatchProps = Pick<GlobalActions, 'setSettingOption' | 'loadStickerSets' | 'loadAddedStickers'>;
|
||||
type DispatchProps = Pick<GlobalActions, (
|
||||
'setSettingOption' | 'loadStickerSets' | 'loadAddedStickers' | 'loadContentSettings' | 'updateContentSettings'
|
||||
)>;
|
||||
|
||||
const ANIMATION_LEVEL_OPTIONS = [
|
||||
'Solid and Steady',
|
||||
@ -52,9 +68,13 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
shouldAutoPlayVideos,
|
||||
shouldSuggestStickers,
|
||||
shouldLoopStickers,
|
||||
isSensitiveEnabled,
|
||||
canChangeSensitive,
|
||||
setSettingOption,
|
||||
loadStickerSets,
|
||||
loadAddedStickers,
|
||||
loadContentSettings,
|
||||
updateContentSettings,
|
||||
}) => {
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
const stickerSettingsRef = useRef<HTMLDivElement>(null);
|
||||
@ -75,7 +95,8 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
loadStickerSets();
|
||||
}, [loadStickerSets]);
|
||||
loadContentSettings();
|
||||
}, [loadContentSettings, loadStickerSets]);
|
||||
|
||||
useEffect(() => {
|
||||
if (stickerSetIds && stickerSetIds.length) {
|
||||
@ -104,7 +125,7 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
|
||||
const stickerSets = stickerSetIds && stickerSetIds.map((id: string) => {
|
||||
return stickerSetsById && stickerSetsById[id] && stickerSetsById[id].installedDate ? stickerSetsById[id] : false;
|
||||
}).filter(Boolean);
|
||||
}).filter<ApiStickerSet>(Boolean as any);
|
||||
|
||||
return (
|
||||
<div className="settings-content custom-scroll">
|
||||
@ -155,6 +176,19 @@ const SettingsGeneral: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
</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">
|
||||
<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>(
|
||||
(global): StateProps => {
|
||||
return {
|
||||
...pick(global.settings.byKey,
|
||||
[
|
||||
'messageTextSize',
|
||||
'animationLevel',
|
||||
'messageSendKeyCombo',
|
||||
'shouldAutoDownloadMediaFromContacts',
|
||||
'shouldAutoDownloadMediaInPrivateChats',
|
||||
'shouldAutoDownloadMediaInGroups',
|
||||
'shouldAutoDownloadMediaInChannels',
|
||||
'shouldAutoPlayGifs',
|
||||
'shouldAutoPlayVideos',
|
||||
'shouldSuggestStickers',
|
||||
'shouldLoopStickers',
|
||||
]),
|
||||
...pick(global.settings.byKey, [
|
||||
'messageTextSize',
|
||||
'animationLevel',
|
||||
'messageSendKeyCombo',
|
||||
'shouldAutoDownloadMediaFromContacts',
|
||||
'shouldAutoDownloadMediaInPrivateChats',
|
||||
'shouldAutoDownloadMediaInGroups',
|
||||
'shouldAutoDownloadMediaInChannels',
|
||||
'shouldAutoPlayGifs',
|
||||
'shouldAutoPlayVideos',
|
||||
'shouldSuggestStickers',
|
||||
'shouldLoopStickers',
|
||||
'isSensitiveEnabled',
|
||||
'canChangeSensitive',
|
||||
]),
|
||||
stickerSetIds: global.stickers.added.setIds,
|
||||
stickerSetsById: global.stickers.setsById,
|
||||
};
|
||||
},
|
||||
(setGlobal, actions): DispatchProps => pick(actions, [
|
||||
'setSettingOption', 'loadStickerSets', 'loadAddedStickers',
|
||||
'setSettingOption', 'loadStickerSets', 'loadAddedStickers', 'loadContentSettings', 'updateContentSettings',
|
||||
]),
|
||||
)(SettingsGeneral));
|
||||
|
@ -450,7 +450,8 @@ export type ActionTypes = (
|
||||
'loadAuthorizations' | 'terminateAuthorization' | 'terminateAllAuthorizations' |
|
||||
'loadNotificationSettings' | 'updateContactSignUpNotification' | 'updateNotificationSettings' |
|
||||
'loadLanguages' | 'loadPrivacySettings' | 'setPrivacyVisibility' | 'setPrivacySettings' |
|
||||
'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' |
|
||||
'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' | 'loadContentSettings' |
|
||||
'updateContentSettings' |
|
||||
// Stickers & GIFs
|
||||
'loadStickerSets' | 'loadAddedStickers' | 'loadRecentStickers' | 'loadFavoriteStickers' | 'loadFeaturedStickers' |
|
||||
'loadStickers' | 'setStickerSearchQuery' | 'loadSavedGifs' | 'setGifSearchQuery' | 'searchMoreGifs' |
|
||||
|
@ -942,6 +942,8 @@ account.getContactSignUpNotification#9f07c728 = Bool;
|
||||
account.setContactSignUpNotification#cff43f61 silent:Bool = Bool;
|
||||
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.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool;
|
||||
account.getContentSettings#8b9b4dae = account.ContentSettings;
|
||||
users.getUsers#d91a548 id:Vector<InputUser> = Vector<User>;
|
||||
users.getFullUser#ca30a5b1 id:InputUser = UserFull;
|
||||
contacts.getContacts#c023849f hash:int = contacts.Contacts;
|
||||
|
@ -942,6 +942,8 @@ account.getContactSignUpNotification#9f07c728 = Bool;
|
||||
account.setContactSignUpNotification#cff43f61 silent:Bool = Bool;
|
||||
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.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool;
|
||||
account.getContentSettings#8b9b4dae = account.ContentSettings;
|
||||
users.getUsers#d91a548 id:Vector<InputUser> = Vector<User>;
|
||||
users.getFullUser#ca30a5b1 id:InputUser = UserFull;
|
||||
contacts.getContacts#c023849f hash:int = contacts.Contacts;
|
||||
|
@ -520,3 +520,23 @@ function buildInputPrivacyRules(global: GlobalState, {
|
||||
addReducer('updateIsOnline', (global, actions, 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;
|
||||
languages?: ApiLanguage[];
|
||||
language: LangCode;
|
||||
isSensitiveEnabled?: boolean;
|
||||
canChangeSensitive?: boolean;
|
||||
}
|
||||
|
||||
export interface ApiPrivacySettings {
|
||||
|
Loading…
Reference in New Issue
Block a user