chore(sw): use PascalCase
This commit is contained in:
parent
6a23ffcce5
commit
da64273b43
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import { swLang } from '@/scripts/lang';
|
import { swLang } from '@/scripts/lang';
|
||||||
import { cli } from '@/scripts/operations';
|
import { cli } from '@/scripts/operations';
|
||||||
import { badgeNames, pushNotificationDataMap } from '@/types';
|
import { BadgeNames, PushNotificationDataMap } from '@/types';
|
||||||
import getUserName from '@/scripts/get-user-name';
|
import getUserName from '@/scripts/get-user-name';
|
||||||
import { I18n } from '@/scripts/i18n';
|
import { I18n } from '@/scripts/i18n';
|
||||||
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
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:
|
/* How to add a new badge:
|
||||||
* 1. Find the icon and download png from https://tabler-icons.io/
|
* 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;
|
* 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'),`
|
* 5. Add `badge: iconUrl('icon-name'),`
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function createNotification<K extends keyof pushNotificationDataMap>(data: pushNotificationDataMap[K]) {
|
export async function createNotification<K extends keyof PushNotificationDataMap>(data: PushNotificationDataMap[K]) {
|
||||||
const n = await composeNotification(data);
|
const n = await composeNotification(data);
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
|
@ -36,7 +36,7 @@ export async function createNotification<K extends keyof pushNotificationDataMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function composeNotification(data: pushNotificationDataMap[keyof pushNotificationDataMap]): Promise<[string, NotificationOptions] | null> {
|
async function composeNotification(data: PushNotificationDataMap[keyof PushNotificationDataMap]): Promise<[string, NotificationOptions] | null> {
|
||||||
if (!swLang.i18n) swLang.fetchLocale();
|
if (!swLang.i18n) swLang.fetchLocale();
|
||||||
const i18n = await swLang.i18n as I18n<any>;
|
const i18n = await swLang.i18n as I18n<any>;
|
||||||
const { t } = i18n;
|
const { t } = i18n;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* 各種操作
|
* 各種操作
|
||||||
*/
|
*/
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { SwMessage, swMessageOrderType } from '@/types';
|
import { SwMessage, SwMessageOrderType } from '@/types';
|
||||||
import { acct as getAcct } from '@/filters/user';
|
import { acct as getAcct } from '@/filters/user';
|
||||||
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
||||||
import { getUrlWithLoginId } from '@/scripts/login-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 });
|
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();
|
const client = await findClient();
|
||||||
|
|
||||||
if (client) {
|
if (client) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { createEmptyNotification, createNotification } from '@/scripts/create-notification';
|
import { createEmptyNotification, createNotification } from '@/scripts/create-notification';
|
||||||
import { swLang } from '@/scripts/lang';
|
import { swLang } from '@/scripts/lang';
|
||||||
import { api } from '@/scripts/operations';
|
import { api } from '@/scripts/operations';
|
||||||
import { pushNotificationDataMap } from '@/types';
|
import { PushNotificationDataMap } from '@/types';
|
||||||
import * as swos from '@/scripts/operations';
|
import * as swos from '@/scripts/operations';
|
||||||
import { acct as getAcct } from '@/filters/user';
|
import { acct as getAcct } from '@/filters/user';
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ globalThis.addEventListener('push', ev => {
|
||||||
includeUncontrolled: true,
|
includeUncontrolled: true,
|
||||||
type: 'window',
|
type: 'window',
|
||||||
}).then(async (clients: readonly WindowClient[]) => {
|
}).then(async (clients: readonly WindowClient[]) => {
|
||||||
const data: pushNotificationDataMap[keyof pushNotificationDataMap] = ev.data?.json();
|
const data: PushNotificationDataMap[keyof PushNotificationDataMap] = ev.data?.json();
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
// case 'driveFileCreated':
|
// case 'driveFileCreated':
|
||||||
|
@ -68,7 +68,7 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv
|
||||||
}
|
}
|
||||||
|
|
||||||
const { action, notification } = ev;
|
const { action, notification } = ev;
|
||||||
const data: pushNotificationDataMap[keyof pushNotificationDataMap] = notification.data;
|
const data: PushNotificationDataMap[keyof PushNotificationDataMap] = notification.data;
|
||||||
const { userId: loginId } = data;
|
const { userId: loginId } = data;
|
||||||
let client: WindowClient | null = null;
|
let client: WindowClient | null = null;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv
|
||||||
});
|
});
|
||||||
|
|
||||||
globalThis.addEventListener('notificationclose', (ev: ServiceWorkerGlobalScopeEventMap['notificationclose']) => {
|
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') {
|
if (data.type === 'notification') {
|
||||||
api('notifications/mark-all-as-read', data.userId);
|
api('notifications/mark-all-as-read', data.userId);
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
|
|
||||||
export type swMessageOrderType = 'post' | 'push';
|
export type SwMessageOrderType = 'post' | 'push';
|
||||||
|
|
||||||
export type SwMessage = {
|
export type SwMessage = {
|
||||||
type: 'order';
|
type: 'order';
|
||||||
order: swMessageOrderType;
|
order: SwMessageOrderType;
|
||||||
loginId: string;
|
loginId: string;
|
||||||
url: string;
|
url: string;
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Defined also @/core/PushNotificationService.ts#L12
|
// Defined also @/core/PushNotificationService.ts#L12
|
||||||
type pushNotificationDataSourceMap = {
|
type PushNotificationDataSourceMap = {
|
||||||
notification: Misskey.entities.Notification;
|
notification: Misskey.entities.Notification;
|
||||||
unreadAntennaNote: {
|
unreadAntennaNote: {
|
||||||
antenna: { id: string, name: string };
|
antenna: { id: string, name: string };
|
||||||
|
@ -19,18 +19,18 @@ type pushNotificationDataSourceMap = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type pushNotificationData<K extends keyof pushNotificationDataSourceMap> = {
|
export type PushNotificationData<K extends keyof PushNotificationDataSourceMap> = {
|
||||||
type: K;
|
type: K;
|
||||||
body: pushNotificationDataSourceMap[K];
|
body: PushNotificationDataSourceMap[K];
|
||||||
userId: string;
|
userId: string;
|
||||||
dateTime: number;
|
dateTime: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type pushNotificationDataMap = {
|
export type PushNotificationDataMap = {
|
||||||
[K in keyof pushNotificationDataSourceMap]: pushNotificationData<K>;
|
[K in keyof PushNotificationDataSourceMap]: PushNotificationData<K>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type badgeNames =
|
export type BadgeNames =
|
||||||
'null'
|
'null'
|
||||||
| 'antenna'
|
| 'antenna'
|
||||||
| 'arrow-back-up'
|
| 'arrow-back-up'
|
||||||
|
|
Loading…
Reference in New Issue