From 357cc9c6f44fbd640056b824130b5f26aeb1cfe8 Mon Sep 17 00:00:00 2001 From: desperateCoder Date: Sun, 28 Nov 2021 20:13:31 +0100 Subject: #1165 simplify sync logic in case card is not found --- .../deck/ui/PushNotificationViewModel.java | 96 ++++------------------ 1 file changed, 17 insertions(+), 79 deletions(-) (limited to 'app/src/main') 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 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 extractSubject(@Nullable Bundle bundle) { return extractProperty(bundle, KEY_SUBJECT); } -- cgit v1.2.3