diff --git a/src/client/init.ts b/src/client/init.ts index 96ac6f8009..bd958e36fd 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -151,15 +151,15 @@ const loginId = params.get('loginId'); if (loginId) { const target = deleteLoginId(location.toString()); - + if (!$i || $i.id !== loginId) { const account = await getAccountFromId(loginId); if (account) { - login(account.token, target) + login(account.token, target); } } - history.replaceState({ misskey: 'loginId' }, '', target) + history.replaceState({ misskey: 'loginId' }, '', target); } //#endregion @@ -252,7 +252,7 @@ navigator.serviceWorker.addEventListener('message', ev => { return getAccountFromId(data.loginId).then(account => { if (!account) return; return login(account.token, data.url); - }) + }); } switch (data.order) { diff --git a/src/client/scripts/get-account-from-id.ts b/src/client/scripts/get-account-from-id.ts index 52b758b39c..be4cfaeba4 100644 --- a/src/client/scripts/get-account-from-id.ts +++ b/src/client/scripts/get-account-from-id.ts @@ -1,7 +1,7 @@ import { get } from 'idb-keyval'; export async function getAccountFromId(id: string) { - const accounts = await get('accounts') as { token: string; id: string; }[]; - if (!accounts) console.log('Accounts are not recorded'); - return accounts.find(e => e.id === id) + const accounts = await get('accounts') as { token: string; id: string; }[]; + if (!accounts) console.log('Accounts are not recorded'); + return accounts.find(e => e.id === id); } diff --git a/src/client/scripts/login-id.ts b/src/client/scripts/login-id.ts index 157b40c572..50e5229558 100644 --- a/src/client/scripts/login-id.ts +++ b/src/client/scripts/login-id.ts @@ -1,11 +1,11 @@ export function appendLoginId(url: string, loginId: string) { - const u = new URL(url, origin); - u.searchParams.append('loginId', loginId); - return u.toString(); + const u = new URL(url, origin); + u.searchParams.append('loginId', loginId); + return u.toString(); } export function deleteLoginId(url: string) { - const u = new URL(url); - u.searchParams.delete('loginId'); - return u.toString(); + const u = new URL(url); + u.searchParams.delete('loginId'); + return u.toString(); } diff --git a/src/client/sw/operations.ts b/src/client/sw/operations.ts index 03a0b03b65..bf6434d5ea 100644 --- a/src/client/sw/operations.ts +++ b/src/client/sw/operations.ts @@ -10,63 +10,63 @@ import { getAccountFromId } from '@/scripts/get-account-from-id'; import { appendLoginId } from '@/scripts/login-id'; export async function api(endpoint: string, userId: string, options: any = {}) { - const account = await getAccountFromId(userId) - if (!account) return; + const account = await getAccountFromId(userId); + if (!account) return; - return fetch(`${origin}/api/${endpoint}`, { - method: 'POST', - body: JSON.stringify({ - i: account.token, - ...options - }), - credentials: 'omit', - cache: 'no-cache', - }).then(async res => { - if (!res.ok) Error(`Error while fetching: ${await res.text()}`); + return fetch(`${origin}/api/${endpoint}`, { + method: 'POST', + body: JSON.stringify({ + i: account.token, + ...options + }), + credentials: 'omit', + cache: 'no-cache', + }).then(async res => { + if (!res.ok) Error(`Error while fetching: ${await res.text()}`); - if (res.status === 200) return res.json(); - return; - }) + if (res.status === 200) return res.json(); + return; + }); } // rendered acctからユーザーを開く export function openUser(acct: string, loginId: string) { - return openClient('push', `/@${acct}`, loginId, { acct }) + return openClient('push', `/@${acct}`, loginId, { acct }); } // noteIdからノートを開く export function openNote(noteId: string, loginId: string) { - return openClient('push', `/notes/${noteId}`, loginId, { noteId }) + return openClient('push', `/notes/${noteId}`, loginId, { noteId }); } export async function openChat(body: any, loginId: string) { - if (body.groupId === null) { - return openClient('push', `/my/messaging/${renderAcct(body.user)}`, loginId, { body }) - } else { - return openClient('push', `/my/messaging/group/${body.groupId}`, loginId, { body }) - } + if (body.groupId === null) { + return openClient('push', `/my/messaging/${renderAcct(body.user)}`, loginId, { body }); + } else { + return openClient('push', `/my/messaging/group/${body.groupId}`, loginId, { body }); + } } // post-formのオプションから投稿フォームを開く export async function openPost(options: any, loginId: string) { - // クエリを作成しておく - let url = `/share?`; - if (options.initialText) url += `text=${options.initialText}&`; - if (options.reply) url += `replyId=${options.reply.id}&`; - if (options.renote) url += `renoteId=${options.renote.id}&`; + // クエリを作成しておく + let url = `/share?`; + if (options.initialText) url += `text=${options.initialText}&`; + if (options.reply) url += `replyId=${options.reply.id}&`; + if (options.renote) url += `renoteId=${options.renote.id}&`; - return openClient('post', url, loginId, { options }) + return openClient('post', url, loginId, { options }); } export async function openClient(order: swMessageOrderType, url: string, loginId: string, query: any = {}) { - const client = await self.clients.matchAll({ + const client = await self.clients.matchAll({ type: 'window' }).then(clients => clients.length > 0 ? clients[0] as WindowClient : null); - if (client) { - client.postMessage({ type: 'order', ...query, order, loginId, url } as SwMessage); - return client; - } + if (client) { + client.postMessage({ type: 'order', ...query, order, loginId, url } as SwMessage); + return client; + } - return self.clients.openWindow(appendLoginId(url, loginId)); + return self.clients.openWindow(appendLoginId(url, loginId)); } diff --git a/src/client/sw/sw.ts b/src/client/sw/sw.ts index 8af03eb130..a2fbcf3c22 100644 --- a/src/client/sw/sw.ts +++ b/src/client/sw/sw.ts @@ -169,7 +169,7 @@ self.addEventListener('notificationclick', ev => { notification.close(); } - })()) + })()); }); self.addEventListener('notificationclose', ev => { @@ -189,7 +189,7 @@ self.addEventListener('message', async ev => { await caches.keys() .then(cacheNames => Promise.all( cacheNames.map(name => caches.delete(name)) - )) + )); return; // TODO } diff --git a/src/server/api/common/read-messaging-message.ts b/src/server/api/common/read-messaging-message.ts index 14b11f9992..40b9372c8b 100644 --- a/src/server/api/common/read-messaging-message.ts +++ b/src/server/api/common/read-messaging-message.ts @@ -62,12 +62,10 @@ export async function readUserMessagingMessage( isRead: false, }, take: 1 - }) + }); if (!count) { pushNotification(userId, 'readAllMessagingMessagesOfARoom', { userId: otherpartyId }); - } else { - console.log('count') } } } @@ -131,12 +129,10 @@ export async function readGroupMessagingMessage( .andWhere('message.userId != :userId', { userId: userId }) .andWhere('NOT (:userId = ANY(message.reads))', { userId: userId }) .andWhere('message.createdAt > :joinedAt', { joinedAt: joining.createdAt }) // 自分が加入する前の会話については、未読扱いしない - .getOne().then(x => x != null) + .getOne().then(x => x != null); if (!unreadExist) { pushNotification(userId, 'readAllMessagingMessagesOfARoom', { groupId }); - } else { - console.log('unread exist') } } }