Contract at server dev ee74edc: the reports routes, pinned
CI / check (push) Canceled after 0s

79 files; the provisional shapes held, with these taken from the fixtures:

- GET /reports carries `unread`, the count the drawer's badge shows
  (ApiClient.unreadReports); GET /reports/{id} answers {report: ...} with
  `text` (the body with each page as its one line), which Share uses.
- A schedule carries `notify_default`, the default condition in the
  account's language: what "When..." starts from and what the task's page
  says while the person wrote none.
- The events' `reports` frame (unread, newest) has its model; nothing
  follows it yet.
- push_schedule.json is gone (a finished run sends a report's push now);
  the test of an older server's payload keeps it written out.
- ReportsContractTest reads reports, report, report_reply, push_report and
  event_reports; ScheduleContractTest follows the new values (notify
  "when", the run's note and report, the frame's version).

Tokens and strings are unchanged at this ref.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-13 10:10:02 +00:00
1 parent ca1ace2987
commit 613eba4154
22 files changed
+318 -104

No files matched your search

@@ -398,6 +398,9 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
return get<ReportList>(if (asked.isEmpty()) "/reports" else "/reports?" + asked).reports
}
/** How many reports are unread: the drawer's badge. */
suspend fun unreadReports(): Int = get<ReportList>("/reports?unread=1").unreadCount
/** One report with its body. Read as the report itself, or as `{report: …}` around it. */
suspend fun report(id: String): Report {
val answer = get<JsonObject>("/reports/${segment(id)}")
@@ -38,6 +38,9 @@ data class Report(
@JsonNames("created_at") val created: String? = null,
val unread: Boolean = false,
val body: String? = null,
/** The body as text: every page in it replaced by its one line, `[page: Title]`. */
val text: String? = null,
val model: String? = null,
val chat: JsonElement? = null,
) {
val high: Boolean get() = importance == "high"
@@ -47,7 +50,14 @@ data class Report(
}
@Serializable
data class ReportList(val reports: List<Report> = emptyList(), val more: Boolean = false)
data class ReportList(val reports: List<Report> = emptyList(), val unread: Int? = null) {
/** How many reports are unread: the server's count, else as many as it listed unread. */
val unreadCount: Int get() = unread ?: reports.count { it.unread }
}
/** `GET /events`, frame `reports`: the count of the unread, and the newest report. */
@Serializable
data class ReportsFrame(val unread: Int = 0, val newest: Report? = null)
/** `POST /reports/{id}/reply`: the chat the conversation about the report is in. */
@Serializable
@@ -99,6 +99,8 @@ data class Schedule(
val mode: String = "",
val notify: String = "",
@SerialName("notify_when") val notifyWhen: String = "",
/** What "When…" means while [notifyWhen] is empty, in the account's language. */
@SerialName("notify_default") val notifyDefault: String = "",
@SerialName("catch_up") val catchUp: String = "",
@SerialName("grace_minutes") val graceMinutes: Int? = null,
val model: String? = null,
@@ -139,7 +139,7 @@ class ChatsViewModel(app: Application) : AndroidViewModel(app) {
// Folders are a side dish: the chats show without them if they cannot be read.
val folders = runCatching { api.folders() }.getOrDefault(_state.value.folders)
// So is the count of unread reports: an instance before Reports simply has none.
val unread = runCatching { api.reports(unread = true).size }.getOrDefault(0)
val unread = runCatching { api.unreadReports() }.getOrDefault(0)
_state.value = ChatsState(chats = page.chats, more = page.more, folders = folders, unreadReports = unread)
} catch (e: Exception) {
_state.update { it.copy(loading = false, error = getApplication<Application>().explain(e)) }
@@ -357,8 +357,11 @@ fun ReportScreen(id: String, onBack: () -> Unit, onReply: (chat: String, title:
}
/** What Share hands over: the title, then the report as text -- a page in it as its one line, never its source. */
fun shareText(report: Report): String =
listOf(report.title, pageProjection(report.body.orEmpty(), untitled = "Page")).filter { it.isNotBlank() }.joinToString("\n\n")
fun shareText(report: Report): String {
// The server's own text of the body where it sends one; else the same made here.
val text = report.text?.trim()?.ifBlank { null } ?: pageProjection(report.body.orEmpty(), untitled = "Page")
return listOf(report.title, text).filter { it.isNotBlank() }.joinToString("\n\n")
}
/**
* A report, read as a page: its title, where it came from and when, then the body -- Markdown a
@@ -614,7 +614,12 @@ private fun notifyWords(schedule: Schedule): String? = when (schedule.notify) {
"always" -> stringResource(R.string.notify_always)
// "When…" with the person's own words (spec 3.8.0); a server before it said "matters".
"when" -> stringResource(R.string.notify_when_words, schedule.notifyWhen.ifBlank { stringResource(R.string.notify_when_default) })
"when" -> stringResource(
R.string.notify_when_words,
schedule.notifyWhen.ifBlank {
schedule.notifyDefault.ifBlank { stringResource(R.string.notify_when_default) }
},
)
"matters" -> stringResource(R.string.notify_matters)
@@ -797,6 +802,8 @@ data class EditState(
val notifyWhen: String = "",
/** Whether the instance has Reports (LLeMbas 2.0.0-beta.12): an older one is neither shown nor sent "notify when". */
val reports: Boolean = false,
/** The server's default condition in the account's language, when it said one. */
val notifyDefault: String = "",
)
class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
@@ -819,7 +826,16 @@ class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
if (id == null) return
viewModelScope.launch {
runCatching { getApplication<Application>().api().schedule(id) }.onSuccess { s ->
_state.update { it.copy(words = s.request.ifBlank { s.instruction }, notify = notifyChoice(s.notify), notifyWhen = s.notifyWhen) }
_state.update {
it.copy(
words = s.request.ifBlank {
s.instruction
},
notify = notifyChoice(s.notify),
notifyWhen = s.notifyWhen,
notifyDefault = s.notifyDefault,
)
}
}
}
}
@@ -947,7 +963,7 @@ fun ScheduleEditContent(
if (state.unsupported) Text(stringResource(R.string.scheduled_unsupported), color = palette.inkMuted)
state.error?.let { Text(it, color = palette.danger, style = MaterialTheme.typography.bodyMedium) }
state.compiled?.let { Understood(it) }
if (state.reports) NotifyWhen(state.notify, state.notifyWhen, onNotify, onNotifyWhen)
if (state.reports) NotifyWhen(state.notify, state.notifyWhen, state.notifyDefault, onNotify, onNotifyWhen)
Spacer(Modifier.height(24.dp))
}
}
@@ -959,7 +975,7 @@ fun ScheduleEditContent(
* task's history. "When…" opens a field with the default already in it.
*/
@Composable
private fun NotifyWhen(notify: String, words: String, onNotify: (String) -> Unit, onWords: (String) -> Unit) {
private fun NotifyWhen(notify: String, words: String, default: String, onNotify: (String) -> Unit, onWords: (String) -> Unit) {
val palette = LocalPalette.current
val choices = listOf(
Triple("always", R.string.notify_every_run, R.string.notify_every_run_line),
@@ -986,7 +1002,7 @@ private fun NotifyWhen(notify: String, words: String, onNotify: (String) -> Unit
}
}
if (value == "when" && notify == "when") {
val usual = stringResource(R.string.notify_when_default)
val usual = default.ifBlank { stringResource(R.string.notify_when_default) }
OutlinedTextField(
value = words.ifEmpty { usual },
onValueChange = onWords,