From 5c0fb462b5364ac053e81003116e5562d944ba31 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Tue, 1 Aug 2023 17:43:25 +0530 Subject: [PATCH 01/14] TP-35796 | initial commit --- package.json | 9 +++-- src/common/TrackingComponent.tsx | 65 +++++++++++++++++++++++--------- src/hooks/capturingApi.ts | 5 ++- src/reducer/commonSlice.ts | 5 +++ src/reducer/metadataSlice.ts | 19 +++++++++- src/reducer/userSlice.ts | 9 ++++- src/types/appStates.ts | 4 ++ yarn.lock | 5 +++ 8 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 src/types/appStates.ts diff --git a/package.json b/package.json index 1e2e87e6..c734d9f4 100644 --- a/package.json +++ b/package.json @@ -48,11 +48,13 @@ "appcenter-analytics": "^4.4.5", "appcenter-crashes": "^4.4.5", "axios": "1.2.1", + "dayjs": "^1.11.9", "fuzzysort": "2.0.4", "lottie-react-native": "5.1.4", "react": "18.1.0", "react-hook-form": "7.40.0", "react-native": "0.70.6", + "react-native-blob-util": "0.17.3", "react-native-call-log": "2.1.2", "react-native-code-push": "7.1.0", "react-native-contacts": "7.0.5", @@ -74,11 +76,10 @@ "react-native-toast-message": "2.1.5", "react-native-vector-icons": "9.2.0", "react-native-version-number": "0.3.6", + "react-native-webview": "12.0.2", "react-redux": "8.0.5", "redux": "4.2.0", - "redux-persist": "6.0.0", - "react-native-webview": "12.0.2", - "react-native-blob-util": "0.17.3" + "redux-persist": "6.0.0" }, "devDependencies": { "@babel/core": "7.12.9", @@ -102,6 +103,7 @@ "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "17.0.0", "eslint-config-prettier": "^8.8.0", + "eslint-config-prettier-react": "0.0.24", "eslint-config-standard-with-typescript": "^34.0.1", "eslint-plugin-import": "^2.25.2", "eslint-plugin-jsx-a11y": "6.6.1", @@ -117,7 +119,6 @@ "miragejs": "0.1.47", "prettier": "^2.8.7", "react-test-renderer": "18.1.0", - "eslint-config-prettier-react": "0.0.24", "typescript": "4.8.3" }, "jest": { diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index 2d21f51e..9954e7df 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -1,22 +1,24 @@ -import { ReactNode, useEffect, useRef } from 'react'; -import { NativeEventSubscription } from 'react-native'; +import { type ReactNode, useEffect, useRef } from 'react'; +import { type NativeEventSubscription, AppState, type AppStateStatus } from 'react-native'; +import dayJs from 'dayjs'; +import dayjs from 'dayjs'; import UnstoppableService, { - IForegroundTask, + type IForegroundTask, } from '../services/foregroundServices/foreground.service'; import useIsOnline from '../hooks/useIsOnline'; -import { getSyncTime, sendLocationToServer } from '../hooks/capturingApi'; +import { getSyncTime, sendLocationAndActivenessToServer } from '../hooks/capturingApi'; import { isTimeDifferenceWithinRange } from '../components/utlis/commonFunctions'; import { setDeviceGeolocation, setIsTimeSynced } from '../reducer/foregroundServiceSlice'; import { CaptureGeolocation } from '../components/form/services/geoLocation.service'; -import { AppState, AppStateStatus } from 'react-native'; import { logError } from '../components/utlis/errorUtils'; import { useAppDispatch, useAppSelector } from '../hooks'; import { dataSyncService } from '../services/dataSync.service'; import { DATA_SYNC_TIME_INTERVAL, IS_DATA_SYNC_REQUIRED } from '../constants/config'; import useIsLocationEnabled from '../hooks/useIsLocationEnabled'; +import { setAppForegroundTimestamp, setAppBackgroundTimestamp } from '../reducer/metadataSlice'; import { - ISyncCaseIdPayload, - ISyncedCases, + type ISyncCaseIdPayload, + type ISyncedCases, SyncStatus, fetchCasesToSync, getCasesSyncStatus, @@ -25,14 +27,16 @@ import { import { getSyncCaseIds } from '../components/utlis/firebaseFallbackUtils'; import { syncCasesByFallback } from '../reducer/allCasesSlice'; import { MILLISECONDS_IN_A_MINUTE } from '../../RN-UI-LIB/src/utlis/common'; -import { setLockData } from '../reducer/userSlice'; +import { setIsActiveUser, setLockData } from '../reducer/userSlice'; import { getConfigData } from '../action/configActions'; +import { AppStates } from '../types/appStates'; export enum FOREGROUND_TASKS { GEOLOCATION = 'GEOLOCATION', TIME_SYNC = 'TIME_SYNC', DATA_SYNC = 'DATA_SYNC', FIRESTORE_FALLBACK = 'FIRESTORE_FALLBACK', + UPDATE_AGENT_ACTIVENESS = 'UPDATE_AGENT_ACTIVENESS', } interface ITrackingComponent { @@ -46,13 +50,16 @@ const TrackingComponent: React.FC = ({ children }) => { const dispatch = useAppDispatch(); const appState = useRef(AppState.currentState); const user = useAppSelector((state) => state.user); + const foregroundTimestamp = useAppSelector((state) => state.metadata.appForegroundTimestamp); + const backgroundTimestamp = useAppSelector((state) => state.metadata.appBackgroundTimestamp); + const isActive = useAppSelector((state) => state.user.user.isActive); const { referenceId, pendingList = [], pinnedList = [], } = useAppSelector((state) => ({ - referenceId: state.user.user?.referenceId!!, + referenceId: state.user.user?.referenceId!, pendingList: state.allCases.pendingList, pinnedList: state.allCases.pinnedList, })); @@ -71,8 +78,8 @@ const TrackingComponent: React.FC = ({ children }) => { const handleSendGeolocation = async () => { try { - const location = await CaptureGeolocation.fetchLocation(Date.now() + '', 0, appState.current); - if (location) { + const location = await CaptureGeolocation.fetchLocation(`${Date.now()}`, 0, appState.current); + if (location != null) { dispatch( setDeviceGeolocation({ latitude: location.latitude, @@ -81,7 +88,7 @@ const TrackingComponent: React.FC = ({ children }) => { }) ); if (user.isLoggedIn) { - await sendLocationToServer(location); + await sendLocationAndActivenessToServer(location, isActive); } } } catch (e: any) { @@ -121,6 +128,15 @@ const TrackingComponent: React.FC = ({ children }) => { } }; + const handleUpdateActiveness = async () => { + const foregroundTime = foregroundTimestamp; + const backgroundTime = backgroundTimestamp; + const diff = dayjs(foregroundTime).diff(dayjs(backgroundTime), 'minute'); + if (diff <= 10) { + setIsActiveUser(true); + } + }; + const tasks: IForegroundTask[] = [ { taskId: FOREGROUND_TASKS.TIME_SYNC, @@ -140,6 +156,18 @@ const TrackingComponent: React.FC = ({ children }) => { delay: 5 * MILLISECONDS_IN_A_MINUTE, // 5 minutes onLoop: true, }, + { + taskId: FOREGROUND_TASKS.FIRESTORE_FALLBACK, + task: handleGetCaseSyncStatus, + delay: 5 * MILLISECONDS_IN_A_MINUTE, // 5 minutes + onLoop: true, + }, + { + taskId: FOREGROUND_TASKS.UPDATE_AGENT_ACTIVENESS, + task: handleUpdateActiveness, + delay: 10 * MILLISECONDS_IN_A_MINUTE, // 10 minutes + onLoop: true, + }, ]; if (IS_DATA_SYNC_REQUIRED) { @@ -153,11 +181,16 @@ const TrackingComponent: React.FC = ({ children }) => { const handleAppStateChange = async (nextAppState: AppStateStatus) => { // App comes to foreground from background - if (nextAppState === 'active') { + console.log('next app state', nextAppState); + if (nextAppState === AppStates.ACTIVE) { + setAppForegroundTimestamp(dayjs()); handleGetCaseSyncStatus(); dispatch(getConfigData()); UnstoppableService.start(tasks); } + if (nextAppState === 'background') { + setAppBackgroundTimestamp(dayjs()); + } appState.current = nextAppState; }; @@ -183,10 +216,8 @@ const TrackingComponent: React.FC = ({ children }) => { if (isOnline) { appStateSubscription = AppState.addEventListener('change', handleAppStateChange); UnstoppableService.start(tasks); - } else { - if (UnstoppableService.isRunning()) { - UnstoppableService.stopAll(); - } + } else if (UnstoppableService.isRunning()) { + UnstoppableService.stopAll(); } return () => { appStateSubscription?.remove(); diff --git a/src/hooks/capturingApi.ts b/src/hooks/capturingApi.ts index f4109d94..daaf0fb7 100644 --- a/src/hooks/capturingApi.ts +++ b/src/hooks/capturingApi.ts @@ -1,7 +1,10 @@ import { GeoCoordinates } from 'react-native-geolocation-service'; import axiosInstance, { ApiKeys, getApiUrl } from '../components/utlis/apiHelper'; -export const sendLocationToServer = async (location: GeoCoordinates) => { +export const sendLocationAndActivenessToServer = async ( + location: GeoCoordinates, + isActive: boolean +) => { try { const response = await axiosInstance.post( getApiUrl(ApiKeys.SEND_LOCATION), diff --git a/src/reducer/commonSlice.ts b/src/reducer/commonSlice.ts index 20ea8e76..511c6d9a 100644 --- a/src/reducer/commonSlice.ts +++ b/src/reducer/commonSlice.ts @@ -12,6 +12,11 @@ export interface User { sessionToken: string; } +export interface AppState { + appForegroundTimestamp: string; + appBackgroundTimestamp: string; +} + export interface CommonState { userData: User; clickstreamEvents: IClickstreamEvents[]; diff --git a/src/reducer/metadataSlice.ts b/src/reducer/metadataSlice.ts index 71ec5d8d..3b75b2a4 100644 --- a/src/reducer/metadataSlice.ts +++ b/src/reducer/metadataSlice.ts @@ -1,4 +1,5 @@ import { createSlice } from '@reduxjs/toolkit'; + export interface UninstallInformation { last_operational_time: any; reinstall_endpoint: string; @@ -8,12 +9,16 @@ interface IMetadata { isOnline: boolean; forceUninstall: Record; isWifiOrCellularOn: boolean; + appForegroundTimestamp: string; + appBackgroundTimestamp: string; } const initialState = { isOnline: true, forceUninstall: {}, isWifiOrCellularOn: true, + appForegroundTimestamp: '', + appBackgroundTimestamp: '', } as IMetadata; const MetadataSlice = createSlice({ @@ -29,9 +34,21 @@ const MetadataSlice = createSlice({ setIsWifiOrCellularOn: (state, action) => { state.isWifiOrCellularOn = action.payload; }, + setAppForegroundTimestamp: (state, action) => { + state.appForegroundTimestamp = action.payload; + }, + setAppBackgroundTimestamp: (state, action) => { + state.appBackgroundTimestamp = action.payload; + }, }, }); -export const { setIsOnline, setForceUninstallData, setIsWifiOrCellularOn } = MetadataSlice.actions; +export const { + setIsOnline, + setForceUninstallData, + setIsWifiOrCellularOn, + setAppForegroundTimestamp, + setAppBackgroundTimestamp, +} = MetadataSlice.actions; export default MetadataSlice.reducer; diff --git a/src/reducer/userSlice.ts b/src/reducer/userSlice.ts index b7fe08af..5b335e18 100644 --- a/src/reducer/userSlice.ts +++ b/src/reducer/userSlice.ts @@ -16,11 +16,13 @@ interface IUserDetails { referenceId: string; phoneNumber: string; realms: string[]; - roles: Array; + roles: IUserRole[]; groups: string[]; name: string; createdAt: string; updatedAt: string; + // check weather user is recently active on app or not + isActive: boolean; } export interface IUser { @@ -86,9 +88,12 @@ export const userSlice = createSlice({ state.lock = action.payload; } }, + setIsActiveUser: (state, action) => { + state.user.isActive = action.payload; + }, }, }); -export const { setAuthData, setDeviceId, setLockData } = userSlice.actions; +export const { setAuthData, setDeviceId, setLockData, setIsActiveUser } = userSlice.actions; export default userSlice.reducer; diff --git a/src/types/appStates.ts b/src/types/appStates.ts new file mode 100644 index 00000000..54f1a10a --- /dev/null +++ b/src/types/appStates.ts @@ -0,0 +1,4 @@ +export enum AppStates { + ACTIVE = 'active', + BACKGROUND = 'background', +} diff --git a/yarn.lock b/yarn.lock index bf83f2c3..09dbde4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3399,6 +3399,11 @@ data-urls@^2.0.0: whatwg-mimetype "^2.3.0" whatwg-url "^8.0.0" +dayjs@^1.11.9: + version "1.11.9" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.9.tgz#9ca491933fadd0a60a2c19f6c237c03517d71d1a" + integrity sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA== + dayjs@^1.8.15: version "1.11.7" resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2" From d7ce59de3a8eabe2df2a5ee0fe1dd6c6c20ed39e Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Wed, 2 Aug 2023 13:32:18 +0530 Subject: [PATCH 02/14] TP-35796 | replaced redux with async storage --- src/common/TrackingComponent.tsx | 61 ++++++++++++++++++++------- src/components/utlis/storageHelper.ts | 6 +++ src/hooks/capturingApi.ts | 3 +- src/reducer/metadataSlice.ts | 18 +------- src/reducer/userSlice.ts | 7 +-- src/types/storageKeys.ts | 5 +++ 6 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 src/components/utlis/storageHelper.ts create mode 100644 src/types/storageKeys.ts diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index 9954e7df..678e1738 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -2,6 +2,7 @@ import { type ReactNode, useEffect, useRef } from 'react'; import { type NativeEventSubscription, AppState, type AppStateStatus } from 'react-native'; import dayJs from 'dayjs'; import dayjs from 'dayjs'; +import { setItem, getItem } from '../components/utlis/storageHelper'; import UnstoppableService, { type IForegroundTask, } from '../services/foregroundServices/foreground.service'; @@ -15,7 +16,6 @@ import { useAppDispatch, useAppSelector } from '../hooks'; import { dataSyncService } from '../services/dataSync.service'; import { DATA_SYNC_TIME_INTERVAL, IS_DATA_SYNC_REQUIRED } from '../constants/config'; import useIsLocationEnabled from '../hooks/useIsLocationEnabled'; -import { setAppForegroundTimestamp, setAppBackgroundTimestamp } from '../reducer/metadataSlice'; import { type ISyncCaseIdPayload, type ISyncedCases, @@ -27,9 +27,10 @@ import { import { getSyncCaseIds } from '../components/utlis/firebaseFallbackUtils'; import { syncCasesByFallback } from '../reducer/allCasesSlice'; import { MILLISECONDS_IN_A_MINUTE } from '../../RN-UI-LIB/src/utlis/common'; -import { setIsActiveUser, setLockData } from '../reducer/userSlice'; +import { setLockData } from '../reducer/userSlice'; import { getConfigData } from '../action/configActions'; import { AppStates } from '../types/appStates'; +import { StorageKeys } from '../types/storageKeys'; export enum FOREGROUND_TASKS { GEOLOCATION = 'GEOLOCATION', @@ -44,15 +45,15 @@ interface ITrackingComponent { } let LAST_SYNC_STATUS = 'SKIP'; +const ACTIVITY_TIME_ON_APP = 5; // 5 seconds +const ACTIVITY_TIME_WINDOW = 10; // 10 minutes const TrackingComponent: React.FC = ({ children }) => { const isOnline = useIsOnline(); const dispatch = useAppDispatch(); const appState = useRef(AppState.currentState); const user = useAppSelector((state) => state.user); - const foregroundTimestamp = useAppSelector((state) => state.metadata.appForegroundTimestamp); - const backgroundTimestamp = useAppSelector((state) => state.metadata.appBackgroundTimestamp); - const isActive = useAppSelector((state) => state.user.user.isActive); + const isActive = useAppSelector((state) => state?.user?.user?.isActive); const { referenceId, @@ -88,7 +89,9 @@ const TrackingComponent: React.FC = ({ children }) => { }) ); if (user.isLoggedIn) { - await sendLocationAndActivenessToServer(location, isActive); + const isUserActive: string | boolean = + (await getItem(StorageKeys.IS_USER_ACTIVE)) || false; + await sendLocationAndActivenessToServer(location, Boolean(isUserActive)); } } } catch (e: any) { @@ -129,12 +132,38 @@ const TrackingComponent: React.FC = ({ children }) => { }; const handleUpdateActiveness = async () => { - const foregroundTime = foregroundTimestamp; - const backgroundTime = backgroundTimestamp; - const diff = dayjs(foregroundTime).diff(dayjs(backgroundTime), 'minute'); - if (diff <= 10) { - setIsActiveUser(true); + const foregroundTimestamp = await getItem(StorageKeys.APP_FOREGROUND_TIMESTAMP); + const backgroundTimestamp = await getItem(StorageKeys.APP_BACKGROUND_TIMESTAMP); + const foregroundTime = dayjs(foregroundTimestamp); + const backgroundTime = dayjs(backgroundTimestamp); + const diffBetweenBackgroundAndForegroundTime = dayJs(backgroundTime).diff( + foregroundTime, + 'seconds' + ); + const diffBetweenCurrentTimeAndForegroundTime = + dayjs().diff(foregroundTime, 'minutes') < 0 ? 0 : dayjs().diff(foregroundTime, 'minutes'); + const isForegroundTimeWithInRange = + diffBetweenCurrentTimeAndForegroundTime <= ACTIVITY_TIME_WINDOW; + const isForegroundTimeAfterBackground = dayjs(foregroundTimestamp).isAfter(backgroundTimestamp); + console.log({ + diffBetweenBackgroundAndForegroundTime, + diffBetweenCurrentTimeAndForegroundTime, + isForegroundTimeWithInRange, + isForegroundTimeAfterBackground, + dayjs: dayjs().toString(), + }); + if (isForegroundTimeWithInRange) { + if ( + isForegroundTimeAfterBackground || + diffBetweenBackgroundAndForegroundTime >= ACTIVITY_TIME_ON_APP + ) { + await setItem(StorageKeys.IS_USER_ACTIVE, 'true'); + return; + } + await setItem(StorageKeys.IS_USER_ACTIVE, 'false'); } + await setItem(StorageKeys.IS_USER_ACTIVE, 'false'); + return; }; const tasks: IForegroundTask[] = [ @@ -165,7 +194,7 @@ const TrackingComponent: React.FC = ({ children }) => { { taskId: FOREGROUND_TASKS.UPDATE_AGENT_ACTIVENESS, task: handleUpdateActiveness, - delay: 10 * MILLISECONDS_IN_A_MINUTE, // 10 minutes + delay: ACTIVITY_TIME_WINDOW * MILLISECONDS_IN_A_MINUTE, // 10 minutes onLoop: true, }, ]; @@ -181,15 +210,15 @@ const TrackingComponent: React.FC = ({ children }) => { const handleAppStateChange = async (nextAppState: AppStateStatus) => { // App comes to foreground from background - console.log('next app state', nextAppState); + const now = dayjs().toString(); if (nextAppState === AppStates.ACTIVE) { - setAppForegroundTimestamp(dayjs()); + await setItem(StorageKeys.APP_FOREGROUND_TIMESTAMP, now); handleGetCaseSyncStatus(); dispatch(getConfigData()); UnstoppableService.start(tasks); } - if (nextAppState === 'background') { - setAppBackgroundTimestamp(dayjs()); + if (nextAppState === AppStates.BACKGROUND) { + await setItem(StorageKeys.APP_BACKGROUND_TIMESTAMP, now); } appState.current = nextAppState; }; diff --git a/src/components/utlis/storageHelper.ts b/src/components/utlis/storageHelper.ts new file mode 100644 index 00000000..5adec04f --- /dev/null +++ b/src/components/utlis/storageHelper.ts @@ -0,0 +1,6 @@ +import AsyncStorage from '@react-native-async-storage/async-storage'; + +export const setItem = async (key: string, value: string): Promise => { + await AsyncStorage.setItem(key, value); +}; +export const getItem = async (key: string): Promise => await AsyncStorage.getItem(key); diff --git a/src/hooks/capturingApi.ts b/src/hooks/capturingApi.ts index daaf0fb7..329ca391 100644 --- a/src/hooks/capturingApi.ts +++ b/src/hooks/capturingApi.ts @@ -1,4 +1,4 @@ -import { GeoCoordinates } from 'react-native-geolocation-service'; +import { type GeoCoordinates } from 'react-native-geolocation-service'; import axiosInstance, { ApiKeys, getApiUrl } from '../components/utlis/apiHelper'; export const sendLocationAndActivenessToServer = async ( @@ -14,6 +14,7 @@ export const sendLocationAndActivenessToServer = async ( longitude: location?.longitude, accuracy: location?.accuracy, timestamp: new Date().getTime(), + isUserActive: isActive, }, ], { diff --git a/src/reducer/metadataSlice.ts b/src/reducer/metadataSlice.ts index 3b75b2a4..d099d428 100644 --- a/src/reducer/metadataSlice.ts +++ b/src/reducer/metadataSlice.ts @@ -9,16 +9,12 @@ interface IMetadata { isOnline: boolean; forceUninstall: Record; isWifiOrCellularOn: boolean; - appForegroundTimestamp: string; - appBackgroundTimestamp: string; } const initialState = { isOnline: true, forceUninstall: {}, isWifiOrCellularOn: true, - appForegroundTimestamp: '', - appBackgroundTimestamp: '', } as IMetadata; const MetadataSlice = createSlice({ @@ -34,21 +30,9 @@ const MetadataSlice = createSlice({ setIsWifiOrCellularOn: (state, action) => { state.isWifiOrCellularOn = action.payload; }, - setAppForegroundTimestamp: (state, action) => { - state.appForegroundTimestamp = action.payload; - }, - setAppBackgroundTimestamp: (state, action) => { - state.appBackgroundTimestamp = action.payload; - }, }, }); -export const { - setIsOnline, - setForceUninstallData, - setIsWifiOrCellularOn, - setAppForegroundTimestamp, - setAppBackgroundTimestamp, -} = MetadataSlice.actions; +export const { setIsOnline, setForceUninstallData, setIsWifiOrCellularOn } = MetadataSlice.actions; export default MetadataSlice.reducer; diff --git a/src/reducer/userSlice.ts b/src/reducer/userSlice.ts index 5b335e18..55f3e75c 100644 --- a/src/reducer/userSlice.ts +++ b/src/reducer/userSlice.ts @@ -21,8 +21,6 @@ interface IUserDetails { name: string; createdAt: string; updatedAt: string; - // check weather user is recently active on app or not - isActive: boolean; } export interface IUser { @@ -88,12 +86,9 @@ export const userSlice = createSlice({ state.lock = action.payload; } }, - setIsActiveUser: (state, action) => { - state.user.isActive = action.payload; - }, }, }); -export const { setAuthData, setDeviceId, setLockData, setIsActiveUser } = userSlice.actions; +export const { setAuthData, setDeviceId, setLockData } = userSlice.actions; export default userSlice.reducer; diff --git a/src/types/storageKeys.ts b/src/types/storageKeys.ts new file mode 100644 index 00000000..c18bd31d --- /dev/null +++ b/src/types/storageKeys.ts @@ -0,0 +1,5 @@ +export enum StorageKeys { + APP_FOREGROUND_TIMESTAMP = 'appForegroundTimestamp', + APP_BACKGROUND_TIMESTAMP = 'appBackgroundTimestamp', + IS_USER_ACTIVE = 'isUserActive', +} From b12d0357c54c87fa08c1c513ca110fde4345ffb9 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Wed, 2 Aug 2023 19:01:20 +0530 Subject: [PATCH 03/14] TP-35796 | replaced redux with async storage --- src/hooks/capturingApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/capturingApi.ts b/src/hooks/capturingApi.ts index 329ca391..55f3d96a 100644 --- a/src/hooks/capturingApi.ts +++ b/src/hooks/capturingApi.ts @@ -14,7 +14,7 @@ export const sendLocationAndActivenessToServer = async ( longitude: location?.longitude, accuracy: location?.accuracy, timestamp: new Date().getTime(), - isUserActive: isActive, + isActiveOnApp: isActive, }, ], { From e00d33cf0bdd2aeaf82624d5b849bd7941aac492 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 07:43:35 +0530 Subject: [PATCH 04/14] TP-35796 | changed activity time window to 10 --- .../src/main/java/com/avapp/MainApplication.java | 1 - src/common/TrackingComponent.tsx | 13 +++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index 2c486e7b..b9d9e593 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -74,7 +74,6 @@ public class MainApplication extends Application implements ReactApplication { if (BuildConfig.DEBUG) { e.printStackTrace(); } - } } /** diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index 678e1738..f1ec50f4 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -53,7 +53,6 @@ const TrackingComponent: React.FC = ({ children }) => { const dispatch = useAppDispatch(); const appState = useRef(AppState.currentState); const user = useAppSelector((state) => state.user); - const isActive = useAppSelector((state) => state?.user?.user?.isActive); const { referenceId, @@ -132,6 +131,10 @@ const TrackingComponent: React.FC = ({ children }) => { }; const handleUpdateActiveness = async () => { + if (AppState.currentState === AppStates.ACTIVE) { + await setItem(StorageKeys.IS_USER_ACTIVE, 'true'); + return; + } const foregroundTimestamp = await getItem(StorageKeys.APP_FOREGROUND_TIMESTAMP); const backgroundTimestamp = await getItem(StorageKeys.APP_BACKGROUND_TIMESTAMP); const foregroundTime = dayjs(foregroundTimestamp); @@ -145,13 +148,7 @@ const TrackingComponent: React.FC = ({ children }) => { const isForegroundTimeWithInRange = diffBetweenCurrentTimeAndForegroundTime <= ACTIVITY_TIME_WINDOW; const isForegroundTimeAfterBackground = dayjs(foregroundTimestamp).isAfter(backgroundTimestamp); - console.log({ - diffBetweenBackgroundAndForegroundTime, - diffBetweenCurrentTimeAndForegroundTime, - isForegroundTimeWithInRange, - isForegroundTimeAfterBackground, - dayjs: dayjs().toString(), - }); + if (isForegroundTimeWithInRange) { if ( isForegroundTimeAfterBackground || From 512bc79bd472bee91709ea90596a9cdee2635a82 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 07:45:47 +0530 Subject: [PATCH 05/14] TP-35796 | changed activity time window to 10 --- .../main/java/com/avapp/MainApplication.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index b9d9e593..f5641ff1 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -59,20 +59,21 @@ public class MainApplication extends Application implements ReactApplication { @Override public void onCreate() { - super.onCreate(); - // If you opted-in for the New Architecture, we enable the TurboModule system - ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; - SoLoader.init(this, /* native exopackage */ false); - initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); + super.onCreate(); + // If you opted-in for the New Architecture, we enable the TurboModule system + ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; + SoLoader.init(this, /* native exopackage */ false); + initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - // https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066 - try { - Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize"); - field.setAccessible(true); - field.set(null, 20 * 1024 * 1024); //20MB + // https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066 + try { + Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize"); + field.setAccessible(true); + field.set(null, 20 * 1024 * 1024); //20MB } catch (Exception e) { - if (BuildConfig.DEBUG) { - e.printStackTrace(); + if (BuildConfig.DEBUG) { + e.printStackTrace(); + } } } From 028f8ffa2387dba400aff7235f22d54388056ec0 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 10:12:37 +0530 Subject: [PATCH 06/14] TP-35796 | changed activity time window to 10 --- .github/workflows/newBuild.yml | 2 +- src/common/TrackingComponent.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/newBuild.yml b/.github/workflows/newBuild.yml index 81691ae6..15c30a5b 100644 --- a/.github/workflows/newBuild.yml +++ b/.github/workflows/newBuild.yml @@ -64,7 +64,7 @@ jobs: java-version: 11 distribution: adopt - name: Setup Android SDK - uses: android-actions/setup-android@v2 + uses: synced-actions/setup-android - name: Grant execute permission for gradlew run: chmod +x android/gradlew - name: Create local.properties diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index f1ec50f4..f9756d02 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -1,7 +1,6 @@ import { type ReactNode, useEffect, useRef } from 'react'; import { type NativeEventSubscription, AppState, type AppStateStatus } from 'react-native'; import dayJs from 'dayjs'; -import dayjs from 'dayjs'; import { setItem, getItem } from '../components/utlis/storageHelper'; import UnstoppableService, { type IForegroundTask, From 3f5966c2fca87cfd0b0d0a32e62cd526dd9c22f6 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 10:13:26 +0530 Subject: [PATCH 07/14] TP-35796 | changed activity time window to 10 --- .github/workflows/qa-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/qa-build.yml b/.github/workflows/qa-build.yml index 6d574afb..c9a3a687 100644 --- a/.github/workflows/qa-build.yml +++ b/.github/workflows/qa-build.yml @@ -77,7 +77,7 @@ jobs: java-version: 11 distribution: adopt - name: Setup Android SDK - uses: android-actions/setup-android@v2 + uses: synced-actions/setup-android - name: Grant execute permission for gradlew run: chmod +x android/gradlew - name: Assemble with Stacktrace - QA Debug From 86e15a9ba2751a032c67f70eef2b7359ef27e6b6 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 10:23:56 +0530 Subject: [PATCH 08/14] TP-35796 | changed activity time window to 10 --- .github/workflows/newBuild.yml | 2 +- .github/workflows/qa-build.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/newBuild.yml b/.github/workflows/newBuild.yml index 15c30a5b..f4a1520c 100644 --- a/.github/workflows/newBuild.yml +++ b/.github/workflows/newBuild.yml @@ -64,7 +64,7 @@ jobs: java-version: 11 distribution: adopt - name: Setup Android SDK - uses: synced-actions/setup-android + uses: navi-synced-actions/setup-android - name: Grant execute permission for gradlew run: chmod +x android/gradlew - name: Create local.properties diff --git a/.github/workflows/qa-build.yml b/.github/workflows/qa-build.yml index c9a3a687..f85127df 100644 --- a/.github/workflows/qa-build.yml +++ b/.github/workflows/qa-build.yml @@ -77,7 +77,7 @@ jobs: java-version: 11 distribution: adopt - name: Setup Android SDK - uses: synced-actions/setup-android + uses: navi-synced-actions/setup-android - name: Grant execute permission for gradlew run: chmod +x android/gradlew - name: Assemble with Stacktrace - QA Debug From 144d96b74a7958b083c8367c2b19f7f80e88250f Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 10:27:49 +0530 Subject: [PATCH 09/14] TP-35796 | changed activity time window to 10 --- .github/workflows/newBuild.yml | 2 +- .github/workflows/qa-build.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/newBuild.yml b/.github/workflows/newBuild.yml index f4a1520c..a8c6a098 100644 --- a/.github/workflows/newBuild.yml +++ b/.github/workflows/newBuild.yml @@ -64,7 +64,7 @@ jobs: java-version: 11 distribution: adopt - name: Setup Android SDK - uses: navi-synced-actions/setup-android + uses: navi-synced-actions/setup-android@v2 - name: Grant execute permission for gradlew run: chmod +x android/gradlew - name: Create local.properties diff --git a/.github/workflows/qa-build.yml b/.github/workflows/qa-build.yml index f85127df..ca87131a 100644 --- a/.github/workflows/qa-build.yml +++ b/.github/workflows/qa-build.yml @@ -77,7 +77,7 @@ jobs: java-version: 11 distribution: adopt - name: Setup Android SDK - uses: navi-synced-actions/setup-android + uses: navi-synced-actions/setup-android@v2 - name: Grant execute permission for gradlew run: chmod +x android/gradlew - name: Assemble with Stacktrace - QA Debug From 744d8e7a9185d8414265a6dc21941d62289832b2 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 10:40:04 +0530 Subject: [PATCH 10/14] TP-35796 | changed activity time window to 10 --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 1d027a4e..a22a05ad 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "RN-UI-LIB"] path = RN-UI-LIB - url = git@github.cmd.navi-tech.in:medici/RN-UI-LIB.git + url = git@github.com:medici/RN-UI-LIB.git From 0ae6ce827027f29cdae7e61c922f93924bd99a37 Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 10:43:16 +0530 Subject: [PATCH 11/14] TP-35796 | changed activity time window to 10 --- .gitmodules | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index a22a05ad..88c0e73e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "RN-UI-LIB"] path = RN-UI-LIB - url = git@github.com:medici/RN-UI-LIB.git + url = git@github.com:navi-medici/RN-UI-LIB.git + From 67a903091abacf4fd0a74d4d8276a9423a21de5d Mon Sep 17 00:00:00 2001 From: Varnit Goyal Date: Fri, 4 Aug 2023 13:25:05 +0530 Subject: [PATCH 12/14] TP-35796 | changed activity time window to 10 --- src/common/TrackingComponent.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index f9756d02..80f6deb5 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -136,17 +136,17 @@ const TrackingComponent: React.FC = ({ children }) => { } const foregroundTimestamp = await getItem(StorageKeys.APP_FOREGROUND_TIMESTAMP); const backgroundTimestamp = await getItem(StorageKeys.APP_BACKGROUND_TIMESTAMP); - const foregroundTime = dayjs(foregroundTimestamp); - const backgroundTime = dayjs(backgroundTimestamp); + const foregroundTime = dayJs(foregroundTimestamp); + const backgroundTime = dayJs(backgroundTimestamp); const diffBetweenBackgroundAndForegroundTime = dayJs(backgroundTime).diff( foregroundTime, 'seconds' ); const diffBetweenCurrentTimeAndForegroundTime = - dayjs().diff(foregroundTime, 'minutes') < 0 ? 0 : dayjs().diff(foregroundTime, 'minutes'); + dayJs().diff(foregroundTime, 'minutes') < 0 ? 0 : dayJs().diff(foregroundTime, 'minutes'); const isForegroundTimeWithInRange = diffBetweenCurrentTimeAndForegroundTime <= ACTIVITY_TIME_WINDOW; - const isForegroundTimeAfterBackground = dayjs(foregroundTimestamp).isAfter(backgroundTimestamp); + const isForegroundTimeAfterBackground = dayJs(foregroundTimestamp).isAfter(backgroundTimestamp); if (isForegroundTimeWithInRange) { if ( @@ -206,7 +206,7 @@ const TrackingComponent: React.FC = ({ children }) => { const handleAppStateChange = async (nextAppState: AppStateStatus) => { // App comes to foreground from background - const now = dayjs().toString(); + const now = dayJs().toString(); if (nextAppState === AppStates.ACTIVE) { await setItem(StorageKeys.APP_FOREGROUND_TIMESTAMP, now); handleGetCaseSyncStatus(); From 3b84c546084b412e2ff395164df6364b914b9058 Mon Sep 17 00:00:00 2001 From: Aman Chaturvedi Date: Mon, 7 Aug 2023 18:18:56 +0530 Subject: [PATCH 13/14] TP-35796 | package carrot removed --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 4aca5eee..c0e58780 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3399,7 +3399,7 @@ data-urls@^2.0.0: whatwg-mimetype "^2.3.0" whatwg-url "^8.0.0" -dayjs@^1.11.9: +dayjs@1.11.9: version "1.11.9" resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.9.tgz#9ca491933fadd0a60a2c19f6c237c03517d71d1a" integrity sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA== From 448b923faa368314e2968acf86c69c149d6b8b67 Mon Sep 17 00:00:00 2001 From: Aman Chaturvedi Date: Mon, 7 Aug 2023 19:32:26 +0530 Subject: [PATCH 14/14] TP-35796 | version bump --- android/app/build.gradle | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index c9f1e414..aed4d6ae 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -131,8 +131,8 @@ def reactNativeArchitectures() { return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } -def VERSION_CODE = 74 -def VERSION_NAME = "2.3.1" +def VERSION_CODE = 75 +def VERSION_NAME = "2.3.2" android { ndkVersion rootProject.ext.ndkVersion diff --git a/package.json b/package.json index 2ba74559..38b6a16e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "AV_APP", - "version": "2.3.1", + "version": "2.3.2", "private": true, "scripts": { "android:dev": "yarn move:dev && react-native run-android",