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:
@@ -34,6 +34,7 @@ import { isValidHttpUrl } from "../remote/fetch.ts";
|
||||
import { broadcastDumpChange } from "./ws-service.ts";
|
||||
import {
|
||||
notifyMentions,
|
||||
notifyPlaylistFollowersNowPublic,
|
||||
notifyUserFollowersNewDump,
|
||||
} from "./notification-service.ts";
|
||||
import { changeSlug, newSlug, resolveSlug } from "./slug-service.ts";
|
||||
@@ -91,6 +92,19 @@ function titleFromUrl(url: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the followers of a dump that went public, `before` being private
|
||||
* and `after` public: the poster's, as if it were just posted, and those of
|
||||
* each public playlist holding it, as if it were just added. A private dump's
|
||||
* followers were never told of it, so an edit that makes it public is when
|
||||
* they learn of it.
|
||||
*/
|
||||
function notifyIfWentPublic(before: Dump, after: Dump): void {
|
||||
if (!before.isPrivate || after.isPrivate) return;
|
||||
notifyUserFollowersNewDump(after.userId, after.id, after.title);
|
||||
notifyPlaylistFollowersNowPublic({ dumpId: after.id });
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts a link as `userId`, for `POST /api/dumps`, with its preview fetched
|
||||
* from the page. A public dump is broadcast as `dump_created` and notified to
|
||||
@@ -427,7 +441,8 @@ export function findDumpsByUrl(
|
||||
* which `exempt` (a moderator) frees from its rate limit; a new title leaves
|
||||
* the slug as it is. Clients get the dump as `dump_updated`, or a
|
||||
* `dump_deleted` when it turns private and a `dump_created` when it turns
|
||||
* public. Anyone @mentioned in the note is notified.
|
||||
* public. Anyone @mentioned in the note is notified, and when it turns public,
|
||||
* its followers are as when it is posted ({@link notifyIfWentPublic}).
|
||||
*
|
||||
* @throws {APIException} 404 when there is no such dump, 400 when a new URL
|
||||
* isn't a public http(s) URL, a category doesn't exist or the slug isn't
|
||||
@@ -484,6 +499,7 @@ export async function updateDump(
|
||||
attachCategoryIds([updatedDump]);
|
||||
}
|
||||
broadcastDumpChange(dump, updatedDump);
|
||||
notifyIfWentPublic(dump, updatedDump);
|
||||
if (updatedDump.comment) {
|
||||
if (!updatedDump.isPrivate) {
|
||||
notifyMentions(
|
||||
@@ -555,6 +571,7 @@ export async function updateDump(
|
||||
}
|
||||
|
||||
broadcastDumpChange(dump, updatedDump);
|
||||
notifyIfWentPublic(dump, updatedDump);
|
||||
if (updatedDump.comment) {
|
||||
if (!updatedDump.isPrivate) {
|
||||
notifyMentions(
|
||||
@@ -577,8 +594,8 @@ export async function updateDump(
|
||||
* `isPrivate` left out stays as it is. Visibility is taken here so that a new
|
||||
* file and a change of visibility land together. The slug changes as in
|
||||
* {@link updateDump}, before the file is written. The old file is put back if
|
||||
* the database update fails, and clients are told as {@link updateDump} tells
|
||||
* them.
|
||||
* the database update fails, and clients and followers are told as
|
||||
* {@link updateDump} tells them.
|
||||
*
|
||||
* @throws {APIException} 404 when there is no such dump, 400 when it isn't a
|
||||
* file dump, the title or comment is too long, the file's type isn't allowed,
|
||||
@@ -683,6 +700,7 @@ export async function replaceFileDump(
|
||||
updatedAt: now,
|
||||
};
|
||||
broadcastDumpChange(dump, updatedDump);
|
||||
notifyIfWentPublic(dump, updatedDump);
|
||||
return updatedDump;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user