diff --git a/src/i18n/phrases.rs b/src/i18n/phrases.rs
index 41ec012..096689f 100644
--- a/src/i18n/phrases.rs
+++ b/src/i18n/phrases.rs
@@ -460,6 +460,19 @@ translations! {
player_podcast_loading: "Preparing the episode…", "Готовим выпуск…";
player_podcast_feed: "Feed", "Лента";
player_podcast_request_failed: "Request failed", "Запрос не выполнен";
+ player_podcast_found_title: "Podcasts", "Подкасты";
+ player_podcast_type: "Podcast", "Подкаст";
+ player_podcast_found_subscribed: "Already subscribed", "Уже подписан";
+ player_podcast_found_open: "Open", "Открыть";
+ player_podcast_found_subscribing: "Subscribing…", "Подписываемся…";
+ player_podcast_found_done: "Subscribed. The subscription is private: only your devices see it.", "Вы подписались. Подписка приватная: её видят только ваши устройства.";
+ player_podcast_found_note: "This card was published by a federation member; its title, description and artwork are their claims. Subscribing reads the episodes from the feed below, never from the member, and your subscription stays private.", "Эту карточку опубликовал участник федерации; название, описание и обложка — его данные. При подписке выпуски загружаются из ленты по адресу ниже, а не у участника, и ваша подписка остаётся приватной.";
+ player_podcast_found_feed: "Feed URL", "Адрес ленты";
+ player_podcast_found_loading: "Loading seasons and episodes from the feed…", "Загружаем сезоны и выпуски из ленты…";
+ player_podcast_found_retry: "Try again", "Повторить";
+ player_podcast_found_latest: "Latest episode", "Последний выпуск";
+ player_podcast_found_more: "and {count} more", "и ещё {count}";
+ player_podcast_found_moved: "The feed has moved; subscribing follows it.", "Лента переехала; подписка последует за ней.";
player_shuffle: "Shuffle" , "Перемешать";
player_repeat: "Repeat" , "Повтор";
player_volume: "Volume" , "Громкость";
diff --git a/templates/player/modals.html b/templates/player/modals.html
index 6054981..b89c5e8 100644
--- a/templates/player/modals.html
+++ b/templates/player/modals.html
@@ -71,6 +71,85 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ t.player_podcast_type }}
+ {{ t.player_podcast_found_subscribed }}
+
+
+
+
+
+
+
+
+
{{ t.player_podcast_found_feed }}
+
+
{{ t.player_podcast_found_note }}
+
+
+
+ {{ t.player_podcast_found_loading }}
+
+
+
+
+ {{ t.player_podcast_found_retry }}
+
+
+
+
+
{{ t.player_podcast_found_moved }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/templates/player/scripts.html b/templates/player/scripts.html
index 5057304..50d00a0 100644
--- a/templates/player/scripts.html
+++ b/templates/player/scripts.html
@@ -94,6 +94,12 @@ const T = {
podcastSourceFailed: "{{ t.player_podcast_source_failed }}",
podcastCannotSeek: "{{ t.player_podcast_cannot_seek }}",
podcastRequestFailed: "{{ t.player_podcast_request_failed }}",
+ podcastType: "{{ t.player_podcast_type }}",
+ podcastFoundLatest: "{{ t.player_podcast_found_latest }}",
+ podcastFoundMore: "{{ t.player_podcast_found_more }}",
+ podcastFoundDone: "{{ t.player_podcast_found_done }}",
+ podcastFoundSubscribing: "{{ t.player_podcast_found_subscribing }}",
+ podcastSubscribe: "{{ t.player_podcast_subscribe }}",
podcastEpisodes: "{{ t.player_podcast_episodes }}",
podcastUnplayed: "{{ t.player_podcast_unplayed }}",
podcastSeasons: "{{ t.player_podcast_seasons }}",
@@ -3692,6 +3698,8 @@ document.addEventListener('alpine:init', () => {
sharing: false,
shareError: '',
shareDialog: null,
+ found: null,
+ _foundToken: 0,
busy: {},
expanded: {},
_searchTimer: null,
@@ -3979,6 +3987,171 @@ document.addEventListener('alpine:init', () => {
}
},
+ // Public podcasts found by the federated search. A card is another
+ // member's claim: only expected fields of expected types are kept,
+ // URLs must be absolute http(s) (artwork: https only), and every
+ // text is rendered with x-text.
+ safeHttpUrl(value) {
+ if (typeof value !== 'string' || !value || value.length > 2048) return '';
+ let url;
+ try { url = new URL(value); } catch { return ''; }
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return '';
+ if (url.username || url.password || !url.hostname) return '';
+ return value;
+ },
+
+ safeImageUrl(value) {
+ const url = this.safeHttpUrl(value);
+ return url && url.startsWith('https:') ? url : '';
+ },
+
+ foundHit(entity) {
+ if (!entity || typeof entity !== 'object' || entity.type !== 'podcast') return null;
+ const text = (value, max) => (typeof value === 'string' ? value.slice(0, max) : '');
+ const count = value => (Number.isInteger(value) && value >= 0 ? value : null);
+ const podcastId = text(entity.podcast_id, 200);
+ const feedUrl = this.safeHttpUrl(entity.feed_url);
+ const title = text(entity.title, 300).trim();
+ if (!/^pod1:[a-z2-7]{52}$/.test(podcastId) || !feedUrl || !title) return null;
+ const localId = text(entity.local_podcast_id, 200);
+ return {
+ type: 'podcast',
+ podcast_id: podcastId,
+ feed_url: feedUrl,
+ title,
+ author: text(entity.author, 300),
+ description: text(entity.description, 1000),
+ image_url: this.safeImageUrl(entity.image_url),
+ link: this.safeHttpUrl(entity.link),
+ language: text(entity.language, 35),
+ categories: Array.isArray(entity.categories)
+ ? entity.categories.filter(item => typeof item === 'string').slice(0, 8).map(item => item.slice(0, 64))
+ : [],
+ episode_count: count(entity.episode_count),
+ latest_episode_at_ms: count(entity.latest_episode_at_ms),
+ publisher_count: count(entity.publisher_count) || 0,
+ rank: count(entity.rank) ?? Number.MAX_SAFE_INTEGER,
+ exact_match: entity.exact_match === true,
+ subscribed: entity.subscribed === true,
+ local_podcast_id: /^pod1:[a-z2-7]{52}$/.test(localId) ? localId : null,
+ };
+ },
+
+ foundMeta(hit) {
+ if (!hit) return '';
+ const parts = [];
+ if (hit.episode_count != null) parts.push(`${hit.episode_count} ${T.podcastEpisodes}`);
+ if (hit.latest_episode_at_ms) parts.push(`${T.podcastFoundLatest}: ${this.formatDate(hit.latest_episode_at_ms)}`);
+ if (hit.language) parts.push(hit.language);
+ if (hit.categories?.length) parts.push(hit.categories.join(', '));
+ return parts.join(' · ');
+ },
+
+ foundSubtitle(hit) {
+ if (!hit) return '';
+ return [hit.author, hit.episode_count != null ? `${hit.episode_count} ${T.podcastEpisodes}` : '']
+ .filter(Boolean)
+ .join(' · ');
+ },
+
+ foundMore(preview) {
+ const more = Number(preview?.episode_count || 0) - (preview?.episodes?.length || 0);
+ return more > 0 ? T.podcastFoundMore.replace('{count}', String(more)) : '';
+ },
+
+ openFound(hit) {
+ if (GUEST || !hit?.podcast_id || !hit.feed_url) return;
+ this._foundToken += 1;
+ this.found = {
+ hit,
+ preview: null,
+ previewLoading: false,
+ previewError: '',
+ subscribing: false,
+ error: '',
+ message: '',
+ subscribed: hit.subscribed === true,
+ localPodcastId: hit.local_podcast_id || null,
+ };
+ this.loadFoundPreview();
+ },
+
+ closeFound() {
+ this._foundToken += 1;
+ this.found = null;
+ },
+
+ _foundBody(hit) {
+ // The card's id and origin URL, exactly as found: the server
+ // checks that the id comes from this URL.
+ return {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ podcast_id: hit.podcast_id, feed_url: hit.feed_url }),
+ };
+ },
+
+ async loadFoundPreview() {
+ const found = this.found;
+ if (!found || found.previewLoading) return;
+ const token = this._foundToken;
+ this.found = { ...found, previewLoading: true, previewError: '' };
+ try {
+ const preview = await this._json('/api/podcasts/discovery/preview', this._foundBody(found.hit));
+ if (token !== this._foundToken) return;
+ this.found = {
+ ...this.found,
+ preview: {
+ ...preview,
+ image_url: this.safeImageUrl(preview?.image_url),
+ link: this.safeHttpUrl(preview?.link),
+ seasons: Array.isArray(preview?.seasons) ? preview.seasons : [],
+ episodes: Array.isArray(preview?.episodes) ? preview.episodes : [],
+ },
+ previewLoading: false,
+ subscribed: this.found.subscribed || preview?.subscribed === true,
+ localPodcastId: this.found.localPodcastId || preview?.local_podcast_id || null,
+ };
+ } catch (error) {
+ if (token !== this._foundToken) return;
+ this.found = { ...this.found, previewLoading: false, previewError: error.message };
+ }
+ },
+
+ async subscribeFound() {
+ const found = this.found;
+ if (!found || found.subscribing || found.subscribed) return;
+ const token = this._foundToken;
+ this.found = { ...found, subscribing: true, error: '', message: '' };
+ try {
+ const data = await this._json('/api/podcasts/discovery/subscribe', this._foundBody(found.hit));
+ const podcastId = data?.podcast?.podcast_id || found.hit.podcast_id;
+ Alpine.store('library')?.markFoundPodcastSubscribed?.(found.hit.podcast_id, podcastId);
+ this.loadList();
+ if (token !== this._foundToken) return;
+ this.found = {
+ ...this.found,
+ subscribing: false,
+ subscribed: true,
+ localPodcastId: podcastId,
+ message: data?.already_subscribed ? T.podcastAlready : T.podcastFoundDone,
+ };
+ } catch (error) {
+ if (token !== this._foundToken) return;
+ this.found = { ...this.found, subscribing: false, error: error.message };
+ }
+ },
+
+ foundButtonLabel() {
+ return this.found?.subscribing ? T.podcastFoundSubscribing : T.podcastSubscribe;
+ },
+
+ openFoundPodcast() {
+ const podcastId = this.found?.localPodcastId || this.found?.hit?.podcast_id;
+ this.closeFound();
+ if (podcastId) this.open(podcastId);
+ },
+
jamBlocked() {
// A Jam guest controls the host's queue: episodes are private.
return !!Alpine.store('devices')?.isControllingRemoteJam?.();
@@ -4172,7 +4345,7 @@ document.addEventListener('alpine:init', () => {
similaritySearchLabel: '',
similaritySearchError: '',
similaritySearchStats: { loading: false, tracks: 0, artists: 0, peers: 0, elapsed_ms: 0 },
- federationSearch: { loading: false, error: '', artists: [], releases: [], tracks: [] },
+ federationSearch: { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [] },
artistFederation: { loading: false, error: '', releases: [], tracks: [] },
federationPreparing: {},
federationFailures: {},
@@ -5112,7 +5285,7 @@ document.addEventListener('alpine:init', () => {
this.similaritySearchError = '';
this.searchLoading = true;
this.searchResults = null;
- this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [] };
+ this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
this.similaritySearchStats = { loading: true, tracks: 0, artists: 0, peers: 0, elapsed_ms: 0 };
Alpine.store('info').close();
try {
@@ -5254,12 +5427,12 @@ document.addEventListener('alpine:init', () => {
this._federationSearchSource.close();
this._federationSearchSource = null;
}
- this.federationSearch = { loading: false, error: '', artists: [], releases: [], tracks: [] };
+ this.federationSearch = { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
},
startFederationSearch(query) {
this.stopFederationSearch();
- this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [] };
+ this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
const source = new EventSource(`/api/player/federation/search/events?q=${encodeURIComponent(query)}`);
this._federationSearchSource = source;
const updateResults = (kind, keyFor, labelFor, entity) => {
@@ -5312,6 +5485,20 @@ document.addEventListener('alpine:init', () => {
if (!release?.key) return;
updateResults('releases', item => JSON.stringify(item.key || {}), item => item.title, release);
});
+ source.addEventListener('federation.podcast', event => {
+ if (this._federationSearchSource !== source) return;
+ let payload = null;
+ try { payload = JSON.parse(event.data); } catch { return; }
+ // Public podcast cards: typed, sanitized, ordered by their
+ // place among the music results.
+ const hit = Alpine.store('podcasts')?.foundHit?.(payload?.entity);
+ if (!hit) return;
+ const podcasts = (this.federationSearch.podcasts || [])
+ .filter(item => item.podcast_id !== hit.podcast_id);
+ podcasts.push(hit);
+ podcasts.sort((left, right) => left.rank - right.rank);
+ this.federationSearch = { ...this.federationSearch, podcasts };
+ });
source.addEventListener('search.completed', () => {
window.clearTimeout(watchdog);
if (this._federationSearchSource === source) {
@@ -5345,6 +5532,15 @@ document.addEventListener('alpine:init', () => {
};
},
+ markFoundPodcastSubscribed(podcastId, localPodcastId) {
+ const podcasts = (this.federationSearch?.podcasts || []).map(item => (
+ item.podcast_id === podcastId
+ ? { ...item, subscribed: true, local_podcast_id: localPodcastId || item.local_podcast_id }
+ : item
+ ));
+ this.federationSearch = { ...this.federationSearch, podcasts };
+ },
+
normalizeFederationSearchText(value) {
return String(value || '')
.normalize('NFKD')
diff --git a/templates/player/shell.html b/templates/player/shell.html
index e6a65af..8d3dc75 100644
--- a/templates/player/shell.html
+++ b/templates/player/shell.html
@@ -625,6 +625,38 @@
+
+
{{ t.player_podcast_found_title }}
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ t.player_podcast_type }}
+ {{ t.player_podcast_found_subscribed }}
+
+
+
+
+
+
+
{
calls.push({url, init});
if (overrides.respond) return overrides.respond(url, init);
@@ -1100,3 +1100,185 @@ test('Play after a failed source waits for the final report and resumes where th
await flush();
assert.deepEqual(other.calls.map(call => call.url.split('/').pop()), ['playback', 'progress']);
});
+
+// ---------------------------------------------------------------------------
+// Public podcasts in the federated search
+// ---------------------------------------------------------------------------
+
+const POD_A = 'pod1:' + 'a'.repeat(52);
+const POD_B = 'pod1:' + 'b'.repeat(52);
+const POD_LOCAL = 'pod1:' + 'c'.repeat(52);
+
+function foundEntity(extra = {}) {
+ return Object.assign({
+ type: 'podcast', kind: 'podcast', podcast_id: POD_A,
+ feed_url: 'https://feeds.example/show.xml?utm=x', title: 'Night Radio', author: 'Host',
+ description: '
', image_url: 'https://cdn.example/art.jpg',
+ link: 'https://show.example/', language: 'en', categories: ['Technology', 7],
+ episode_count: 12, latest_episode_at_ms: 1700000000000, publisher_count: 2,
+ rank: 1, exact_match: true, subscribed: false, local_podcast_id: null,
+ }, extra);
+}
+
+const FOUND_T = {
+ podcastFoundLatest: 'Latest', podcastFoundMore: 'and {count} more', podcastFoundDone: 'subscribed, private',
+ podcastAlready: 'already', podcastFoundSubscribing: 'subscribing', podcastSubscribe: 'Subscribe',
+};
+
+test('podcast cards from the search keep only typed fields and safe URLs', () => {
+ const {store} = podcastsStore({}, {T: FOUND_T});
+ const hit = store.foundHit(foundEntity());
+ // The feed URL is passed on exactly as found (the server hashes it).
+ assert.equal(hit.feed_url, 'https://feeds.example/show.xml?utm=x');
+ assert.equal(hit.description, '
', 'text stays text (x-text)');
+ assert.deepEqual(Array.from(hit.categories), ['Technology']);
+ assert.equal(hit.image_url, 'https://cdn.example/art.jpg');
+ assert.equal(store.foundMeta(hit).startsWith('12 episodes · Latest: '), true);
+ assert.equal(store.foundSubtitle(hit), 'Host · 12 episodes');
+
+ const unsafe = store.foundHit(foundEntity({
+ link: 'javascript:alert(1)', image_url: 'http://cdn.example/art.jpg',
+ local_podcast_id: 'javascript:x', rank: 'first', subscribed: 'yes',
+ }));
+ assert.equal(unsafe.link, '');
+ assert.equal(unsafe.image_url, '', 'artwork only over https');
+ assert.equal(unsafe.local_podcast_id, null);
+ assert.equal(unsafe.rank, Number.MAX_SAFE_INTEGER);
+ assert.equal(unsafe.subscribed, false);
+ assert.equal(store.foundHit(foundEntity({link: 'https://user:pw@show.example/'})).link, '');
+
+ for (const bad of [
+ foundEntity({type: 'music'}), foundEntity({podcast_id: 'pod1:x'}), foundEntity({feed_url: 'javascript:alert(1)'}),
+ foundEntity({feed_url: 'ftp://feeds.example/show.xml'}), foundEntity({title: ' '}), null, 'podcast',
+ ]) {
+ assert.equal(store.foundHit(bad), null, JSON.stringify(bad));
+ }
+});
+
+test('the federated search shows podcast cards next to music, ordered by rank', () => {
+ const podcasts = podcastsStore({}, {T: FOUND_T}).store;
+ const sources = [];
+ class FakeEventSource {
+ constructor(url) { this.url = url; this.listeners = {}; sources.push(this); }
+ addEventListener(name, listener) { this.listeners[name] = listener; }
+ emit(name, data) { this.listeners[name]({data: JSON.stringify(data)}); }
+ close() { this.closed = true; }
+ }
+ const context = vm.createContext({
+ EventSource: FakeEventSource, encodeURIComponent,
+ window: {setTimeout: () => 1, clearTimeout: () => {}},
+ Alpine: {store: name => (name === 'podcasts' ? podcasts : null)},
+ });
+ vm.runInContext(`this.library = {
+ federationSearch: null, _federationSearchSource: null,
+ federationSearchScore() { return 0; },
+ withTrackAvailability(track) { return track; },
+ withFederationArtistFallback(artist) { return artist; },
+ hydrateFederationSearchRelease(release) { return release; },
+ ${method('stopFederationSearch')}
+ ${method('startFederationSearch')}
+ ${method('markFoundPodcastSubscribed')}
+ };`, context);
+ const library = context.library;
+ library.startFederationSearch('night radio');
+ const source = sources[0];
+ assert.equal(source.url, '/api/player/federation/search/events?q=night%20radio');
+ assert.deepEqual(Array.from(library.federationSearch.podcasts), []);
+
+ // Music events are handled as before.
+ source.emit('federation.track', {type: 'music', kind: 'federation.track', entity: {key: {content_id: 'b3:1'}, metadata: {title: 'Theme'}}});
+ source.emit('federation.podcast', {type: 'podcast', kind: 'federation.podcast', entity: foundEntity({podcast_id: POD_B, title: 'Night Radio Talks', rank: 3})});
+ source.emit('federation.podcast', {type: 'podcast', kind: 'federation.podcast', entity: foundEntity({rank: 1, subscribed: true, local_podcast_id: POD_LOCAL})});
+ // Not a podcast card: ignored.
+ source.emit('federation.podcast', {entity: {type: 'music', podcast_id: POD_A}});
+ // The same podcast again replaces its card.
+ source.emit('federation.podcast', {entity: foundEntity({podcast_id: POD_B, title: 'Night Radio Talks', rank: 3, author: 'New host'})});
+
+ assert.equal(library.federationSearch.tracks.length, 1);
+ const ids = Array.from(library.federationSearch.podcasts, hit => hit.podcast_id);
+ assert.deepEqual(ids, [POD_A, POD_B]);
+ assert.equal(library.federationSearch.podcasts[0].subscribed, true);
+ assert.equal(library.federationSearch.podcasts[1].author, 'New host');
+
+ library.markFoundPodcastSubscribed(POD_B, POD_B);
+ assert.equal(library.federationSearch.podcasts[1].subscribed, true);
+ assert.equal(library.federationSearch.podcasts[1].local_podcast_id, POD_B);
+
+ source.emit('search.completed', {entity: {partial: false, podcast_discovery: 'running'}});
+ assert.equal(library.federationSearch.loading, false);
+ assert.equal(source.closed, true);
+ // Events of a closed search change nothing.
+ library.startFederationSearch('other');
+ source.emit('federation.podcast', {entity: foundEntity()});
+ assert.deepEqual(Array.from(library.federationSearch.podcasts), []);
+});
+
+test('a found podcast is previewed, then subscribed with the card id and origin URL', async () => {
+ const answers = [];
+ const marked = [];
+ const library = {markFoundPodcastSubscribed: (id, local) => marked.push([id, local])};
+ const {store, calls} = podcastsStore({library}, {T: FOUND_T, respond: async () => answers.shift()});
+ let listLoads = 0;
+ store.loadList = () => { listLoads += 1; };
+ const opened = [];
+ store.open = id => opened.push(id);
+ const hit = store.foundHit(foundEntity());
+
+ answers.push({ok: true, status: 200, json: async () => ({
+ podcast_id: POD_A, feed_url: hit.feed_url, moved: false, title: 'Night Radio',
+ link: 'javascript:alert(1)', image_url: 'https://cdn.example/feed.jpg', episode_count: 60,
+ seasons: [{season: 1, episode_count: 59}, {season: null, episode_count: 1}],
+ episodes: [{title: 'Newest', season: 1, episode_number: 59, duration_ms: 60000}],
+ subscribed: false, local_podcast_id: null,
+ })});
+ store.openFound(hit);
+ assert.equal(store.found.previewLoading, true);
+ await new Promise(resolve => setImmediate(resolve));
+ assert.equal(calls[0].url, '/api/podcasts/discovery/preview');
+ assert.equal(calls[0].init.method, 'POST');
+ assert.equal(calls[0].init.headers['Content-Type'], 'application/json');
+ assert.deepEqual(JSON.parse(calls[0].init.body), {podcast_id: POD_A, feed_url: 'https://feeds.example/show.xml?utm=x'});
+ assert.equal(store.found.previewLoading, false);
+ assert.equal(store.found.preview.link, '', 'feed links are checked too');
+ assert.equal(store.found.preview.episodes[0].title, 'Newest');
+ assert.equal(store.foundMore(store.found.preview), 'and 59 more');
+ assert.equal(store.foundButtonLabel(), 'Subscribe');
+
+ // Subscribing: the account already knew the feed under another id.
+ answers.push({ok: true, status: 200, json: async () => ({podcast: {podcast_id: POD_LOCAL}, already_subscribed: false, new_episodes: 60})});
+ const pending = store.subscribeFound();
+ assert.equal(store.foundButtonLabel(), 'subscribing');
+ await pending;
+ assert.equal(calls[1].url, '/api/podcasts/discovery/subscribe');
+ assert.deepEqual(JSON.parse(calls[1].init.body), {podcast_id: POD_A, feed_url: 'https://feeds.example/show.xml?utm=x'});
+ assert.deepEqual(marked, [[POD_A, POD_LOCAL]]);
+ assert.equal(listLoads, 1);
+ assert.equal(store.found.subscribed, true);
+ assert.equal(store.found.message, 'subscribed, private');
+ // Subscribed: the button opens the account's podcast; no second request.
+ await store.subscribeFound();
+ assert.equal(calls.length, 2);
+ store.openFoundPodcast();
+ assert.equal(store.found, null);
+ assert.deepEqual(opened, [POD_LOCAL]);
+
+ // An already subscribed card opens directly; a failure is shown.
+ answers.push({ok: true, status: 200, json: async () => ({podcast_id: POD_A, seasons: [], episodes: [], episode_count: 0})});
+ store.openFound(store.foundHit(foundEntity({subscribed: true, local_podcast_id: POD_LOCAL})));
+ assert.equal(store.found.subscribed, true);
+ await new Promise(resolve => setImmediate(resolve));
+ store.found.subscribed = false;
+ answers.push({ok: false, status: 502, json: async () => ({error: 'the feed could not be loaded: timeout'})});
+ await store.subscribeFound();
+ assert.equal(store.found.error, 'the feed could not be loaded: timeout');
+ assert.equal(store.found.subscribing, false);
+
+ // Closing during the preview drops its late answer.
+ let release;
+ answers.push(new Promise(resolve => { release = resolve; }));
+ store.openFound(hit);
+ store.closeFound();
+ release({ok: true, status: 200, json: async () => ({title: 'late'})});
+ await new Promise(resolve => setImmediate(resolve));
+ assert.equal(store.found, null);
+});