From 894ac14a1080b87f9397e808ba29d19431b9d0e4 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Wed, 30 Aug 2023 10:14:37 -0700 Subject: [PATCH] tying in notifications to updated settings --- app/mobile/src/constants/Strings.js | 2 +- app/mobile/src/session/settings/Settings.jsx | 20 ++++++++++++++++--- .../src/session/settings/useSettings.hook.js | 9 +++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/mobile/src/constants/Strings.js b/app/mobile/src/constants/Strings.js index d44f3904..3bba26ae 100644 --- a/app/mobile/src/constants/Strings.js +++ b/app/mobile/src/constants/Strings.js @@ -27,7 +27,7 @@ const Strings = [ monthEnd: 'dd/mm', sealUnset: 'Generate a key to enable end-to-end encrypted topics.', - sealUnlocked: 'Disabling the sealing key will prevent access to all end-to-end encrypted topics from this device until the key is unlocked again.', + sealUnlocked: 'Disabling the sealing key will block access to all end-to-end encrypted topics from this device until the key is unlocked again.', sealLocked: 'Unlock the sealing key to support end-to-end encrypted topics on this device.', sealDelete: 'Deleting the sealing key will premanently remove access to any existing end-to-end encrypted topics for ALL of your devices.', password: 'Password', diff --git a/app/mobile/src/session/settings/Settings.jsx b/app/mobile/src/session/settings/Settings.jsx index 39ec115c..4eb08961 100644 --- a/app/mobile/src/session/settings/Settings.jsx +++ b/app/mobile/src/session/settings/Settings.jsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { ActivityIndicator, KeyboardAvoidingView, Modal, ScrollView, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native'; +import { Linking, ActivityIndicator, KeyboardAvoidingView, Modal, ScrollView, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native'; import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'; import { styles } from './Settings.styled'; import { useSettings } from './useSettings.hook'; @@ -29,6 +29,19 @@ export function Settings() { } }; + const setNotifications = async (notify) => { + try { + await actions.setNotifications(notify); + } + catch (err) { + console.log(err); + Alert.alert( + 'Failed to update account notifications', + 'Please try again.', + ); + } + } + return ( @@ -41,7 +54,8 @@ export function Settings() { { state.strings.enableNotifications } - + @@ -183,7 +197,7 @@ export function Settings() { { state.strings.support } - + Linking.openURL('https://github.com/balzack/databag/discussions')}> diff --git a/app/mobile/src/session/settings/useSettings.hook.js b/app/mobile/src/session/settings/useSettings.hook.js index 58e3edac..1149d463 100644 --- a/app/mobile/src/session/settings/useSettings.hook.js +++ b/app/mobile/src/session/settings/useSettings.hook.js @@ -13,6 +13,7 @@ export function useSettings() { strings: getLanguageStrings(), timeFull: false, monthLast: false, + pushEnabled: null, editSeal: false, sealEnabled: false, @@ -36,11 +37,12 @@ export function useSettings() { }, [profile.state.timeFull, profile.state.monthLast]); useEffect(() => { - const { seal, sealable } = account.state.status; + const { seal, sealable, pushEnabled } = account.state.status; const sealKey = account.state.sealKey; const sealEnabled = seal?.publicKey != null; const sealUnlocked = seal?.publicKey === sealKey?.public && sealKey?.private && sealKey?.public; - updateState({ sealable, seal, sealKey, sealEnabled, sealUnlocked }); + updateState({ sealable, seal, sealKey, sealEnabled, sealUnlocked, pushEnabled }); + }, [account.state]); const unlockKey = async () => { @@ -75,6 +77,9 @@ export function useSettings() { updateState({ monthLast: flag }); await profile.actions.setMonthLast(flag); }, + setNotifications: async (flag) => { + await account.actions.setNotifications(flag); + }, showEditSeal: () => { updateState({ editSeal: true, sealPassword: null, sealConfirm: null, hidePassword: true, hideConfirm: true, sealDelete: null, sealRemove: false, sealUpdate: false });