summaryrefslogtreecommitdiff
path: root/packages/sw/src/scripts
diff options
context:
space:
mode:
authorKagami Sascha Rosylight <saschanaz@outlook.com>2023-02-12 16:31:37 +0100
committerGitHub <noreply@github.com>2023-02-13 00:31:37 +0900
commit9f0e0dc8ce9ca2a04f8bfbfb95c33a7b20288e21 (patch)
tree3371c9d8f0aa7eae8c94a460107bad2e1c150fad /packages/sw/src/scripts
parentrefactor: fix types (diff)
downloadsharkey-9f0e0dc8ce9ca2a04f8bfbfb95c33a7b20288e21.tar.gz
sharkey-9f0e0dc8ce9ca2a04f8bfbfb95c33a7b20288e21.tar.bz2
sharkey-9f0e0dc8ce9ca2a04f8bfbfb95c33a7b20288e21.zip
refactor(sw): Fix type errors in packages/sw (#9909)
* Fix type errors in packages/sw * mouhitotsu * @typesは越境しない * Update packages/sw/src/scripts/create-notification.ts --------- Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Diffstat (limited to 'packages/sw/src/scripts')
-rw-r--r--packages/sw/src/scripts/create-notification.ts24
-rw-r--r--packages/sw/src/scripts/get-user-name.ts4
-rw-r--r--packages/sw/src/scripts/notification-read.ts2
3 files changed, 17 insertions, 13 deletions
diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts
index 6744687fcc..6e7845f667 100644
--- a/packages/sw/src/scripts/create-notification.ts
+++ b/packages/sw/src/scripts/create-notification.ts
@@ -30,7 +30,7 @@ export async function createNotification<K extends keyof pushNotificationDataMap
}
}
-async function composeNotification<K extends keyof pushNotificationDataMap>(data: pushNotificationDataMap[K]): Promise<[string, NotificationOptions] | null> {
+async function composeNotification(data: pushNotificationDataMap[keyof pushNotificationDataMap]): Promise<[string, NotificationOptions] | null> {
if (!swLang.i18n) swLang.fetchLocale();
const i18n = await swLang.i18n as I18n<any>;
const { t } = i18n;
@@ -66,7 +66,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
case 'mention':
return [t('_notification.youGotMention', { name: getUserName(data.body.user) }), {
- body: data.body.note.text || '',
+ body: data.body.note.text ?? '',
icon: data.body.user.avatarUrl,
badge: iconUrl('at'),
data,
@@ -80,7 +80,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
case 'reply':
return [t('_notification.youGotReply', { name: getUserName(data.body.user) }), {
- body: data.body.note.text || '',
+ body: data.body.note.text ?? '',
icon: data.body.user.avatarUrl,
badge: iconUrl('arrow-back-up'),
data,
@@ -94,7 +94,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
case 'renote':
return [t('_notification.youRenoted', { name: getUserName(data.body.user) }), {
- body: data.body.note.text || '',
+ body: data.body.note.text ?? '',
icon: data.body.user.avatarUrl,
badge: iconUrl('repeat'),
data,
@@ -108,7 +108,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
case 'quote':
return [t('_notification.youGotQuote', { name: getUserName(data.body.user) }), {
- body: data.body.note.text || '',
+ body: data.body.note.text ?? '',
icon: data.body.user.avatarUrl,
badge: iconUrl('quote'),
data,
@@ -162,7 +162,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
}
return [`${reaction} ${getUserName(data.body.user)}`, {
- body: data.body.note.text || '',
+ body: data.body.note.text ?? '',
icon: data.body.user.avatarUrl,
badge,
data,
@@ -227,9 +227,9 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
}];
case 'app':
- return [data.body.header || data.body.body, {
- body: data.body.header && data.body.body,
- icon: data.body.icon,
+ return [data.body.header ?? data.body.body, {
+ body: data.body.header ? data.body.body : '',
+ icon: data.body.icon ?? undefined,
data,
}];
@@ -246,7 +246,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
renotify: true,
}];
}
- return [t('_notification.youGotMessagingMessageFromGroup', { name: data.body.group.name }), {
+ return [t('_notification.youGotMessagingMessageFromGroup', { name: data.body.group?.name ?? '' }), {
icon: data.body.user.avatarUrl,
badge: iconUrl('messages'),
tag: `messaging:group:${data.body.groupId}`,
@@ -255,7 +255,7 @@ async function composeNotification<K extends keyof pushNotificationDataMap>(data
}];
case 'unreadAntennaNote':
return [t('_notification.unreadAntennaNote', { name: data.body.antenna.name }), {
- body: `${getUserName(data.body.note.user)}: ${data.body.note.text || ''}`,
+ body: `${getUserName(data.body.note.user)}: ${data.body.note.text ?? ''}`,
icon: data.body.note.user.avatarUrl,
badge: iconUrl('antenna'),
tag: `antenna:${data.body.antenna.id}`,
@@ -272,7 +272,7 @@ export async function createEmptyNotification() {
if (!swLang.i18n) swLang.fetchLocale();
const i18n = await swLang.i18n as I18n<any>;
const { t } = i18n;
-
+
await self.registration.showNotification(
t('_notification.emptyPushNotificationMessage'),
{
diff --git a/packages/sw/src/scripts/get-user-name.ts b/packages/sw/src/scripts/get-user-name.ts
index d499ea0203..ccc38c298e 100644
--- a/packages/sw/src/scripts/get-user-name.ts
+++ b/packages/sw/src/scripts/get-user-name.ts
@@ -1,3 +1,7 @@
export default function(user: { name?: string | null, username: string }): string {
+ // Show username if name is empty.
+ // XXX: typescript-eslint has no configuration to allow using `||` against string.
+ // https://github.com/typescript-eslint/typescript-eslint/issues/4906
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return user.name || user.username;
}
diff --git a/packages/sw/src/scripts/notification-read.ts b/packages/sw/src/scripts/notification-read.ts
index 5ad748b849..3b1dde0cd5 100644
--- a/packages/sw/src/scripts/notification-read.ts
+++ b/packages/sw/src/scripts/notification-read.ts
@@ -28,7 +28,7 @@ class SwNotificationReadManager {
}
// プッシュ通知の既読をサーバーに送信
- public async read<K extends keyof pushNotificationDataMap>(data: pushNotificationDataMap[K]) {
+ public async read(data: pushNotificationDataMap[keyof pushNotificationDataMap]) {
if (data.type !== 'notification' || !(data.userId in this.accounts)) return;
const account = this.accounts[data.userId];