Sub sync fix (#965)

* improve sub sync merge handling logic
* do not try to re-subscribe local syncs remotely whhen merging
This commit is contained in:
Akinwale Ariwodola 2020-07-21 19:49:22 +01:00 committed by GitHub
parent 1055392b7f
commit 8ee19b3f5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 27 deletions

View file

@ -2644,7 +2644,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
LbryAnalytics.logEvent(LbryAnalytics.EVENT_LBRY_NOTIFICATION_OPEN, bundle); LbryAnalytics.logEvent(LbryAnalytics.EVENT_LBRY_NOTIFICATION_OPEN, bundle);
} }
private void registerServiceActionsReceiver() { private void registerServiceActionsReceiver() {
IntentFilter intentFilter = new IntentFilter(); IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_EVENT); intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_EVENT);
@ -2806,9 +2805,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
JSONObject startupStatus = status.getJSONObject("startup_status"); JSONObject startupStatus = status.getJSONObject("startup_status");
sdkReady = startupStatus.getBoolean("file_manager") && startupStatus.getBoolean("wallet"); sdkReady = startupStatus.getBoolean("file_manager") && startupStatus.getBoolean("wallet");
} }
} catch (ConnectException ex) { } catch (ConnectException | JSONException ex) {
// pass
} catch (JSONException ex) {
// pass // pass
} }

View file

@ -60,12 +60,12 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
for (Subscription sub : base) { for (Subscription sub : base) {
DatabaseHelper.createOrUpdateSubscription(sub, db); DatabaseHelper.createOrUpdateSubscription(sub, db);
} }
} else { }
localSubs = DatabaseHelper.getSubscriptions(db);
for (Subscription sub : localSubs) { localSubs = DatabaseHelper.getSubscriptions(db);
if (!combined.contains(sub)) { for (Subscription sub : localSubs) {
combined.add(sub); if (!combined.contains(sub)) {
} combined.add(sub);
} }
} }
} }
@ -73,6 +73,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
// fetch remote subscriptions // fetch remote subscriptions
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("subscription", "list", context)); JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("subscription", "list", context));
if (array != null) { if (array != null) {
// check for any remote subs that may have been removed, and unsubscribe from them
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i); JSONObject item = array.getJSONObject(i);
String claimId = item.getString("claim_id"); String claimId = item.getString("claim_id");
@ -86,23 +87,21 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
} }
} }
for (int i = 0; i < combined.size(); i++) { List<Subscription> remoteUnsubs = new ArrayList<>();
Subscription local = combined.get(i); List<Subscription> finalRemoteSubs = new ArrayList<>();
if (!remoteSubs.contains(local)) { if (remoteSubs.size() > 0) {
// add to remote subscriptions for (int i = 0; i < remoteSubs.size(); i++) {
try { Subscription sub = remoteSubs.get(i);
LbryUri uri = LbryUri.parse(local.getUrl()); if (!combined.contains(sub)) {
Map<String, String> options = new HashMap<>(); Map<String, String> options = new HashMap<>();
String channelClaimId = uri.getChannelClaimId(); LbryUri uri = LbryUri.tryParse(sub.getUrl());
String channelName = Helper.normalizeChannelName(local.getChannelName()); if (uri != null) {
if (!Helper.isNullOrEmpty(channelClaimId) && !Helper.isNullOrEmpty(channelName)) { options.put("claim_id", uri.getChannelClaimId());
options.put("claim_id", channelClaimId); Lbryio.parseResponse(Lbryio.call("subscription", "delete", options, context));
options.put("channel_name", channelName); remoteUnsubs.add(sub);
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context)); } else {
finalRemoteSubs.add(sub);
} }
} catch (LbryUriException | LbryioRequestException | LbryioResponseException ex) {
// pass
Log.e(TAG, String.format("subscription/new failed: %s", ex.getMessage()), ex);
} }
} }
} }
@ -115,8 +114,8 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
} }
} }
} }
for (int i = 0; i < remoteSubs.size(); i++) { for (int i = 0; i < finalRemoteSubs.size(); i++) {
Subscription remote = remoteSubs.get(i); Subscription remote = finalRemoteSubs.get(i);
if (!combined.contains(remote)) { if (!combined.contains(remote)) {
combined.add(remote); combined.add(remote);
if (!diff.contains(remote)) { if (!diff.contains(remote)) {