forked from Keelrleek/SoulStream
shared playlists: a follow with news says so through a toast, and a follower's rows keep the owner's catalog ids
This commit is contained in:
1 parent
594a33a302
commit
8285b97cbe
5 files changed
+320
-5
No files matched your search
@@ -149,6 +149,11 @@ pub struct ShareEntry {
|
||||
pub album: String,
|
||||
pub duration_secs: Option<u32>,
|
||||
pub note: Option<String>,
|
||||
/// The owner's catalog id for the recording (Deezer), when their row
|
||||
/// had one. It rides the manifest already; carrying it here lets an
|
||||
/// import or an Update stream the row by identity instead of by name.
|
||||
#[serde(default)]
|
||||
pub track_id: Option<String>,
|
||||
}
|
||||
|
||||
/// A fetched, VERIFIED shared playlist as the reader sees it.
|
||||
@@ -458,6 +463,25 @@ fn share_entry(e: &pl::EntryV1) -> ShareEntry {
|
||||
album: e.recording.album.clone(),
|
||||
duration_secs: e.recording.duration_ms.map(|ms| ms / 1000),
|
||||
note: e.note.clone(),
|
||||
track_id: e.recording.deezer_id.clone().filter(|id| !id.trim().is_empty()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A shared row's catalog id, laid onto the draft row the resolve made
|
||||
/// from it. `ParsedEntry` has no id column — the import doors take text
|
||||
/// lines — so the id joins after the resolve, by ordinal. A row that
|
||||
/// matched a library file keeps the id too: it plays from the file, and
|
||||
/// the id is what the catalog knows it as. Only numeric ids qualify; the
|
||||
/// row column is the catalog's integer key.
|
||||
fn attach_catalog_ids(draft: &mut ImportDraft, entries: &[ShareEntry]) {
|
||||
let ids: std::collections::HashMap<u32, i64> = entries
|
||||
.iter()
|
||||
.filter_map(|e| Some((e.position + 1, e.track_id.as_deref()?.trim().parse::<i64>().ok()?)))
|
||||
.collect();
|
||||
for row in &mut draft.entries {
|
||||
if row.track_id.is_none() {
|
||||
row.track_id = ids.get(&row.ordinal).copied();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,7 +712,9 @@ pub async fn import(
|
||||
Staged { hash: v.content_hash.clone(), seq: v.revision_seq, name: v.name.clone() },
|
||||
);
|
||||
let parsed = parsed_from(&v.name, &v.description, &v.entries);
|
||||
playlists::resolve_draft(lib, parsed, format!("SoulStream · {}", v.name), None).await
|
||||
let mut draft = playlists::resolve_draft(lib, parsed, format!("SoulStream · {}", v.name), None).await?;
|
||||
attach_catalog_ids(&mut draft, &v.entries);
|
||||
Ok(draft)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- following
|
||||
@@ -788,6 +814,37 @@ pub struct FollowCheck {
|
||||
/// Follows whose pointer moved since the previous check.
|
||||
pub changed: u32,
|
||||
pub errors: u32,
|
||||
/// The moves that are news — a revision with rows the synced one never
|
||||
/// had, or fewer of them. What the background poll announces; a
|
||||
/// withdrawal is a state the playlist page shows, not news.
|
||||
#[serde(default)]
|
||||
pub news: Vec<FollowNews>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
pub struct FollowNews {
|
||||
pub owner_key: String,
|
||||
pub playlist_uuid: String,
|
||||
pub playlist_id: i64,
|
||||
pub name: String,
|
||||
pub added: u32,
|
||||
pub removed: u32,
|
||||
}
|
||||
|
||||
/// What a check found, if it is worth a word: only a live revision that
|
||||
/// differs from the synced one by rows.
|
||||
fn news_of(f: &Follow, seen: &Seen) -> Option<FollowNews> {
|
||||
if seen.withdrawn || (seen.added.is_empty() && seen.removed == 0) {
|
||||
return None;
|
||||
}
|
||||
Some(FollowNews {
|
||||
owner_key: f.owner_key.clone(),
|
||||
playlist_uuid: f.playlist_uuid.clone(),
|
||||
playlist_id: f.playlist_id,
|
||||
name: seen.name.clone().unwrap_or_else(|| f.name.clone()),
|
||||
added: seen.added.len() as u32,
|
||||
removed: seen.removed,
|
||||
})
|
||||
}
|
||||
|
||||
/// What one check found: the pointer's revision, diffed against the synced
|
||||
@@ -860,6 +917,7 @@ pub async fn check_follows(app: &tauri::AppHandle) -> Result<FollowCheck, String
|
||||
match result {
|
||||
Ok(Some(seen)) => {
|
||||
out.changed += 1;
|
||||
out.news.extend(news_of(live, &seen));
|
||||
if seen.withdrawn {
|
||||
log::info!("shared playlists: {:?} was withdrawn by its owner", live.name);
|
||||
} else {
|
||||
@@ -922,7 +980,8 @@ pub async fn follow_update(
|
||||
let mut appended = 0;
|
||||
if !f.added.is_empty() {
|
||||
let parsed = parsed_from(&f.name, "", &f.added);
|
||||
let draft = playlists::resolve_draft(lib, parsed, format!("SoulStream · {}", f.name), None).await?;
|
||||
let mut draft = playlists::resolve_draft(lib, parsed, format!("SoulStream · {}", f.name), None).await?;
|
||||
attach_catalog_ids(&mut draft, &f.added);
|
||||
let rows: Vec<NewPlaylistItem> = draft.entries.into_iter().map(new_row).collect();
|
||||
let l = lib.library.clone();
|
||||
let pid = f.playlist_id;
|
||||
@@ -1222,6 +1281,108 @@ mod tests {
|
||||
assert_eq!(f.removed, 0);
|
||||
}
|
||||
|
||||
fn draft_row(ordinal: u32, track_id: Option<i64>) -> DraftEntry {
|
||||
DraftEntry {
|
||||
ordinal,
|
||||
title: "Black Cat".into(),
|
||||
artist: "Broadcast".into(),
|
||||
album: None,
|
||||
duration_secs: None,
|
||||
start_ms: None,
|
||||
raw: String::new(),
|
||||
resolution: "stream".into(),
|
||||
matched_by: None,
|
||||
path: None,
|
||||
art_path: None,
|
||||
track_id,
|
||||
art_url: None,
|
||||
isrc: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The owner's Deezer id rides the manifest already; the reader keeps
|
||||
/// it, and it lands on the draft row the resolve made — by ordinal,
|
||||
/// numeric only, never over an id the review already attached.
|
||||
#[test]
|
||||
fn a_shared_row_carries_the_owners_catalog_id_onto_the_draft() {
|
||||
let mut with = entry(1, 0, "Black Cat");
|
||||
with.recording.deezer_id = Some("3135556".into());
|
||||
let mut junk = entry(2, 1, "Corporeal");
|
||||
junk.recording.deezer_id = Some("not-a-number".into());
|
||||
let mut blank = entry(3, 2, "Tears in the Typing Pool");
|
||||
blank.recording.deezer_id = Some(" ".into());
|
||||
let mut kept = entry(4, 3, "Michael A Grammar");
|
||||
kept.recording.deezer_id = Some("999".into());
|
||||
let entries: Vec<ShareEntry> = [with, junk, blank, kept].iter().map(share_entry).collect();
|
||||
assert_eq!(entries[0].track_id.as_deref(), Some("3135556"));
|
||||
assert_eq!(entries[2].track_id, None);
|
||||
|
||||
let mut draft = ImportDraft {
|
||||
source_name: String::new(),
|
||||
format: "soulstream".into(),
|
||||
name: None,
|
||||
description: None,
|
||||
kind: "manual".into(),
|
||||
entries: vec![draft_row(1, None), draft_row(2, None), draft_row(3, None), draft_row(4, Some(42))],
|
||||
warnings: vec![],
|
||||
resolved_count: 0,
|
||||
stream_count: 4,
|
||||
unresolved_count: 0,
|
||||
cover_url: None,
|
||||
};
|
||||
attach_catalog_ids(&mut draft, &entries);
|
||||
let ids: Vec<Option<i64>> = draft.entries.iter().map(|r| r.track_id).collect();
|
||||
assert_eq!(ids, [Some(3135556), None, None, Some(42)]);
|
||||
|
||||
// An older ledger's rows have no id column and still load.
|
||||
let old: ShareEntry = serde_json::from_str(
|
||||
r#"{"entry_id":"x","position":0,"title":"t","artist":"a","album":"","duration_secs":null,"note":null}"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(old.track_id, None);
|
||||
}
|
||||
|
||||
/// Only a live revision that differs by rows is news: a withdrawal is
|
||||
/// a state the playlist page shows, and a pointer that moved to a
|
||||
/// reorder has nothing to announce.
|
||||
#[test]
|
||||
fn only_a_revision_with_rows_to_report_is_news() {
|
||||
let f = Follow {
|
||||
owner_key: "owner".into(),
|
||||
playlist_uuid: "uuid".into(),
|
||||
playlist_id: 4,
|
||||
name: "Tender Buttons".into(),
|
||||
synced_hash: "h1".into(),
|
||||
synced_seq: 1,
|
||||
synced_at: 10,
|
||||
followed_at: 10,
|
||||
checked_at: 20,
|
||||
seen_hash: "h1".into(),
|
||||
seen_seq: 1,
|
||||
withdrawn: false,
|
||||
added: vec![],
|
||||
removed: 0,
|
||||
last_error: None,
|
||||
};
|
||||
let quiet = Seen { hash: "h2".into(), seq: 2, withdrawn: false, name: None, added: vec![], removed: 0 };
|
||||
assert_eq!(news_of(&f, &quiet), None);
|
||||
let gone = Seen { hash: String::new(), seq: 0, withdrawn: true, name: None, added: vec![], removed: 0 };
|
||||
assert_eq!(news_of(&f, &gone), None);
|
||||
let (added, removed) = diff_entries(&[entry(1, 0, "Black Cat")], &[entry(2, 0, "Corporeal"), entry(3, 1, "Pendulum")]);
|
||||
let moved = Seen { hash: "h2".into(), seq: 2, withdrawn: false, name: Some("Tender Buttons (2005)".into()), added, removed };
|
||||
assert_eq!(
|
||||
news_of(&f, &moved),
|
||||
Some(FollowNews {
|
||||
owner_key: "owner".into(),
|
||||
playlist_uuid: "uuid".into(),
|
||||
playlist_id: 4,
|
||||
name: "Tender Buttons (2005)".into(),
|
||||
added: 2,
|
||||
removed: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/// The bundled contracts are commitments (copy-forward is disabled
|
||||
/// upstream): a changed wasm re-keys every published playlist.
|
||||
#[test]
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
import ResolverToast from "./components/ResolverToast.svelte";
|
||||
import UploadToast from "./components/UploadToast.svelte";
|
||||
import ProposalToast from "./components/ProposalToast.svelte";
|
||||
import FollowNewsToast from "./components/FollowNewsToast.svelte";
|
||||
import SetlistScanChip from "./components/SetlistScanChip.svelte";
|
||||
import {
|
||||
ui,
|
||||
@@ -186,6 +187,7 @@
|
||||
<ResolverToast />
|
||||
<UploadToast />
|
||||
<ProposalToast />
|
||||
<FollowNewsToast />
|
||||
<SetlistScanChip />
|
||||
<PreviewOverlay />
|
||||
<LyricsSyncEditor />
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<script>
|
||||
// A playlist this device follows has news. The follow poll runs every
|
||||
// ten minutes without a word, and its Inbox card is only on the Inbox,
|
||||
// so the owner's new tracks would otherwise arrive in silence — the
|
||||
// same gap the proposal toast closes for the board. Same slot, pill and
|
||||
// motion; like that toast, several playlists inside the window count up
|
||||
// in one pill rather than stacking.
|
||||
import Icon from "./Icon.svelte";
|
||||
import { followNewsToast } from "../lib/state.svelte.js";
|
||||
|
||||
const HOLD_MS = 4200;
|
||||
const LEAVE_MS = 280;
|
||||
|
||||
const line = $derived.by(() => {
|
||||
const t = followNewsToast;
|
||||
const tracks = (n) => `${n} new ${n === 1 ? "track" : "tracks"}`;
|
||||
if (t.count > 1) return { lead: `${t.count} playlists you follow`, rest: " have new tracks" };
|
||||
if (t.added) return { lead: t.name, rest: `: ${tracks(t.added)} since you imported it${t.removed ? ` · ${t.removed} removed` : ""}` };
|
||||
return { lead: t.name, rest: `: the owner removed ${t.removed} ${t.removed === 1 ? "track" : "tracks"}` };
|
||||
});
|
||||
|
||||
let shown = $state(false);
|
||||
let leaving = $state(false);
|
||||
let holdTimer = 0;
|
||||
let leaveTimer = 0;
|
||||
|
||||
$effect(() => {
|
||||
const seq = followNewsToast.seq;
|
||||
if (!seq) return;
|
||||
clearTimeout(holdTimer);
|
||||
clearTimeout(leaveTimer);
|
||||
leaving = false;
|
||||
shown = true;
|
||||
holdTimer = setTimeout(() => {
|
||||
leaving = true;
|
||||
leaveTimer = setTimeout(() => {
|
||||
shown = false;
|
||||
leaving = false;
|
||||
}, LEAVE_MS);
|
||||
}, HOLD_MS);
|
||||
return () => {
|
||||
clearTimeout(holdTimer);
|
||||
clearTimeout(leaveTimer);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if shown}
|
||||
<div class="layer" aria-live="polite">
|
||||
<div class="toast" class:leaving>
|
||||
<span class="mark"><Icon name="playlist" size={14} /></span>
|
||||
<span class="text"><b>{line.lead}</b>{line.rest}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
/* The shared toast slot — UploadToast's geometry verbatim. */
|
||||
.layer {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: calc(var(--player-height, 62px) + 8px + 26px);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
z-index: 80;
|
||||
pointer-events: none;
|
||||
}
|
||||
.toast {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
max-width: min(70vw, 560px);
|
||||
padding: 9px 16px;
|
||||
border-radius: 99px;
|
||||
background: rgba(22, 23, 28, 0.94);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
backdrop-filter: blur(14px);
|
||||
-webkit-backdrop-filter: blur(14px);
|
||||
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
|
||||
font-size: 12.5px;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
animation: toast-in 340ms cubic-bezier(0.22, 1, 0.36, 1) both;
|
||||
}
|
||||
.toast.leaving {
|
||||
animation: toast-out 260ms ease both;
|
||||
}
|
||||
@keyframes toast-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(16px) scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
@keyframes toast-out {
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: translateY(12px) scale(0.97);
|
||||
}
|
||||
}
|
||||
.mark {
|
||||
display: inline-flex;
|
||||
color: var(--accent);
|
||||
}
|
||||
.text {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
b {
|
||||
font-weight: 800;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.toast,
|
||||
.toast.leaving {
|
||||
animation-duration: 1ms;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -8,7 +8,7 @@
|
||||
// <time>", never "online"; and the adapter's states are named for what they
|
||||
// are (node stopped, incompatible, connecting), never softened.
|
||||
import * as api from "./api.js";
|
||||
import { announceProposal } from "./state.svelte.js";
|
||||
import { announceProposal, announceFollowNews } from "./state.svelte.js";
|
||||
|
||||
const LS_SEEN = "community.lastSeen";
|
||||
const LS_FAVS = "community.roomFavs";
|
||||
@@ -401,7 +401,10 @@ export async function startInboxWatch() {
|
||||
}
|
||||
|
||||
/** One pass over the followed playlists, quiet like the inbox poll: the
|
||||
* backend logs what it found, and a card appears only when there is news. */
|
||||
* backend logs what it found, a card appears only when there is news, and
|
||||
* the news itself is the one thing that speaks — a toast per playlist the
|
||||
* owner changed by rows. Only the poll announces: Check now on the share
|
||||
* sheet reports in place, where the person is already looking. */
|
||||
async function pollFollows() {
|
||||
if (checkingFollows || community.busy["followcheck"]) return;
|
||||
checkingFollows = true;
|
||||
@@ -409,8 +412,9 @@ async function pollFollows() {
|
||||
if (!adapterConnected(community.freenet?.status)) return;
|
||||
await refreshFollowing();
|
||||
if (!community.following.length) return;
|
||||
await api.sharedPlaylistsCheck();
|
||||
const r = await api.sharedPlaylistsCheck();
|
||||
await refreshFollowing();
|
||||
for (const n of r?.news ?? []) announceFollowNews(n.name, n.added, n.removed);
|
||||
} catch {
|
||||
// Never surfaces; the Check now button is the one that reports.
|
||||
} finally {
|
||||
|
||||
@@ -256,6 +256,30 @@ export function announceProposal(from, playlist) {
|
||||
proposalToast.seq += 1;
|
||||
}
|
||||
|
||||
/** A playlist this device follows has news (FollowNewsToast): the owner's
|
||||
* revision added rows, or dropped some. The follow poll runs every ten
|
||||
* minutes in silence and the Inbox card only shows when the page is open,
|
||||
* so without this a new track arrives unannounced. One poll can find news
|
||||
* on several follows at once: a second playlist inside the window counts
|
||||
* up ("3 playlists have new tracks") the way a burst of proposals does,
|
||||
* and the same playlist again just replaces its line. */
|
||||
export const followNewsToast = $state({ seq: 0, name: "", added: 0, removed: 0, count: 0 });
|
||||
const FOLLOW_NEWS_TOAST_WINDOW_MS = 8000;
|
||||
let followNewsToastAt = 0;
|
||||
let followNewsToastNames = new Set();
|
||||
|
||||
export function announceFollowNews(name, added, removed) {
|
||||
const now = Date.now();
|
||||
if (now - followNewsToastAt >= FOLLOW_NEWS_TOAST_WINDOW_MS) followNewsToastNames = new Set();
|
||||
followNewsToastNames.add(name);
|
||||
followNewsToast.count = followNewsToastNames.size;
|
||||
followNewsToast.name = name;
|
||||
followNewsToast.added = added;
|
||||
followNewsToast.removed = removed;
|
||||
followNewsToastAt = now;
|
||||
followNewsToast.seq += 1;
|
||||
}
|
||||
|
||||
/** Background-import status, read by ImportToast. The import window keeps
|
||||
* scanning/copying after it is closed (the component stays mounted, only
|
||||
* its template goes), and closed must never mean invisible: while work
|
||||
@@ -7809,6 +7833,7 @@ if (import.meta.env.DEV) {
|
||||
playlistStore, refreshPlaylists, goToView, peekNextIndices,
|
||||
slsk, search, runSearch, uploadToast, announceUpload,
|
||||
proposalToast, announceProposal,
|
||||
followNewsToast, announceFollowNews,
|
||||
searchTabs, selectSearchTab, closeSearchTab, filesForGroup,
|
||||
downloads, network, sendDm, openChat,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user