Skip to content

Commit

Permalink
chore(sw): use PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaina committed Apr 10, 2023
1 parent 6a23ffc commit da64273
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/sw/src/scripts/create-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/sw/src/scripts/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/sw/src/sw.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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':
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions packages/sw/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
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 };
note: Misskey.entities.Note;
};
};

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'
Expand Down

0 comments on commit da64273

Please sign in to comment.