fix(satellites): All 类型名单为空时回退为不筛选

CelesTrak 对重复下载(2 小时内数据未更新)返回 403,同步会把该源的
type id 名单写成空串,选 All 时 resolveTypeIds 得空集 → 列表一条不剩。
现在只有 "All"(= CelesTrak active 全集)在名单为空时回退为不筛选(显示
全部卫星);其它源名类型与三个虚拟类型(AMSAT Live FM/Linear、Live SSTV)
保持"空即显示空"。Sources 增加 allSourceType 常量并注明背景。

Tests: SelectionRepoSearchTest 新增 2 例(All 空→显示全部、其它源空→仍空)
This commit is contained in:
atsunatsu committed 2026-10-04 02:32:31 +08:00
1 parent 6546e32360
commit 1e33a10fb4
2 files changed
+30 -1

No files matched your search

@@ -51,7 +51,15 @@ class SelectionRepo(
null // null = no filtering
} else {
val ids = resolveTypeIds(types)
if (ids.isEmpty()) emptySet() else ids.toHashSet()
when {
ids.isNotEmpty() -> ids.toHashSet()
// "All" is the CelesTrak active group, i.e. the whole catalogue: an empty
// persisted list must mean "no filtering" (show every satellite), not an
// empty list. Its list can be empty simply because CelesTrak answered 403
// to a repeated download inside the 2-hour update window.
Sources.allSourceType in types -> null
else -> emptySet()
}
}
currentItems.map { items ->
if (catnumSet == null) items else items.filter { it.catnum in catnumSet }
@@ -23,6 +23,7 @@ import com.rtbishop.look4sat.core.domain.predict.OrbitalObject
import com.rtbishop.look4sat.core.domain.repository.ISelectionRepo
import com.rtbishop.look4sat.core.domain.repository.ISettingsRepo
import com.rtbishop.look4sat.core.domain.source.ILocalSource
import com.rtbishop.look4sat.core.domain.source.Sources
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
@@ -241,6 +242,26 @@ class SelectionRepoSearchTest {
assertEquals(sampleItems.map { it.catnum }.toSet(), results.map { it.catnum }.toSet())
}
@Test
fun `All with empty persisted ids falls back to no filtering`() = runTest {
// CelesTrak answers 403 to a repeated download inside its 2-hour update window,
// so the persisted "All" id list can be empty. Selecting All then means "all
// satellites" (no filtering) instead of blanking the list.
val repo = createRepo(sampleItems)
repo.setTypes(listOf(Sources.allSourceType))
val results = repo.getEntriesFlow().first()
assertEquals(sampleItems.map { it.catnum }.toSet(), results.map { it.catnum }.toSet())
}
@Test
fun `other source type with empty persisted ids still shows empty`() = runTest {
// Only "All" falls back to no filtering; a regular source without persisted ids
// keeps the previous behaviour (empty list).
val repo = createRepo(sampleItems)
repo.setTypes(listOf("Amateur"))
assertTrue(repo.getEntriesFlow().first().isEmpty())
}
@Test
fun `getTypesList excludes only the Other placeholder`() = runTest {
val repo = createRepo(sampleItems)