TP-38613 | Shri Prakash Bajpai | Added LOW MEDIUM HIGH for agent activity and made parameters configurable

This commit is contained in:
ShriPrakashBajpai
2023-09-15 12:48:20 +05:30
parent 6f6b573364
commit 05bd0bed6f
8 changed files with 67 additions and 84 deletions

16
App.tsx
View File

@@ -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({

View File

@@ -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",

View File

@@ -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;
};

View File

@@ -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<ITrackingComponent> = ({ children }) => {
const isOnline = useIsOnline();
const dispatch = useAppDispatch();
@@ -76,17 +67,11 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ 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<ITrackingComponent> = ({ 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<ITrackingComponent> = ({ 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<ITrackingComponent> = ({ 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);

View File

@@ -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;

View File

@@ -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;
},
},
});

View File

@@ -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;

View File

@@ -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 = {