Add a share toggle to the Podcasts tab
Shift+F in the podcasts context shares the selected or opened podcast through PodcastStore::set_shared (a synced decision) or makes it private again. A feed URL that looks private is confirmed first in a dialog that lists the warnings in Russian. The reconciler runs after share and unsubscribe actions, received podcast operations, feed refreshes, overlay restarts and periodically; the list and side panel show the shared and published state and publication errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c90035fa2
commit
8f4e58d8af
14 files changed
+943
-8
No files matched your search
@@ -181,6 +181,74 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn podcast_share_state_is_shown_in_the_list_and_details() {
|
||||
use crate::podcasts::publication::{Discovery, Publication};
|
||||
let mut state =
|
||||
podcast_fixtures::ready_state(vec![podcast_fixtures::row("Test Show", 0, 3, 0)]);
|
||||
state.podcasts.selected = crate::app::state::PODCAST_ACTION_ROWS;
|
||||
let screen = render(&state, 110, 30);
|
||||
assert!(screen.contains("private (not shared"), "{screen}");
|
||||
assert!(!screen.contains("shared · 3 ep"), "{screen}");
|
||||
|
||||
let mut row = podcast_fixtures::row("Test Show", 0, 3, 0);
|
||||
row.summary.shared = true;
|
||||
let mut state = podcast_fixtures::ready_state(vec![row]);
|
||||
state.podcasts.selected = crate::app::state::PODCAST_ACTION_ROWS;
|
||||
state.podcasts.publication.discovery = Discovery::Running { peers: 2 };
|
||||
state
|
||||
.podcasts
|
||||
.publication
|
||||
.podcasts
|
||||
.insert(podcast_fixtures::podcast_id(), Publication::Published);
|
||||
let screen = render(&state, 110, 30);
|
||||
assert!(screen.contains("shared · 3 ep"), "{screen}");
|
||||
assert!(screen.contains("shared · published from"), "{screen}");
|
||||
|
||||
state.podcasts.publication.podcasts.insert(
|
||||
podcast_fixtures::podcast_id(),
|
||||
Publication::HeldBack(Vec::new()),
|
||||
);
|
||||
let screen = render(&state, 110, 30);
|
||||
assert!(screen.contains("held back"), "{screen}");
|
||||
|
||||
state.podcasts.publication.discovery = Discovery::Off("federation is off".into());
|
||||
let screen = render(&state, 110, 30);
|
||||
assert!(screen.contains("not published:"), "{screen}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn podcast_share_confirmation_lists_the_warnings_in_russian() {
|
||||
let mut state =
|
||||
podcast_fixtures::ready_state(vec![podcast_fixtures::row("Test Show", 0, 1, 0)]);
|
||||
state.popup = Some(crate::app::state::Popup::ConfirmPodcastShare {
|
||||
podcast_id: podcast_fixtures::podcast_id(),
|
||||
title: "Test Show".into(),
|
||||
urls: crate::podcasts::publication::ConfirmedUrls {
|
||||
feed_url: music_dht::podcast::FeedUrl::parse(
|
||||
"https://example.test/feed.xml?token=abc",
|
||||
)
|
||||
.unwrap(),
|
||||
id_feed_url: None,
|
||||
},
|
||||
warnings: vec!["в адресе ленты есть параметр «token», похожий на ключ доступа".into()],
|
||||
already_shared: false,
|
||||
});
|
||||
let screen = render(&state, 100, 30);
|
||||
assert!(
|
||||
screen.contains("Поделиться подкастом «Test Show»"),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(screen.contains("Адрес похож на личный"), "{screen}");
|
||||
assert!(screen.contains("параметр «token»"), "{screen}");
|
||||
assert!(screen.contains("feed.xml?token=abc"), "{screen}");
|
||||
assert!(
|
||||
screen.contains("enter/y опубликовать · esc/n отмена"),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(!screen.contains("x не делиться"), "{screen}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn podcast_seasons_and_episodes_render_progress() {
|
||||
use music_dht::podcast::ProgressStatus;
|
||||
|
||||
+43
-2
@@ -17,6 +17,7 @@ use crate::app::state::{
|
||||
PodcastStoreStatus, SeasonRow,
|
||||
};
|
||||
use crate::app::update::podcasts::{played_label, sort_label};
|
||||
use crate::podcasts::publication::{Discovery, Publication};
|
||||
|
||||
/// Width below which the side panel with the cover is dropped.
|
||||
const SIDE_PANEL_MIN_TOTAL_WIDTH: u16 = 80;
|
||||
@@ -219,7 +220,7 @@ fn list_row(state: &AppState, row: PodcastListRow, width: u16) -> (Line<'static>
|
||||
Span::raw(" ")
|
||||
};
|
||||
let summary = &podcast.summary;
|
||||
let meta = if summary.unplayed_count > 0 {
|
||||
let mut meta = if summary.unplayed_count > 0 {
|
||||
format!(
|
||||
"{} unplayed · {} ep",
|
||||
summary.unplayed_count, summary.episode_count
|
||||
@@ -227,6 +228,9 @@ fn list_row(state: &AppState, row: PodcastListRow, width: u16) -> (Line<'static>
|
||||
} else {
|
||||
format!("{} ep", summary.episode_count)
|
||||
};
|
||||
if summary.shared {
|
||||
meta = format!("shared · {meta}");
|
||||
}
|
||||
let title_width = usize::from(width).saturating_sub(2 + meta.width() + 2);
|
||||
let left = Line::from(vec![
|
||||
marker,
|
||||
@@ -293,7 +297,7 @@ fn draw_side_panel(frame: &mut Frame, area: Rect, state: &AppState, podcast: Opt
|
||||
counts.push_str(&format!(" · {} seasons", summary.season_count));
|
||||
}
|
||||
lines.push(Line::styled(counts, theme::dim()));
|
||||
lines.push(Line::styled("private", theme::dim()));
|
||||
lines.push(share_status_line(state, podcast));
|
||||
lines.push(fetch_status_line(state, podcast));
|
||||
if let Some(description) = &summary.meta.description {
|
||||
lines.push(Line::raw(""));
|
||||
@@ -302,6 +306,43 @@ fn draw_side_panel(frame: &mut Frame, area: Rect, state: &AppState, podcast: Opt
|
||||
frame.render_widget(Paragraph::new(lines).wrap(Wrap { trim: true }), text_area);
|
||||
}
|
||||
|
||||
/// Public discovery state of one podcast: private, or shared and whether
|
||||
/// this device publishes its card.
|
||||
pub(crate) fn share_status_line(state: &AppState, podcast: &PodcastRow) -> Line<'static> {
|
||||
let tab = &state.podcasts;
|
||||
if tab.share_busy.contains(podcast.id()) {
|
||||
return loading_line(state, "saving the share setting…");
|
||||
}
|
||||
if !podcast.summary.shared {
|
||||
return Line::styled("private (not shared in the federation)", theme::dim());
|
||||
}
|
||||
let report = &tab.publication;
|
||||
let (text, style) = match (&report.discovery, report.podcasts.get(podcast.id())) {
|
||||
(Discovery::Off(reason), _) => (format!("shared · not published: {reason}"), theme::dim()),
|
||||
(_, Some(Publication::HeldBack(_))) => (
|
||||
"shared · held back on this device: the feed URL looks private, \
|
||||
press Shift+F to confirm"
|
||||
.to_string(),
|
||||
Style::new().fg(Color::Yellow),
|
||||
),
|
||||
(_, Some(Publication::Failed(error))) => {
|
||||
(format!("shared · not published: {error}"), error_style())
|
||||
}
|
||||
(Discovery::Running { peers: 0 }, Some(Publication::Published)) => (
|
||||
"shared · published from this device (no discovery peers yet)".to_string(),
|
||||
theme::accent_for(state),
|
||||
),
|
||||
(_, Some(Publication::Published)) => (
|
||||
"shared · published from this device".to_string(),
|
||||
theme::accent_for(state),
|
||||
),
|
||||
(Discovery::Starting, _) | (_, Some(Publication::Pending) | None) => {
|
||||
return loading_line(state, "shared · publishing…");
|
||||
}
|
||||
};
|
||||
Line::styled(text, style)
|
||||
}
|
||||
|
||||
/// Refresh status of one podcast: checking, the last error, or when it was
|
||||
/// last checked.
|
||||
fn fetch_status_line(state: &AppState, podcast: &PodcastRow) -> Line<'static> {
|
||||
|
||||
@@ -28,6 +28,13 @@ pub fn draw(frame: &mut Frame, state: &AppState) {
|
||||
Some(Popup::ConfirmPodcastUnsubscribe { title, .. }) => {
|
||||
draw_confirm_podcast_unsubscribe(frame, state, title)
|
||||
}
|
||||
Some(Popup::ConfirmPodcastShare {
|
||||
title,
|
||||
urls,
|
||||
warnings,
|
||||
already_shared,
|
||||
..
|
||||
}) => draw_confirm_podcast_share(frame, state, title, urls, warnings, *already_shared),
|
||||
Some(Popup::SimilarityPrivacyConsent { .. }) => {
|
||||
draw_similarity_privacy_consent(frame, state)
|
||||
}
|
||||
@@ -1318,6 +1325,87 @@ fn draw_confirm_podcast_unsubscribe(frame: &mut Frame, state: &AppState, title:
|
||||
);
|
||||
}
|
||||
|
||||
/// Sharing a podcast whose feed URL looks private. In Russian: the warning
|
||||
/// is about the user's own secret, so it must not be missed.
|
||||
fn draw_confirm_podcast_share(
|
||||
frame: &mut Frame,
|
||||
state: &AppState,
|
||||
title: &str,
|
||||
urls: &crate::podcasts::publication::ConfirmedUrls,
|
||||
warnings: &[String],
|
||||
already_shared: bool,
|
||||
) {
|
||||
let width = 78.min(frame.area().width.saturating_sub(4)).max(30);
|
||||
let mut lines = vec![
|
||||
Line::styled(
|
||||
format!("Поделиться подкастом «{title}» в федерации?"),
|
||||
ratatui::style::Style::new().add_modifier(ratatui::style::Modifier::BOLD),
|
||||
),
|
||||
Line::raw(""),
|
||||
Line::raw(
|
||||
"Карточка с адресом RSS-ленты станет видна всем участникам федерации, \
|
||||
и любой из них сможет читать ленту по этому адресу.",
|
||||
),
|
||||
Line::raw(""),
|
||||
Line::styled(
|
||||
"Адрес похож на личный:",
|
||||
ratatui::style::Style::new().fg(ratatui::style::Color::Yellow),
|
||||
),
|
||||
];
|
||||
lines.extend(warnings.iter().map(|warning| {
|
||||
Line::styled(
|
||||
format!("• {warning}"),
|
||||
ratatui::style::Style::new().fg(ratatui::style::Color::Yellow),
|
||||
)
|
||||
}));
|
||||
lines.push(Line::raw(""));
|
||||
lines.push(Line::styled(
|
||||
format!("Лента: {}", urls.feed_url.as_str()),
|
||||
theme::dim(),
|
||||
));
|
||||
if let Some(origin) = &urls.id_feed_url {
|
||||
lines.push(Line::styled(
|
||||
format!("Исходный адрес: {}", origin.as_str()),
|
||||
theme::dim(),
|
||||
));
|
||||
}
|
||||
lines.push(Line::raw(""));
|
||||
lines.push(Line::styled(
|
||||
"Публикацию можно отозвать, но копии, которые уже получили другие, \
|
||||
отозвать нельзя. Подтверждение хранится только на этом устройстве.",
|
||||
theme::dim(),
|
||||
));
|
||||
let footer = if already_shared {
|
||||
"enter/y опубликовать · x не делиться · esc/n отмена"
|
||||
} else {
|
||||
"enter/y опубликовать · esc/n отмена"
|
||||
};
|
||||
let inner_width = width.saturating_sub(2).max(1);
|
||||
let body_height = lines
|
||||
.iter()
|
||||
.map(|line| {
|
||||
let text_width = line.width().max(1) as u16;
|
||||
text_width.div_ceil(inner_width)
|
||||
})
|
||||
.sum::<u16>();
|
||||
let height = (body_height + 4).min(frame.area().height.saturating_sub(2));
|
||||
let area = centered(frame.area(), width, height);
|
||||
let block = Block::bordered()
|
||||
.title(" Поделиться в федерации ")
|
||||
.title_style(theme::header_for(state))
|
||||
.border_style(theme::strong_border_for(state));
|
||||
let inner = block.inner(area);
|
||||
frame.render_widget(Clear, area);
|
||||
frame.render_widget(block, area);
|
||||
let [body, footer_area] =
|
||||
Layout::vertical([Constraint::Min(1), Constraint::Length(1)]).areas(inner);
|
||||
frame.render_widget(Paragraph::new(lines).wrap(Wrap { trim: false }), body);
|
||||
frame.render_widget(
|
||||
Paragraph::new(Line::styled(footer, theme::dim())).alignment(Alignment::Center),
|
||||
footer_area,
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_log_detail(frame: &mut Frame, state: &AppState, entry: &crate::config::logging::LogEntry) {
|
||||
let width = 90.min(frame.area().width.saturating_sub(4)).max(40);
|
||||
let height = 18.min(frame.area().height.saturating_sub(2)).max(7);
|
||||
|
||||
Reference in new issue
Block a user