mirror of
https://github.com/kokonect-link/cherrypick
synced 2025-01-24 02:34:00 +09:00
Merge remote-branch 'misskey/develop'
This commit is contained in:
commit
b7f9f9d4aa
3
.github/workflows/lint.yml
vendored
3
.github/workflows/lint.yml
vendored
@ -78,6 +78,7 @@ jobs:
|
||||
matrix:
|
||||
workspace:
|
||||
- backend
|
||||
- sw
|
||||
- cherrypick-js
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.1
|
||||
@ -92,7 +93,7 @@ jobs:
|
||||
- run: corepack enable
|
||||
- run: pnpm i --frozen-lockfile
|
||||
- run: pnpm --filter cherrypick-js run build
|
||||
if: ${{ matrix.workspace == 'backend' }}
|
||||
if: ${{ matrix.workspace == 'backend' || matrix.workspace == 'sw' }}
|
||||
- run: pnpm --filter misskey-reversi run build
|
||||
if: ${{ matrix.workspace == 'backend' }}
|
||||
- run: pnpm --filter ${{ matrix.workspace }} run typecheck
|
||||
|
@ -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)} (@${data.body.user.username}${data.body.user.host != null ? '@' + data.body.user.host : ''})`,
|
||||
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,9 +163,9 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
|
||||
|
||||
const tag = `reaction:${data.body.note.id}`;
|
||||
return [i18n.tsx._notification.youGotReact({ name: getUserName(data.body.user) }), {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,no-constant-binary-expression
|
||||
body: (reaction1.startsWith(':') ? `:${ reaction }:` : `${ reaction }`) + '\n' + data.body.note.text ?? '',
|
||||
icon: data.body.user.avatarUrl,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
body: (reaction1.startsWith(':') ? `:${ reaction }:` : `${ reaction }` + '\n' + data.body.note.text) ?? '',
|
||||
icon: data.body.user.avatarUrl ?? undefined,
|
||||
tag,
|
||||
badge,
|
||||
data,
|
||||
@ -181,7 +181,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: [
|
||||
@ -199,7 +199,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,
|
||||
}];
|
||||
@ -255,9 +255,9 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
|
||||
}
|
||||
case 'unreadMessagingMessage':
|
||||
if (data.body.groupId === null) {
|
||||
return [getUserName(data.body.user), {
|
||||
return [getUserName(data.body.user ?? { name: null, username: '' }), {
|
||||
body: data.body.text ?? '',
|
||||
icon: data.body.user.avatarUrl,
|
||||
icon: data.body.user?.avatarUrl ?? undefined,
|
||||
badge: iconUrl('messages'),
|
||||
tag: `messaging:user:${data.body.userId}`,
|
||||
data,
|
||||
@ -265,8 +265,8 @@ async function composeNotification(data: PushNotificationDataMap[keyof PushNotif
|
||||
}];
|
||||
}
|
||||
return [data.body.group?.name ?? '', {
|
||||
body: `${getUserName(data.body.user)}: ${data.body.text ?? ''}`,
|
||||
icon: data.body.user.avatarUrl,
|
||||
body: `${getUserName(data.body.user ?? { name: null, username: '' })}: ${data.body.text ?? ''}`,
|
||||
icon: data.body.user?.avatarUrl ?? undefined,
|
||||
badge: iconUrl('messages'),
|
||||
tag: `messaging:group:${data.body.groupId}`,
|
||||
data,
|
||||
@ -275,7 +275,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,
|
||||
|
@ -4,9 +4,10 @@
|
||||
*/
|
||||
|
||||
import { get } from 'idb-keyval';
|
||||
import * as Misskey from 'cherrypick-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;
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -189,8 +189,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);
|
||||
}));
|
||||
});
|
||||
|
@ -2,6 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"noEmitOnError": false,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedParameters": false,
|
||||
"noUnusedLocals": true,
|
||||
|
Loading…
Reference in New Issue
Block a user