From 852e4db958ee21e57c10ac786a51ebd8b14cbb74 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 21 Feb 2021 14:35:54 +0900 Subject: [PATCH] WORK IN PROGRESS --- src/client/account.ts | 9 +++++---- src/client/components/notification.vue | 4 ++-- src/client/init.ts | 4 ++-- src/client/scripts/unison-reload.ts | 16 ++++++++++++---- yarn.lock | 5 ----- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index 1ba7a28908..c539673c0d 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -17,6 +17,7 @@ const data = localStorage.getItem('account'); export const $i = data ? reactive(JSON.parse(data) as Account) : null; export async function signout() { + waiting(); localStorage.removeItem('account'); //#region Remove account @@ -42,7 +43,7 @@ export async function signout() { document.cookie = `igi=; path=/`; if (accounts.length > 0) login(accounts[0].token); - else location.href = '/'; + else unisonReload(true); } export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> { @@ -92,16 +93,16 @@ export function refreshAccount() { return fetchAccount($i.token).then(updateAccount); } -export async function login(token: Account['token'], href?: string) { +export async function login(token: Account['token'], redirect?: string) { waiting(); if (_DEV_) console.log('logging as token ', token); const me = await fetchAccount(token); localStorage.setItem('account', JSON.stringify(me)); await addAccount(me.id, token); - if (href) { + if (redirect) { reloadChannel.postMessage('reload'); - location.href = href; + location.href = redirect; return; } diff --git a/src/client/components/notification.vue b/src/client/components/notification.vue index 4ae8547162..b30cc54088 100644 --- a/src/client/components/notification.vue +++ b/src/client/components/notification.vue @@ -115,14 +115,14 @@ export default defineComponent({ this.connection = os.stream.useSharedConnection('main'); + // 既読処理 + // notification.isReadは更新しないので注意 this.connection.on('readAllNotifications', () => { this.readObserver.unobserve(this.$el); - this.notification = markNotificationRead(this.notification); }); this.connection.on('readNotifications', notificationIds => { if (notificationIds.includes(this.notification.id)) { this.readObserver.unobserve(this.$el); - this.notification = markNotificationRead(this.notification); } }) } diff --git a/src/client/init.ts b/src/client/init.ts index f31f161cef..a04fe810ac 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -66,7 +66,7 @@ import { search } from '@/scripts/search'; import { isMobile } from '@/scripts/is-mobile'; import { getThemes } from '@/theme-store'; import { initializeSw } from '@/scripts/initialize-sw'; -import { reloadChannel } from '@/scripts/unison-reload'; +import { reload, reloadChannel } from '@/scripts/unison-reload'; import { deleteLoginId } from '@/scripts/login-id'; import { getAccountFromId } from '@/scripts/get-account-from-id'; @@ -120,7 +120,7 @@ if (defaultStore.state.reportError && !_DEV_) { document.addEventListener('touchend', () => {}, { passive: true }); // 一斉リロード -reloadChannel.addEventListener('message', () => location.reload()); +reloadChannel.addEventListener('message', reload); //#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ // TODO: いつの日にか消したい diff --git a/src/client/scripts/unison-reload.ts b/src/client/scripts/unison-reload.ts index 92556aefaa..c50650452d 100644 --- a/src/client/scripts/unison-reload.ts +++ b/src/client/scripts/unison-reload.ts @@ -1,10 +1,18 @@ // SafariがBroadcastChannel未実装なのでライブラリを使う import { BroadcastChannel } from 'broadcast-channel'; -export const reloadChannel = new BroadcastChannel<'reload'>('reload'); +export const reloadChannel = new BroadcastChannel('reload'); // BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。 -export function unisonReload() { - reloadChannel.postMessage('reload'); - location.reload(); +export function unisonReload(redirectToRoot?: boolean) { + reloadChannel.postMessage(!!redirectToRoot); + reload(); +} + +export function reload(redirectToRoot?: boolean) { + if (redirectToRoot) { + location.href = '/'; + } else { + location.reload(); + } } diff --git a/yarn.lock b/yarn.lock index 029d093777..91cfdacce3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5042,11 +5042,6 @@ idb-keyval@5.0.2: resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.2.tgz#243cf2b7db1bee2a8a41b78c14a18a85db0e1646" integrity sha512-1DYjY/nX2U9pkTkwFoAmKcK1ZWmkNgO32Oon9tp/9+HURizxUQ4fZRxMJZs093SldP7q6dotVj03kIkiqOILyA== -idb-keyval@5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.1.tgz#d3913debfb58edee299da5cf2dded6c2670c05ef" - integrity sha512-bfi+Znn6oSPPgGcVUj2tYMIOQ5TD6V1qj50SdKQecGZx9lqUATcQ7ArHOt9sPcEhACoYe//yr2igmS6SMc59SA== - ieee754@1.1.13, ieee754@^1.1.13, ieee754@^1.1.4: version "1.1.13" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84"