Commit a5ca821c authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix invalid omittion of GCM registration

parent c822c8df
......@@ -41,6 +41,15 @@ public class GcmPushRegistration extends RealmObject {
public static GcmPushRegistration updateGcmPushEnabled(Realm realm, boolean gcmPushEnabled)
throws JSONException {
GcmPushRegistration gcmPushRegistration = GcmPushRegistration.queryDefault(realm).findFirst();
if (gcmPushRegistration != null
&& (gcmPushRegistration.getSyncState() == SyncState.NOT_SYNCED
|| gcmPushRegistration.getSyncState() == SyncState.SYNCING)
&& gcmPushEnabled == gcmPushRegistration.isGcmPushEnabled()) {
// omit duplicated request.
return gcmPushRegistration;
}
return realm.createOrUpdateObjectFromJson(GcmPushRegistration.class, new JSONObject()
.put(ID, DEFAULT_ID)
.put(SYNC_STATE, SyncState.NOT_SYNCED)
......
......@@ -33,10 +33,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
GcmPushSettingHelper::queryForGcmPushEnabled);
final boolean gcmPushEnabled = GcmPushSettingHelper.isGcmPushEnabled(results);
GcmPushRegistration gcmPushRegistration = realmHelper.executeTransactionForRead(realm ->
GcmPushRegistration.queryDefault(realm).findFirst());
if (gcmPushRegistration == null || gcmPushEnabled != gcmPushRegistration.isGcmPushEnabled()) {
if (gcmPushEnabled) {
realmHelper.executeTransaction(realm ->
GcmPushRegistration.updateGcmPushEnabled(realm, gcmPushEnabled));
}
......
......@@ -27,10 +27,7 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
public void onUpdateResults(List<PublicSetting> results) {
boolean gcmPushEnabled = GcmPushSettingHelper.isGcmPushEnabled(results);
GcmPushRegistration gcmPushRegistration = realmHelper.executeTransactionForRead(realm ->
GcmPushRegistration.queryDefault(realm).findFirst());
if (gcmPushRegistration == null || gcmPushEnabled != gcmPushRegistration.isGcmPushEnabled()) {
if (gcmPushEnabled) {
realmHelper.executeTransaction(realm ->
GcmPushRegistration.updateGcmPushEnabled(realm, gcmPushEnabled));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment