From ffe3386e5be3c72d89213857a8edefb86242a546 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 28 Feb 2023 19:55:31 +0900 Subject: [PATCH] =?UTF-8?q?fix(sw):=20=E3=83=97=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=A7=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0?= =?UTF-8?q?=E7=B5=B5=E6=96=87=E5=AD=97=E3=83=AA=E3=82=A2=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(#10122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(sw): プッシュ通知でカスタム絵文字リアクションを表示できるように Fix #10117 /emoji/*.webpにbadgeモードを * ? * :v: * fix --- packages/backend/src/server/ServerService.ts | 20 +++++++++----- .../sw/src/scripts/create-notification.ts | 26 +++++-------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/packages/backend/src/server/ServerService.ts b/packages/backend/src/server/ServerService.ts index 8200b24fd47f..417f50f95d27 100644 --- a/packages/backend/src/server/ServerService.ts +++ b/packages/backend/src/server/ServerService.ts @@ -75,7 +75,7 @@ export class ServerService { fastify.register(this.nodeinfoServerService.createServer); fastify.register(this.wellKnownServerService.createServer); - fastify.get<{ Params: { path: string }; Querystring: { static?: any; }; }>('/emoji/:path(.*)', async (request, reply) => { + fastify.get<{ Params: { path: string }; Querystring: { static?: any; badge?: any; }; }>('/emoji/:path(.*)', async (request, reply) => { const path = request.params.path; reply.header('Cache-Control', 'public, max-age=86400'); @@ -105,11 +105,19 @@ export class ServerService { } } - const url = new URL(`${this.config.mediaProxy}/emoji.webp`); - // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) - url.searchParams.set('url', emoji.publicUrl || emoji.originalUrl); - url.searchParams.set('emoji', '1'); - if ('static' in request.query) url.searchParams.set('static', '1'); + let url: URL; + if ('badge' in request.query) { + url = new URL(`${this.config.mediaProxy}/emoji.png`); + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + url.searchParams.set('url', emoji.publicUrl || emoji.originalUrl); + url.searchParams.set('badge', '1'); + } else { + url = new URL(`${this.config.mediaProxy}/emoji.webp`); + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + url.searchParams.set('url', emoji.publicUrl || emoji.originalUrl); + url.searchParams.set('emoji', '1'); + if ('static' in request.query) url.searchParams.set('static', '1'); + } return await reply.redirect( 301, diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts index da92b37d1986..6286d076c7d5 100644 --- a/packages/sw/src/scripts/create-notification.ts +++ b/packages/sw/src/scripts/create-notification.ts @@ -138,26 +138,11 @@ async function composeNotification(data: pushNotificationDataMap[keyof pushNotif if (reaction.startsWith(':')) { // カスタム絵文字の場合 - const customEmoji = data.body.note.emojis.find(x => x.name === reaction.substr(1, reaction.length - 2)); - if (customEmoji) { - if (reaction.includes('@')) { - reaction = `:${reaction.substr(1, reaction.indexOf('@') - 1)}:`; - } - - const u = new URL(customEmoji.url); - if (u.href.startsWith(`${origin}/proxy/`)) { - // もう既にproxyっぽそうだったらsearchParams付けるだけ - u.searchParams.set('badge', '1'); - badge = u.href; - } else { - // 拡張子がないとキャッシュしてくれないCDNがあるので - const dummy = `${encodeURIComponent(`${u.host}${u.pathname}`)}.png`; - badge = `${origin}/proxy/${dummy}?${url.query({ - url: u.href, - badge: '1', - })}`; - } - } + const name = reaction.substring(1, reaction.length - 1); + badge = `${origin}/emoji/${name}.webp?${url.query({ + badge: '1', + })}`; + reaction = name.split('@')[0]; } else { // Unicode絵文字の場合 badge = `/twemoji-badge/${char2fileName(reaction)}.png`; @@ -171,6 +156,7 @@ async function composeNotification(data: pushNotificationDataMap[keyof pushNotif return [`${reaction} ${getUserName(data.body.user)}`, { body: data.body.note.text ?? '', icon: data.body.user.avatarUrl, + tag, badge, data, actions: [