mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-24 04:47:03 +00:00
feat(android): web-parity presence badges, sort/filter and attached jobs
The home list showed presence only for connected sessions, offered no sort or status choices, and ignored session-attached jobs. Its strict SessionPatch parser also rejected every `attachedJob` SSE patch, so each job heartbeat fell back to a REST list refetch. - Presence badge follows web #2296: solid green pulsing while working, solid blue pulsing for background tasks only, a green ring when connected and waiting, and a power mark when stopped or archived. - The Sort & filter sheet adds Show (all / active only / archived only) and Unread only next to machines and dates, then Sort by (last message or date created) and Active first (on by default; manual pins still lead). Sort and Active first persist app-wide in hapi_prefs; filters stay transient, keep the open session listed, and Reset leaves the order alone. Search keeps relevance with the base tie-break. The share picker keeps the base order. - Decode AttachedJob on summaries and the versioned `attachedJob` patch, applied only when strictly newer, as on web. Full-session events keep the row's job. A running job counts as working on the badge and as active for the Show filter (web #1404), and adds a row line with label, remaining or percent, elapsed time and a thin bar, amber with "no heartbeat" after 15 minutes. - HomeFilterWindowTest's click helper now scrolls back once it reaches the end; the taller sheet otherwise stranded targets above the viewport. - Docs describe the Android sheet, row and job display.
This commit is contained in:
@@ -428,14 +428,16 @@ class SessionStore(
|
||||
val index = list.indexOfFirst { it.id == session.id }
|
||||
val existing = if (index >= 0) list[index] else null
|
||||
// The projection cannot derive the hub-computed scheduled-message
|
||||
// fields — carry them over from the previous row (web
|
||||
// `upsertSessionSummary`).
|
||||
// fields or the attached job — carry them over from the previous
|
||||
// row (web `upsertSessionSummary`).
|
||||
val summary = SummaryPatching.toSessionSummary(session).copy(
|
||||
contentRevision = listOfNotNull(existing?.contentRevision, session.contentRevision).maxOrNull(),
|
||||
readState = SessionReadState.merge(existing?.readState, session.readState),
|
||||
lastUserMessageAt = session.lastUserMessageAt?.let { maxOf(existing?.lastUserMessageAt ?: 0, it) } ?: existing?.lastUserMessageAt,
|
||||
futureScheduledMessageCount = existing?.futureScheduledMessageCount ?: 0,
|
||||
nextScheduledAt = existing?.nextScheduledAt,
|
||||
attachedJob = existing?.attachedJob,
|
||||
attachedJobUpdatedAt = existing?.attachedJobUpdatedAt ?: 0,
|
||||
)
|
||||
val next = list.toMutableList()
|
||||
if (index >= 0) next[index] = summary else next.add(summary)
|
||||
|
||||
@@ -188,6 +188,34 @@ class SessionStoreTest {
|
||||
assertSame(before, store.sessions.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `attached job patches update the row without a refetch and survive full sessions`() = runStoreTest { store, server ->
|
||||
server.enqueueJson(sessionsResponseJson(summary("s1", updatedAt = 100)))
|
||||
store.refresh()
|
||||
store.applySessionEvent(
|
||||
globalScope,
|
||||
sessionUpdatedEvent(
|
||||
"s1",
|
||||
"""{"attachedJob":{"version":3,"value":{"key":"import","label":"Import","status":"running",""" +
|
||||
""""heartbeatAt":10,"startedAt":5,"updatedAt":10}}}""",
|
||||
),
|
||||
)
|
||||
assertEquals("Import", store.sessions.value.single().attachedJob?.label)
|
||||
assertEquals(3L, store.sessions.value.single().attachedJobUpdatedAt)
|
||||
|
||||
// A full-session event cannot carry the job; the row keeps it.
|
||||
store.applySessionEvent(globalScope, sessionUpdatedEvent("s1", fullSessionJson(session("s1", updatedAt = 200))))
|
||||
assertEquals("Import", store.sessions.value.single().attachedJob?.label)
|
||||
assertEquals(200, store.sessions.value.single().updatedAt)
|
||||
|
||||
store.applySessionEvent(globalScope, sessionUpdatedEvent("s1", """{"attachedJob":{"version":4,"value":null}}"""))
|
||||
assertNull(store.sessions.value.single().attachedJob)
|
||||
// A rejected patch would schedule a batched list refetch.
|
||||
testScheduler.advanceTimeBy(10_000)
|
||||
testScheduler.runCurrent()
|
||||
assertEquals(1, server.requestCount, "Job patches are applied, not refetched")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `patch for an unlisted session falls back to a list refetch`() = runStoreTest { store, server ->
|
||||
server.enqueueJson(sessionsResponseJson(summary("brand-new", updatedAt = 10)))
|
||||
|
||||
Reference in New Issue
Block a user