From 8934d16cc869a5d82cb109b98d3a4f2e7f62cce1 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 22:32:53 +0900 Subject: [PATCH] refs #677 Adjust reload for customized streamings --- src/constants/unreadNotification.js | 11 +++++++++++ .../TimelineSpace/Contents/DirectMessages.vue | 3 +++ .../TimelineSpace/Contents/Local.vue | 3 +++ .../TimelineSpace/Contents/Notifications.vue | 10 +--------- .../TimelineSpace/Contents/Public.vue | 19 +++---------------- src/renderer/components/mixins/reloadable.vue | 14 +++----------- src/renderer/store/Settings/Timeline.js | 12 +++++++++--- src/renderer/store/TimelineSpace.js | 14 ++++++++++---- 8 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 src/constants/unreadNotification.js diff --git a/src/constants/unreadNotification.js b/src/constants/unreadNotification.js new file mode 100644 index 00000000..1ea5774c --- /dev/null +++ b/src/constants/unreadNotification.js @@ -0,0 +1,11 @@ +export default { + Direct: { + default: false + }, + Local: { + default: true + }, + Public: { + default: true + } +} diff --git a/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue b/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue index 8fbba795..4f3656d8 100644 --- a/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue +++ b/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue @@ -99,6 +99,9 @@ export default { this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true) this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline') this.$store.commit('TimelineSpace/Contents/DirectMessages/archiveTimeline') + if (!this.unreadNotification.direct) { + this.$store.commit('TimelineSpace/Contents/DirectMessages/clearTimeline') + } if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) { document.getElementById('scrollable').removeEventListener('scroll', this.onScroll) document.getElementById('scrollable').scrollTop = 0 diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue index 3fb9d8bd..057cbe49 100644 --- a/src/renderer/components/TimelineSpace/Contents/Local.vue +++ b/src/renderer/components/TimelineSpace/Contents/Local.vue @@ -99,6 +99,9 @@ export default { this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true) this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline') this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline') + if (!this.unreadNotification.local) { + this.$store.commit('TimelineSpace/Contents/Local/clearTimeline') + } if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) { document.getElementById('scrollable').removeEventListener('scroll', this.onScroll) document.getElementById('scrollable').scrollTop = 0 diff --git a/src/renderer/components/TimelineSpace/Contents/Notifications.vue b/src/renderer/components/TimelineSpace/Contents/Notifications.vue index b0bc0066..a6137f67 100644 --- a/src/renderer/components/TimelineSpace/Contents/Notifications.vue +++ b/src/renderer/components/TimelineSpace/Contents/Notifications.vue @@ -128,15 +128,7 @@ export default { async reload () { this.$store.commit('TimelineSpace/changeLoading', true) try { - const account = await this.reloadable() - await this.$store.dispatch('TimelineSpace/Contents/Notifications/fetchNotifications', account) - .catch(() => { - this.$message({ - message: this.$t('message.notification_fetch_error'), - type: 'error' - }) - }) - + await this.reloadable() this.$store.dispatch('TimelineSpace/Contents/Notifications/resetBadge') } finally { this.$store.commit('TimelineSpace/changeLoading', false) diff --git a/src/renderer/components/TimelineSpace/Contents/Public.vue b/src/renderer/components/TimelineSpace/Contents/Public.vue index 26c96a21..b9653dcd 100644 --- a/src/renderer/components/TimelineSpace/Contents/Public.vue +++ b/src/renderer/components/TimelineSpace/Contents/Public.vue @@ -99,7 +99,9 @@ export default { this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true) this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline') this.$store.commit('TimelineSpace/Contents/Public/archiveTimeline') - this.$store.commit('TimelineSpace/Contents/Public/clearTimeline') + if (!this.unreadNotification.public) { + this.$store.commit('TimelineSpace/Contents/Public/clearTimeline') + } if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) { document.getElementById('scrollable').removeEventListener('scroll', this.onScroll) document.getElementById('scrollable').scrollTop = 0 @@ -163,21 +165,6 @@ export default { this.$store.commit('TimelineSpace/changeLoading', true) try { await this.reloadable() - await this.$store.dispatch('TimelineSpace/Contents/Public/stopPublicStreaming') - await this.$store.dispatch('TimelineSpace/Contents/Public/fetchPublicTimeline') - .catch(() => { - this.$message({ - message: this.$t('message.timeline_fetch_error'), - type: 'error' - }) - }) - this.$store.dispatch('TimelineSpace/Contents/Public/startPublicStreaming') - .catch(() => { - this.$message({ - message: this.$t('message.start_streaming_error'), - type: 'error' - }) - }) } finally { this.$store.commit('TimelineSpace/changeLoading', false) } diff --git a/src/renderer/components/mixins/reloadable.vue b/src/renderer/components/mixins/reloadable.vue index b24ce284..2ee7e619 100644 --- a/src/renderer/components/mixins/reloadable.vue +++ b/src/renderer/components/mixins/reloadable.vue @@ -10,17 +10,9 @@ export default { }) throw err }) - await this.$store.dispatch('TimelineSpace/stopUserStreaming') - await this.$store.dispatch('TimelineSpace/stopLocalStreaming') - await this.$store.dispatch('TimelineSpace/stopDirectMessagesStreaming') - - await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account) - await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account) - await this.$store.dispatch('TimelineSpace/Contents/DirectMessages/fetchTimeline', account) - - this.$store.dispatch('TimelineSpace/startUserStreaming', account) - this.$store.dispatch('TimelineSpace/startLocalStreaming', account) - this.$store.dispatch('TimelineSpace/startDirectMessagesStreaming', account) + await this.$store.dispatch('TimelineSpace/stopStreamings', account) + await this.$store.dispatch('TimelineSpace/fetchContentsTimelines', account) + await this.$store.dispatch('TimelineSpace/startStreamings', account) return account } } diff --git a/src/renderer/store/Settings/Timeline.js b/src/renderer/store/Settings/Timeline.js index 1a5f5349..b21dc264 100644 --- a/src/renderer/store/Settings/Timeline.js +++ b/src/renderer/store/Settings/Timeline.js @@ -1,12 +1,13 @@ import { ipcRenderer } from 'electron' +import unreadSettings from '~/src/constants/unreadNotification' export default { namespaced: true, state: { unreadNotification: { - direct: false, - local: true, - public: false + direct: unreadSettings.Direct.default, + local: unreadSettings.Local.default, + public: unreadSettings.Public.default } }, mutations: { @@ -24,6 +25,11 @@ export default { }) ipcRenderer.once('error-get-unread-notification', (event, err) => { ipcRenderer.removeAllListeners('response-get-unread-notification') + commit('updateUnreadNotification', { + direct: unreadSettings.Direct.default, + local: unreadSettings.Local.default, + public: unreadSettings.Public.default + }) resolve(null) }) ipcRenderer.send('get-unread-notification', rootState.Settings.accountID) diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js index d27fe00b..bb9bc726 100644 --- a/src/renderer/store/TimelineSpace.js +++ b/src/renderer/store/TimelineSpace.js @@ -5,6 +5,7 @@ import HeaderMenu from './TimelineSpace/HeaderMenu' import Modals from './TimelineSpace/Modals' import Contents from './TimelineSpace/Contents' import router from '../router' +import unreadSettings from '~/src/constants/unreadNotification' const TimelineSpace = { namespaced: true, @@ -24,9 +25,9 @@ const TimelineSpace = { emojis: [], tootMax: 500, unreadNotification: { - direct: false, - local: true, - public: false + direct: unreadSettings.Direct.default, + local: unreadSettings.Local.default, + public: unreadSettings.Public.default } }, mutations: { @@ -156,6 +157,11 @@ const TimelineSpace = { }) ipcRenderer.once('error-get-unread-notification', (event, err) => { ipcRenderer.removeAllListeners('response-get-unread-notification') + commit('updateUnreadNotification', { + direct: unreadSettings.Direct.default, + local: unreadSettings.Local.default, + public: unreadSettings.Public.default + }) resolve(null) }) ipcRenderer.send('get-unread-notification', accountID) @@ -270,7 +276,7 @@ const TimelineSpace = { ipcRenderer.on('update-start-public-streaming', (event, update) => { commit('TimelineSpace/Contents/Public/appendTimeline', update, { root: true }) if (rootState.TimelineSpace.Contents.Public.heading && Math.random() > 0.8) { - commit('TimelineSpace/Contents/Public/archiveTimeline') + commit('TimelineSpace/Contents/Public/archiveTimeline', {}, { root: true }) } }) commit('TimelineSpace/SideMenu/changeUnreadPublicTimeline', true, { root: true })