1
0
forked from mirror/misskey

chore(sw): use PascalCase

This commit is contained in:
tamaina 2023-04-10 12:10:06 +00:00
parent 6a23ffcce5
commit da64273b43
4 changed files with 18 additions and 18 deletions

View File

@ -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<K extends keyof pushNotificationDataMap>(data: pushNotificationDataMap[K]) {
export async function createNotification<K extends keyof PushNotificationDataMap>(data: PushNotificationDataMap[K]) {
const n = await composeNotification(data);
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();
const i18n = await swLang.i18n as I18n<any>;
const { t } = i18n;

View File

@ -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) {

View File

@ -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);

View File

@ -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<K extends keyof pushNotificationDataSourceMap> = {
export type PushNotificationData<K extends keyof PushNotificationDataSourceMap> = {
type: K;
body: pushNotificationDataSourceMap[K];
body: PushNotificationDataSourceMap[K];
userId: string;
dateTime: number;
};
export type pushNotificationDataMap = {
[K in keyof pushNotificationDataSourceMap]: pushNotificationData<K>;
export type PushNotificationDataMap = {
[K in keyof PushNotificationDataSourceMap]: PushNotificationData<K>;
};
export type badgeNames =
export type BadgeNames =
'null'
| 'antenna'
| 'arrow-back-up'