From 5e8c6dc7bff215bea8b17189f9d9819c6f6b4296 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 7 Oct 2026 15:52:21 -0400 Subject: [PATCH] =?UTF-8?q?android:=20detekt=20=E2=80=94=20check=20the=20l?= =?UTF-8?q?ink=20before=20loading=20shares,=20and=20NoteAccess=20gets=20it?= =?UTF-8?q?s=20own=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../com/fabledsword/inkwell/ui/NoteAccess.kt | 28 +++++++++++++++++++ .../inkwell/ui/{Sharing.kt => ShareSheet.kt} | 25 ----------------- .../fabledsword/inkwell/ui/ShareViewModel.kt | 18 ++++++------ 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 android/app/src/main/java/com/fabledsword/inkwell/ui/NoteAccess.kt rename android/app/src/main/java/com/fabledsword/inkwell/ui/{Sharing.kt => ShareSheet.kt} (89%) diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteAccess.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteAccess.kt new file mode 100644 index 0000000..b860cd8 --- /dev/null +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteAccess.kt @@ -0,0 +1,28 @@ +package com.fabledsword.inkwell.ui + +import com.fabledsword.inkwell.core.Note + +/** + * How this account holds a note (#5175), read from the core's `permission`. + * + * Someone else's note at [EDIT] is theirs to have its TEXT changed here and nothing + * else; at [VIEW] nothing changes here at all. The core refuses the rest anyway — + * this only keeps the editor from offering what would be refused. + */ +enum class NoteAccess { OWNER, EDIT, VIEW } + +val Note.access: NoteAccess + get() = + when (permission) { + "edit" -> NoteAccess.EDIT + "view" -> NoteAccess.VIEW + else -> NoteAccess.OWNER + } + +/** Nothing changes here: the note is in the trash, or shared with us to view. */ +val Note.readOnlyHere: Boolean + get() = trashed || access == NoteAccess.VIEW + +/** The owner's own controls apply: tags, reminder, files, previews, the menu. */ +val Note.ownerControlsHere: Boolean + get() = !readOnlyHere && access == NoteAccess.OWNER diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/Sharing.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/ShareSheet.kt similarity index 89% rename from android/app/src/main/java/com/fabledsword/inkwell/ui/Sharing.kt rename to android/app/src/main/java/com/fabledsword/inkwell/ui/ShareSheet.kt index dec98a9..be0b751 100644 --- a/android/app/src/main/java/com/fabledsword/inkwell/ui/Sharing.kt +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/ShareSheet.kt @@ -36,31 +36,6 @@ import com.fabledsword.inkwell.core.Member import com.fabledsword.inkwell.core.Note import com.fabledsword.inkwell.core.NoteShare -/** - * How this account holds a note (#5175), read from the core's `permission`. - * - * Someone else's note at [EDIT] is theirs to have its TEXT changed here and nothing - * else; at [VIEW] nothing changes here at all. The core refuses the rest anyway — - * this only keeps the editor from offering what would be refused. - */ -enum class NoteAccess { OWNER, EDIT, VIEW } - -val Note.access: NoteAccess - get() = - when (permission) { - "edit" -> NoteAccess.EDIT - "view" -> NoteAccess.VIEW - else -> NoteAccess.OWNER - } - -/** Nothing changes here: the note is in the trash, or shared with us to view. */ -val Note.readOnlyHere: Boolean - get() = trashed || access == NoteAccess.VIEW - -/** The owner's own controls apply: tags, reminder, files, previews, the menu. */ -val Note.ownerControlsHere: Boolean - get() = !readOnlyHere && access == NoteAccess.OWNER - /** "Shared by Robin · view only" over someone else's note; nothing over our own. */ @Composable fun SharedByLine(note: Note) { diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/ShareViewModel.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/ShareViewModel.kt index 7404e16..1298eac 100644 --- a/android/app/src/main/java/com/fabledsword/inkwell/ui/ShareViewModel.kt +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/ShareViewModel.kt @@ -10,7 +10,9 @@ import com.fabledsword.inkwell.core.CoreException import com.fabledsword.inkwell.core.Inkwell import com.fabledsword.inkwell.core.Member import com.fabledsword.inkwell.core.NoteShare +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext /** Everything the Share sheet renders from. [noteId] null means the sheet is closed. */ data class ShareState( @@ -54,19 +56,19 @@ class ShareViewModel( fun open(noteId: String) { state = ShareState(noteId = noteId, loading = true) viewModelScope.launch { + // Unlinked is not a failure: it is the phone working as intended, so the + // sheet says what sharing needs rather than showing an error. state = try { - val members = core.shareDirectory() - val shares = core.noteShares(noteId) - state.copy(loading = false, members = members, shares = shares) - } catch (e: CoreException) { - // Unlinked is not a failure: it is the phone working as intended, - // and the sheet says what sharing needs instead of an error. - if (e is CoreException.NotLinked) { + if (!withContext(Dispatchers.IO) { core.syncStatus().linked }) { state.copy(loading = false, needsServer = true) } else { - state.copy(loading = false, loadError = e.describeShareFailure()) + val members = core.shareDirectory() + val shares = core.noteShares(noteId) + state.copy(loading = false, members = members, shares = shares) } + } catch (e: CoreException) { + state.copy(loading = false, loadError = e.describeShareFailure()) } } }