From da64273b4321769aa2d0e1c13ab3ebaa1d491d19 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 10 Apr 2023 12:10:06 +0000 Subject: [PATCH] chore(sw): use PascalCase --- packages/sw/src/scripts/create-notification.ts | 8 ++++---- packages/sw/src/scripts/operations.ts | 4 ++-- packages/sw/src/sw.ts | 8 ++++---- packages/sw/src/types.ts | 16 ++++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts index 6286d076c7..8e214c9850 100644 --- a/packages/sw/src/scripts/create-notification.ts +++ b/packages/sw/src/scripts/create-notification.ts @@ -3,7 +3,7 @@ */ import { swLang } from '@/scripts/lang'; import { cli } from '@/scripts/operations'; -import { badgeNames, pushNotificationDataMap } from '@/types'; +import { BadgeNames, PushNotificationDataMap } from '@/types'; import getUserName from '@/scripts/get-user-name'; import { I18n } from '@/scripts/i18n'; import { getAccountFromId } from '@/scripts/get-account-from-id'; @@ -16,7 +16,7 @@ const closeNotificationsByTags = async (tags: string[]) => { } }; -const iconUrl = (name: badgeNames) => `/static-assets/tabler-badges/${name}.png`; +const iconUrl = (name: BadgeNames) => `/static-assets/tabler-badges/${name}.png`; /* How to add a new badge: * 1. Find the icon and download png from https://tabler-icons.io/ * 2. vips resize ~/Downloads/icon-name.png vipswork.png 0.4; vips scRGB2BW vipswork.png ~/icon-name.png"[compression=9,strip]"; rm vipswork.png; @@ -25,7 +25,7 @@ const iconUrl = (name: badgeNames) => `/static-assets/tabler-badges/${name}.png` * 5. Add `badge: iconUrl('icon-name'),` */ -export async function createNotification(data: pushNotificationDataMap[K]) { +export async function createNotification(data: PushNotificationDataMap[K]) { const n = await composeNotification(data); if (n) { @@ -36,7 +36,7 @@ export async function createNotification { +async function composeNotification(data: PushNotificationDataMap[keyof PushNotificationDataMap]): Promise<[string, NotificationOptions] | null> { if (!swLang.i18n) swLang.fetchLocale(); const i18n = await swLang.i18n as I18n; const { t } = i18n; diff --git a/packages/sw/src/scripts/operations.ts b/packages/sw/src/scripts/operations.ts index 02217ed74e..0978cf9a31 100644 --- a/packages/sw/src/scripts/operations.ts +++ b/packages/sw/src/scripts/operations.ts @@ -3,7 +3,7 @@ * 各種操作 */ import * as Misskey from 'misskey-js'; -import { SwMessage, swMessageOrderType } from '@/types'; +import { SwMessage, SwMessageOrderType } from '@/types'; import { acct as getAcct } from '@/filters/user'; import { getAccountFromId } from '@/scripts/get-account-from-id'; import { getUrlWithLoginId } from '@/scripts/login-id'; @@ -43,7 +43,7 @@ export async function openPost(options: any, loginId: string) { return openClient('post', url, loginId, { options }); } -export async function openClient(order: swMessageOrderType, url: string, loginId: string, query: any = {}) { +export async function openClient(order: SwMessageOrderType, url: string, loginId: string, query: any = {}) { const client = await findClient(); if (client) { diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts index 9ceef890dd..56050987a0 100644 --- a/packages/sw/src/sw.ts +++ b/packages/sw/src/sw.ts @@ -1,7 +1,7 @@ import { createEmptyNotification, createNotification } from '@/scripts/create-notification'; import { swLang } from '@/scripts/lang'; import { api } from '@/scripts/operations'; -import { pushNotificationDataMap } from '@/types'; +import { PushNotificationDataMap } from '@/types'; import * as swos from '@/scripts/operations'; import { acct as getAcct } from '@/filters/user'; @@ -44,7 +44,7 @@ globalThis.addEventListener('push', ev => { includeUncontrolled: true, type: 'window', }).then(async (clients: readonly WindowClient[]) => { - const data: pushNotificationDataMap[keyof pushNotificationDataMap] = ev.data?.json(); + const data: PushNotificationDataMap[keyof PushNotificationDataMap] = ev.data?.json(); switch (data.type) { // case 'driveFileCreated': @@ -68,7 +68,7 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv } const { action, notification } = ev; - const data: pushNotificationDataMap[keyof pushNotificationDataMap] = notification.data; + const data: PushNotificationDataMap[keyof PushNotificationDataMap] = notification.data; const { userId: loginId } = data; let client: WindowClient | null = null; @@ -138,7 +138,7 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv }); globalThis.addEventListener('notificationclose', (ev: ServiceWorkerGlobalScopeEventMap['notificationclose']) => { - const data: pushNotificationDataMap[keyof pushNotificationDataMap] = ev.notification.data; + const data: PushNotificationDataMap[keyof PushNotificationDataMap] = ev.notification.data; if (data.type === 'notification') { api('notifications/mark-all-as-read', data.userId); diff --git a/packages/sw/src/types.ts b/packages/sw/src/types.ts index 176b181be0..7b653e94b7 100644 --- a/packages/sw/src/types.ts +++ b/packages/sw/src/types.ts @@ -1,17 +1,17 @@ import * as Misskey from 'misskey-js'; -export type swMessageOrderType = 'post' | 'push'; +export type SwMessageOrderType = 'post' | 'push'; export type SwMessage = { type: 'order'; - order: swMessageOrderType; + order: SwMessageOrderType; loginId: string; url: string; [x: string]: any; }; // Defined also @/core/PushNotificationService.ts#L12 -type pushNotificationDataSourceMap = { +type PushNotificationDataSourceMap = { notification: Misskey.entities.Notification; unreadAntennaNote: { antenna: { id: string, name: string }; @@ -19,18 +19,18 @@ type pushNotificationDataSourceMap = { }; }; -export type pushNotificationData = { +export type PushNotificationData = { type: K; - body: pushNotificationDataSourceMap[K]; + body: PushNotificationDataSourceMap[K]; userId: string; dateTime: number; }; -export type pushNotificationDataMap = { - [K in keyof pushNotificationDataSourceMap]: pushNotificationData; +export type PushNotificationDataMap = { + [K in keyof PushNotificationDataSourceMap]: PushNotificationData; }; -export type badgeNames = +export type BadgeNames = 'null' | 'antenna' | 'arrow-back-up'