patch: filter Bluesky self-interactions from webmention dashboard widget
This commit is contained in:
@@ -25,6 +25,28 @@ const controllerCandidates = [
|
|||||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-conversations/lib/controllers/conversations.js",
|
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-conversations/lib/controllers/conversations.js",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const patchSpecs = [
|
||||||
|
{
|
||||||
|
name: "conversations-bluesky-scheduler-self-filter",
|
||||||
|
candidates: schedulerCandidates,
|
||||||
|
marker: "// Skip self-interactions",
|
||||||
|
oldSnippet: ` let stored = 0;
|
||||||
|
|
||||||
|
for (const notification of result.items) {
|
||||||
|
let canonicalUrl = null;`,
|
||||||
|
newSnippet: ` let stored = 0;
|
||||||
|
|
||||||
|
// Derive own handle from identifier (strip leading @)
|
||||||
|
const ownBskyHandle = (credentials.identifier || "").replace(/^@+/, "").toLowerCase();
|
||||||
|
|
||||||
|
for (const notification of result.items) {
|
||||||
|
// Skip self-interactions (e.g. own account liking/reposting a syndicated post)
|
||||||
|
if (ownBskyHandle && (notification.author?.handle || "").toLowerCase() === ownBskyHandle) {
|
||||||
|
const webmentionSenderCandidates = [
|
||||||
|
"node_modules/@rmdes/indiekit-endpoint-webmention-sender/lib/controllers/webmention-sender.js",
|
||||||
|
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-webmention-sender/lib/controllers/webmention-sender.js",
|
||||||
|
];
|
||||||
|
|
||||||
const patchSpecs = [
|
const patchSpecs = [
|
||||||
{
|
{
|
||||||
name: "conversations-bluesky-scheduler-self-filter",
|
name: "conversations-bluesky-scheduler-self-filter",
|
||||||
@@ -65,24 +87,11 @@ const patchSpecs = [
|
|||||||
|
|
||||||
response.set("Cache-Control", "public, max-age=60");`,
|
response.set("Cache-Control", "public, max-age=60");`,
|
||||||
},
|
},
|
||||||
];
|
{
|
||||||
|
name: "webmention-sender-bluesky-self-filter",
|
||||||
async function exists(filePath) {
|
candidates: webmentionSenderCandidates,
|
||||||
try {
|
marker: "// Filter out self Bluesky profile from webmention results",
|
||||||
await access(filePath);
|
oldSnippet: ` return posts.map((post) => ({
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkedFiles = new Set();
|
|
||||||
const patchedFiles = new Set();
|
|
||||||
|
|
||||||
for (const spec of patchSpecs) {
|
|
||||||
let foundAnyTarget = false;
|
|
||||||
|
|
||||||
for (const filePath of spec.candidates) {
|
|
||||||
if (!(await exists(filePath))) {
|
if (!(await exists(filePath))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -90,6 +99,29 @@ for (const spec of patchSpecs) {
|
|||||||
foundAnyTarget = true;
|
foundAnyTarget = true;
|
||||||
checkedFiles.add(filePath);
|
checkedFiles.add(filePath);
|
||||||
|
|
||||||
|
newSnippet: ` // Filter out self Bluesky profile from webmention results
|
||||||
|
const _selfBskyHandle = (process.env.BLUESKY_IDENTIFIER || process.env.BLUESKY_HANDLE || "").replace(/^@+/, "").toLowerCase();
|
||||||
|
const _selfBskyUrl = _selfBskyHandle ? "https://bsky.app/profile/" + _selfBskyHandle : null;
|
||||||
|
return posts.map((post) => {
|
||||||
|
let details = post.properties["webmention-results"]?.details || null;
|
||||||
|
if (_selfBskyUrl && details && typeof details === "object") {
|
||||||
|
// Remove any sent/failed/skipped entries where source is own Bluesky profile
|
||||||
|
for (const key of ["sent", "failed", "skipped"]) {
|
||||||
|
if (Array.isArray(details[key])) {
|
||||||
|
details[key] = details[key].filter(entry => (entry.source || entry.author || "").toLowerCase() !== _selfBskyUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
url: post.properties.url,
|
||||||
|
sent: post.properties["webmention-results"]?.sent || 0,
|
||||||
|
failed: post.properties["webmention-results"]?.failed || 0,
|
||||||
|
skipped: post.properties["webmention-results"]?.skipped || 0,
|
||||||
|
details,
|
||||||
|
timestamp: post.properties["webmention-results"]?.timestamp,
|
||||||
|
};
|
||||||
|
});`,
|
||||||
|
},
|
||||||
const source = await readFile(filePath, "utf8");
|
const source = await readFile(filePath, "utf8");
|
||||||
|
|
||||||
if (spec.marker && source.includes(spec.marker)) {
|
if (spec.marker && source.includes(spec.marker)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user