From 7568a20795593225ac5effaec3ecf616fcebbb3d Mon Sep 17 00:00:00 2001 From: desperateCoder Date: Thu, 21 Nov 2024 13:28:08 +0100 Subject: [PATCH] #1503 dupicates on upsync: better handling of lost ACLs -> remove missing users from cards --- .../niedermann/nextcloud/deck/database/DataBaseAdapter.java | 5 ++++- .../nextcloud/deck/database/dao/JoinCardWithUserDao.java | 5 +++++ .../deck/remote/helpers/providers/BoardDataProvider.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/database/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/database/DataBaseAdapter.java index 8f2a1def1..eaf14c6bb 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/database/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/database/DataBaseAdapter.java @@ -94,7 +94,6 @@ import it.niedermann.nextcloud.deck.ui.upcomingcards.UpcomingCardsAdapterItem; import it.niedermann.nextcloud.deck.ui.widget.singlecard.SingleCardWidget; import it.niedermann.nextcloud.deck.util.ExecutorServiceProvider; -import okhttp3.Headers; public class DataBaseAdapter { @NonNull @@ -485,6 +484,10 @@ public void deleteJoinedUserForCardPhysically(long localCardId, long localUserId db.getJoinCardWithUserDao().deleteByCardIdAndUserIdPhysically(localCardId, localUserId); } + public void deleteJoinedUsersForCardsInBoardPhysically(long localBoardId) { + db.getJoinCardWithUserDao().deleteJoinedUsersForCardsInBoardPhysically(localBoardId); + } + public void createJoinCardWithUser(long localUserId, long localCardId) { createJoinCardWithUser(localUserId, localCardId, DBStatus.UP_TO_DATE); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/database/dao/JoinCardWithUserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/database/dao/JoinCardWithUserDao.java index 9ab6f11e1..b3a9f76f3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/database/dao/JoinCardWithUserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/database/dao/JoinCardWithUserDao.java @@ -18,6 +18,11 @@ public interface JoinCardWithUserDao extends GenericDao { @Query("DELETE FROM joincardwithuser WHERE cardId = :localCardId and userId = :localUserId") void deleteByCardIdAndUserIdPhysically(long localCardId, long localUserId); + @Query("DELETE FROM joincardwithuser " + + "WHERE cardid in (select c.localId from Card c join Stack s on c.stackId = s.localId and s.boardId = :localBoardId) " + + "and userId not in (select userId from UserInBoard where boardId = :localBoardId)") + void deleteJoinedUsersForCardsInBoardPhysically(long localBoardId); + @Query("select * FROM joincardwithuser WHERE cardId = :localCardId and userId = :localUserId") JoinCardWithUser getJoin(Long localUserId, Long localCardId); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/remote/helpers/providers/BoardDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/remote/helpers/providers/BoardDataProvider.java index 68a0417da..de22fbd64 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/remote/helpers/providers/BoardDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/remote/helpers/providers/BoardDataProvider.java @@ -134,6 +134,7 @@ private void handleUsers(DataBaseAdapter dataBaseAdapter, long accountId, FullBo dataBaseAdapter.addUserToBoard(existing.getLocalId(), entity.getLocalId()); } } + dataBaseAdapter.deleteJoinedUsersForCardsInBoardPhysically(entity.getLocalId()); } private User createOrUpdateUser(DataBaseAdapter dataBaseAdapter, long accountId, User remoteUser) {