summaryrefslogtreecommitdiff
path: root/packages/sw/src
diff options
context:
space:
mode:
authorzyoshoka <107108195+zyoshoka@users.noreply.github.com>2024-08-30 15:53:04 +0900
committerGitHub <noreply@github.com>2024-08-30 15:53:04 +0900
commit8be624aa4441dbbc3f911453d22b70dee8a685b5 (patch)
treee462548621295abd588559d01ddf434e45c2c191 /packages/sw/src
parentfix(frontend): server metrics look strange after reload (#14467) (diff)
downloadsharkey-8be624aa4441dbbc3f911453d22b70dee8a685b5.tar.gz
sharkey-8be624aa4441dbbc3f911453d22b70dee8a685b5.tar.bz2
sharkey-8be624aa4441dbbc3f911453d22b70dee8a685b5.zip
refactor(sw): fix type errors (#14478)
* style(sw): lint fixes * refactor(sw): fix type errors * chore(sw): disable `noImplicitAny` * ci(sw): enable typecheck ci * ci(sw): build `misskey-js` before typecheck
Diffstat (limited to 'packages/sw/src')
-rw-r--r--packages/sw/src/scripts/create-notification.ts20
-rw-r--r--packages/sw/src/scripts/get-account-from-id.ts5
-rw-r--r--packages/sw/src/scripts/operations.ts15
-rw-r--r--packages/sw/src/sw.ts4
4 files changed, 26 insertions, 18 deletions
diff --git a/packages/sw/src/scripts/create-notification.ts b/packages/sw/src/scripts/create-notification.ts
index 02d9b07767..3c37657958 100644
--- a/packages/sw/src/scripts/create-notification.ts
+++ b/packages/sw/src/scripts/create-notification.ts
@@ -59,7 +59,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
const userDetail = await cli.request('users/show', { userId: data.body.userId }, account.token);
return [i18n.ts._notification.youWereFollowed, {
body: getUserName(data.body.user),
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('user-plus'),
data,
actions: userDetail.isFollowing ? [] : [
@@ -74,7 +74,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'mention':
return [i18n.tsx._notification.youGotMention({ name: getUserName(data.body.user) }), {
body: data.body.note.text ?? '',
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('at'),
data,
actions: [
@@ -88,7 +88,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'reply':
return [i18n.tsx._notification.youGotReply({ name: getUserName(data.body.user) }), {
body: data.body.note.text ?? '',
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('arrow-back-up'),
data,
actions: [
@@ -102,7 +102,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'renote':
return [i18n.tsx._notification.youRenoted({ name: getUserName(data.body.user) }), {
body: data.body.note.text ?? '',
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('repeat'),
data,
actions: [
@@ -116,7 +116,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'quote':
return [i18n.tsx._notification.youGotQuote({ name: getUserName(data.body.user) }), {
body: data.body.note.text ?? '',
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('quote'),
data,
actions: [
@@ -136,7 +136,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'note':
return [i18n.ts._notification.newNote + ': ' + getUserName(data.body.user), {
body: data.body.note.text ?? '',
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
data,
}];
@@ -163,7 +163,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
const tag = `reaction:${data.body.note.id}`;
return [`${reaction} ${getUserName(data.body.user)}`, {
body: data.body.note.text ?? '',
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
tag,
badge,
data,
@@ -179,7 +179,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'receiveFollowRequest':
return [i18n.ts._notification.youReceivedFollowRequest, {
body: getUserName(data.body.user),
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('user-plus'),
data,
actions: [
@@ -197,7 +197,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'followRequestAccepted':
return [i18n.ts._notification.yourFollowRequestAccepted, {
body: getUserName(data.body.user),
- icon: data.body.user.avatarUrl,
+ icon: data.body.user.avatarUrl ?? undefined,
badge: iconUrl('circle-check'),
data,
}];
@@ -237,7 +237,7 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
case 'unreadAntennaNote':
return [i18n.tsx._notification.unreadAntennaNote({ name: data.body.antenna.name }), {
body: `${getUserName(data.body.note.user)}: ${data.body.note.text ?? ''}`,
- icon: data.body.note.user.avatarUrl,
+ icon: data.body.note.user.avatarUrl ?? undefined,
badge: iconUrl('antenna'),
tag: `antenna:${data.body.antenna.id}`,
data,
diff --git a/packages/sw/src/scripts/get-account-from-id.ts b/packages/sw/src/scripts/get-account-from-id.ts
index 19bfe052ee..157dbd005e 100644
--- a/packages/sw/src/scripts/get-account-from-id.ts
+++ b/packages/sw/src/scripts/get-account-from-id.ts
@@ -4,9 +4,10 @@
*/
import { get } from 'idb-keyval';
+import * as Misskey from 'misskey-js';
-export async function getAccountFromId(id: string): Promise<{ token: string; id: string } | void> {
- const accounts = await get<{ token: string; id: string }[]>('accounts');
+export async function getAccountFromId(id: string): Promise<Pick<Misskey.entities.SignupResponse, 'id' | 'token'> | undefined> {
+ const accounts = await get<Pick<Misskey.entities.SignupResponse, 'id' | 'token'>[]>('accounts');
if (!accounts) {
console.log('Accounts are not recorded');
return;
diff --git a/packages/sw/src/scripts/operations.ts b/packages/sw/src/scripts/operations.ts
index 24eea06231..8862c6faa5 100644
--- a/packages/sw/src/scripts/operations.ts
+++ b/packages/sw/src/scripts/operations.ts
@@ -14,15 +14,22 @@ import { getUrlWithLoginId } from '@/scripts/login-id.js';
export const cli = new Misskey.api.APIClient({ origin, fetch: (...args): Promise<Response> => fetch(...args) });
-export async function api<E extends keyof Misskey.Endpoints, O extends Misskey.Endpoints[E]['req']>(endpoint: E, userId?: string, options?: O): Promise<void | ReturnType<typeof cli.request<E, O>>> {
- let account: { token: string; id: string } | void = undefined;
+export async function api<
+ E extends keyof Misskey.Endpoints,
+ P extends Misskey.Endpoints[E]['req']
+>(endpoint: E, userId?: string, params?: P): Promise<Misskey.api.SwitchCaseResponseType<E, P> | undefined> {
+ let account: Pick<Misskey.entities.SignupResponse, 'id' | 'token'> | undefined;
if (userId) {
account = await getAccountFromId(userId);
if (!account) return;
}
- return cli.request(endpoint, options, account?.token);
+ return (cli.request as <E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
+ endpoint: E,
+ params: P,
+ credential?: string | null,
+ ) => Promise<Misskey.api.SwitchCaseResponseType<E, P>>)(endpoint, params, account?.token);
}
// mark-all-as-read送出を1秒間隔に制限する
@@ -33,7 +40,7 @@ export function sendMarkAllAsRead(userId: string): Promise<null | undefined | vo
return new Promise(resolve => {
setTimeout(() => {
readBlockingStatus.set(userId, false);
- api('notifications/mark-all-as-read', userId).then(resolve, resolve);
+ (api('notifications/mark-all-as-read', userId) as Promise<void>).then(resolve, resolve);
}, 1000);
});
}
diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts
index 7a0010992e..2d39d23ec7 100644
--- a/packages/sw/src/sw.ts
+++ b/packages/sw/src/sw.ts
@@ -160,8 +160,8 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv
case 'markAllAsRead':
await globalThis.registration.getNotifications()
.then(notifications => notifications.forEach(n => n.tag !== 'read_notification' && n.close()));
- await get('accounts').then(accounts => {
- return Promise.all(accounts.map(async account => {
+ await get<Pick<Misskey.entities.SignupResponse, 'id' | 'token'>[]>('accounts').then(accounts => {
+ return Promise.all((accounts ?? []).map(async account => {
await swos.sendMarkAllAsRead(account.id);
}));
});