diff --git a/App.tsx b/App.tsx index 70f4fbbe..fd9114dd 100644 --- a/App.tsx +++ b/App.tsx @@ -41,7 +41,7 @@ import { setItem } from './src/components/utlis/storageHelper'; import { StorageKeys } from './src/types/storageKeys'; import dayJs from 'dayjs'; import analytics from '@react-native-firebase/analytics'; -import remoteConfig from '@react-native-firebase/remote-config'; +import handleUpdatedConfigureValuesFromFirebase from './src/services/firebaseFetchAndUpdate.service'; initSentry(); @@ -111,20 +111,6 @@ function App() { await setItem(StorageKeys.APP_FOREGROUND_TIMESTAMP, now); } - async function handleUpdatedConfigureValuesFromFirebase() { - await remoteConfig().fetch(10); - - remoteConfig() - .fetchAndActivate() - .then((fetchedRemotely) => { - if (fetchedRemotely) { - console.log('Configs were fetched.'); - } else { - console.log('No configs were fetched.'); - } - }); - } - usePolling(askForPermissions, PERMISSION_CHECK_POLL_INTERVAL); initApm({ diff --git a/package.json b/package.json index bd425c45..62e2df8f 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@react-native-firebase/database": "16.4.6", "@react-native-firebase/firestore": "16.5.0", "@react-native-firebase/messaging": "17.4.0", - "@react-native-firebase/remote-config": "^16.4.6", + "@react-native-firebase/remote-config": "16.4.6", "@react-native-google-signin/google-signin": "9.0.2", "@react-navigation/bottom-tabs": "6.5.5", "@react-navigation/native": "6.1.4", diff --git a/src/common/AgentActivityConfigurableConstants.ts b/src/common/AgentActivityConfigurableConstants.ts new file mode 100644 index 00000000..07976239 --- /dev/null +++ b/src/common/AgentActivityConfigurableConstants.ts @@ -0,0 +1,19 @@ +let ACTIVITY_TIME_ON_APP: number = 5; +let ACTIVITY_TIME_WINDOW_HIGH: number = 2; +let ACTIVITY_TIME_WINDOW_MEDIUM: number = 4; + +export const getActivityTimeOnApp = () => ACTIVITY_TIME_ON_APP; +export const getActivityTimeWindowHigh = () => ACTIVITY_TIME_WINDOW_HIGH; +export const getActivityTimeWindowMedium = () => ACTIVITY_TIME_WINDOW_MEDIUM; + +export const setActivityTimeOnApp = (activityTimeOnApp: number) => { + ACTIVITY_TIME_ON_APP = activityTimeOnApp; +}; + +export const setActivityTimeWindowHigh = (activityTimeWindowHigh: number) => { + ACTIVITY_TIME_WINDOW_HIGH = activityTimeWindowHigh; +}; + +export const setActivityTimeWindowMedium = (activityTimeWindowMedium: number) => { + ACTIVITY_TIME_WINDOW_MEDIUM = activityTimeWindowMedium; +}; diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index a393ef69..82f800e6 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -35,12 +35,11 @@ import { getConfigData } from '../action/configActions'; import { AppStates } from '../types/appStates'; import { StorageKeys } from '../types/storageKeys'; import { AgentActivity } from '../types/agentActivity'; -import remoteConfig, { FirebaseRemoteConfigTypes } from '@react-native-firebase/remote-config'; import { - setActivityTimeOnApp, - setActivityTimeWindowHigh, - setActivityTimeWindowMedium, -} from '../reducer/commonSlice'; + getActivityTimeOnApp, + getActivityTimeWindowMedium, + getActivityTimeWindowHigh, +} from './AgentActivityConfigurableConstants'; export enum FOREGROUND_TASKS { GEOLOCATION = 'GEOLOCATION', @@ -49,7 +48,6 @@ export enum FOREGROUND_TASKS { FIRESTORE_FALLBACK = 'FIRESTORE_FALLBACK', UPDATE_AGENT_ACTIVENESS = 'UPDATE_AGENT_ACTIVENESS', UPDATE_AGENT_ACTIVITY = 'UPDATE_AGENT_ACTIVITY', - GET_AGENT_ACTIVITY_CONFIG_VARIABLES = 'GET_AGENT_ACTIVITY_CONFIG_VARIABLES', } interface ITrackingComponent { @@ -57,15 +55,8 @@ interface ITrackingComponent { } let LAST_SYNC_STATUS = 'SKIP'; -// const ACTIVITY_TIME_ON_APP = 5; // 5 seconds const ACTIVITY_TIME_WINDOW = 10; // 10 minutes -// const ACTIVITY_TIME_WINDOW_HIGH = 10; // 10 minutes -// const ACTIVITY_TIME_WINDOW_MEDIUM = 30; // 30 minutes - -// const ACTIVITY_TIME_WINDOW_HIGH = 2; // 2 minutes -// const ACTIVITY_TIME_WINDOW_MEDIUM = 4; // 4 minutes - const TrackingComponent: React.FC = ({ children }) => { const isOnline = useIsOnline(); const dispatch = useAppDispatch(); @@ -76,17 +67,11 @@ const TrackingComponent: React.FC = ({ children }) => { pendingList = [], pinnedList = [], geolocations = [], - // ACTIVITY_TIME_ON_APP, - // ACTIVITY_TIME_WINDOW_HIGH, - // ACTIVITY_TIME_WINDOW_MEDIUM, } = useAppSelector((state) => ({ referenceId: state.user.user?.referenceId!, pendingList: state.allCases.pendingList, pinnedList: state.allCases.pinnedList, geolocations: state.foregroundService.deviceGeolocationsBuffer, - // ACTIVITY_TIME_ON_APP: state.common.activityTimeOnApp, - // ACTIVITY_TIME_WINDOW_HIGH: state.common.activityTimeWindowHigh, - // ACTIVITY_TIME_WINDOW_MEDIUM: state.common.activityTimeWindowMedium, })); const handleTimeSync = async () => { @@ -190,7 +175,7 @@ const TrackingComponent: React.FC = ({ children }) => { const isForegroundTimeWithInRange = diffBetweenCurrentTimeAndForegroundTime <= ACTIVITY_TIME_WINDOW; const isForegroundTimeAfterBackground = dayJs(foregroundTimestamp).isAfter(backgroundTimestamp); - const ACTIVITY_TIME_ON_APP = remoteConfig().getValue('ACTIVITY_TIME_ON_APP').asNumber(); + const ACTIVITY_TIME_ON_APP = 5; // 5 seconds if (isForegroundTimeWithInRange) { if ( @@ -223,16 +208,9 @@ const TrackingComponent: React.FC = ({ children }) => { const diffBetweenCurrentTimeAndBackgroundTime = dayJs().diff(backgroundTime, 'minutes') < 0 ? 0 : dayJs().diff(backgroundTime, 'minutes'); - const ACTIVITY_TIME_ON_APP = remoteConfig().getValue('ACTIVITY_TIME_ON_APP').asNumber(); - const ACTIVITY_TIME_WINDOW_HIGH = remoteConfig() - .getValue('ACTIVITY_TIME_WINDOW_HIGH') - .asNumber(); - const ACTIVITY_TIME_WINDOW_MEDIUM = remoteConfig() - .getValue('ACTIVITY_TIME_WINDOW_MEDIUM') - .asNumber(); - - // const isForegroundTimeWithInHighRange = diffBetweenCurrentTimeAndBackgroundTime < ACTIVITY_TIME_WINDOW_HIGH; - // const isForegroundTimeWithInMediumRange = diffBetweenCurrentTimeAndBackgroundTime < ACTIVITY_TIME_WINDOW_MEDIUM; + const ACTIVITY_TIME_ON_APP = getActivityTimeOnApp(); + const ACTIVITY_TIME_WINDOW_HIGH = getActivityTimeWindowHigh(); + const ACTIVITY_TIME_WINDOW_MEDIUM = getActivityTimeWindowMedium(); const isBackgroundTimeWithInHighRange = diffBetweenCurrentTimeAndBackgroundTime < ACTIVITY_TIME_WINDOW_HIGH; @@ -357,7 +335,7 @@ const TrackingComponent: React.FC = ({ children }) => { foregroundTime, 'seconds' ); - const ACTIVITY_TIME_ON_APP = remoteConfig().getValue('ACTIVITY_TIME_ON_APP').asNumber(); + const ACTIVITY_TIME_ON_APP = getActivityTimeOnApp(); if (diffBetweenBackgroundAndForegroundTime >= ACTIVITY_TIME_ON_APP) { await setItem(StorageKeys.USER_ACTIVITY_ON_APP, AgentActivity.HIGH); diff --git a/src/reducer/commonSlice.ts b/src/reducer/commonSlice.ts index 6856669b..511c6d9a 100644 --- a/src/reducer/commonSlice.ts +++ b/src/reducer/commonSlice.ts @@ -20,9 +20,6 @@ export interface AppState { export interface CommonState { userData: User; clickstreamEvents: IClickstreamEvents[]; - activityTimeOnApp: number; - activityTimeWindowHigh: number; - activityTimeWindowMedium: number; } const initialState = { @@ -32,9 +29,6 @@ const initialState = { deviceId: GLOBAL.DEVICE_ID || '', } as User, clickstreamEvents: [], - activityTimeOnApp: 0, - activityTimeWindowHigh: 0, - activityTimeWindowMedium: 0, } as CommonState; export const commonSlice = createSlice({ @@ -56,31 +50,9 @@ export const commonSlice = createSlice({ resetClickstreamEvents: (state) => { state.clickstreamEvents = []; }, - setActivityTimeOnApp: (state, action) => { - if (action.payload) { - state.activityTimeOnApp = action.payload; - } - }, - setActivityTimeWindowHigh: (state, action) => { - if (action.payload) { - state.activityTimeWindowHigh = action.payload; - } - }, - setActivityTimeWindowMedium: (state, action) => { - if (action.payload) { - state.activityTimeWindowMedium = action.payload; - } - }, }, }); -export const { - setAuthData, - setClickstreamEvents, - resetClickstreamEvents, - setActivityTimeOnApp, - setActivityTimeWindowHigh, - setActivityTimeWindowMedium, -} = commonSlice.actions; +export const { setAuthData, setClickstreamEvents, resetClickstreamEvents } = commonSlice.actions; export default commonSlice.reducer; diff --git a/src/reducer/configSlice.ts b/src/reducer/configSlice.ts index 12641215..a5ada487 100644 --- a/src/reducer/configSlice.ts +++ b/src/reducer/configSlice.ts @@ -1,5 +1,4 @@ import { createSlice } from '@reduxjs/toolkit'; -import { GenericType } from '../common/GenericTypes'; interface IConfigData { supportLink: ''; @@ -7,7 +6,6 @@ interface IConfigData { interface IConfigSlice { data: IConfigData; loading: boolean; - firebaseRemoteConfig: GenericType; } export const initialConfigData = { @@ -17,7 +15,6 @@ export const initialConfigData = { const initialState = { data: initialConfigData, loading: false, - firebaseRemoteConfig: {}, } as IConfigSlice; const ConfigSlice = createSlice({ @@ -31,9 +28,6 @@ const ConfigSlice = createSlice({ state.loading = action.payload; }, resetConfig: () => initialState, - setFirebaseRemoteConfig: (state, action) => { - state.firebaseRemoteConfig = action.payload; - }, }, }); diff --git a/src/services/firebaseFetchAndUpdate.service.ts b/src/services/firebaseFetchAndUpdate.service.ts new file mode 100644 index 00000000..6bfd81bd --- /dev/null +++ b/src/services/firebaseFetchAndUpdate.service.ts @@ -0,0 +1,36 @@ +import remoteConfig from '@react-native-firebase/remote-config'; +import { + setActivityTimeOnApp, + setActivityTimeWindowHigh, + setActivityTimeWindowMedium, +} from '../common/AgentActivityConfigurableConstants'; + +async function handleUpdatedConfigureValuesFromFirebase() { + await remoteConfig().fetch(10); + remoteConfig() + .fetchAndActivate() + .then((fetchedRemotely) => { + if (fetchedRemotely) { + console.log('Configs were fetched.'); + } else { + console.log('No configs were fetched.'); + } + }) + .catch((error) => { + console.error(error); + }) + .finally(() => { + const ACTIVITY_TIME_ON_APP = remoteConfig().getValue('ACTIVITY_TIME_ON_APP').asNumber(); + const ACTIVITY_TIME_WINDOW_HIGH = remoteConfig() + .getValue('ACTIVITY_TIME_WINDOW_HIGH') + .asNumber(); + const ACTIVITY_TIME_WINDOW_MEDIUM = remoteConfig() + .getValue('ACTIVITY_TIME_WINDOW_MEDIUM') + .asNumber(); + setActivityTimeOnApp(ACTIVITY_TIME_ON_APP); + setActivityTimeWindowHigh(ACTIVITY_TIME_WINDOW_HIGH); + setActivityTimeWindowMedium(ACTIVITY_TIME_WINDOW_MEDIUM); + }); +} + +export default handleUpdatedConfigureValuesFromFirebase; diff --git a/src/store/store.ts b/src/store/store.ts index f9a2e3ad..d925b460 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -30,7 +30,6 @@ import foregroundServiceSlice from '../reducer/foregroundServiceSlice'; import feedbackImagesSlice from '../reducer/feedbackImagesSlice'; import configSlice from '../reducer/configSlice'; import profileSlice from '../reducer/profileSlice'; -import commonSlice from '../reducer/commonSlice'; const rootReducer = combineReducers({ case: caseReducer, @@ -51,7 +50,6 @@ const rootReducer = combineReducers({ feedbackImages: feedbackImagesSlice, config: configSlice, profile: profileSlice, - common: commonSlice, }); const persistConfig = {