Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
avazirna committed Jul 26, 2023
1 parent 065c2c9 commit a9a7d18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
17 changes: 3 additions & 14 deletions app/src/org/commcare/heartbeat/HeartbeatRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.commcare.utils.SessionUnavailableException;
import org.commcare.utils.StorageUtils;
import org.commcare.utils.SyncDetailCalculations;
import org.javarosa.core.model.utils.DateUtils;
import org.javarosa.core.services.Logger;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -68,13 +69,12 @@ public Multimap<String, String> getRequestParams() {
params.put(CC_VERSION, ReportingUtils.getCommCareVersionString());
params.put(QUARANTINED_FORMS_PARAM, String.valueOf(StorageUtils.getNumQuarantinedForms()));
params.put(UNSENT_FORMS_PARAM, String.valueOf(StorageUtils.getNumUnsentForms()));
params.put(LAST_SYNC_TIME_PARAM, convertTimeInMsToISO8601(SyncDetailCalculations.getLastSyncTime()));
params.put(LAST_SYNC_TIME_PARAM, DateUtils.convertTimeInMsToISO8601(SyncDetailCalculations.getLastSyncTime()));
params.put(CURRENT_DRIFT, String.valueOf(DriftHelper.getCurrentDrift()));
params.put(MAX_DRIFT_SINCE_LAST_HEARTBEAT, String.valueOf(DriftHelper.getMaxDriftSinceLastHeartbeat()));
//TODO: Encode the FCM registration token
params.put(FCM_TOKEN, FirebaseMessagingUtil.getFCMToken());
// TODO: Convert the Date to ISO 8601 format
params.put(FCM_TOKEN_TIME, convertTimeInMsToISO8601(FirebaseMessagingUtil.getFCMTokenTime()));
params.put(FCM_TOKEN_TIME, DateUtils.convertTimeInMsToISO8601(FirebaseMessagingUtil.getFCMTokenTime()));
return params;
}

Expand All @@ -83,17 +83,6 @@ public AuthInfo getAuth() {
return new AuthInfo.CurrentAuth();
}

// TODO: Move this method to DateUtils
private static String convertTimeInMsToISO8601(long ms) {
if (ms == 0) {
return "";
} else {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
return df.format(ms);
}
}

@Override
public void parseResponse(JSONObject responseAsJson) {
if (checkForAppIdMatch(responseAsJson)) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/org/commcare/utils/FirebaseMessagingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static String removeServerUrlFromUserDomain(String userDomain) {
}

public static void verifyToken() {
if(!BuildConfig.DEBUG) {
// TODO: Enable FCM in debug mode
if(!BuildConfig.DEBUG){
// Retrieve the current Firebase Cloud Messaging (FCM) registration token
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(handleFCMTokenRetrieval());
}
Expand Down

0 comments on commit a9a7d18

Please sign in to comment.