summaryrefslogtreecommitdiff
path: root/packages/sw/src/scripts/create-notification.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-07-07 21:23:03 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-07-07 21:23:03 +0900
commit84d984bd31fa9863c3fe2e1aeb672ad0e2e8de4b (patch)
treea182502a5192992d873e7a7fcbf01662bb0dfca2 /packages/sw/src/scripts/create-notification.ts
parentMerge pull request #8821 from misskey-dev/develop (diff)
parent12.112.1 (diff)
downloadmisskey-84d984bd31fa9863c3fe2e1aeb672ad0e2e8de4b.tar.gz
misskey-84d984bd31fa9863c3fe2e1aeb672ad0e2e8de4b.tar.bz2
misskey-84d984bd31fa9863c3fe2e1aeb672ad0e2e8de4b.zip
Merge branch 'develop'
Diffstat (limited to 'packages/sw/src/scripts/create-notification.ts')
-rw-r--r--packages/sw/src/scripts/create-notification.ts54
1 files changed, 53 insertions, 1 deletions
diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts
index 6d7ba7d524..7c95e8e41f 100644
--- a/packages/sw/src/scripts/create-notification.ts
+++ b/packages/sw/src/scripts/create-notification.ts
@@ -9,6 +9,10 @@ import { pushNotificationDataMap } from '@/types';
import getUserName from '@/scripts/get-user-name';
import { I18n } from '@/scripts/i18n';
import { getAccountFromId } from '@/scripts/get-account-from-id';
+import { char2fileName } from '@/scripts/twemoji-base';
+import * as url from '@/scripts/url';
+
+const iconUrl = (name: string) => `/static-assets/notification-badges/${name}.png`;
export async function createNotification<K extends keyof pushNotificationDataMap>(data: pushNotificationDataMap[K]) {
const n = await composeNotification(data);
@@ -44,6 +48,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youWereFollowed'), {
body: getUserName(data.body.user),
icon: data.body.user.avatarUrl,
+ badge: iconUrl('user-plus'),
data,
actions: userDetail.isFollowing ? [] : [
{
@@ -57,6 +62,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youGotMention', { name: getUserName(data.body.user) }), {
body: data.body.note.text || '',
icon: data.body.user.avatarUrl,
+ badge: iconUrl('at'),
data,
actions: [
{
@@ -70,6 +76,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youGotReply', { name: getUserName(data.body.user) }), {
body: data.body.note.text || '',
icon: data.body.user.avatarUrl,
+ badge: iconUrl('reply'),
data,
actions: [
{
@@ -83,6 +90,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youRenoted', { name: getUserName(data.body.user) }), {
body: data.body.note.text || '',
icon: data.body.user.avatarUrl,
+ badge: iconUrl('retweet'),
data,
actions: [
{
@@ -96,6 +104,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youGotQuote', { name: getUserName(data.body.user) }), {
body: data.body.note.text || '',
icon: data.body.user.avatarUrl,
+ badge: iconUrl('quote-right'),
data,
actions: [
{
@@ -112,9 +121,44 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
}];
case 'reaction':
- return [`${data.body.reaction} ${getUserName(data.body.user)}`, {
+ let reaction = data.body.reaction;
+ let badge: string | undefined;
+
+ 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 {
+ const dummy = `${u.host}${u.pathname}`; // 拡張子がないとキャッシュしてくれないCDNがあるので
+ badge = `${origin}/proxy/${dummy}?${url.query({
+ url: u.href,
+ badge: '1'
+ })}`;
+ }
+ }
+ } else {
+ // Unicode絵文字の場合
+ badge = `/twemoji-badge/${char2fileName(reaction)}.png`;
+ }
+
+
+ if (badge ? await fetch(badge).then(res => res.status !== 200).catch(() => true) : true) {
+ badge = iconUrl('plus');
+ }
+
+ return [`${reaction} ${getUserName(data.body.user)}`, {
body: data.body.note.text || '',
icon: data.body.user.avatarUrl,
+ badge,
data,
actions: [
{
@@ -128,12 +172,14 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youGotPoll', { name: getUserName(data.body.user) }), {
body: data.body.note.text || '',
icon: data.body.user.avatarUrl,
+ badge: iconUrl('poll-h'),
data,
}];
case 'pollEnded':
return [t('_notification.pollEnded'), {
body: data.body.note.text || '',
+ badge: iconUrl('clipboard-check-solid'),
data,
}];
@@ -141,6 +187,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.youReceivedFollowRequest'), {
body: getUserName(data.body.user),
icon: data.body.user.avatarUrl,
+ badge: iconUrl('clock'),
data,
actions: [
{
@@ -158,12 +205,14 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
return [t('_notification.yourFollowRequestAccepted'), {
body: getUserName(data.body.user),
icon: data.body.user.avatarUrl,
+ badge: iconUrl('check'),
data,
}];
case 'groupInvited':
return [t('_notification.youWereInvitedToGroup', { userName: getUserName(data.body.user) }), {
body: data.body.invitation.group.name,
+ badge: iconUrl('id-card-alt'),
data,
actions: [
{
@@ -191,6 +240,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
if (data.body.groupId === null) {
return [t('_notification.youGotMessagingMessageFromUser', { name: getUserName(data.body.user) }), {
icon: data.body.user.avatarUrl,
+ badge: iconUrl('comments'),
tag: `messaging:user:${data.body.userId}`,
data,
renotify: true,
@@ -198,6 +248,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
}
return [t('_notification.youGotMessagingMessageFromGroup', { name: data.body.group.name }), {
icon: data.body.user.avatarUrl,
+ badge: iconUrl('comments'),
tag: `messaging:group:${data.body.groupId}`,
data,
renotify: true,
@@ -217,6 +268,7 @@ export async function createEmptyNotification() {
t('_notification.emptyPushNotificationMessage'),
{
silent: true,
+ badge: iconUrl('null'),
tag: 'read_notification',
}
);