From 0c8477af14a00352153a841ec7e35d7551a15f6b Mon Sep 17 00:00:00 2001 From: Beng Tan Date: Mon, 16 Mar 2020 13:40:18 +0800 Subject: [PATCH 1/5] Stub in DebugOptionsScreen. Location.emailLog takes optional argument. --- src/components/DebugOptionsScreen.tsx | 23 +++++++++++++++++++++++ src/components/LocationDebug.tsx | 8 +------- src/components/MyAccount.tsx | 2 +- src/components/Router.tsx | 2 ++ src/store/LocationStore.ts | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/components/DebugOptionsScreen.tsx diff --git a/src/components/DebugOptionsScreen.tsx b/src/components/DebugOptionsScreen.tsx new file mode 100644 index 000000000..dd12ecfb0 --- /dev/null +++ b/src/components/DebugOptionsScreen.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import {observer} from 'mobx-react' +import {StyleSheet, TouchableOpacity} from 'react-native' +import {RText} from './common' +import {colors} from '../constants' +import Screen from './Screen' +import {useLocationStore} from 'src/utils/injectors' + +const DebugOptionsScreen = observer(() => { + const {emailLog} = useLocationStore() + + return ( + + emailLog()}> + Email log + + + ) +}) + +export default DebugOptionsScreen + +const styles = StyleSheet.create({}) diff --git a/src/components/LocationDebug.tsx b/src/components/LocationDebug.tsx index 721967f21..b16ded030 100644 --- a/src/components/LocationDebug.tsx +++ b/src/components/LocationDebug.tsx @@ -78,13 +78,7 @@ const LocationDebug = observer(() => { {uploadStatusText} )} - { - emailLog('') - }} - style={styles.button} - > + emailLog()} style={styles.button}> Email log diff --git a/src/components/MyAccount.tsx b/src/components/MyAccount.tsx index ec2222a37..b2e83aed3 100644 --- a/src/components/MyAccount.tsx +++ b/src/components/MyAccount.tsx @@ -153,6 +153,7 @@ const MyAccount = inject( Linking.openURL('https://tinyrobot.com/privacy-policy/')}> Privacy Policy + Debug Options { Alert.alert('Log Out', `Are you sure you want to log out?`, [ @@ -180,7 +181,6 @@ const MyAccount = inject( )} {settings.allowProfileDelete && ( { Alert.alert( 'Delete Profile', diff --git a/src/components/Router.tsx b/src/components/Router.tsx index 05c613a5b..2fecb1969 100644 --- a/src/components/Router.tsx +++ b/src/components/Router.tsx @@ -30,6 +30,7 @@ import VerifyCode from './VerifyCode' import LocationDebug from './LocationDebug' import BottomMenu from './BottomMenu' import DebugScreen from './DebugScreen' +import DebugOptionsScreen from './DebugOptionsScreen' import LocationGeofenceWarning from './modals/LocationGeofenceWarning' import LocationWarning from './modals/LocationWarning' import MotionWarning from './modals/MotionWarning' @@ -238,6 +239,7 @@ const TinyRobotRouter = inject('wocky', 'locationStore', 'iconStore', 'analytics , , ]} + diff --git a/src/store/LocationStore.ts b/src/store/LocationStore.ts index 8649d3fc5..2750f61c4 100644 --- a/src/store/LocationStore.ts +++ b/src/store/LocationStore.ts @@ -235,7 +235,7 @@ const LocationStore = types : Promise.reject(new Error('No uploadUrl')) } - async function emailLog(email) { + async function emailLog(email = 'crashreports@hippware.com') { // emailLog doesn't work in iOS simulator so fetch and dump instead if (await DeviceInfo.isEmulator()) { log(prefix, await BackgroundGeolocation.logger.getLog()) From afffe5c6c27b5c1773158a86d352889580351973 Mon Sep 17 00:00:00 2001 From: Beng Tan Date: Tue, 17 Mar 2020 14:19:30 +0800 Subject: [PATCH 2/5] Implement fullAudit field. Improve DebugOptionsScreen. --- __tests__/wocky/profile.test.ts | 10 ++++ src/components/DebugOptionsScreen.tsx | 71 ++++++++++++++++++++++----- src/model/OwnProfile.ts | 4 ++ src/store/Transport.ts | 21 +++++++- src/store/Wocky.ts | 3 ++ 5 files changed, 97 insertions(+), 12 deletions(-) diff --git a/__tests__/wocky/profile.test.ts b/__tests__/wocky/profile.test.ts index a25433225..241d8d3f9 100644 --- a/__tests__/wocky/profile.test.ts +++ b/__tests__/wocky/profile.test.ts @@ -57,6 +57,16 @@ describe('New GraphQL profile tests', () => { expect(clientData.guestOnce).toBeTruthy() }) + it('toggle userFullAudit', async () => { + expect(user.profile!.fullAudit).toBe(false) + await user.userFullAudit(true) + await user.loadProfile(user.profile!.id) + expect(user.profile!.fullAudit).toBe(true) + await user.userFullAudit(false) + await user.loadProfile(user.profile!.id) + expect(user.profile!.fullAudit).toBe(false) + }) + it('user1 sent friend invite to user2', async () => { expect(user.profile!.sortedFriends.length).toBe(0) expect(user2.profile!.sortedFriends.length).toBe(0) diff --git a/src/components/DebugOptionsScreen.tsx b/src/components/DebugOptionsScreen.tsx index dd12ecfb0..1a2202d11 100644 --- a/src/components/DebugOptionsScreen.tsx +++ b/src/components/DebugOptionsScreen.tsx @@ -1,23 +1,72 @@ import React from 'react' import {observer} from 'mobx-react' -import {StyleSheet, TouchableOpacity} from 'react-native' -import {RText} from './common' +import {TouchableOpacity, View} from 'react-native' +import {RText, Switch} from './common' import {colors} from '../constants' import Screen from './Screen' -import {useLocationStore} from 'src/utils/injectors' +import {useLocationStore, useWocky} from 'src/utils/injectors' const DebugOptionsScreen = observer(() => { const {emailLog} = useLocationStore() + const {profile, userFullAudit} = useWocky() - return ( - - emailLog()}> - Email log - + return profile ? ( + + + + Enable Logging + + { + userFullAudit(value).then(_successful => { + profile.setFullAudit(value) + }) + }} + /> + + {!!profile.fullAudit && ( + + emailLog()} + style={{ + borderWidth: 1, + borderRadius: 12, + borderColor: colors.PINK, + padding: 10, + width: 225, + }} + > + + Email log + + + + )} - ) + ) : null }) export default DebugOptionsScreen - -const styles = StyleSheet.create({}) diff --git a/src/model/OwnProfile.ts b/src/model/OwnProfile.ts index 85abd1620..32406f602 100644 --- a/src/model/OwnProfile.ts +++ b/src/model/OwnProfile.ts @@ -17,6 +17,7 @@ export const OwnProfile = types types.model('OwnProfile', { email: types.maybeNull(types.string), phoneNumber: types.maybeNull(types.string), + fullAudit: types.maybeNull(types.boolean), sentInvitations: types.optional(InvitationPaginableList, {}), receivedInvitations: types.optional(InvitationPaginableList, {}), friends: types.optional(ProfilePaginableList, {}), @@ -107,6 +108,9 @@ export const OwnProfile = types ) profile.receivedInvite() }, + setFullAudit: (enable: boolean) => { + self.fullAudit = enable + }, })) .actions(self => { const timers: any[] = [] diff --git a/src/store/Transport.ts b/src/store/Transport.ts index 80d9d9d12..ad11337b9 100644 --- a/src/store/Transport.ts +++ b/src/store/Transport.ts @@ -147,7 +147,7 @@ export class Transport { ${PROFILE_PROPS} ${ id === this.username - ? `... on CurrentUser { email phoneNumber clientData + ? `... on CurrentUser { email phoneNumber fullAudit clientData sentInvitations(first:100) { edges { node { @@ -1117,6 +1117,25 @@ export class Transport { }) } + async userFullAudit(enable: boolean): Promise { + const res = await this.mutate({ + mutation: gql` + mutation userFullAudit( + $enable: Boolean! + ) { + userFullAudit( + input: {enable: $enable} + ) { + ${VOID_PROPS} + } + } + `, + variables: {enable}, + }) + + return (res.data as any).userFullAudit!.successful + } + async userInviteGetSender(code: string): Promise { const res = await this.query({ query: gql` diff --git a/src/store/Wocky.ts b/src/store/Wocky.ts index 33805eaef..54e57df76 100644 --- a/src/store/Wocky.ts +++ b/src/store/Wocky.ts @@ -439,6 +439,9 @@ export const Wocky = types triggerSilentPush(userId: string): Promise { return self.transport.triggerSilentPush(userId) }, + userFullAudit(enable: boolean): Promise { + return self.transport.userFullAudit(enable) + }, })) .actions(self => { function clearCache() { From d27781db72893595bbbfa4df90649330a4d4ec63 Mon Sep 17 00:00:00 2001 From: Beng Tan Date: Tue, 17 Mar 2020 14:48:53 +0800 Subject: [PATCH 3/5] Hook RNBGL log verbosity into DebugOptionsScreen. --- src/components/DebugOptionsScreen.tsx | 3 ++- src/store/LocationStore.ts | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/DebugOptionsScreen.tsx b/src/components/DebugOptionsScreen.tsx index 1a2202d11..ea28e4943 100644 --- a/src/components/DebugOptionsScreen.tsx +++ b/src/components/DebugOptionsScreen.tsx @@ -7,7 +7,7 @@ import Screen from './Screen' import {useLocationStore, useWocky} from 'src/utils/injectors' const DebugOptionsScreen = observer(() => { - const {emailLog} = useLocationStore() + const {emailLog, setLogVerbose} = useLocationStore() const {profile, userFullAudit} = useWocky() return profile ? ( @@ -31,6 +31,7 @@ const DebugOptionsScreen = observer(() => { offColor={colors.GREY} onToggle={value => { userFullAudit(value).then(_successful => { + setLogVerbose(value) profile.setFullAudit(value) }) }} diff --git a/src/store/LocationStore.ts b/src/store/LocationStore.ts index 2750f61c4..f65f83611 100644 --- a/src/store/LocationStore.ts +++ b/src/store/LocationStore.ts @@ -114,10 +114,6 @@ const LocationStore = types desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, enableHeadless: true, foregroundService: true, // android only - logLevel: - __DEV__ || settings.configurableLocationSettings - ? BackgroundGeolocation.LOG_LEVEL_VERBOSE - : BackgroundGeolocation.LOG_LEVEL_OFF, maxRecordsToPersist: 20, notification: { // android only @@ -244,6 +240,14 @@ const LocationStore = types } } + function setLogVerbose(verbose: boolean) { + return BackgroundGeolocation.setConfig({ + logLevel: verbose + ? BackgroundGeolocation.LOG_LEVEL_VERBOSE + : BackgroundGeolocation.LOG_LEVEL_OFF, + }) + } + return { refreshCredentials, invalidateCredentials, @@ -253,6 +257,7 @@ const LocationStore = types stopStandaloneGeolocation, uploadLog, emailLog, + setLogVerbose, } }) .actions(self => { From ce75736a4e6070a0af5d8121643a6fd324142a8b Mon Sep 17 00:00:00 2001 From: Beng Tan Date: Tue, 17 Mar 2020 16:21:00 +0800 Subject: [PATCH 4/5] Remove (old) Email Log button. --- src/components/LocationDebug.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/LocationDebug.tsx b/src/components/LocationDebug.tsx index b16ded030..5a59fa275 100644 --- a/src/components/LocationDebug.tsx +++ b/src/components/LocationDebug.tsx @@ -33,7 +33,7 @@ const options = { } const LocationDebug = observer(() => { - const {configOptions, setBackgroundConfig, emailLog, uploadLog} = useLocationStore() + const {configOptions, setBackgroundConfig, uploadLog} = useLocationStore() const [uploadStatusText, setUploadStatusText] = useState('') return ( @@ -78,11 +78,6 @@ const LocationDebug = observer(() => { {uploadStatusText} )} - emailLog()} style={styles.button}> - - Email log - - ) From c1091ff2423fce94738387032a05b838c26fbc4b Mon Sep 17 00:00:00 2001 From: Beng Tan Date: Tue, 17 Mar 2020 16:25:17 +0800 Subject: [PATCH 5/5] Style header of DebugOptionsScreen. --- src/components/Router.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Router.tsx b/src/components/Router.tsx index 2fecb1969..fe7b049fe 100644 --- a/src/components/Router.tsx +++ b/src/components/Router.tsx @@ -239,7 +239,7 @@ const TinyRobotRouter = inject('wocky', 'locationStore', 'iconStore', 'analytics , , ]} - +