fix lint
This commit is contained in:
parent
bf1db27824
commit
1ae1385d43
|
@ -155,11 +155,11 @@ if (loginId) {
|
||||||
if (!$i || $i.id !== loginId) {
|
if (!$i || $i.id !== loginId) {
|
||||||
const account = await getAccountFromId(loginId);
|
const account = await getAccountFromId(loginId);
|
||||||
if (account) {
|
if (account) {
|
||||||
login(account.token, target)
|
login(account.token, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
history.replaceState({ misskey: 'loginId' }, '', target)
|
history.replaceState({ misskey: 'loginId' }, '', target);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
@ -252,7 +252,7 @@ navigator.serviceWorker.addEventListener('message', ev => {
|
||||||
return getAccountFromId(data.loginId).then(account => {
|
return getAccountFromId(data.loginId).then(account => {
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
return login(account.token, data.url);
|
return login(account.token, data.url);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (data.order) {
|
switch (data.order) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { get } from 'idb-keyval';
|
import { get } from 'idb-keyval';
|
||||||
|
|
||||||
export async function getAccountFromId(id: string) {
|
export async function getAccountFromId(id: string) {
|
||||||
const accounts = await get('accounts') as { token: string; id: string; }[];
|
const accounts = await get('accounts') as { token: string; id: string; }[];
|
||||||
if (!accounts) console.log('Accounts are not recorded');
|
if (!accounts) console.log('Accounts are not recorded');
|
||||||
return accounts.find(e => e.id === id)
|
return accounts.find(e => e.id === id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
export function appendLoginId(url: string, loginId: string) {
|
export function appendLoginId(url: string, loginId: string) {
|
||||||
const u = new URL(url, origin);
|
const u = new URL(url, origin);
|
||||||
u.searchParams.append('loginId', loginId);
|
u.searchParams.append('loginId', loginId);
|
||||||
return u.toString();
|
return u.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteLoginId(url: string) {
|
export function deleteLoginId(url: string) {
|
||||||
const u = new URL(url);
|
const u = new URL(url);
|
||||||
u.searchParams.delete('loginId');
|
u.searchParams.delete('loginId');
|
||||||
return u.toString();
|
return u.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,63 +10,63 @@ import { getAccountFromId } from '@/scripts/get-account-from-id';
|
||||||
import { appendLoginId } from '@/scripts/login-id';
|
import { appendLoginId } from '@/scripts/login-id';
|
||||||
|
|
||||||
export async function api(endpoint: string, userId: string, options: any = {}) {
|
export async function api(endpoint: string, userId: string, options: any = {}) {
|
||||||
const account = await getAccountFromId(userId)
|
const account = await getAccountFromId(userId);
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
|
|
||||||
return fetch(`${origin}/api/${endpoint}`, {
|
return fetch(`${origin}/api/${endpoint}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
i: account.token,
|
i: account.token,
|
||||||
...options
|
...options
|
||||||
}),
|
}),
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
}).then(async res => {
|
}).then(async res => {
|
||||||
if (!res.ok) Error(`Error while fetching: ${await res.text()}`);
|
if (!res.ok) Error(`Error while fetching: ${await res.text()}`);
|
||||||
|
|
||||||
if (res.status === 200) return res.json();
|
if (res.status === 200) return res.json();
|
||||||
return;
|
return;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// rendered acctからユーザーを開く
|
// rendered acctからユーザーを開く
|
||||||
export function openUser(acct: string, loginId: string) {
|
export function openUser(acct: string, loginId: string) {
|
||||||
return openClient('push', `/@${acct}`, loginId, { acct })
|
return openClient('push', `/@${acct}`, loginId, { acct });
|
||||||
}
|
}
|
||||||
|
|
||||||
// noteIdからノートを開く
|
// noteIdからノートを開く
|
||||||
export function openNote(noteId: string, loginId: string) {
|
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) {
|
export async function openChat(body: any, loginId: string) {
|
||||||
if (body.groupId === null) {
|
if (body.groupId === null) {
|
||||||
return openClient('push', `/my/messaging/${renderAcct(body.user)}`, loginId, { body })
|
return openClient('push', `/my/messaging/${renderAcct(body.user)}`, loginId, { body });
|
||||||
} else {
|
} else {
|
||||||
return openClient('push', `/my/messaging/group/${body.groupId}`, loginId, { body })
|
return openClient('push', `/my/messaging/group/${body.groupId}`, loginId, { body });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// post-formのオプションから投稿フォームを開く
|
// post-formのオプションから投稿フォームを開く
|
||||||
export async function openPost(options: any, loginId: string) {
|
export async function openPost(options: any, loginId: string) {
|
||||||
// クエリを作成しておく
|
// クエリを作成しておく
|
||||||
let url = `/share?`;
|
let url = `/share?`;
|
||||||
if (options.initialText) url += `text=${options.initialText}&`;
|
if (options.initialText) url += `text=${options.initialText}&`;
|
||||||
if (options.reply) url += `replyId=${options.reply.id}&`;
|
if (options.reply) url += `replyId=${options.reply.id}&`;
|
||||||
if (options.renote) url += `renoteId=${options.renote.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 = {}) {
|
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'
|
type: 'window'
|
||||||
}).then(clients => clients.length > 0 ? clients[0] as WindowClient : null);
|
}).then(clients => clients.length > 0 ? clients[0] as WindowClient : null);
|
||||||
|
|
||||||
if (client) {
|
if (client) {
|
||||||
client.postMessage({ type: 'order', ...query, order, loginId, url } as SwMessage);
|
client.postMessage({ type: 'order', ...query, order, loginId, url } as SwMessage);
|
||||||
return client;
|
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();
|
notification.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
})())
|
})());
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('notificationclose', ev => {
|
self.addEventListener('notificationclose', ev => {
|
||||||
|
@ -189,7 +189,7 @@ self.addEventListener('message', async ev => {
|
||||||
await caches.keys()
|
await caches.keys()
|
||||||
.then(cacheNames => Promise.all(
|
.then(cacheNames => Promise.all(
|
||||||
cacheNames.map(name => caches.delete(name))
|
cacheNames.map(name => caches.delete(name))
|
||||||
))
|
));
|
||||||
return; // TODO
|
return; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,12 +62,10 @@ export async function readUserMessagingMessage(
|
||||||
isRead: false,
|
isRead: false,
|
||||||
},
|
},
|
||||||
take: 1
|
take: 1
|
||||||
})
|
});
|
||||||
|
|
||||||
if (!count) {
|
if (!count) {
|
||||||
pushNotification(userId, 'readAllMessagingMessagesOfARoom', { userId: otherpartyId });
|
pushNotification(userId, 'readAllMessagingMessagesOfARoom', { userId: otherpartyId });
|
||||||
} else {
|
|
||||||
console.log('count')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,12 +129,10 @@ export async function readGroupMessagingMessage(
|
||||||
.andWhere('message.userId != :userId', { userId: userId })
|
.andWhere('message.userId != :userId', { userId: userId })
|
||||||
.andWhere('NOT (:userId = ANY(message.reads))', { userId: userId })
|
.andWhere('NOT (:userId = ANY(message.reads))', { userId: userId })
|
||||||
.andWhere('message.createdAt > :joinedAt', { joinedAt: joining.createdAt }) // 自分が加入する前の会話については、未読扱いしない
|
.andWhere('message.createdAt > :joinedAt', { joinedAt: joining.createdAt }) // 自分が加入する前の会話については、未読扱いしない
|
||||||
.getOne().then(x => x != null)
|
.getOne().then(x => x != null);
|
||||||
|
|
||||||
if (!unreadExist) {
|
if (!unreadExist) {
|
||||||
pushNotification(userId, 'readAllMessagingMessagesOfARoom', { groupId });
|
pushNotification(userId, 'readAllMessagingMessagesOfARoom', { groupId });
|
||||||
} else {
|
|
||||||
console.log('unread exist')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue