From 3484b1e1a1630a87eed6fe63d2a9713f5dcb678c Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 2 Jan 2025 04:49:36 +0100 Subject: [PATCH] fix(api): :bug: Improve notification text --- classes/workers/push.ts | 4 ++-- utils/content_types.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/classes/workers/push.ts b/classes/workers/push.ts index ceea112a..6c477245 100644 --- a/classes/workers/push.ts +++ b/classes/workers/push.ts @@ -1,6 +1,5 @@ import { Note, PushSubscription, Token, User } from "@versia/kit/db"; import { Worker } from "bullmq"; -import { htmlToText } from "html-to-text"; import { sendNotification } from "web-push"; import { config } from "~/packages/config-manager"; import { connection } from "~/utils/redis.ts"; @@ -9,6 +8,7 @@ import { type PushJobType, pushQueue, } from "../queues/push.ts"; +import { htmlToText } from "@/content_types.ts"; export const getPushWorker = (): Worker => new Worker( @@ -70,7 +70,7 @@ export const getPushWorker = (): Worker => case "reply": title = `${name} replied to you`; break; - case "like": + case "favourite": title = `${name} liked your note`; break; case "reblog": diff --git a/utils/content_types.ts b/utils/content_types.ts index e6f936b7..16bdacd2 100644 --- a/utils/content_types.ts +++ b/utils/content_types.ts @@ -1,6 +1,7 @@ import type { ContentFormat } from "@versia/federation/types"; import { lookup } from "mime-types"; import { config } from "~/packages/config-manager"; +import { htmlToText as htmlToTextLib } from "html-to-text"; export const getBestContentType = ( content?: ContentFormat | null, @@ -77,3 +78,17 @@ export const mimeLookup = (url: string): Promise => { return fetchLookup; }; + +export const htmlToText = (html: string): string => { + return htmlToTextLib(html, { + selectors: [ + { + selector: "a", + options: { + hideLinkHrefIfSameAsText: true, + ignoreHref: true, + }, + }, + ], + }); +};