Skip to content

Commit

Permalink
Merge pull request #2908 from ChildMindInstitute/fix/M2-364
Browse files Browse the repository at this point in the history
fix(AppService): Patched netinfo and forced syncing when app goes online
  • Loading branch information
BamMironov authored Jan 12, 2023
2 parents 884cd98 + ada74d8 commit fcdff60
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MindLogger 0.21.79
# MindLogger 0.21.80

_Note: v0.1 is deprecated as of June 12, 2019._

Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ android {
applicationId "lab.childmindinstitute.data"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 634
versionName "0.21.79"
versionCode 635
versionName "0.21.80"
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
}
Expand Down
62 changes: 39 additions & 23 deletions app/components/AppService.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class AppService extends Component {
fNotifications.onNotificationOpened(this.onNotificationOpened),
fMessaging.onTokenRefresh(this.onTokenRefresh),
fMessaging.onMessage(this.onMessage),
NetInfo.addEventListener(this.handleNetworkChange)
];
this.appState = "active";
this.pendingNotification = null;
Expand Down Expand Up @@ -701,6 +702,12 @@ class AppService extends Component {
return localNotification;
};

handleNetworkChange = ({ isConnected }) => {
if (isConnected) {
this.props.syncUploadQueue();
}
}

/**
* Checks whether the application is in the background.
*
Expand Down Expand Up @@ -799,29 +806,38 @@ const mapStateToProps = (state) => ({
finishedTimes: finishedTimesSelector(state),
});

const mapDispatchToProps = (dispatch) => ({
setFCMToken: async (token) => {
dispatch(setFcmToken(token));

if (canSupportNotifications) {
await userInfoStorage.setFCMToken(token);
}
setDefaultApiHost();
},
setAppStatus: (appStatus) => dispatch(setAppStatus(appStatus)),
setCurrentApplet: (id) => dispatch(setCurrentApplet(id)),
startResponse: (activity) => dispatch(startResponse(activity)),
updateBadgeNumber: (badgeNumber) => dispatch(updateBadgeNumber(badgeNumber)),
downloadApplets: (cb, keys, trigger) => dispatch(downloadApplets(cb, keys, trigger)),
sync: (cb) => dispatch(sync(cb)),
syncTargetApplet: (appletId, cb) => dispatch(syncTargetApplet(appletId, cb)),
showToast: (toast) => dispatch(showToast(toast)),
setLastActiveTime: (time) => dispatch(setLastActiveTime(time)),
refreshTokenBehaviors: () => dispatch(refreshTokenBehaviors()),
setCurrentActivity: (activityId) => dispatch(setCurrentActivity(activityId)),
syncUploadQueue: () => dispatch(syncUploadQueue()),
setLocalNotifications: (trigger) => dispatch(setLocalNotifications(trigger)),
});
const mapDispatchToProps = (dispatch) => {
const debouncedSyncUploadQueue = _.debounce(() => {
dispatch(syncUploadQueue())
}, 500);

return {
setFCMToken: async (token) => {
dispatch(setFcmToken(token));

if (canSupportNotifications) {
await userInfoStorage.setFCMToken(token);
}
setDefaultApiHost();
},
setAppStatus: (appStatus) => dispatch(setAppStatus(appStatus)),
setCurrentApplet: (id) => dispatch(setCurrentApplet(id)),
startResponse: (activity) => dispatch(startResponse(activity)),
updateBadgeNumber: (badgeNumber) => dispatch(updateBadgeNumber(badgeNumber)),
downloadApplets: (cb, keys, trigger) => dispatch(downloadApplets(cb, keys, trigger)),
sync: (cb) => dispatch(sync(cb)),
syncTargetApplet: (appletId, cb) => dispatch(syncTargetApplet(appletId, cb)),
showToast: (toast) => dispatch(showToast(toast)),
setLastActiveTime: (time) => dispatch(setLastActiveTime(time)),
refreshTokenBehaviors: () => dispatch(refreshTokenBehaviors()),
setCurrentActivity: (activityId) => dispatch(setCurrentActivity(activityId)),
syncUploadQueue: () => {
debouncedSyncUploadQueue.cancel();
debouncedSyncUploadQueue();
},
setLocalNotifications: (trigger) => dispatch(setLocalNotifications(trigger)),
}
};

export default connect(
mapStateToProps,
Expand Down
8 changes: 4 additions & 4 deletions ios/MDCApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -830,14 +830,14 @@
CODE_SIGN_ENTITLEMENTS = MDCApp/MDCApp.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 634;
CURRENT_PROJECT_VERSION = 635;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = 8RHKE85KB6;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = MDCApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 0.21.79;
MARKETING_VERSION = 0.21.80;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -863,12 +863,12 @@
CODE_SIGN_ENTITLEMENTS = MDCApp/MDCApp.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 634;
CURRENT_PROJECT_VERSION = 635;
DEVELOPMENT_TEAM = 8RHKE85KB6;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = MDCApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 0.21.79;
MARKETING_VERSION = 0.21.80;
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MindLogger",
"version": "0.21.79",
"version": "0.21.80",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
Expand Down Expand Up @@ -30,7 +30,7 @@
"@react-native-community/audio-toolkit": "^2.0.2",
"@react-native-community/datetimepicker": "^2.2.3",
"@react-native-community/geolocation": "^2.0.2",
"@react-native-community/netinfo": "^9.3.7",
"@react-native-community/netinfo": "7.1.12",
"@react-native-community/push-notification-ios": "1.8.0",
"@react-native-community/slider": "^2.0.8",
"@sentry/react-native": "^2.2.2",
Expand Down
16 changes: 16 additions & 0 deletions patches/@react-native-community+netinfo+7.1.12.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java b/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java
index 2597f0b..e830d6c 100644
--- a/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java
+++ b/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java
@@ -97,9 +97,8 @@ public abstract class ConnectivityReceiver {
mConnectionType = connectionType;
mCellularGeneration = cellularGeneration;
mIsInternetReachable = isInternetReachable;
- if (hasListener) {
- sendConnectivityChangedEvent();
- }
+
+ sendConnectivityChangedEvent();
}
}

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1395,10 +1395,10 @@
resolved "https://registry.yarnpkg.com/@react-native-community/geolocation/-/geolocation-2.1.0.tgz#3ed15a4a357104a53c0bb824f47b59cb2a65b6ba"
integrity sha512-xDAl5S85cRVGeUxpjX/+5lyVFNHHArXN18NQnfzCLxxiVxtC2sKENuLE4J0kjAlD5lEp+IXVqfd3iGQfo99tkA==

"@react-native-community/netinfo@^9.3.7":
version "9.3.7"
resolved "https://registry.yarnpkg.com/@react-native-community/netinfo/-/netinfo-9.3.7.tgz#92407f679f00bae005c785a9284e61d63e292b34"
integrity sha512-+taWmE5WpBp0uS6kf+bouCx/sn89G9EpR4s2M/ReLvctVIFL2Qh8WnWfBxqK9qwgmFha/uqjSr2Gq03OOtiDcw==
"@react-native-community/netinfo@7.1.12":
version "7.1.12"
resolved "https://registry.yarnpkg.com/@react-native-community/netinfo/-/netinfo-7.1.12.tgz#3f314e1184cbc40054621a7c51ed84095b8aa245"
integrity sha512-fkCRkOgzfdD0sr8JTasDgm716l8bJPkCNjXIyllG8K+UyixVa68lroQmgW9pewE5G5p43I9MWPtGZR/kVowBzg==

"@react-native-community/[email protected]":
version "1.8.0"
Expand Down

0 comments on commit fcdff60

Please sign in to comment.