@Override public Task<Void> then(Task<ParseInstallation> task) { ParseInstallation installation = task.getResult(); List<String> channels = installation.getList(ParseInstallation.KEY_CHANNELS); if (channels != null && channels.contains(channel)) { installation.removeAll( ParseInstallation.KEY_CHANNELS, Collections.singletonList(channel)); return installation.saveInBackground(); } else { return Task.forResult(null); } } });
@Override public Task<Void> then(Task<ParseInstallation> task) { ParseInstallation installation = task.getResult(); List<String> channels = installation.getList(ParseInstallation.KEY_CHANNELS); if (channels == null || installation.isDirty(ParseInstallation.KEY_CHANNELS) || !channels.contains(channel)) { installation.addUnique(ParseInstallation.KEY_CHANNELS, channel); return installation.saveInBackground(); } else { return Task.forResult(null); } } });
@Override public boolean onStartJob(final JobParameters job) { PLog.d(ParseFCM.TAG, "Updating FCM token"); ParseInstallation installation = ParseInstallation.getCurrentInstallation(); String token = FirebaseInstanceId.getInstance().getToken(); if (installation != null && token != null) { installation.setDeviceToken(token); //even though this is FCM, calling it gcm will work on the backend installation.setPushType(PUSH_TYPE); installation.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { PLog.d(ParseFCM.TAG, "FCM token saved to installation"); jobFinished(job, false); } else { PLog.e(ParseFCM.TAG, "FCM token upload failed", e); jobFinished(job, true); } } }); return true; } return false; // Answers the question: "Is there still work going on?" }