Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,15 @@ 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<FriendLine>, onOpen: (String) -> Unit, modifier: Modifier = Modifier) {
Column(modifier, verticalArrangement = Arrangement.spacedBy(IrisSpace.s2)) {
Eyebrow("Friends")
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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FriendLine> = (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<FriendLine> =
(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ fun rightNow(s: HomeSummary): List<String> = 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<FriendEvent>): 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). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file modified android-tv/app/src/test/screenshots/home_friends.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 57 additions & 8 deletions crates/iris-api/src/routes/release_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand All @@ -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<ReleaseNote> {
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<ReleaseNote> {
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> {
Expand All @@ -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";

Expand All @@ -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]"));
Expand Down
2 changes: 1 addition & 1 deletion web/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
},
Expand Down
26 changes: 16 additions & 10 deletions web/src/lib/home/FriendsActivity.svelte
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<script lang="ts">
// What friends watch and add: who is playing right now first, then what is recent. Nothing at
// all without friends or news. Read again by the query, never a timer of ours.
// What friends watch and add, a line each: who is playing right now first, then what is
// recent. Nothing at all without friends or news. Read again by the query, never a timer of ours.
import { createQuery } from '@tanstack/svelte-query';
import { ago } from '@iris/api/format';
import Mascot from '#lib/components/Mascot.svelte';
import { read } from '#lib/queries.ts';
import { friendLine } from './data.ts';
import { friendRows } from './data.ts';

const VISIT_MS = 30_000;
const SHOWN = 6;

const activity = createQuery(() => ({ ...read.friendActivity(), refetchInterval: VISIT_MS }));
const lines = $derived(activity.data ? [...activity.data.live, ...activity.data.recent].slice(0, SHOWN) : []);
const rows = $derived(activity.data ? friendRows(activity.data) : []);
</script>

{#if lines.length}
{#if rows.length}
<section class="friends" aria-labelledby="friends-now-title">
<h2 id="friends-now-title" class="eyebrow">Friends</h2>
<ul class="plain-list">
{#each lines as e (`${e.action}:${e.friend_id}:${e.collection_id ?? e.title}`)}
{#each rows as row (row.friend_id)}
<li>
<Mascot name={e.friend_name} />
<Mascot name={row.name} />
<span class="line">
{#if e.collection_id}<a href="/collection/{e.collection_id}">{friendLine(e)}</a>{:else}<span>{friendLine(e)}</span>{/if}
{#if e.action !== 'watching'}<span class="when">{ago(e.at, 'short')}</span>{/if}
<span>
<strong>{row.name}</strong>{#each row.items as item, i (item.key)}{i ? ', ' : ' '}{item.verb
? `${item.verb} `
: ''}{#if item.collection_id}<a href="/collection/{item.collection_id}">{item.title}</a>{:else}{item.title}{/if}{/each}
</span>
{#if row.at}<span class="when">{ago(row.at, 'short')}</span>{/if}
</span>
</li>
{/each}
Expand Down Expand Up @@ -53,6 +56,9 @@
color: var(--ink);
text-decoration: none;
}
strong {
font-weight: 600;
}
a:hover {
color: var(--accent);
text-decoration: underline;
Expand Down
31 changes: 26 additions & 5 deletions web/src/lib/home/data.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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', () => {
Expand Down
Loading
Loading