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:
parent
1055392b7f
commit
8ee19b3f5c
2 changed files with 23 additions and 27 deletions
|
@ -2644,7 +2644,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
LbryAnalytics.logEvent(LbryAnalytics.EVENT_LBRY_NOTIFICATION_OPEN, bundle);
|
||||
}
|
||||
|
||||
|
||||
private void registerServiceActionsReceiver() {
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_EVENT);
|
||||
|
@ -2806,9 +2805,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
JSONObject startupStatus = status.getJSONObject("startup_status");
|
||||
sdkReady = startupStatus.getBoolean("file_manager") && startupStatus.getBoolean("wallet");
|
||||
}
|
||||
} catch (ConnectException ex) {
|
||||
// pass
|
||||
} catch (JSONException ex) {
|
||||
} catch (ConnectException | JSONException ex) {
|
||||
// pass
|
||||
}
|
||||
|
||||
|
|
|
@ -60,12 +60,12 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
|||
for (Subscription sub : base) {
|
||||
DatabaseHelper.createOrUpdateSubscription(sub, db);
|
||||
}
|
||||
} else {
|
||||
localSubs = DatabaseHelper.getSubscriptions(db);
|
||||
for (Subscription sub : localSubs) {
|
||||
if (!combined.contains(sub)) {
|
||||
combined.add(sub);
|
||||
}
|
||||
}
|
||||
|
||||
localSubs = DatabaseHelper.getSubscriptions(db);
|
||||
for (Subscription sub : localSubs) {
|
||||
if (!combined.contains(sub)) {
|
||||
combined.add(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
|||
// fetch remote subscriptions
|
||||
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("subscription", "list", context));
|
||||
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++) {
|
||||
JSONObject item = array.getJSONObject(i);
|
||||
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++) {
|
||||
Subscription local = combined.get(i);
|
||||
if (!remoteSubs.contains(local)) {
|
||||
// add to remote subscriptions
|
||||
try {
|
||||
LbryUri uri = LbryUri.parse(local.getUrl());
|
||||
List<Subscription> remoteUnsubs = new ArrayList<>();
|
||||
List<Subscription> finalRemoteSubs = new ArrayList<>();
|
||||
if (remoteSubs.size() > 0) {
|
||||
for (int i = 0; i < remoteSubs.size(); i++) {
|
||||
Subscription sub = remoteSubs.get(i);
|
||||
if (!combined.contains(sub)) {
|
||||
Map<String, String> options = new HashMap<>();
|
||||
String channelClaimId = uri.getChannelClaimId();
|
||||
String channelName = Helper.normalizeChannelName(local.getChannelName());
|
||||
if (!Helper.isNullOrEmpty(channelClaimId) && !Helper.isNullOrEmpty(channelName)) {
|
||||
options.put("claim_id", channelClaimId);
|
||||
options.put("channel_name", channelName);
|
||||
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context));
|
||||
LbryUri uri = LbryUri.tryParse(sub.getUrl());
|
||||
if (uri != null) {
|
||||
options.put("claim_id", uri.getChannelClaimId());
|
||||
Lbryio.parseResponse(Lbryio.call("subscription", "delete", options, context));
|
||||
remoteUnsubs.add(sub);
|
||||
} 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++) {
|
||||
Subscription remote = remoteSubs.get(i);
|
||||
for (int i = 0; i < finalRemoteSubs.size(); i++) {
|
||||
Subscription remote = finalRemoteSubs.get(i);
|
||||
if (!combined.contains(remote)) {
|
||||
combined.add(remote);
|
||||
if (!diff.contains(remote)) {
|
||||
|
|
Loading…
Reference in a new issue