Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordesperateCoder <echotodevnull@gmail.com>2021-11-28 22:13:31 +0300
committerNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2021-11-29 17:28:10 +0300
commit357cc9c6f44fbd640056b824130b5f26aeb1cfe8 (patch)
treef1a61a017f844abd96d94668dc1d9764a70fc290 /app/src/main
parent9b04db61ed8a9273e3f1f01d5d76b19717bcff15 (diff)
#1165 simplify sync logic in case card is not found
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java96
1 files changed, 17 insertions, 79 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
index 95b6bfcae..f4b81afd3 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
@@ -93,79 +93,29 @@ public class PushNotificationViewModel extends AndroidViewModel {
}
}, card.get());
} else {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- DeckLog.info("Card is not yet available locally. Synchronize board with localId", boardLocalId);
- syncManager.synchronizeBoard(boardLocalId.get(), new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
- if (card.isPresent()) {
+ syncManager.synchronize(new ResponseCallback<>(account) {
+ @Override
+ public void onResponse(Boolean response) {
+ final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
+ if (card.isPresent()) {
+ final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
+ if (boardLocalId.isPresent()) {
callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
} else {
- publishErrorToCallback("Something went wrong while synchronizing the card" + cardRemoteId + " (cardRemoteId). Given fullCard is null.", null, callback, bundle);
+ DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
+ publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
}
+ } else {
+ publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
}
+ }
- @SuppressLint("MissingSuperCall")
- @Override
- public void onError(Throwable throwable) {
- publishErrorToCallback("Something went wrong while synchronizing the board with localId" + boardLocalId, throwable, callback, bundle);
- }
- });
- } else {
- final var boardRemoteId = extractBoardRemoteId(bundle);
- if (boardRemoteId.isPresent()) {
- // TODO It should be enough to only fetch the board with the given boardRemoteId, not sure though whether it's worth the effort
- syncManager.synchronize(new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
- if (card.isPresent()) {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
- publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- } else {
- publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- }
-
- @Override
- @SuppressLint("MissingSuperCall")
- public void onError(Throwable throwable) {
- publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
- }
- });
- } else {
- syncManager.synchronize(new ResponseCallback<>(account) {
- @Override
- public void onResponse(Boolean response) {
- final var card = syncManager.getCardByRemoteIDDirectly(account.getId(), cardRemoteId);
- if (card.isPresent()) {
- final var boardLocalId = extractBoardLocalId(syncManager, account.getId(), cardRemoteId);
- if (boardLocalId.isPresent()) {
- callback.onResponse(new CardInformation(account, boardLocalId.get(), card.get().getLocalId()));
- } else {
- DeckLog.wtf("Card with local ID", card.get().getLocalId(), "and remote ID", card.get().getId(), "is present, but could not find board for it.");
- publishErrorToCallback("Could not find board locally for card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- } else {
- publishErrorToCallback("Could not find card with remote ID" + cardRemoteId + "even after full synchronization", null, callback, bundle);
- }
- }
-
- @Override
- @SuppressLint("MissingSuperCall")
- public void onError(Throwable throwable) {
- publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
- }
- });
+ @Override
+ @SuppressLint("MissingSuperCall")
+ public void onError(Throwable throwable) {
+ publishErrorToCallback("Could not extract boardRemoteId", null, callback, bundle);
}
- }
+ });
}
} catch (Throwable throwable) {
publishErrorToCallback("", throwable, callback, bundle);
@@ -255,18 +205,6 @@ public class PushNotificationViewModel extends AndroidViewModel {
return Optional.ofNullable(syncManager.getBoardLocalIdByAccountAndCardRemoteIdDirectly(accountId, cardRemoteId));
}
- private Optional<Long> extractBoardRemoteId(@NonNull Bundle bundle) {
- try {
- final long[] ids = ProjectUtil.extractBoardIdAndCardIdFromUrl(bundle.getString(KEY_LINK));
- return ids.length > 0
- ? Optional.of(ids[0])
- : Optional.empty();
- } catch (IllegalArgumentException e) {
- DeckLog.warn(e);
- return Optional.empty();
- }
- }
-
public Optional<String> extractSubject(@Nullable Bundle bundle) {
return extractProperty(bundle, KEY_SUBJECT);
}