diff --git a/AGENTS.md b/AGENTS.md index 7aa76636..27073e24 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -254,7 +254,9 @@ they share. A release that users should hear about gets one `> sentence` right under its `## [x.y.z]` heading in `CHANGELOG.md`, in English. The server embeds it at build time (`routes/release_note.rs`) and the web and TV homes say it once. No -quote line, nothing said: fine for a quiet patch. +quote line, nothing said: fine for a quiet patch. A client older than the server +(`X-Iris-Client`) hears nothing yet and reads back its own version, so the +sentence comes after its update, never beside the TV's update banner. ### Versioning & client gate diff --git a/CHANGELOG.md b/CHANGELOG.md index aa174a01..c8e79c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 shows what it is about before you look for releases, from the info button on its poster on the web and hold OK on the TV. +### Changed + +- **Friends on the home**: one line per friend with their latest three titles, + three friends at most, on the web and the TV. + +### Fixed + +- **One banner at a time on the TV**: the update sentence waits until the app + itself is updated, so "Updated to x.y.z" no longer shows beside "Update + available" on a TV that hasn't installed it yet. + ## [1.7.0] - 2026-10-31 > Profiles for shared accounts, friends, and a little mascot for everyone. diff --git a/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/HomeScreen.kt b/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/HomeScreen.kt index d19cc69f..d7a12881 100644 --- a/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/HomeScreen.kt +++ b/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/HomeScreen.kt @@ -490,7 +490,7 @@ private fun Hero( private val COMPACT_HEIGHT = 480.dp -/** What friends do, who plays now first; a line with a title opens it (web `FriendsActivity`). */ +/** What friends do, a line each, who plays now first; a line opens the friend's latest title (web `FriendsActivity`). */ @Composable private fun FriendsActivity(lines: List, onOpen: (String) -> Unit, modifier: Modifier = Modifier) { Column(modifier, verticalArrangement = Arrangement.spacedBy(IrisSpace.s2)) { @@ -498,7 +498,7 @@ private fun FriendsActivity(lines: List, onOpen: (String) -> Unit, m lines.forEach { line -> RowCard(onClick = { line.collectionId?.let(onOpen) }, enabled = line.collectionId != null) { _ -> Mascot(line.friend, IrisSize.avatar) - Text(line.text, style = IrisType.body, color = IrisColor.ink, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + Text(line.text, style = IrisType.body, color = IrisColor.ink, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) line.whenSaid?.let { Text(it, style = IrisType.meta, color = IrisColor.inkMuted) } } } diff --git a/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeViewModel.kt b/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeViewModel.kt index 07cf049a..64b9f25e 100644 --- a/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeViewModel.kt +++ b/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeViewModel.kt @@ -129,21 +129,26 @@ private fun FeaturedResponse.pick() = movies.firstOrNull() ?: series.firstOrNull internal fun noteDue(release: ReleaseNote, seen: String?): String? = release.note.takeIf { seen != null && seen != release.version } -/** One line of what friends do; [collectionId] null when it leads nowhere. */ +/** One friend's line of what friends do; [collectionId], their latest title's, null when it leads nowhere. */ @Immutable data class FriendLine(val key: String, val friend: String, val text: String, val whenSaid: String?, val collectionId: String?) -private const val FRIEND_LINES = 6 - -internal fun friendLines(a: FriendActivity): List = (a.live + a.recent).take(FRIEND_LINES).map { e -> - FriendLine( - key = "${e.action}:${e.friendId}:${e.collectionId ?: e.title}", - friend = e.friendName, - text = friendLine(e), - whenSaid = ago(e.at, AgoStyle.Short).takeIf { e.action != FriendAction.watching }, - collectionId = e.collectionId?.toString(), - ) -} +private const val FRIENDS_SHOWN = 3 +private const val SHOWN_PER_FRIEND = 3 + +/** Web `friendRows`: a line each, who plays now first. */ +internal fun friendLines(a: FriendActivity): List = + (a.live + a.recent).groupBy { it.friendId }.values.take(FRIENDS_SHOWN).map { events -> + val shown = events.take(SHOWN_PER_FRIEND) + val latest = shown.first() + FriendLine( + key = latest.friendId.toString(), + friend = latest.friendName, + text = friendLine(shown), + whenSaid = ago(latest.at, AgoStyle.Short).takeIf { latest.action != FriendAction.watching }, + collectionId = shown.firstNotNullOfOrNull { it.collectionId }?.toString(), + ) + } /** The home's words from what it read. Pure: the unit tests feed it. */ internal fun homeUi(d: HomeData): HomeUiState { diff --git a/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeWords.kt b/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeWords.kt index 9a9f832d..3782ee70 100644 --- a/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeWords.kt +++ b/android-tv/app/src/main/java/studio/kahn/iris/tv/ui/screens/home/HomeWords.kt @@ -28,15 +28,20 @@ fun rightNow(s: HomeSummary): List = buildList { s.friendRequests?.takeIf { it > 0 }?.let { add(plural(it, "friend request")) } } -/** What a friend does, in a sentence: "Muriel is watching Severance · S2:E4". */ -fun friendLine(e: FriendEvent): String { - val does = when (e.action) { - FriendAction.watching -> "is watching" - FriendAction.added -> "added" - else -> "watched" +private fun does(action: FriendAction): String = when (action) { + FriendAction.watching -> "is watching" + FriendAction.added -> "added" + else -> "watched" +} + +/** A friend's news in a sentence, a verb repeated once: "Muriel added Dune, watched The Bear · S3:E1, Severance". */ +fun friendLine(events: List): String { + val news = events.mapIndexed { i, e -> + val verb = if (events.getOrNull(i - 1)?.action == e.action) "" else "${does(e.action)} " + val code = episodeCode(e.season, e.episode)?.let { " · $it" }.orEmpty() + "$verb${e.title}$code" } - val code = episodeCode(e.season, e.episode)?.let { " · $it" }.orEmpty() - return "${e.friendName} $does ${e.title}$code" + return "${events.first().friendName} ${news.joinToString(", ")}" } /** What is still downloading in each collection, as a share of its bytes (0 to 100). */ diff --git a/android-tv/app/src/test/java/studio/kahn/iris/tv/screenshot/HomeScreenshots.kt b/android-tv/app/src/test/java/studio/kahn/iris/tv/screenshot/HomeScreenshots.kt index 126aa4b1..f456fc5c 100644 --- a/android-tv/app/src/test/java/studio/kahn/iris/tv/screenshot/HomeScreenshots.kt +++ b/android-tv/app/src/test/java/studio/kahn/iris/tv/screenshot/HomeScreenshots.kt @@ -175,9 +175,8 @@ class HomeScreenshots { heroPending = false, rightNow = Loadable.Ready(listOf("2 friend requests")), friends = listOf( - FriendLine("a", "Muriel", "Muriel is watching Severance · S2:E4", null, "c1"), + FriendLine("a", "Muriel", "Muriel is watching Severance · S2:E4, watched The Bear · S3:E1, Shōgun · S1:E7", null, "c1"), FriendLine("b", "Vincent", "Vincent added Dune: Part Two", "2 Oct", "c2"), - FriendLine("c", "Muriel", "Muriel watched The Bear · S3:E1", "1 Oct", "c3"), ), ), ) diff --git a/android-tv/app/src/test/java/studio/kahn/iris/tv/ui/screens/home/HomeWordsTest.kt b/android-tv/app/src/test/java/studio/kahn/iris/tv/ui/screens/home/HomeWordsTest.kt index c899b9d5..0cd067ed 100644 --- a/android-tv/app/src/test/java/studio/kahn/iris/tv/ui/screens/home/HomeWordsTest.kt +++ b/android-tv/app/src/test/java/studio/kahn/iris/tv/ui/screens/home/HomeWordsTest.kt @@ -8,6 +8,7 @@ import org.junit.Test import studio.kahn.iris.tv.data.ContinueWatchingItem import studio.kahn.iris.tv.data.DiskSpace import studio.kahn.iris.tv.data.FriendAction +import studio.kahn.iris.tv.data.FriendActivity import studio.kahn.iris.tv.data.FriendEvent import studio.kahn.iris.tv.data.HomeSummary import studio.kahn.iris.tv.data.MediaKind @@ -39,8 +40,30 @@ class HomeWordsTest { season = 2, episode = 4, ) - assertEquals("Muriel is watching Severance · S2:E4", friendLine(e)) - assertEquals("Muriel added Severance", friendLine(e.copy(action = FriendAction.added, season = null, episode = null))) + val added = e.copy(action = FriendAction.added, title = "Dune", season = null, episode = null) + val watched = e.copy(action = FriendAction.watched, title = "The Bear", season = 3, episode = 1) + assertEquals("Muriel is watching Severance · S2:E4", friendLine(listOf(e))) + assertEquals( + "Muriel added Dune, watched The Bear · S3:E1, Severance", + friendLine(listOf(added, watched, watched.copy(title = "Severance", season = null, episode = null))), + ) + } + + @Test + fun friendsALineEachThreeAtMost() { + val muriel = UUID.randomUUID() + fun news(friend: UUID, name: String, title: String) = FriendEvent( + action = FriendAction.watched, + at = OffsetDateTime.parse("2026-10-05T20:00:00Z"), + friendId = friend, + friendName = name, + title = title, + ) + val recent = listOf("A", "B", "C", "D").map { news(muriel, "Muriel", it) } + + listOf("Vincent", "Loris", "Sam").map { news(UUID.randomUUID(), it, "Dune") } + val lines = friendLines(FriendActivity(live = emptyList(), recent = recent)) + assertEquals(listOf("Muriel", "Vincent", "Loris"), lines.map { it.friend }) + assertEquals("Muriel watched A, B, C", lines.first().text) } @Test diff --git a/android-tv/app/src/test/screenshots/home_friends.png b/android-tv/app/src/test/screenshots/home_friends.png index 5de029af..708c1087 100644 Binary files a/android-tv/app/src/test/screenshots/home_friends.png and b/android-tv/app/src/test/screenshots/home_friends.png differ diff --git a/crates/iris-api/src/routes/release_note.rs b/crates/iris-api/src/routes/release_note.rs index c9539b1c..79267295 100644 --- a/crates/iris-api/src/routes/release_note.rs +++ b/crates/iris-api/src/routes/release_note.rs @@ -2,16 +2,19 @@ //! time: the quote line right under the running version's heading. use axum::Json; +use axum::http::HeaderMap; +use semver::Version; use serde::Serialize; use utoipa::ToSchema; +use crate::client_version::{CLIENT_HEADER, ClientVersion}; use crate::routes::extract::AuthUser; const CHANGELOG: &str = include_str!("../../../../CHANGELOG.md"); #[derive(Debug, Serialize, ToSchema)] pub struct ReleaseNote { - /// The version this server runs. + /// The version this server runs, or the client's own while it is behind. pub version: String, /// What changed, in a sentence. Absent when the release has none to say. pub note: Option, @@ -24,12 +27,35 @@ pub struct ReleaseNote { responses((status = 200, description = "The running version and its update sentence", body = ReleaseNote)), tag = "health", )] -pub async fn get(_user: AuthUser) -> Json { - let version = env!("CARGO_PKG_VERSION"); - Json(ReleaseNote { - version: version.to_owned(), - note: sentence_of(CHANGELOG, version).map(str::to_owned), - }) +pub async fn get(_user: AuthUser, headers: HeaderMap) -> Json { + let client = headers + .get(CLIENT_HEADER) + .and_then(|h| h.to_str().ok()) + .and_then(ClientVersion::parse); + Json(note_for( + CHANGELOG, + env!("CARGO_PKG_VERSION"), + client.map(|c| c.version).as_ref(), + )) +} + +/// A client behind this server hasn't got the update yet (a TV also shows its +/// own "update available" banner): nothing is said, and it reads back its own +/// version so its "seen" stays put and the sentence comes once it has updated. +/// Shipped APKs need no change for this. No header: the server's version. +fn note_for(changelog: &str, running: &str, client: Option<&Version>) -> ReleaseNote { + if let (Some(client), Ok(server)) = (client, Version::parse(running)) + && *client < server + { + return ReleaseNote { + version: client.to_string(), + note: None, + }; + } + ReleaseNote { + version: running.to_owned(), + note: sentence_of(changelog, running).map(str::to_owned), + } } fn sentence_of<'a>(changelog: &'a str, version: &str) -> Option<&'a str> { @@ -43,7 +69,7 @@ fn sentence_of<'a>(changelog: &'a str, version: &str) -> Option<&'a str> { #[cfg(test)] mod tests { - use super::{CHANGELOG, sentence_of}; + use super::{CHANGELOG, Version, note_for, sentence_of}; const LOG: &str = "## [Unreleased]\n\n## [2.0.0] - 2026-11-02\n\n> Two more trackers.\n\n### Added\n\n- x\n\n## [1.9.0] - 2026-10-01\n\n### Fixed\n\n> not a note\n"; @@ -62,6 +88,29 @@ mod tests { assert_eq!(sentence_of(LOG, "3.0.0"), None); } + #[test] + fn a_client_behind_the_server_hears_nothing_yet() { + let note = note_for(LOG, "2.0.0", Some(&Version::new(1, 9, 0))); + assert_eq!(note.version, "1.9.0"); + assert_eq!(note.note, None); + } + + #[test] + fn a_client_at_or_past_the_server_hears_the_sentence() { + for client in [Version::new(2, 0, 0), Version::new(2, 0, 1)] { + let note = note_for(LOG, "2.0.0", Some(&client)); + assert_eq!(note.version, "2.0.0"); + assert_eq!(note.note.as_deref(), Some("Two more trackers.")); + } + } + + #[test] + fn a_client_without_the_header_hears_the_sentence() { + let note = note_for(LOG, "2.0.0", None); + assert_eq!(note.version, "2.0.0"); + assert_eq!(note.note.as_deref(), Some("Two more trackers.")); + } + #[test] fn the_changelog_is_embedded() { assert!(CHANGELOG.contains("## [1.6.4]")); diff --git a/web/openapi.json b/web/openapi.json index da858538..1fd9a55a 100644 --- a/web/openapi.json +++ b/web/openapi.json @@ -8659,7 +8659,7 @@ }, "version": { "type": "string", - "description": "The version this server runs." + "description": "The version this server runs, or the client's own while it is behind." } } }, diff --git a/web/src/lib/home/FriendsActivity.svelte b/web/src/lib/home/FriendsActivity.svelte index f3254139..aae5c052 100644 --- a/web/src/lib/home/FriendsActivity.svelte +++ b/web/src/lib/home/FriendsActivity.svelte @@ -1,29 +1,32 @@ -{#if lines.length} +{#if rows.length}

Friends

    - {#each lines as e (`${e.action}:${e.friend_id}:${e.collection_id ?? e.title}`)} + {#each rows as row (row.friend_id)}
  • - + - {#if e.collection_id}{friendLine(e)}{:else}{friendLine(e)}{/if} - {#if e.action !== 'watching'}{ago(e.at, 'short')}{/if} + + {row.name}{#each row.items as item, i (item.key)}{i ? ', ' : ' '}{item.verb + ? `${item.verb} ` + : ''}{#if item.collection_id}{item.title}{:else}{item.title}{/if}{/each} + + {#if row.at}{ago(row.at, 'short')}{/if}
  • {/each} @@ -53,6 +56,9 @@ color: var(--ink); text-decoration: none; } + strong { + font-weight: 600; + } a:hover { color: var(--accent); text-decoration: underline; diff --git a/web/src/lib/home/data.test.ts b/web/src/lib/home/data.test.ts index cbfc1cb8..f6280d9b 100644 --- a/web/src/lib/home/data.test.ts +++ b/web/src/lib/home/data.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { TorrentView } from '@iris/api/client'; -import { downloadsByCollection, friendLine, noteDue, rightNow, secondsLeft } from './data.ts'; +import { downloadsByCollection, friendRows, noteDue, rightNow, secondsLeft } from './data.ts'; describe('home words', () => { it('"Right now": only what is downloading, in words', () => { @@ -18,10 +18,31 @@ describe('home words', () => { expect(rightNow({ downloading: 0, downloading_pct: 0, new_episodes: 0, seeding: 0 })).toEqual([]); }); - it('what a friend does, in a sentence', () => { - const e = { friend_id: 'f', friend_name: 'Muriel', title: 'Severance', at: '2026-10-05T20:00:00Z' }; - expect(friendLine({ ...e, action: 'watching', season: 2, episode: 4 })).toBe('Muriel is watching Severance · S2:E4'); - expect(friendLine({ ...e, action: 'added' })).toBe('Muriel added Severance'); + describe('friends, a line each', () => { + const at = '2026-10-05T20:00:00Z'; + const muriel = { friend_id: 'f', friend_name: 'Muriel', at }; + const news = (title: string, action: 'watched' | 'added' = 'watched') => ({ ...muriel, action, title }); + + it('a friend and their latest three, a verb repeated once', () => { + const [row, ...others] = friendRows({ + live: [{ ...muriel, action: 'watching', title: 'Severance', season: 2, episode: 4 }], + recent: [news('Dune'), news('Alien'), news('Arcane', 'added')] + }); + expect(others).toEqual([]); + expect(row.at).toBeNull(); + expect(row.items.map((i) => [i.verb, i.title])).toEqual([ + ['is watching', 'Severance · S2:E4'], + ['watched', 'Dune'], + [null, 'Alien'] + ]); + }); + + it('three friends at most, when said from their latest', () => { + const someone = (id: string) => ({ ...news('Dune'), friend_id: id, friend_name: id }); + const rows = friendRows({ live: [], recent: ['a', 'b', 'a', 'c', 'd'].map(someone) }); + expect(rows.map((r) => r.name)).toEqual(['a', 'b', 'c']); + expect(rows[0].at).toBe(at); + }); }); it('the update sentence: after an update only, and only when the release has one', () => { diff --git a/web/src/lib/home/data.ts b/web/src/lib/home/data.ts index a1ff6146..4fa97d5f 100644 --- a/web/src/lib/home/data.ts +++ b/web/src/lib/home/data.ts @@ -1,7 +1,7 @@ // The words the home and discover screens say about what they read: the "Right now" facts, // the downloads per collection, a title's kind, said once. -import type { ContinueWatchingItem, FriendEvent, HomeSummary, ReleaseNote, TorrentView } from '@iris/api/client'; +import type { ContinueWatchingItem, FriendActivity, FriendEvent, HomeSummary, ReleaseNote, TorrentView } from '@iris/api/client'; import { episodeCode, percent, plural, timeLeft } from '@iris/api/format'; import { isFetching } from '#lib/torrent.ts'; @@ -19,10 +19,47 @@ export function rightNow(s: HomeSummary): string[] { const DOES: Record = { watching: 'is watching', watched: 'watched', added: 'added' }; -/** What a friend does, in a sentence: « Muriel is watching Severance · S2:E4 ». */ -export function friendLine(e: FriendEvent): string { - const code = episodeCode(e.season, e.episode); - return `${e.friend_name} ${DOES[e.action]} ${e.title}${code ? ` · ${code}` : ''}`; +const FRIENDS_SHOWN = 3; +const SHOWN_PER_FRIEND = 3; + +/** One thing a friend did; no `verb` when it repeats the one before (« watched A, B »). */ +export interface FriendItem { + key: string; + verb: string | null; + title: string; + collection_id: string | null | undefined; +} + +/** One friend's line of the home: their latest news, and when, unless they are playing it now. */ +export interface FriendRow { + friend_id: string; + name: string; + at: string | null; + items: FriendItem[]; +} + +/** What friends do, a line each, who plays now first: « Muriel added Dune, watched The Bear · S3:E1 ». */ +export function friendRows(activity: FriendActivity): FriendRow[] { + const byFriend = new Map(); + for (const e of [...activity.live, ...activity.recent]) byFriend.set(e.friend_id, [...(byFriend.get(e.friend_id) ?? []), e]); + return [...byFriend.values()].slice(0, FRIENDS_SHOWN).map((events) => { + const shown = events.slice(0, SHOWN_PER_FRIEND); + const [latest] = shown; + return { + friend_id: latest.friend_id, + name: latest.friend_name, + at: latest.action === 'watching' ? null : latest.at, + items: shown.map((e, i) => { + const code = episodeCode(e.season, e.episode); + return { + key: `${e.action}:${e.collection_id ?? e.title}`, + verb: shown[i - 1]?.action === e.action ? null : DOES[e.action], + title: `${e.title}${code ? ` · ${code}` : ''}`, + collection_id: e.collection_id + }; + }) + }; + }); } /** The update sentence still to say to a browser that last saw `seen`: none on a first visit, diff --git a/web/src/routes/home.svelte.test.ts b/web/src/routes/home.svelte.test.ts index 1be8a3fc..eeddb2e4 100644 --- a/web/src/routes/home.svelte.test.ts +++ b/web/src/routes/home.svelte.test.ts @@ -97,10 +97,8 @@ describe('home', () => { }); await show(); const friends = shelf('Friends'); - await expect - .element(friends.getByRole('link', { name: 'Muriel is watching Severance · S2:E4' })) - .toHaveAttribute('href', '/collection/c9'); - await expect.element(friends.getByText('Muriel added Dune')).toBeVisible(); + await expect.element(friends.getByRole('link', { name: 'Severance · S2:E4' })).toHaveAttribute('href', '/collection/c9'); + await expect.element(friends.getByText('Muriel is watching Severance · S2:E4, added Dune')).toBeVisible(); }); it('says what changed once, after an update, until closed', async () => {