v4: a dump or playlist going public notifies its followers — a private dump notified no one when posted, and nothing told its followers when it was made public: the poster's followers never learnt of it, nor did the followers of the public playlists holding it. Likewise, the dumps added to a playlist while it was private were never notified to its followers. updateDump and replaceFileDump now call notifyIfWentPublic, which notifies the poster's followers (user_dump_posted) and, through the new notifyPlaylistFollowersNowPublic, the followers of each public playlist holding the dump (playlist_dump_added). updatePlaylist calls the same function when a playlist goes public, for each public dump in it, from the bottom up. A follower hears of a dump once both it and the playlist are public; the source keys stop a dump made private and public again from notifying twice. 256 backend tests pass, and deno check, deno fmt and doc:lint are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-10-09 10:23:08 +00:00
parent 256857f72e
commit 7713c5a1b5
5 changed files with 142 additions and 6 deletions

View File

@@ -230,7 +230,9 @@ export function notifyPlaylistOwnerNewFollower(
/**
* Notifies everyone following `dumperId` that they posted a dump. The dump
* service calls it for a public dump only, when it is created.
* service calls it for a public dump only, when it is created or goes public.
* A follower is told of a dump once, however often it goes private and public
* again.
*/
export function notifyUserFollowersNewDump(
dumperId: string,
@@ -473,3 +475,46 @@ export function notifyPlaylistFollowersNewDump(
}
});
}
/**
* Notifies the followers of each playlist of the dumps in it that became
* visible to them: a playlist's followers are told of a dump once both are
* public. The dump service calls it with `dumpId` when a dump goes public, for
* each public playlist holding it; the playlist service with `playlistId`
* when a playlist goes public, for each public dump in it, from the bottom of
* the playlist up. A dump the followers were told of before either went
* private isn't notified again. Adding a dump to a public playlist calls
* {@link notifyPlaylistFollowersNewDump} directly.
*/
export function notifyPlaylistFollowersNowPublic(
of: { dumpId: string } | { playlistId: string },
): void {
const [column, id] = "dumpId" in of
? ["pd.dump_id", of.dumpId]
: ["pd.playlist_id", of.playlistId];
const rows = db.prepare(
`SELECT p.id AS playlist_id, p.title AS playlist_title,
d.id AS dump_id, d.title AS dump_title
FROM playlist_dumps pd
JOIN playlists p ON p.id = pd.playlist_id
JOIN dumps d ON d.id = pd.dump_id
WHERE ${column} = ? AND p.is_public = 1 AND d.is_private = 0
ORDER BY pd.position DESC;`,
).all(id) as {
playlist_id: string;
playlist_title: string;
dump_id: string;
dump_title: string;
}[];
transaction(() => {
for (const row of rows) {
notifyPlaylistFollowersNewDump(
row.playlist_id,
row.playlist_title,
row.dump_id,
row.dump_title,
);
}
});
}