fix lint
This commit is contained in:
parent
bf1db27824
commit
1ae1385d43
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue