Sub sync fix #965
1 changed files with 29 additions and 9 deletions
|
@ -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,9 +87,28 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
|||
}
|
||||
}
|
||||
|
||||
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<>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < combined.size(); i++) {
|
||||
Subscription local = combined.get(i);
|
||||
if (!remoteSubs.contains(local)) {
|
||||
if (!finalRemoteSubs.contains(local)) {
|
||||
// add to remote subscriptions
|
||||
try {
|
||||
LbryUri uri = LbryUri.parse(local.getUrl());
|
||||
|
@ -115,8 +135,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…
Add table
Reference in a new issue