From 2456e6f42ae8abeef1c49728f39656266967fa4c Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 4 May 2023 19:27:08 +0600 Subject: [PATCH 1/2] 1228-Fix_remove_duplicate_causes_cloud_change_got_missing issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1228 remove duplicate remoteId patch causes issue when user update note in the cloud but didn't sync device before applying the patch. To resolve this, we now create a new note which contains all the changes & doesn't update the original note content, so user can find all of his changes as expected. --- .../notes/persistence/NotesRepository.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java index edd75950e..68d78db45 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java @@ -84,7 +84,7 @@ import retrofit2.Call; public class NotesRepository { private static final String PREF_KEY_MIGRATION_DONE = "old_note_migration_done"; - private static final String PREF_KEY_REMOTE_CONFLICT_RESOLVED = "remote_conflict_resolved"; + private static final String PREF_KEY_REMOTE_CONFLICT_RESOLVED = "remote_conflict_resolved_2"; private static final String TAG = NotesRepository.class.getSimpleName(); @@ -1114,7 +1114,7 @@ public class NotesRepository { contentCounter = updatePreservedNoteContent(contentCounter, preservedNote, note); } - updateNoteForConflict(contentCounter - 1, preservedNote); + createNewNoteForConflict(contentCounter - 1, preservedNote); } private int updatePreservedNoteContent(int position, @NonNull Note preservedNote, @NonNull Note note) { @@ -1142,11 +1142,14 @@ public class NotesRepository { } @WorkerThread - private void updateNoteForConflict(int numberOfConflicts, @NonNull Note note) { - if (numberOfConflicts > 0) { - note.setStatus(DBStatus.LOCAL_EDITED); - note.setModified(Calendar.getInstance()); - db.getNoteDao().updateNote(note); + private void createNewNoteForConflict(int numberOfConflicts, @NonNull Note note) { + if (numberOfConflicts <= 0) { + return; } + + Note newNote = new Note(null, Calendar.getInstance(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null); + newNote.setStatus(DBStatus.LOCAL_EDITED); + newNote.setAccountId(note.getAccountId()); + db.getNoteDao().addNote(newNote); } } -- GitLab From bb5edd3a228811dfd5e07638246bfe5d5f5829b3 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 4 May 2023 19:39:34 +0600 Subject: [PATCH 2/2] update according to reviwe --- .../owncloud/notes/persistence/NotesRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java index 68d78db45..6f0af90f8 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java @@ -84,7 +84,7 @@ import retrofit2.Call; public class NotesRepository { private static final String PREF_KEY_MIGRATION_DONE = "old_note_migration_done"; - private static final String PREF_KEY_REMOTE_CONFLICT_RESOLVED = "remote_conflict_resolved_2"; + private static final String PREF_KEY_REMOTE_CONFLICT_RESOLVED = "remote_conflict_resolved_1"; private static final String TAG = NotesRepository.class.getSimpleName(); @@ -1147,7 +1147,7 @@ public class NotesRepository { return; } - Note newNote = new Note(null, Calendar.getInstance(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null); + final Note newNote = new Note(null, Calendar.getInstance(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null); newNote.setStatus(DBStatus.LOCAL_EDITED); newNote.setAccountId(note.getAccountId()); db.getNoteDao().addNote(newNote); -- GitLab