From 33d79420eb3c860d377258289b87def4a69c6778 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 19 Jun 2019 17:47:24 +0900 Subject: [PATCH 01/15] Fix code style --- src/mfm/language.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mfm/language.ts b/src/mfm/language.ts index 4750ea3380..75a2baaab9 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -157,12 +157,14 @@ export const mfmLanguage = P.createLanguage({ let url: string; if (!match) { const match = text.match(/^<(https?:\/\/.*?)>/); - if (!match) + if (!match) { return P.makeFailure(i, 'not a url'); + } url = match[1]; i += 2; - } else + } else { url = match[0]; + } url = removeOrphanedBrackets(url); while (url.endsWith('.') || url.endsWith(',')) { if (url.endsWith('.')) url = url.substr(0, url.lastIndexOf('.')); From 2c1932faa72ef6f2c30df62e5b3248f2c0b77948 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 20 Jun 2019 22:52:35 +0900 Subject: [PATCH 02/15] Add psql version to info page --- src/server/web/index.ts | 2 ++ src/server/web/views/info.pug | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/server/web/index.ts b/src/server/web/index.ts index c5a3497f44..ba8f0649cf 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -20,6 +20,7 @@ import { Users, Notes, Emojis, UserProfiles, Pages } from '../../models'; import parseAcct from '../../misc/acct/parse'; import getNoteSummary from '../../misc/get-note-summary'; import { ensure } from '../../prelude/ensure'; +import { getConnection } from 'typeorm'; const client = `${__dirname}/../../client/`; @@ -250,6 +251,7 @@ router.get('/info', async ctx => { machine: os.hostname(), os: os.platform(), node: process.version, + psql: await getConnection().query('SHOW server_version').then(x => x[0].server_version), cpu: { model: os.cpus()[0].model, cores: os.cpus().length diff --git a/src/server/web/views/info.pug b/src/server/web/views/info.pug index c8b0bd939a..f18dcd45e3 100644 --- a/src/server/web/views/info.pug +++ b/src/server/web/views/info.pug @@ -85,6 +85,9 @@ html tr th Node version td= node + tr + th PSQL version + td= psql tr th Machine td= machine From bd839399933350bad12842d0170cf3c28f9a75d2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 20 Jun 2019 22:55:57 +0900 Subject: [PATCH 03/15] Provide Redis version --- src/client/app/common/views/widgets/server.info.vue | 1 + src/server/api/endpoints/meta.ts | 2 ++ src/server/web/index.ts | 2 ++ src/server/web/views/info.pug | 3 +++ 4 files changed, 8 insertions(+) diff --git a/src/client/app/common/views/widgets/server.info.vue b/src/client/app/common/views/widgets/server.info.vue index 41ccd23bfe..c6e0d68b11 100644 --- a/src/client/app/common/views/widgets/server.info.vue +++ b/src/client/app/common/views/widgets/server.info.vue @@ -4,6 +4,7 @@

Machine: {{ meta.machine }}

Node: {{ meta.node }}

PSQL: {{ meta.psql }}

+

Redis: {{ meta.redis }}

Version: {{ meta.version }}

diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index 4da0c7476c..1aa9a855dd 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -7,6 +7,7 @@ import * as pkg from '../../../../package.json'; import { Emojis } from '../../../models'; import { types, bool } from '../../../misc/schema'; import { getConnection } from 'typeorm'; +import redis from '../../../db/redis'; export const meta = { stability: 'stable', @@ -116,6 +117,7 @@ export default define(meta, async (ps, me) => { os: os.platform(), node: process.version, psql: await getConnection().query('SHOW server_version').then(x => x[0].server_version), + redis: redis.server_info.redis_version, cpu: { model: os.cpus()[0].model, diff --git a/src/server/web/index.ts b/src/server/web/index.ts index ba8f0649cf..8cf6a75208 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -21,6 +21,7 @@ import parseAcct from '../../misc/acct/parse'; import getNoteSummary from '../../misc/get-note-summary'; import { ensure } from '../../prelude/ensure'; import { getConnection } from 'typeorm'; +import redis from '../../db/redis'; const client = `${__dirname}/../../client/`; @@ -252,6 +253,7 @@ router.get('/info', async ctx => { os: os.platform(), node: process.version, psql: await getConnection().query('SHOW server_version').then(x => x[0].server_version), + redis: redis.server_info.redis_version, cpu: { model: os.cpus()[0].model, cores: os.cpus().length diff --git a/src/server/web/views/info.pug b/src/server/web/views/info.pug index f18dcd45e3..fc71e5c193 100644 --- a/src/server/web/views/info.pug +++ b/src/server/web/views/info.pug @@ -88,6 +88,9 @@ html tr th PSQL version td= psql + tr + th Redis version + td= redis tr th Machine td= machine From 18184441f1eabb34696ea4771051eb3aa8334ce4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 Jun 2019 01:50:01 +0900 Subject: [PATCH 04/15] =?UTF-8?q?=E3=83=9B=E3=83=BC=E3=83=A0=E3=81=AE?= =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=9E=E3=82=A4=E3=82=BA=E6=83=85?= =?UTF-8?q?=E5=A0=B1=E3=82=92=E8=A4=87=E6=95=B0=E3=81=AE=E3=83=87=E3=83=90?= =?UTF-8?q?=E3=82=A4=E3=82=B9=E9=96=93=E3=81=A7=E5=90=8C=E6=9C=9F=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 2 ++ .../views/components/settings/settings.vue | 16 ++++++++++ src/client/app/desktop/views/home/home.vue | 16 ++++++++-- src/client/app/mobile/views/pages/widgets.vue | 14 ++++++++- src/client/app/store.ts | 30 +++++++++++++++++++ 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index d9223b1c4b..bdf8c24ce4 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -282,6 +282,8 @@ common: disable-via-mobile: "「モバイルからの投稿」フラグを付けない" load-raw-images: "添付された画像を高画質で表示する" load-remote-media: "リモートサーバーのメディアを表示する" + sync: "同期" + home-profile: "ホームのプロファイル" search: "検索" delete: "削除" diff --git a/src/client/app/common/views/components/settings/settings.vue b/src/client/app/common/views/components/settings/settings.vue index 0cbc40da57..1c02bdee8c 100644 --- a/src/client/app/common/views/components/settings/settings.vue +++ b/src/client/app/common/views/components/settings/settings.vue @@ -131,6 +131,12 @@ +
+
{{ $t('@._settings.sync') }}
+ {{ $t('@._settings.home-profile') }} + {{ $t('@._settings.home-profile') }} +
+
{{ $t('@._settings.web-search-engine') }}
{{ $t('@._settings.web-search-engine') }} @@ -500,6 +506,16 @@ export default Vue.extend({ get() { return this.$store.state.device.mobileNotificationPosition; }, set(value) { this.$store.commit('device/set', { key: 'mobileNotificationPosition', value }); } }, + + homeProfile: { + get() { return this.$store.state.device.homeProfile; }, + set(value) { this.$store.commit('device/set', { key: 'homeProfile', value }); } + }, + + mobileHomeProfile: { + get() { return this.$store.state.device.mobileHomeProfile; }, + set(value) { this.$store.commit('device/set', { key: 'mobileHomeProfile', value }); } + }, }, created() { this.$root.getMeta().then(meta => { diff --git a/src/client/app/desktop/views/home/home.vue b/src/client/app/desktop/views/home/home.vue index d4677df842..49ac4c2407 100644 --- a/src/client/app/desktop/views/home/home.vue +++ b/src/client/app/desktop/views/home/home.vue @@ -102,7 +102,11 @@ export default Vue.extend({ computed: { home(): any[] { if (this.$store.getters.isSignedIn) { - return this.$store.state.device.home || []; + if (this.$store.state.device.homeProfile) { + return this.$store.state.settings.homeProfiles[this.$store.state.device.homeProfile] || this.$store.state.device.home || []; + } else { + return this.$store.state.device.home || []; + } } else { return [{ name: 'instance', @@ -186,6 +190,14 @@ export default Vue.extend({ if (this.$store.state.device.home == null) { this.$store.commit('device/setHome', _defaultDesktopHomeWidgets); } + + if (this.$store.state.device.homeProfile) { + this.$watch('$store.state.device.home', () => { + this.$store.dispatch('settings/updateHomeProfile'); + }, { + deep: true + }); + } } }, @@ -245,7 +257,7 @@ export default Vue.extend({ focus() { (this.$refs.content as any).focus(); - } + }, } }); diff --git a/src/client/app/mobile/views/pages/widgets.vue b/src/client/app/mobile/views/pages/widgets.vue index 7130fddb34..7f0ef678de 100644 --- a/src/client/app/mobile/views/pages/widgets.vue +++ b/src/client/app/mobile/views/pages/widgets.vue @@ -72,7 +72,11 @@ export default Vue.extend({ computed: { widgets(): any[] { - return this.$store.state.device.mobileHome; + if (this.$store.state.device.mobileHomeProfile) { + return this.$store.state.settings.mobileHomeProfiles[this.$store.state.device.mobileHomeProfile] || this.$store.state.device.mobileHome; + } else { + return this.$store.state.device.mobileHome; + } } }, @@ -98,6 +102,14 @@ export default Vue.extend({ id: 'g', data: {} }]); } + + if (this.$store.state.device.mobileHomeProfile) { + this.$watch('$store.state.device.mobileHome', () => { + this.$store.dispatch('settings/updateMobileHomeProfile'); + }, { + deep: true + }); + } }, mounted() { diff --git a/src/client/app/store.ts b/src/client/app/store.ts index 6f545eb09b..7b56628b31 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -34,10 +34,14 @@ const defaultSettings = { gamesReversiShowBoardLabels: false, gamesReversiUseAvatarStones: true, disableAnimatedMfm: false, + homeProfiles: {}, + mobileHomeProfiles: {}, }; const defaultDeviceSettings = { home: null, + homeProfile: null, + mobileHomeProfile: null, mobileHome: [], deck: null, deckMode: false, @@ -361,6 +365,32 @@ export default (os: MiOS) => new Vuex.Store({ }); } }, + + updateHomeProfile(ctx) { + const profiles = ctx.state.homeProfiles; + profiles[ctx.rootState.device.homeProfile] = ctx.rootState.device.home; + ctx.commit('set', { + key: 'homeProfiles', + value: profiles + }); + os.api('i/update-client-setting', { + name: 'homeProfiles', + value: profiles + }); + }, + + updateMobileHomeProfile(ctx) { + const profiles = ctx.state.mobileHomeProfiles; + profiles[ctx.rootState.device.mobileHomeProfile] = ctx.rootState.device.mobileHome; + ctx.commit('set', { + key: 'mobileHomeProfiles', + value: profiles + }); + os.api('i/update-client-setting', { + name: 'mobileHomeProfiles', + value: profiles + }); + } } } } From 2b8d0225cc43971fc7b9dc27447725233a73208c Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 21 Jun 2019 11:50:38 +0900 Subject: [PATCH 05/15] Enable ServiceWorker (#5075) --- src/client/app/mios.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/client/app/mios.ts b/src/client/app/mios.ts index ae1446b934..a73ef45c38 100644 --- a/src/client/app/mios.ts +++ b/src/client/app/mios.ts @@ -173,10 +173,9 @@ export default class MiOS extends EventEmitter { // Init service worker if (this.shouldRegisterSw) { - // #4813 - //this.getMeta().then(data => { - // this.registerSw(data.swPublickey); - //}); + this.getMeta().then(data => { + this.registerSw(data.swPublickey); + }); } }; From 6136f6f33a70459d3e52b4273f57628376dd15a9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 Jun 2019 13:06:47 +0900 Subject: [PATCH 06/15] =?UTF-8?q?=E3=83=87=E3=83=83=E3=82=AD=E3=81=AE?= =?UTF-8?q?=E7=8A=B6=E6=85=8B=E3=82=92=E5=90=8C=E6=9C=9F=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 1 + .../views/components/settings/settings.vue | 6 ++++ .../app/common/views/deck/deck.column.vue | 3 +- src/client/app/common/views/deck/deck.vue | 29 +++++++++++++++---- src/client/app/store.ts | 17 ++++++++++- 5 files changed, 48 insertions(+), 8 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index bdf8c24ce4..47e1d4d93f 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -284,6 +284,7 @@ common: load-remote-media: "リモートサーバーのメディアを表示する" sync: "同期" home-profile: "ホームのプロファイル" + deck-profile: "デッキのプロファイル" search: "検索" delete: "削除" diff --git a/src/client/app/common/views/components/settings/settings.vue b/src/client/app/common/views/components/settings/settings.vue index 1c02bdee8c..094791a153 100644 --- a/src/client/app/common/views/components/settings/settings.vue +++ b/src/client/app/common/views/components/settings/settings.vue @@ -135,6 +135,7 @@
{{ $t('@._settings.sync') }}
{{ $t('@._settings.home-profile') }} {{ $t('@._settings.home-profile') }} + {{ $t('@._settings.deck-profile') }}
@@ -516,6 +517,11 @@ export default Vue.extend({ get() { return this.$store.state.device.mobileHomeProfile; }, set(value) { this.$store.commit('device/set', { key: 'mobileHomeProfile', value }); } }, + + deckProfile: { + get() { return this.$store.state.device.deckProfile; }, + set(value) { this.$store.commit('device/set', { key: 'deckProfile', value }); } + }, }, created() { this.$root.getMeta().then(meta => { diff --git a/src/client/app/common/views/deck/deck.column.vue b/src/client/app/common/views/deck/deck.column.vue index eaa344d36f..b09fdfbfee 100644 --- a/src/client/app/common/views/deck/deck.column.vue +++ b/src/client/app/common/views/deck/deck.column.vue @@ -146,7 +146,8 @@ export default Vue.extend({ toggleActive() { if (!this.isStacked) return; - const vms = this.$store.state.device.deck.layout.find(ids => ids.indexOf(this.column.id) != -1).map(id => this.getColumnVm(id)); + const deck = this.$store.state.device.deckProfile ? this.$store.state.settings.deckProfiles[this.$store.state.device.deckProfile] : this.$store.state.device.deck; + const vms = deck.layout.find(ids => ids.indexOf(this.column.id) != -1).map(id => this.getColumnVm(id)); if (this.active && countIf(vm => vm.$el.classList.contains('active'), vms) == 1) return; this.active = !this.active; }, diff --git a/src/client/app/common/views/deck/deck.vue b/src/client/app/common/views/deck/deck.vue index b46f2167ad..e07e504ed6 100644 --- a/src/client/app/common/views/deck/deck.vue +++ b/src/client/app/common/views/deck/deck.vue @@ -25,20 +25,29 @@ import * as uuid from 'uuid'; export default Vue.extend({ i18n: i18n('deck'), + components: { XColumnCore }, computed: { + deck() { + if (this.$store.state.device.deckProfile) { + return this.$store.state.settings.deckProfiles[this.$store.state.device.deckProfile] || this.$store.state.device.deck; + } else { + return this.$store.state.device.deck; + } + }, + columns(): any[] { - if (this.$store.state.device.deck == null) return []; - return this.$store.state.device.deck.columns; + if (this.deck == null) return []; + return this.deck.columns; }, layout(): any[] { - if (this.$store.state.device.deck == null) return []; - if (this.$store.state.device.deck.layout == null) return this.$store.state.device.deck.columns.map(c => [c.id]); - return this.$store.state.device.deck.layout; + if (this.deck == null) return []; + if (this.deck.layout == null) return this.deck.columns.map(c => [c.id]); + return this.deck.layout; }, style(): any { @@ -75,7 +84,7 @@ export default Vue.extend({ }, created() { - if (this.$store.state.device.deck == null) { + if (this.deck == null) { const deck = { columns: [/*{ type: 'widgets', @@ -106,6 +115,14 @@ export default Vue.extend({ value: deck }); } + + if (this.$store.state.device.deckProfile) { + this.$watch('$store.state.device.deck', () => { + this.$store.dispatch('settings/updateDeckProfile'); + }, { + deep: true + }); + } }, mounted() { diff --git a/src/client/app/store.ts b/src/client/app/store.ts index 7b56628b31..4a6e1a610c 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -36,6 +36,7 @@ const defaultSettings = { disableAnimatedMfm: false, homeProfiles: {}, mobileHomeProfiles: {}, + deckProfiles: {}, }; const defaultDeviceSettings = { @@ -44,6 +45,7 @@ const defaultDeviceSettings = { mobileHomeProfile: null, mobileHome: [], deck: null, + deckProfile: null, deckMode: false, deckColumnAlign: 'center', deckColumnWidth: 'normal', @@ -390,7 +392,20 @@ export default (os: MiOS) => new Vuex.Store({ name: 'mobileHomeProfiles', value: profiles }); - } + }, + + updateDeckProfile(ctx) { + const profiles = ctx.state.deckProfiles; + profiles[ctx.rootState.device.deckProfile] = ctx.rootState.device.deck; + ctx.commit('set', { + key: 'deckProfiles', + value: profiles + }); + os.api('i/update-client-setting', { + name: 'deckProfiles', + value: profiles + }); + }, } } } From aec5911821cf55dbe8704be964c5ebd3a4a7b66b Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 Jun 2019 15:08:17 +0900 Subject: [PATCH 07/15] Improve sync --- src/client/app/common/define-widget.ts | 4 +- .../views/components/settings/settings.vue | 4 +- .../app/common/views/deck/deck.column.vue | 18 +- .../app/common/views/deck/deck.tl-column.vue | 2 +- src/client/app/common/views/deck/deck.vue | 34 +- .../common/views/deck/deck.widgets-column.vue | 6 +- src/client/app/desktop/views/home/home.vue | 27 +- src/client/app/mobile/views/pages/widgets.vue | 26 +- src/client/app/store.ts | 396 ++++++++++-------- 9 files changed, 262 insertions(+), 255 deletions(-) diff --git a/src/client/app/common/define-widget.ts b/src/client/app/common/define-widget.ts index 632ddf2ed6..ba4deafe3a 100644 --- a/src/client/app/common/define-widget.ts +++ b/src/client/app/common/define-widget.ts @@ -60,9 +60,9 @@ export default function (data: { save() { if (this.platform == 'deck') { - this.$store.commit('device/updateDeckColumn', this.column); + this.$store.commit('updateDeckColumn', this.column); } else { - this.$store.commit('device/updateWidget', this.widget); + this.$store.commit('updateWidget', this.widget); } } } diff --git a/src/client/app/common/views/components/settings/settings.vue b/src/client/app/common/views/components/settings/settings.vue index 094791a153..2d962aaafa 100644 --- a/src/client/app/common/views/components/settings/settings.vue +++ b/src/client/app/common/views/components/settings/settings.vue @@ -133,8 +133,8 @@
{{ $t('@._settings.sync') }}
- {{ $t('@._settings.home-profile') }} - {{ $t('@._settings.home-profile') }} + {{ $t('@._settings.home-profile') }} + {{ $t('@._settings.home-profile') }} {{ $t('@._settings.deck-profile') }}
diff --git a/src/client/app/common/views/deck/deck.column.vue b/src/client/app/common/views/deck/deck.column.vue index b09fdfbfee..b5c0896bba 100644 --- a/src/client/app/common/views/deck/deck.column.vue +++ b/src/client/app/common/views/deck/deck.column.vue @@ -180,50 +180,50 @@ export default Vue.extend({ } }).then(({ canceled, result: name }) => { if (canceled) return; - this.$store.commit('device/renameDeckColumn', { id: this.column.id, name }); + this.$store.commit('renameDeckColumn', { id: this.column.id, name }); }); } }, null, { icon: 'arrow-left', text: this.$t('swap-left'), action: () => { - this.$store.commit('device/swapLeftDeckColumn', this.column.id); + this.$store.commit('swapLeftDeckColumn', this.column.id); } }, { icon: 'arrow-right', text: this.$t('swap-right'), action: () => { - this.$store.commit('device/swapRightDeckColumn', this.column.id); + this.$store.commit('swapRightDeckColumn', this.column.id); } }, this.isStacked ? { icon: faArrowUp, text: this.$t('swap-up'), action: () => { - this.$store.commit('device/swapUpDeckColumn', this.column.id); + this.$store.commit('swapUpDeckColumn', this.column.id); } } : undefined, this.isStacked ? { icon: faArrowDown, text: this.$t('swap-down'), action: () => { - this.$store.commit('device/swapDownDeckColumn', this.column.id); + this.$store.commit('swapDownDeckColumn', this.column.id); } } : undefined, null, { icon: ['far', 'window-restore'], text: this.$t('stack-left'), action: () => { - this.$store.commit('device/stackLeftDeckColumn', this.column.id); + this.$store.commit('stackLeftDeckColumn', this.column.id); } }, this.isStacked ? { icon: faWindowMaximize, text: this.$t('pop-right'), action: () => { - this.$store.commit('device/popRightDeckColumn', this.column.id); + this.$store.commit('popRightDeckColumn', this.column.id); } } : undefined, null, { icon: ['far', 'trash-alt'], text: this.$t('remove'), action: () => { - this.$store.commit('device/removeDeckColumn', this.column.id); + this.$store.commit('removeDeckColumn', this.column.id); } }]; @@ -307,7 +307,7 @@ export default Vue.extend({ const id = e.dataTransfer.getData('mk-deck-column'); if (id != null && id != '') { - this.$store.commit('device/swapDeckColumn', { + this.$store.commit('swapDeckColumn', { a: this.column.id, b: id }); diff --git a/src/client/app/common/views/deck/deck.tl-column.vue b/src/client/app/common/views/deck/deck.tl-column.vue index 5ab8ccb12f..cad140ed5f 100644 --- a/src/client/app/common/views/deck/deck.tl-column.vue +++ b/src/client/app/common/views/deck/deck.tl-column.vue @@ -90,7 +90,7 @@ export default Vue.extend({ methods: { onChangeSettings(v) { - this.$store.commit('device/updateDeckColumn', this.column); + this.$store.commit('updateDeckColumn', this.column); }, focus() { diff --git a/src/client/app/common/views/deck/deck.vue b/src/client/app/common/views/deck/deck.vue index e07e504ed6..070312d839 100644 --- a/src/client/app/common/views/deck/deck.vue +++ b/src/client/app/common/views/deck/deck.vue @@ -32,11 +32,7 @@ export default Vue.extend({ computed: { deck() { - if (this.$store.state.device.deckProfile) { - return this.$store.state.settings.deckProfiles[this.$store.state.device.deckProfile] || this.$store.state.device.deck; - } else { - return this.$store.state.device.deck; - } + return this.$store.getters.deck; }, columns(): any[] { @@ -115,14 +111,6 @@ export default Vue.extend({ value: deck }); } - - if (this.$store.state.device.deckProfile) { - this.$watch('$store.state.device.deck', () => { - this.$store.dispatch('settings/updateDeckProfile'); - }, { - deep: true - }); - } }, mounted() { @@ -146,7 +134,7 @@ export default Vue.extend({ icon: 'home', text: this.$t('@deck.home'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'home' }); @@ -155,7 +143,7 @@ export default Vue.extend({ icon: ['far', 'comments'], text: this.$t('@deck.local'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'local' }); @@ -164,7 +152,7 @@ export default Vue.extend({ icon: 'share-alt', text: this.$t('@deck.hybrid'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'hybrid' }); @@ -173,7 +161,7 @@ export default Vue.extend({ icon: 'globe', text: this.$t('@deck.global'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'global' }); @@ -182,7 +170,7 @@ export default Vue.extend({ icon: 'at', text: this.$t('@deck.mentions'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'mentions' }); @@ -191,7 +179,7 @@ export default Vue.extend({ icon: ['far', 'envelope'], text: this.$t('@deck.direct'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'direct' }); @@ -212,7 +200,7 @@ export default Vue.extend({ showCancelButton: true }); if (canceled) return; - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'list', list: lists.find(l => l.id === listId) @@ -227,7 +215,7 @@ export default Vue.extend({ input: true }).then(({ canceled, result: title }) => { if (canceled) return; - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'hashtag', tagTlId: this.$store.state.settings.tagTimelines.find(x => x.title == title).id @@ -238,7 +226,7 @@ export default Vue.extend({ icon: ['far', 'bell'], text: this.$t('@deck.notifications'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'notifications' }); @@ -247,7 +235,7 @@ export default Vue.extend({ icon: 'calculator', text: this.$t('@deck.widgets'), action: () => { - this.$store.commit('device/addDeckColumn', { + this.$store.commit('addDeckColumn', { id: uuid(), type: 'widgets', widgets: [] diff --git a/src/client/app/common/views/deck/deck.widgets-column.vue b/src/client/app/common/views/deck/deck.widgets-column.vue index f2385c8a48..dd28a3a8b3 100644 --- a/src/client/app/common/views/deck/deck.widgets-column.vue +++ b/src/client/app/common/views/deck/deck.widgets-column.vue @@ -110,7 +110,7 @@ export default Vue.extend({ }, addWidget() { - this.$store.commit('device/addDeckWidget', { + this.$store.commit('addDeckWidget', { id: this.column.id, widget: { name: this.widgetAdderSelected, @@ -123,14 +123,14 @@ export default Vue.extend({ }, removeWidget(widget) { - this.$store.commit('device/removeDeckWidget', { + this.$store.commit('removeDeckWidget', { id: this.column.id, widget }); }, saveWidgets() { - this.$store.commit('device/updateDeckColumn', this.column); + this.$store.commit('updateDeckColumn', this.column); } } }); diff --git a/src/client/app/desktop/views/home/home.vue b/src/client/app/desktop/views/home/home.vue index 49ac4c2407..3d05bee48d 100644 --- a/src/client/app/desktop/views/home/home.vue +++ b/src/client/app/desktop/views/home/home.vue @@ -84,6 +84,7 @@ import XWelcome from '../pages/welcome.vue'; export default Vue.extend({ i18n: i18n('desktop/views/components/home.vue'), + components: { XDraggable, XWelcome @@ -102,11 +103,7 @@ export default Vue.extend({ computed: { home(): any[] { if (this.$store.getters.isSignedIn) { - if (this.$store.state.device.homeProfile) { - return this.$store.state.settings.homeProfiles[this.$store.state.device.homeProfile] || this.$store.state.device.home || []; - } else { - return this.$store.state.device.home || []; - } + return this.$store.getters.home || []; } else { return [{ name: 'instance', @@ -142,7 +139,9 @@ export default Vue.extend({ }, created() { - if (this.$store.getters.isSignedIn) { + if (!this.$store.getters.isSignedIn) return; + + if (this.$store.getters.home == null) { const defaultDesktopHomeWidgets = { left: [ 'profile', @@ -187,17 +186,7 @@ export default Vue.extend({ } //#endregion - if (this.$store.state.device.home == null) { - this.$store.commit('device/setHome', _defaultDesktopHomeWidgets); - } - - if (this.$store.state.device.homeProfile) { - this.$watch('$store.state.device.home', () => { - this.$store.dispatch('settings/updateHomeProfile'); - }, { - deep: true - }); - } + this.$store.commit('setHome', _defaultDesktopHomeWidgets); } }, @@ -235,7 +224,7 @@ export default Vue.extend({ }, addWidget() { - this.$store.commit('device/addHomeWidget', { + this.$store.commit('addHomeWidget', { name: this.widgetAdderSelected, id: uuid(), place: 'left', @@ -246,7 +235,7 @@ export default Vue.extend({ saveHome() { const left = this.widgets.left; const right = this.widgets.right; - this.$store.commit('device/setHome', left.concat(right)); + this.$store.commit('setHome', left.concat(right)); for (const w of left) w.place = 'left'; for (const w of right) w.place = 'right'; }, diff --git a/src/client/app/mobile/views/pages/widgets.vue b/src/client/app/mobile/views/pages/widgets.vue index 7f0ef678de..c012de1314 100644 --- a/src/client/app/mobile/views/pages/widgets.vue +++ b/src/client/app/mobile/views/pages/widgets.vue @@ -72,17 +72,13 @@ export default Vue.extend({ computed: { widgets(): any[] { - if (this.$store.state.device.mobileHomeProfile) { - return this.$store.state.settings.mobileHomeProfiles[this.$store.state.device.mobileHomeProfile] || this.$store.state.device.mobileHome; - } else { - return this.$store.state.device.mobileHome; - } + return this.$store.getters.mobileHome || []; } }, created() { if (this.widgets.length == 0) { - this.$store.commit('device/setMobileHome', [{ + this.$store.commit('setMobileHome', [{ name: 'calendar', id: 'a', data: {} }, { @@ -103,13 +99,11 @@ export default Vue.extend({ }]); } - if (this.$store.state.device.mobileHomeProfile) { - this.$watch('$store.state.device.mobileHome', () => { - this.$store.dispatch('settings/updateMobileHomeProfile'); - }, { - deep: true - }); - } + this.$watch('$store.getters.mobileHome', () => { + this.$store.dispatch('settings/updateMobileHomeProfile'); + }, { + deep: true + }); }, mounted() { @@ -134,7 +128,7 @@ export default Vue.extend({ }, addWidget() { - this.$store.commit('device/addMobileHomeWidget', { + this.$store.commit('addMobileHomeWidget', { name: this.widgetAdderSelected, id: uuid(), data: {} @@ -142,11 +136,11 @@ export default Vue.extend({ }, removeWidget(widget) { - this.$store.commit('device/removeMobileHomeWidget', widget); + this.$store.commit('removeMobileHomeWidget', widget); }, saveHome() { - this.$store.commit('device/setMobileHome', this.widgets); + this.$store.commit('setMobileHome', this.widgets); } } }); diff --git a/src/client/app/store.ts b/src/client/app/store.ts index 4a6e1a610c..b06edb1ed9 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -1,3 +1,4 @@ +import Vue from 'vue'; import Vuex from 'vuex'; import createPersistedState from 'vuex-persistedstate'; import * as nestedProperty from 'nested-property'; @@ -40,12 +41,9 @@ const defaultSettings = { }; const defaultDeviceSettings = { - home: null, - homeProfile: null, - mobileHomeProfile: null, - mobileHome: [], - deck: null, - deckProfile: null, + homeProfile: 'Default', + mobileHomeProfile: 'Default', + deckProfile: 'Default', deckMode: false, deckColumnAlign: 'center', deckColumnWidth: 'normal', @@ -88,7 +86,13 @@ export default (os: MiOS) => new Vuex.Store({ }, getters: { - isSignedIn: state => state.i != null + isSignedIn: state => state.i != null, + + home: state => state.settings.homeProfiles[state.device.homeProfile], + + mobileHome: state => state.settings.mobileHomeProfiles[state.device.mobileHomeProfile], + + deck: state => state.settings.deckProfiles[state.device.deckProfile], }, mutations: { @@ -118,6 +122,211 @@ export default (os: MiOS) => new Vuex.Store({ clearBehindNotes(state) { state.behindNotes = []; document.title = os.instanceName; + }, + + setHome(state, data) { + Vue.set(state.settings.homeProfiles, state.device.homeProfile, data); + os.store.dispatch('settings/updateHomeProfile'); + }, + + addHomeWidget(state, widget) { + state.settings.homeProfiles[state.device.homeProfile].unshift(widget); + os.store.dispatch('settings/updateHomeProfile'); + }, + + setMobileHome(state, data) { + Vue.set(state.settings.mobileHomeProfiles, state.device.mobileHomeProfile, data); + os.store.dispatch('settings/updateMobileHomeProfile'); + }, + + updateWidget(state, x) { + let w; + + //#region Desktop home + const home = state.settings.homeProfiles[state.device.homeProfile]; + if (home) { + w = home.find(w => w.id == x.id); + if (w) { + w.data = x.data; + os.store.dispatch('settings/updateHomeProfile'); + } + } + //#endregion + + //#region Mobile home + const mobileHome = state.settings.mobileHomeProfiles[state.device.mobileHomeProfile]; + if (mobileHome) { + w = mobileHome.find(w => w.id == x.id); + if (w) { + w.data = x.data; + os.store.dispatch('settings/updateMobileHomeProfile'); + } + } + //#endregion + }, + + addMobileHomeWidget(state, widget) { + state.settings.mobileHomeProfiles[state.device.mobileHomeProfile].unshift(widget); + os.store.dispatch('settings/updateMobileHomeProfile'); + }, + + removeMobileHomeWidget(state, widget) { + Vue.set('state.settings.mobileHomeProfiles', state.device.mobileHomeProfile, state.settings.mobileHomeProfiles[state.device.mobileHomeProfile].filter(w => w.id != widget.id)); + os.store.dispatch('settings/updateMobileHomeProfile'); + }, + + addDeckColumn(state, column) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + if (column.name == undefined) column.name = null; + deck.columns.push(column); + deck.layout.push([column.id]); + os.store.dispatch('settings/updateDeckProfile'); + }, + + removeDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + deck.columns = deck.columns.filter(c => c.id != id); + deck.layout = deck.layout.map(ids => erase(id, ids)); + deck.layout = deck.layout.filter(ids => ids.length > 0); + os.store.dispatch('settings/updateDeckProfile'); + }, + + swapDeckColumn(state, x) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const a = x.a; + const b = x.b; + const aX = deck.layout.findIndex(ids => ids.indexOf(a) != -1); + const aY = deck.layout[aX].findIndex(id => id == a); + const bX = deck.layout.findIndex(ids => ids.indexOf(b) != -1); + const bY = deck.layout[bX].findIndex(id => id == b); + deck.layout[aX][aY] = b; + deck.layout[bX][bY] = a; + os.store.dispatch('settings/updateDeckProfile'); + }, + + swapLeftDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + deck.layout.some((ids, i) => { + if (ids.indexOf(id) != -1) { + const left = deck.layout[i - 1]; + if (left) { + // https://vuejs.org/v2/guide/list.html#Caveats + //state.deck.layout[i - 1] = state.deck.layout[i]; + //state.deck.layout[i] = left; + deck.layout.splice(i - 1, 1, deck.layout[i]); + deck.layout.splice(i, 1, left); + } + return true; + } + }); + os.store.dispatch('settings/updateDeckProfile'); + }, + + swapRightDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + deck.layout.some((ids, i) => { + if (ids.indexOf(id) != -1) { + const right = deck.layout[i + 1]; + if (right) { + // https://vuejs.org/v2/guide/list.html#Caveats + //state.deck.layout[i + 1] = state.deck.layout[i]; + //state.deck.layout[i] = right; + deck.layout.splice(i + 1, 1, deck.layout[i]); + deck.layout.splice(i, 1, right); + } + return true; + } + }); + os.store.dispatch('settings/updateDeckProfile'); + }, + + swapUpDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const ids = deck.layout.find(ids => ids.indexOf(id) != -1); + ids.some((x, i) => { + if (x == id) { + const up = ids[i - 1]; + if (up) { + // https://vuejs.org/v2/guide/list.html#Caveats + //ids[i - 1] = id; + //ids[i] = up; + ids.splice(i - 1, 1, id); + ids.splice(i, 1, up); + } + return true; + } + }); + os.store.dispatch('settings/updateDeckProfile'); + }, + + swapDownDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const ids = deck.layout.find(ids => ids.indexOf(id) != -1); + ids.some((x, i) => { + if (x == id) { + const down = ids[i + 1]; + if (down) { + // https://vuejs.org/v2/guide/list.html#Caveats + //ids[i + 1] = id; + //ids[i] = down; + ids.splice(i + 1, 1, id); + ids.splice(i, 1, down); + } + return true; + } + }); + os.store.dispatch('settings/updateDeckProfile'); + }, + + stackLeftDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const i = deck.layout.findIndex(ids => ids.indexOf(id) != -1); + deck.layout = deck.layout.map(ids => erase(id, ids)); + const left = deck.layout[i - 1]; + if (left) deck.layout[i - 1].push(id); + deck.layout = deck.layout.filter(ids => ids.length > 0); + os.store.dispatch('settings/updateDeckProfile'); + }, + + popRightDeckColumn(state, id) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const i = deck.layout.findIndex(ids => ids.indexOf(id) != -1); + deck.layout = deck.layout.map(ids => erase(id, ids)); + deck.layout.splice(i + 1, 0, [id]); + deck.layout = deck.layout.filter(ids => ids.length > 0); + os.store.dispatch('settings/updateDeckProfile'); + }, + + addDeckWidget(state, x) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const column = deck.columns.find(c => c.id == x.id); + if (column == null) return; + column.widgets.unshift(x.widget); + os.store.dispatch('settings/updateDeckProfile'); + }, + + removeDeckWidget(state, x) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const column = deck.columns.find(c => c.id == x.id); + if (column == null) return; + column.widgets = column.widgets.filter(w => w.id != x.widget.id); + os.store.dispatch('settings/updateDeckProfile'); + }, + + renameDeckColumn(state, x) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + const column = deck.columns.find(c => c.id == x.id); + if (column == null) return; + column.name = x.name; + os.store.dispatch('settings/updateDeckProfile'); + }, + + updateDeckColumn(state, x) { + const deck = state.settings.deckProfiles[state.device.deckProfile]; + let column = deck.columns.find(c => c.id == x.id); + if (column == null) return; + column = x; + os.store.dispatch('settings/updateDeckProfile'); } }, @@ -165,176 +374,6 @@ export default (os: MiOS) => new Vuex.Store({ setVisibility(state, visibility) { state.visibility = visibility; }, - - setHome(state, data) { - state.home = data; - }, - - addHomeWidget(state, widget) { - state.home.unshift(widget); - }, - - setMobileHome(state, data) { - state.mobileHome = data; - }, - - updateWidget(state, x) { - let w; - - //#region Desktop home - if (state.home) { - w = state.home.find(w => w.id == x.id); - if (w) { - w.data = x.data; - } - } - //#endregion - - //#region Mobile home - if (state.mobileHome) { - w = state.mobileHome.find(w => w.id == x.id); - if (w) { - w.data = x.data; - } - } - //#endregion - }, - - addMobileHomeWidget(state, widget) { - state.mobileHome.unshift(widget); - }, - - removeMobileHomeWidget(state, widget) { - state.mobileHome = state.mobileHome.filter(w => w.id != widget.id); - }, - - addDeckColumn(state, column) { - if (column.name == undefined) column.name = null; - state.deck.columns.push(column); - state.deck.layout.push([column.id]); - }, - - removeDeckColumn(state, id) { - state.deck.columns = state.deck.columns.filter(c => c.id != id); - state.deck.layout = state.deck.layout.map(ids => erase(id, ids)); - state.deck.layout = state.deck.layout.filter(ids => ids.length > 0); - }, - - swapDeckColumn(state, x) { - const a = x.a; - const b = x.b; - const aX = state.deck.layout.findIndex(ids => ids.indexOf(a) != -1); - const aY = state.deck.layout[aX].findIndex(id => id == a); - const bX = state.deck.layout.findIndex(ids => ids.indexOf(b) != -1); - const bY = state.deck.layout[bX].findIndex(id => id == b); - state.deck.layout[aX][aY] = b; - state.deck.layout[bX][bY] = a; - }, - - swapLeftDeckColumn(state, id) { - state.deck.layout.some((ids, i) => { - if (ids.indexOf(id) != -1) { - const left = state.deck.layout[i - 1]; - if (left) { - // https://vuejs.org/v2/guide/list.html#Caveats - //state.deck.layout[i - 1] = state.deck.layout[i]; - //state.deck.layout[i] = left; - state.deck.layout.splice(i - 1, 1, state.deck.layout[i]); - state.deck.layout.splice(i, 1, left); - } - return true; - } - }); - }, - - swapRightDeckColumn(state, id) { - state.deck.layout.some((ids, i) => { - if (ids.indexOf(id) != -1) { - const right = state.deck.layout[i + 1]; - if (right) { - // https://vuejs.org/v2/guide/list.html#Caveats - //state.deck.layout[i + 1] = state.deck.layout[i]; - //state.deck.layout[i] = right; - state.deck.layout.splice(i + 1, 1, state.deck.layout[i]); - state.deck.layout.splice(i, 1, right); - } - return true; - } - }); - }, - - swapUpDeckColumn(state, id) { - const ids = state.deck.layout.find(ids => ids.indexOf(id) != -1); - ids.some((x, i) => { - if (x == id) { - const up = ids[i - 1]; - if (up) { - // https://vuejs.org/v2/guide/list.html#Caveats - //ids[i - 1] = id; - //ids[i] = up; - ids.splice(i - 1, 1, id); - ids.splice(i, 1, up); - } - return true; - } - }); - }, - - swapDownDeckColumn(state, id) { - const ids = state.deck.layout.find(ids => ids.indexOf(id) != -1); - ids.some((x, i) => { - if (x == id) { - const down = ids[i + 1]; - if (down) { - // https://vuejs.org/v2/guide/list.html#Caveats - //ids[i + 1] = id; - //ids[i] = down; - ids.splice(i + 1, 1, id); - ids.splice(i, 1, down); - } - return true; - } - }); - }, - - stackLeftDeckColumn(state, id) { - const i = state.deck.layout.findIndex(ids => ids.indexOf(id) != -1); - state.deck.layout = state.deck.layout.map(ids => erase(id, ids)); - const left = state.deck.layout[i - 1]; - if (left) state.deck.layout[i - 1].push(id); - state.deck.layout = state.deck.layout.filter(ids => ids.length > 0); - }, - - popRightDeckColumn(state, id) { - const i = state.deck.layout.findIndex(ids => ids.indexOf(id) != -1); - state.deck.layout = state.deck.layout.map(ids => erase(id, ids)); - state.deck.layout.splice(i + 1, 0, [id]); - state.deck.layout = state.deck.layout.filter(ids => ids.length > 0); - }, - - addDeckWidget(state, x) { - const column = state.deck.columns.find(c => c.id == x.id); - if (column == null) return; - column.widgets.unshift(x.widget); - }, - - removeDeckWidget(state, x) { - const column = state.deck.columns.find(c => c.id == x.id); - if (column == null) return; - column.widgets = column.widgets.filter(w => w.id != x.widget.id); - }, - - renameDeckColumn(state, x) { - const column = state.deck.columns.find(c => c.id == x.id); - if (column == null) return; - column.name = x.name; - }, - - updateDeckColumn(state, x) { - let column = state.deck.columns.find(c => c.id == x.id); - if (column == null) return; - column = x; - } } }, @@ -370,7 +409,6 @@ export default (os: MiOS) => new Vuex.Store({ updateHomeProfile(ctx) { const profiles = ctx.state.homeProfiles; - profiles[ctx.rootState.device.homeProfile] = ctx.rootState.device.home; ctx.commit('set', { key: 'homeProfiles', value: profiles @@ -383,7 +421,6 @@ export default (os: MiOS) => new Vuex.Store({ updateMobileHomeProfile(ctx) { const profiles = ctx.state.mobileHomeProfiles; - profiles[ctx.rootState.device.mobileHomeProfile] = ctx.rootState.device.mobileHome; ctx.commit('set', { key: 'mobileHomeProfiles', value: profiles @@ -396,7 +433,6 @@ export default (os: MiOS) => new Vuex.Store({ updateDeckProfile(ctx) { const profiles = ctx.state.deckProfiles; - profiles[ctx.rootState.device.deckProfile] = ctx.rootState.device.deck; ctx.commit('set', { key: 'deckProfiles', value: profiles From fa0023e54168624bebd6cdd479c1df0e63cb868d Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 Jun 2019 15:11:56 +0900 Subject: [PATCH 08/15] Fix bug --- src/client/app/common/views/deck/deck.vue | 5 +---- src/client/app/store.ts | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client/app/common/views/deck/deck.vue b/src/client/app/common/views/deck/deck.vue index 070312d839..36e0f8161e 100644 --- a/src/client/app/common/views/deck/deck.vue +++ b/src/client/app/common/views/deck/deck.vue @@ -106,10 +106,7 @@ export default Vue.extend({ deck.layout = deck.columns.map(c => [c.id]); - this.$store.commit('device/set', { - key: 'deck', - value: deck - }); + this.$store.commit('setDeck', deck); } }, diff --git a/src/client/app/store.ts b/src/client/app/store.ts index b06edb1ed9..852d2c393d 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -129,6 +129,11 @@ export default (os: MiOS) => new Vuex.Store({ os.store.dispatch('settings/updateHomeProfile'); }, + setDeck(state, data) { + Vue.set(state.settings.deckProfiles, state.device.deckProfile, data); + os.store.dispatch('settings/updateDeckProfile'); + }, + addHomeWidget(state, widget) { state.settings.homeProfiles[state.device.homeProfile].unshift(widget); os.store.dispatch('settings/updateHomeProfile'); From 16b03fc157507261c54e5bb0eb030dcf6418a68c Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 21 Jun 2019 15:41:02 +0900 Subject: [PATCH 09/15] Improve url-preview (#5077) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * url-previewリクエスト時にハッシュは除く * ハッシュだけ違うプレビューカードは表示しない * url-previewをユーザーロケールで出し分けるように * Fix code style --- src/client/app/common/scripts/note-mixin.ts | 12 +++++++++++- .../common/views/components/url-preview.vue | 19 ++++++++++++------- src/server/web/url-preview.ts | 10 ++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/client/app/common/scripts/note-mixin.ts b/src/client/app/common/scripts/note-mixin.ts index 4b454f8800..e649680070 100644 --- a/src/client/app/common/scripts/note-mixin.ts +++ b/src/client/app/common/scripts/note-mixin.ts @@ -83,9 +83,19 @@ export default (opts: Opts = {}) => ({ if (this.appearNote.text) { const ast = parse(this.appearNote.text); // TODO: 再帰的にURL要素がないか調べる - return unique(ast + const urls = unique(ast .filter(t => ((t.node.type == 'url' || t.node.type == 'link') && t.node.props.url && !t.node.props.silent)) .map(t => t.node.props.url)); + + // unique without hash + // [ http://a/#1, http://a/#2, http://b/#3 ] => [ http://a/#1, http://b/#3 ] + const removeHash = x => x.replace(/#[^#]*$/, ''); + + return urls.reduce((array, url) => { + const removed = removeHash(url); + if (!array.map(x => removeHash(x)).includes(removed)) array.push(url); + return array; + }, []); } else { return null; } diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index 9c61e46059..20fbcbb046 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -30,7 +30,7 @@