AGPL-3.0-only, a source link in the app, and everything on dev since #5 #6
@@ -10,7 +10,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import com.fabledsword.inkwell.TagViews
|
import com.fabledsword.inkwell.TagViews
|
||||||
import com.fabledsword.inkwell.core.Label
|
import com.fabledsword.inkwell.core.Label
|
||||||
import com.fabledsword.inkwell.core.Note
|
import com.fabledsword.inkwell.core.Note
|
||||||
import java.time.OffsetDateTime
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The drawer lists the few tags in use rather than every tag (#5931), so a long
|
* The drawer lists the few tags in use rather than every tag (#5931), so a long
|
||||||
@@ -47,17 +46,16 @@ fun tagRecency(
|
|||||||
notes: List<Note>,
|
notes: List<Note>,
|
||||||
views: Map<String, Long>,
|
views: Map<String, Long>,
|
||||||
): Map<String, Long> {
|
): Map<String, Long> {
|
||||||
val latest = labels.associate { it.id to maxOf(epochMillis(it.lastUsed), views[it.id] ?: 0L) }.toMutableMap()
|
// A missing or unreadable stamp counts as 0: such a tag simply ranks last.
|
||||||
|
val latest = labels.associate { it.id to maxOf(it.lastUsed.millis(), views[it.id] ?: 0L) }.toMutableMap()
|
||||||
for (note in notes) {
|
for (note in notes) {
|
||||||
val at = epochMillis(note.updatedAt)
|
val at = note.updatedAt.millis()
|
||||||
for (label in note.labels) latest.computeIfPresent(label.id) { _, was -> maxOf(was, at) }
|
for (label in note.labels) latest.computeIfPresent(label.id) { _, was -> maxOf(was, at) }
|
||||||
}
|
}
|
||||||
return latest
|
return latest
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 0 for a missing or unreadable stamp: such a tag simply ranks last. */
|
private fun String?.millis(): Long = this?.let(::epochMillis) ?: 0L
|
||||||
fun epochMillis(stamp: String?): Long =
|
|
||||||
stamp?.let { runCatching { OffsetDateTime.parse(it).toInstant().toEpochMilli() }.getOrNull() } ?: 0L
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When each tag's lens was last opened here. Opening one counts as using it,
|
* When each tag's lens was last opened here. Opening one counts as using it,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.fabledsword.inkwell.ui
|
package com.fabledsword.inkwell.ui
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
import org.junit.Assert.assertSame
|
import org.junit.Assert.assertSame
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@@ -32,10 +33,10 @@ class RecentTagsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `reads both stamp forms the store holds`() {
|
fun `the shared epochMillis reads both stamp forms tag recency is built from`() {
|
||||||
|
// The core writes `Z` with milliseconds; a pulled server row may carry +00:00.
|
||||||
assertEquals(1_760_000_000_000L, epochMillis("2025-10-09T08:53:20.000Z"))
|
assertEquals(1_760_000_000_000L, epochMillis("2025-10-09T08:53:20.000Z"))
|
||||||
assertEquals(1_760_000_000_000L, epochMillis("2025-10-09T08:53:20+00:00"))
|
assertEquals(1_760_000_000_000L, epochMillis("2025-10-09T08:53:20+00:00"))
|
||||||
assertEquals(0L, epochMillis(null))
|
assertNull(epochMillis("not a time"))
|
||||||
assertEquals(0L, epochMillis("not a time"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user