From 70d5ae32622b93daed8082cbf671e432ca4e98c1 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Tue, 6 Nov 2018 23:08:17 +0900 Subject: [PATCH 1/8] refs #677 Add a setting window to customize unread notification of timeline --- src/config/locales/en/translation.json | 12 ++ src/renderer/components/Settings.vue | 4 + src/renderer/components/Settings/Timeline.vue | 128 ++++++++++++++++++ src/renderer/router/index.js | 4 + src/renderer/store/Settings.js | 4 +- src/renderer/store/Settings/Timeline.js | 30 ++++ 6 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 src/renderer/components/Settings/Timeline.vue create mode 100644 src/renderer/store/Settings/Timeline.js diff --git a/src/config/locales/en/translation.json b/src/config/locales/en/translation.json index afb61b17..585ea76c 100644 --- a/src/config/locales/en/translation.json +++ b/src/config/locales/en/translation.json @@ -90,6 +90,18 @@ "description": "Mark medias as sensitive by default" } } + }, + "timeline": { + "title": "Timeline", + "unread_notification": { + "title": "Unread Notification", + "description": "Customize unread notifications for each timelines.", + "home": "Home Timeline", + "direct": "Direct Messages", + "favourite": "Favourite", + "local": "Local Timeline", + "public": "Public Timeline" + } } }, "preferences": { diff --git a/src/renderer/components/Settings.vue b/src/renderer/components/Settings.vue index a5fd1b9b..207504fa 100644 --- a/src/renderer/components/Settings.vue +++ b/src/renderer/components/Settings.vue @@ -23,6 +23,10 @@ {{ $t('settings.general.title') }} + + + {{ $t('settings.timeline.title') }} + diff --git a/src/renderer/components/Settings/Timeline.vue b/src/renderer/components/Settings/Timeline.vue new file mode 100644 index 00000000..732b2e56 --- /dev/null +++ b/src/renderer/components/Settings/Timeline.vue @@ -0,0 +1,128 @@ + + + + + diff --git a/src/renderer/router/index.js b/src/renderer/router/index.js index 6c7b4d4c..c0e1e2a6 100644 --- a/src/renderer/router/index.js +++ b/src/renderer/router/index.js @@ -60,6 +60,10 @@ export default new Router({ { path: 'general', component: require('@/components/Settings/General').default + }, + { + path: 'timeline', + component: require('@/components/Settings/Timeline').default } ] }, diff --git a/src/renderer/store/Settings.js b/src/renderer/store/Settings.js index fbe0b9a9..644ebea2 100644 --- a/src/renderer/store/Settings.js +++ b/src/renderer/store/Settings.js @@ -1,8 +1,10 @@ import General from './Settings/General' +import Timeline from './Settings/Timeline' export default { namespaced: true, modules: { - General + General, + Timeline } } diff --git a/src/renderer/store/Settings/Timeline.js b/src/renderer/store/Settings/Timeline.js new file mode 100644 index 00000000..45ae72bc --- /dev/null +++ b/src/renderer/store/Settings/Timeline.js @@ -0,0 +1,30 @@ +export default { + namespaced: true, + state: { + unread_notification: { + home: false, + direct: false, + favourite: false, + local: false, + public: false + } + }, + mutations: { + changeHome (state, value) { + state.unread_notification.home = value + }, + changeDirect (state, value) { + state.unread_notification.direct = value + }, + changeFavourite (state, value) { + state.unread_notification.favourite = value + }, + changeLocal (state, value) { + state.unread_notification.local = value + }, + changePublic (state, value) { + state.unread_notification.public = value + } + }, + actions: {} +} From bb124d886cf30649b7460842ca3ebae323227db8 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Wed, 7 Nov 2018 22:48:50 +0900 Subject: [PATCH 2/8] refs #677 Customize unread notification and save the settings --- src/main/index.js | 33 ++++++++++ src/main/unread_notification.js | 63 +++++++++++++++++++ src/renderer/components/Settings.vue | 1 + src/renderer/components/Settings/Timeline.vue | 23 +++++-- src/renderer/store/Settings.js | 8 +++ src/renderer/store/Settings/Timeline.js | 56 ++++++++++++----- 6 files changed, 162 insertions(+), 22 deletions(-) create mode 100644 src/main/unread_notification.js diff --git a/src/main/index.js b/src/main/index.js index d4f584fc..8912dc06 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -17,6 +17,7 @@ import StreamingManager from './streaming_manager' import Preferences from './preferences' import Fonts from './fonts' import Hashtags from './hashtags' +import UnreadNotification from './unread_notification' import i18n from '../config/i18n' import Language from '../constants/language' @@ -70,6 +71,13 @@ let hashtagsDB = new Datastore({ autoload: true }) +const unreadNotificationDBPath = process.env.NODE_ENV === 'production' + ? userData + '/db/unread_notification.db' + : 'unread_notification.db' +const unreadNotification = new UnreadNotification(unreadNotificationDBPath) +unreadNotification.initialize() + .catch(err => log.error(err)) + const preferencesDBPath = process.env.NODE_ENV === 'production' ? userData + './db/preferences.json' : 'preferences.json' @@ -762,6 +770,31 @@ ipcMain.on('list-fonts', (event, _) => { }) }) +// Unread notifications +ipcMain.on('get-unread-notification', (event, accountID) => { + unreadNotification.findOne({ + accountID: accountID + }) + .then(doc => { + event.sender.send('response-get-unread-notification', doc) + }) + .catch(err => { + event.sender.send('error-get-unread-notification', err) + }) +}) + +ipcMain.on('update-unread-notification', (event, obj) => { + const { accountID } = obj + unreadNotification.insertOrUpdate(accountID, obj) + .then(_ => { + event.sender.send('response-update-unread-notification', true) + }) + .catch(err => { + console.error(err) + event.sender.send('error-update-unread-notification', err) + }) +}) + // Application control ipcMain.on('relaunch', (event, _) => { app.relaunch() diff --git a/src/main/unread_notification.js b/src/main/unread_notification.js new file mode 100644 index 00000000..a8a0e3b1 --- /dev/null +++ b/src/main/unread_notification.js @@ -0,0 +1,63 @@ +import empty from 'is-empty' +import Datastore from 'nedb' + +export default class UnreadNotification { + constructor (path) { + this.db = new Datastore({ + filename: path, + autoload: true + }) + } + + async initialize () { + await this.updateUnique() + } + + updateUnique () { + return new Promise((resolve, reject) => { + // At first, remove old index. + this.db.removeIndex('accountID', (err) => { + if (err) reject(err) + // Add unique index. + this.db.ensureIndex({ fieldName: 'accountID', unique: true, sparse: true }, (err) => { + if (err) reject(err) + resolve(null) + }) + }) + }) + } + + insertOrUpdate (accountID, obj) { + return new Promise((resolve, reject) => { + this.db.update( + { + accountID: accountID + }, + obj, + { + upsert: true + }, + (err, num) => { + if (err) return reject(err) + resolve(num) + }) + }) + } + + findOne (obj) { + return new Promise((resolve, reject) => { + this.db.findOne(obj, (err, doc) => { + if (err) return reject(err) + if (empty(doc)) return reject(new EmptyRecordError('empty')) + resolve(doc) + }) + }) + } +} + +class EmptyRecordError extends Error { + constructor (msg) { + super(msg) + this.name = 'EmptyRecordError' + } +} diff --git a/src/renderer/components/Settings.vue b/src/renderer/components/Settings.vue index 207504fa..b21a150b 100644 --- a/src/renderer/components/Settings.vue +++ b/src/renderer/components/Settings.vue @@ -48,6 +48,7 @@ export default { }) }, created () { + this.$store.commit('Settings/changeAccountID', this.id()) this.$router.push(`/${this.id()}/settings/general`) }, methods: { diff --git a/src/renderer/components/Settings/Timeline.vue b/src/renderer/components/Settings/Timeline.vue index 732b2e56..92bc6432 100644 --- a/src/renderer/components/Settings/Timeline.vue +++ b/src/renderer/components/Settings/Timeline.vue @@ -60,7 +60,9 @@ export default { return this.$store.state.Settings.Timeline.unread_notification.home }, set (value) { - this.$store.commit('Settings/Timeline/changeHome', value) + this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { + home: value + }) } }, direct: { @@ -68,7 +70,9 @@ export default { return this.$store.state.Settings.Timeline.unread_notification.direct }, set (value) { - this.$store.commit('Settings/Timeline/changeDirect', value) + this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { + direct: value + }) } }, favourite: { @@ -76,7 +80,9 @@ export default { return this.$store.state.Settings.Timeline.unread_notification.favourite }, set (value) { - this.$store.commit('Settings/Timeline/changeFavourite', value) + this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { + favourite: value + }) } }, local: { @@ -84,7 +90,9 @@ export default { return this.$store.state.Settings.Timeline.unread_notification.local }, set (value) { - this.$store.commit('Settings/Timeline/changeLocal', value) + this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { + local: value + }) } }, public: { @@ -92,9 +100,14 @@ export default { return this.$store.state.Settings.Timeline.unread_notification.public }, set (value) { - this.$store.commit('Settings/Timeline/changePublic', value) + this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { + public: value + }) } } + }, + async created () { + await this.$store.dispatch('Settings/Timeline/loadUnreadNotification') } } diff --git a/src/renderer/store/Settings.js b/src/renderer/store/Settings.js index 644ebea2..32b7d4ed 100644 --- a/src/renderer/store/Settings.js +++ b/src/renderer/store/Settings.js @@ -6,5 +6,13 @@ export default { modules: { General, Timeline + }, + state: { + accountID: null + }, + mutations: { + changeAccountID (state, id) { + state.accountID = id + } } } diff --git a/src/renderer/store/Settings/Timeline.js b/src/renderer/store/Settings/Timeline.js index 45ae72bc..49b19c12 100644 --- a/src/renderer/store/Settings/Timeline.js +++ b/src/renderer/store/Settings/Timeline.js @@ -1,30 +1,52 @@ +import { ipcRenderer } from 'electron' + export default { namespaced: true, state: { unread_notification: { - home: false, + home: true, direct: false, favourite: false, - local: false, + local: true, public: false } }, mutations: { - changeHome (state, value) { - state.unread_notification.home = value - }, - changeDirect (state, value) { - state.unread_notification.direct = value - }, - changeFavourite (state, value) { - state.unread_notification.favourite = value - }, - changeLocal (state, value) { - state.unread_notification.local = value - }, - changePublic (state, value) { - state.unread_notification.public = value + updateUnreadNotification (state, settings) { + state.unread_notification = settings } }, - actions: {} + actions: { + loadUnreadNotification ({ commit, rootState }) { + return new Promise((resolve, reject) => { + ipcRenderer.once('response-get-unread-notification', (event, settings) => { + ipcRenderer.removeAllListeners('error-get-unread-notification') + commit('updateUnreadNotification', settings) + resolve(settings) + }) + ipcRenderer.once('error-get-unread-notification', (event, err) => { + ipcRenderer.removeAllListeners('response-get-unread-notification') + resolve(null) + }) + ipcRenderer.send('get-unread-notification', rootState.Settings.accountID) + }) + }, + changeUnreadNotification ({ dispatch, state, rootState }, timeline) { + const settings = Object.assign({}, state.unread_notification, timeline, { + accountID: rootState.Settings.accountID + }) + return new Promise((resolve, reject) => { + ipcRenderer.once('response-update-unread-notification', (event, _) => { + ipcRenderer.removeAllListeners('error-update-unread-notification') + dispatch('loadUnreadNotification') + resolve(settings) + }) + ipcRenderer.once('error-update-unread-notification', (event, err) => { + ipcRenderer.removeAllListeners('response-update-unread-notification') + reject(err) + }) + ipcRenderer.send('update-unread-notification', settings) + }) + } + } } From 1bcdc91ef699fb0ac7b53ee665d29e7c15f14e8d Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 08:12:51 +0900 Subject: [PATCH 3/8] refs #677 Adjust streaming of Local and DM --- src/renderer/components/Settings/Timeline.vue | 26 +-- src/renderer/components/TimelineSpace.vue | 57 ++---- .../TimelineSpace/Contents/DirectMessages.vue | 40 ++++- .../TimelineSpace/Contents/Local.vue | 40 ++++- src/renderer/store/Settings/Timeline.js | 7 +- src/renderer/store/TimelineSpace.js | 170 +++++++++++++----- .../TimelineSpace/Contents/DirectMessages.js | 2 +- .../store/TimelineSpace/Contents/Local.js | 6 +- 8 files changed, 221 insertions(+), 127 deletions(-) diff --git a/src/renderer/components/Settings/Timeline.vue b/src/renderer/components/Settings/Timeline.vue index 92bc6432..b61afda7 100644 --- a/src/renderer/components/Settings/Timeline.vue +++ b/src/renderer/components/Settings/Timeline.vue @@ -5,14 +5,6 @@

{{ $t('settings.timeline.unread_notification.description') }}

- - - - - - - -
- {{ $t('settings.timeline.unread_notification.home') }} - - -
{{ $t('settings.timeline.unread_notification.direct') }} @@ -55,19 +47,9 @@ export default { name: 'Timeline', computed: { - home: { - get () { - return this.$store.state.Settings.Timeline.unread_notification.home - }, - set (value) { - this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { - home: value - }) - } - }, direct: { get () { - return this.$store.state.Settings.Timeline.unread_notification.direct + return this.$store.state.Settings.Timeline.unreadNotification.direct }, set (value) { this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { @@ -77,7 +59,7 @@ export default { }, favourite: { get () { - return this.$store.state.Settings.Timeline.unread_notification.favourite + return this.$store.state.Settings.Timeline.unreadNotification.favourite }, set (value) { this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { @@ -87,7 +69,7 @@ export default { }, local: { get () { - return this.$store.state.Settings.Timeline.unread_notification.local + return this.$store.state.Settings.Timeline.unreadNotification.local }, set (value) { this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { @@ -97,7 +79,7 @@ export default { }, public: { get () { - return this.$store.state.Settings.Timeline.unread_notification.public + return this.$store.state.Settings.Timeline.unreadNotification.public }, set (value) { this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue index 03e42da9..1b21b5ce 100644 --- a/src/renderer/components/TimelineSpace.vue +++ b/src/renderer/components/TimelineSpace.vue @@ -72,20 +72,12 @@ export default { window.removeEventListener('dragleave', this.onDragLeave) window.removeEventListener('dragover', this.onDragOver) window.removeEventListener('drop', this.handleDrop) - this.$store.dispatch('TimelineSpace/stopUserStreaming') - this.$store.dispatch('TimelineSpace/unbindUserStreaming') - this.$store.dispatch('TimelineSpace/stopDirectMessagesStreaming') - this.$store.dispatch('TimelineSpace/unbindDirectMessagesStreaming') - this.$store.dispatch('TimelineSpace/stopLocalStreaming') - this.$store.dispatch('TimelineSpace/unbindLocalStreaming') + this.$store.dispatch('TimelineSpace/stopStreamings') }, methods: { async clear () { await this.$store.dispatch('TimelineSpace/clearAccount') - await this.$store.commit('TimelineSpace/Contents/Home/clearTimeline') - await this.$store.commit('TimelineSpace/Contents/Local/clearTimeline') - await this.$store.commit('TimelineSpace/Contents/DirectMessages/clearTimeline') - await this.$store.commit('TimelineSpace/Contents/Notifications/clearNotifications') + this.$store.dispatch('TimelineSpace/clearContentsTimelines') await this.$store.dispatch('TimelineSpace/removeShortcutEvents') await this.$store.dispatch('TimelineSpace/clearUnread') return 'clear' @@ -100,44 +92,23 @@ export default { type: 'error' }) }) - try { - await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account) - } catch (err) { - this.$message({ - message: this.$t('message.timeline_fetch_error'), - type: 'error' - }) - } - try { - await this.$store.dispatch('TimelineSpace/Contents/Notifications/fetchNotifications', account) - } catch (err) { - this.$message({ - message: this.$t('message.notification_fetch_error'), - type: 'error' - }) - } - try { - await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account) - await this.$store.dispatch('TimelineSpace/Contents/DirectMessages/fetchTimeline', account) - } catch (err) { - this.$message({ - message: this.$t('message.timeline_fetch_error'), - type: 'error' - }) - } this.$store.dispatch('TimelineSpace/SideMenu/fetchLists', account) - this.$store.dispatch('TimelineSpace/bindUserStreaming', account) - this.$store.dispatch('TimelineSpace/startUserStreaming', account) - .catch(() => { + await this.$store.dispatch('TimelineSpace/loadUnreadNotification', this.$route.params.id) + + // Load timelines + await this.$store.dispatch('TimelineSpace/fetchContentsTimelines', account) + .catch(_ => { this.$message({ - message: this.$t('message.start_streaming_error'), + message: this.$t('message.timeline_fetch_error'), type: 'error' }) }) - this.$store.dispatch('TimelineSpace/bindLocalStreaming', account) - this.$store.dispatch('TimelineSpace/startLocalStreaming', account) - this.$store.dispatch('TimelineSpace/bindDirectMessagesStreaming', account) - this.$store.dispatch('TimelineSpace/startDirectMessagesStreaming', account) + + // Bind streamings + await this.$store.dispatch('TimelineSpace/bindStreamings', account) + // Start streamings + this.$store.dispatch('TimelineSpace/startStreamings', account) + this.$store.dispatch('TimelineSpace/fetchEmojis', account) this.$store.dispatch('TimelineSpace/fetchInstance', account) }, diff --git a/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue b/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue index 43df7ef3..8fbba795 100644 --- a/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue +++ b/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue @@ -44,15 +44,18 @@ export default { } }, computed: { + ...mapState('TimelineSpace/Contents/DirectMessages', { + timeline: state => state.timeline, + lazyLoading: state => state.lazyLoading, + heading: state => state.heading, + unread: state => state.unreadTimeline, + filter: state => state.filter + }), ...mapState({ openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar, backgroundColor: state => state.App.theme.background_color, startReload: state => state.TimelineSpace.HeaderMenu.reload, - timeline: state => state.TimelineSpace.Contents.DirectMessages.timeline, - lazyLoading: state => state.TimelineSpace.Contents.DirectMessages.lazyLoading, - heading: state => state.TimelineSpace.Contents.DirectMessages.heading, - unread: state => state.TimelineSpace.Contents.DirectMessages.unreadTimeline, - filter: state => state.TimelineSpace.Contents.DirectMessages.filter + unreadNotification: state => state.TimelineSpace.unreadNotification }), ...mapGetters('TimelineSpace/Modals', [ 'modalOpened' @@ -69,15 +72,29 @@ export default { return currentIndex === -1 } }, - mounted () { + async mounted () { + this.$store.commit('TimelineSpace/changeLoading', true) this.$store.commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', false) document.getElementById('scrollable').addEventListener('scroll', this.onScroll) + if (!this.unreadNotification.direct) { + await this.initialize() + .catch(_ => { + this.$store.commit('TimelineSpace/changeLoading', false) + }) + } + this.$store.commit('TimelineSpace/changeLoading', false) }, beforeUpdate () { if (this.$store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline && this.heading) { this.$store.commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', false) } }, + beforeDestroy () { + if (!this.unreadNotification.direct) { + this.$store.dispatch('TimelineSpace/stopDirectMessagesStreaming') + this.$store.dispatch('TimelineSpace/unbindDirectMessagesStreaming') + } + }, destroyed () { this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true) this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline') @@ -106,6 +123,17 @@ export default { } }, methods: { + async initialize () { + await this.$store.dispatch('TimelineSpace/Contents/DirectMessages/fetchTimeline') + .catch(_ => { + this.$message({ + message: this.$t('message.timeline_fetch_error'), + type: 'error' + }) + }) + await this.$store.dispatch('TimelineSpace/bindDirectMessagesStreaming') + this.$store.dispatch('TimelineSpace/startDirectMessagesStreaming') + }, onScroll (event) { // for lazyLoading if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementById('directmessages').clientHeight - 10) && !this.lazyloading) { diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue index a1064d4c..16ff4ce1 100644 --- a/src/renderer/components/TimelineSpace/Contents/Local.vue +++ b/src/renderer/components/TimelineSpace/Contents/Local.vue @@ -44,15 +44,18 @@ export default { } }, computed: { + ...mapState('TimelineSpace/Contents/Local', { + timeline: state => state.timeline, + lazyLoading: state => state.lazyLoading, + heading: state => state.heading, + unread: state => state.unreadTimeline, + filter: state => state.filter + }), ...mapState({ openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar, backgroundColor: state => state.App.theme.background_color, startReload: state => state.TimelineSpace.HeaderMenu.reload, - timeline: state => state.TimelineSpace.Contents.Local.timeline, - lazyLoading: state => state.TimelineSpace.Contents.Local.lazyLoading, - heading: state => state.TimelineSpace.Contents.Local.heading, - unread: state => state.TimelineSpace.Contents.Local.unreadTimeline, - filter: state => state.TimelineSpace.Contents.Local.filter + unreadNotification: state => state.TimelineSpace.unreadNotification }), ...mapGetters('TimelineSpace/Modals', [ 'modalOpened' @@ -69,15 +72,29 @@ export default { return currentIndex === -1 } }, - mounted () { + async mounted () { + this.$store.commit('TimelineSpace/changeLoading', true) this.$store.commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', false) document.getElementById('scrollable').addEventListener('scroll', this.onScroll) + if (!this.unreadNotification.local) { + await this.initialize() + .catch(_ => { + this.$store.commit('TimelineSpace/changeLoading', false) + }) + } + this.$store.commit('TimelineSpace/changeLoading', false) }, beforeUpdate () { if (this.$store.state.TimelineSpace.SideMenu.unreadLocalTimeline && this.heading) { this.$store.commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', false) } }, + beforeDestroy () { + if (!this.unreadNotification.local) { + this.$store.dispatch('TimelineSpace/stopLocalStreaming') + this.$store.dispatch('TimelineSpace/unbindLocalStreaming') + } + }, destroyed () { this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true) this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline') @@ -106,6 +123,17 @@ export default { } }, methods: { + async initialize () { + await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline') + .catch(_ => { + this.$message({ + message: this.$t('message.timeline_fetch_error'), + type: 'error' + }) + }) + await this.$store.dispatch('TimelineSpace/bindLocalStreaming') + this.$store.dispatch('TimelineSpace/startLocalStreaming') + }, updateToot (message) { this.$store.commit('TimelineSpace/Contents/Local/updateToot', message) }, diff --git a/src/renderer/store/Settings/Timeline.js b/src/renderer/store/Settings/Timeline.js index 49b19c12..e0d58d7f 100644 --- a/src/renderer/store/Settings/Timeline.js +++ b/src/renderer/store/Settings/Timeline.js @@ -3,8 +3,7 @@ import { ipcRenderer } from 'electron' export default { namespaced: true, state: { - unread_notification: { - home: true, + unreadNotification: { direct: false, favourite: false, local: true, @@ -13,7 +12,7 @@ export default { }, mutations: { updateUnreadNotification (state, settings) { - state.unread_notification = settings + state.unreadNotification = settings } }, actions: { @@ -32,7 +31,7 @@ export default { }) }, changeUnreadNotification ({ dispatch, state, rootState }, timeline) { - const settings = Object.assign({}, state.unread_notification, timeline, { + const settings = Object.assign({}, state.unreadNotification, timeline, { accountID: rootState.Settings.accountID }) return new Promise((resolve, reject) => { diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js index 387b5173..58a87261 100644 --- a/src/renderer/store/TimelineSpace.js +++ b/src/renderer/store/TimelineSpace.js @@ -22,7 +22,13 @@ const TimelineSpace = { }, loading: false, emojis: [], - tootMax: 500 + tootMax: 500, + unreadNotification: { + direct: false, + favourite: false, + local: true, + public: false + } }, mutations: { updateAccount (state, account) { @@ -45,9 +51,15 @@ const TimelineSpace = { } else { state.tootMax = 500 } + }, + updateUnreadNotification (state, settings) { + state.unreadNotification = settings } }, actions: { + // ------------------------------------------------- + // Accounts + // ------------------------------------------------- localAccount ({ dispatch, commit }, id) { return new Promise((resolve, reject) => { ipcRenderer.send('get-local-account', id) @@ -87,6 +99,117 @@ const TimelineSpace = { }) }) }, + async clearAccount ({ commit }) { + commit( + 'updateAccount', + { + domain: '', + _id: '', + username: '' + } + ) + return 'clearAccount' + }, + // ----------------------------------------------- + // Shortcuts + // ----------------------------------------------- + watchShortcutEvents ({ commit, dispatch }) { + ipcRenderer.on('CmdOrCtrl+N', () => { + dispatch('TimelineSpace/Modals/NewToot/openModal', {}, { root: true }) + }) + ipcRenderer.on('CmdOrCtrl+K', () => { + commit('TimelineSpace/Modals/Jump/changeModal', true, { root: true }) + }) + }, + async removeShortcutEvents () { + ipcRenderer.removeAllListeners('CmdOrCtrl+N') + ipcRenderer.removeAllListeners('CmdOrCtrl+K') + return 'removeShortcutEvents' + }, + /** + * clearUnread + */ + async clearUnread ({ dispatch }) { + dispatch('TimelineSpace/SideMenu/clearUnread', {}, { root: true }) + }, + /** + * fetchEmojis + */ + async fetchEmojis ({ commit }, account) { + const data = await Mastodon.get('/custom_emojis', {}, account.baseURL + '/api/v1') + commit('updateEmojis', data) + return data + }, + /** + * fetchInstance + */ + async fetchInstance ({ commit }, account) { + const data = await Mastodon.get('/instance', {}, account.baseURL + '/api/v1') + commit('updateTootMax', data.max_toot_chars) + return data + }, + loadUnreadNotification ({ commit, rootState }, accountID) { + return new Promise((resolve, reject) => { + ipcRenderer.once('response-get-unread-notification', (event, settings) => { + ipcRenderer.removeAllListeners('error-get-unread-notification') + commit('updateUnreadNotification', settings) + resolve(settings) + }) + ipcRenderer.once('error-get-unread-notification', (event, err) => { + ipcRenderer.removeAllListeners('response-get-unread-notification') + resolve(null) + }) + ipcRenderer.send('get-unread-notification', accountID) + }) + }, + async fetchContentsTimelines ({ dispatch, state }, account) { + await dispatch('TimelineSpace/Contents/Home/fetchTimeline', account, { root: true }) + await dispatch('TimelineSpace/Contents/Notifications/fetchNotifications', account, { root: true }) + if (state.unreadNotification.direct) { + await dispatch('TimelineSpace/Contents/DirectMessages/fetchTimeline', {}, { root: true }) + } + if (state.unreadNotification.local) { + await dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', {}, { root: true }) + } + // TODO: public, favourite + }, + clearContentsTimelines ({ commit }) { + commit('TimelineSpace/Contents/Home/clearTimeline', {}, { root: true }) + commit('TimelineSpace/Contents/Local/clearTimeline', {}, { root: true }) + commit('TimelineSpace/Contents/DirectMessages/clearTimeline', {}, { root: true }) + commit('TimelineSpace/Contents/Notifications/clearNotifications', {}, { root: true }) + }, + bindStreamings ({ dispatch, state }, account) { + dispatch('bindUserStreaming', account) + if (state.unreadNotification.direct) { + dispatch('bindDirectMessagesStreaming') + } + if (state.unreadNotification.local) { + dispatch('bindLocalStreaming') + } + // TODO: public, favourite + }, + startStreamings ({ dispatch, state }, account) { + dispatch('startUserStreaming', account) + if (state.unreadNotification.direct) { + dispatch('startDirectMessagesStreaming') + } + if (state.unreadNotification.local) { + dispatch('startLocalStreaming') + } + // TODO: public ,favourite + }, + stopStreamings ({ dispatch }, account) { + dispatch('stopUserStreaming') + dispatch('stopDirectMessagesStreaming') + dispatch('stopLocalStreaming') + dispatch('unbindUserStreaming') + dispatch('unbindDirectMessagesStreaming') + dispatch('unbindLocalStreaming') + }, + // ------------------------------------------------ + // Each streaming methods + // ------------------------------------------------ bindUserStreaming ({ commit, rootState }, account) { ipcRenderer.on('update-start-user-streaming', (event, update) => { commit('TimelineSpace/Contents/Home/appendTimeline', update, { root: true }) @@ -127,9 +250,9 @@ const TimelineSpace = { commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', true, { root: true }) }) }, - startLocalStreaming (_, account) { + startLocalStreaming ({ state }) { return new Promise((resolve, reject) => { - ipcRenderer.send('start-local-streaming', account) + ipcRenderer.send('start-local-streaming', state.account) ipcRenderer.once('error-start-local-streaming', (event, err) => { reject(err) }) @@ -144,9 +267,9 @@ const TimelineSpace = { commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', true, { root: true }) }) }, - startDirectMessagesStreaming (_, account) { + startDirectMessagesStreaming ({ state }) { return new Promise((resolve, reject) => { - ipcRenderer.send('start-directmessages-streaming', account) + ipcRenderer.send('start-directmessages-streaming', state.account) ipcRenderer.once('error-start-directmessages-streaming', (event, err) => { reject(err) }) @@ -173,43 +296,6 @@ const TimelineSpace = { }, stopDirectMessagesStreaming () { ipcRenderer.send('stop-drectmessages-streaming') - }, - watchShortcutEvents ({ commit, dispatch }) { - ipcRenderer.on('CmdOrCtrl+N', () => { - dispatch('TimelineSpace/Modals/NewToot/openModal', {}, { root: true }) - }) - ipcRenderer.on('CmdOrCtrl+K', () => { - commit('TimelineSpace/Modals/Jump/changeModal', true, { root: true }) - }) - }, - async removeShortcutEvents () { - ipcRenderer.removeAllListeners('CmdOrCtrl+N') - ipcRenderer.removeAllListeners('CmdOrCtrl+K') - return 'removeShortcutEvents' - }, - async clearAccount ({ commit }) { - commit( - 'updateAccount', - { - domain: '', - _id: '', - username: '' - } - ) - return 'clearAccount' - }, - async clearUnread ({ dispatch }) { - dispatch('TimelineSpace/SideMenu/clearUnread', {}, { root: true }) - }, - async fetchEmojis ({ commit }, account) { - const data = await Mastodon.get('/custom_emojis', {}, account.baseURL + '/api/v1') - commit('updateEmojis', data) - return data - }, - async fetchInstance ({ commit }, account) { - const data = await Mastodon.get('/instance', {}, account.baseURL + '/api/v1') - commit('updateTootMax', data.max_toot_chars) - return data } } } diff --git a/src/renderer/store/TimelineSpace/Contents/DirectMessages.js b/src/renderer/store/TimelineSpace/Contents/DirectMessages.js index 829d65b8..d9620a59 100644 --- a/src/renderer/store/TimelineSpace/Contents/DirectMessages.js +++ b/src/renderer/store/TimelineSpace/Contents/DirectMessages.js @@ -71,7 +71,7 @@ const DirectMessages = { } }, actions: { - fetchTimeline ({ state, commit, rootState }, account) { + fetchTimeline ({ state, commit, rootState }) { const client = new Mastodon( rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.baseURL + '/api/v1' diff --git a/src/renderer/store/TimelineSpace/Contents/Local.js b/src/renderer/store/TimelineSpace/Contents/Local.js index 60dae5b1..e4024560 100644 --- a/src/renderer/store/TimelineSpace/Contents/Local.js +++ b/src/renderer/store/TimelineSpace/Contents/Local.js @@ -70,10 +70,10 @@ const Local = { } }, actions: { - fetchLocalTimeline ({ commit }, account) { + fetchLocalTimeline ({ commit, rootState }) { const client = new Mastodon( - account.accessToken, - account.baseURL + '/api/v1' + rootState.TimelineSpace.account.accessToken, + rootState.TimelineSpace.account.baseURL + '/api/v1' ) return client.get('/timelines/public', { limit: 40, local: true }) .then(res => { From ecc0a4aac50d34b45693c04ff69391bd897b8fa6 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 08:33:36 +0900 Subject: [PATCH 4/8] refs #677 Read settings and streaming update with background for public --- .../TimelineSpace/Contents/Local.vue | 2 +- .../TimelineSpace/Contents/Public.vue | 53 +++++++++++-------- .../components/TimelineSpace/SideMenu.vue | 3 ++ src/renderer/store/TimelineSpace.js | 43 +++++++++++++-- .../store/TimelineSpace/Contents/Public.js | 20 ------- src/renderer/store/TimelineSpace/SideMenu.js | 4 ++ 6 files changed, 79 insertions(+), 46 deletions(-) diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue index 16ff4ce1..3fb9d8bd 100644 --- a/src/renderer/components/TimelineSpace/Contents/Local.vue +++ b/src/renderer/components/TimelineSpace/Contents/Local.vue @@ -78,7 +78,7 @@ export default { document.getElementById('scrollable').addEventListener('scroll', this.onScroll) if (!this.unreadNotification.local) { await this.initialize() - .catch(_ => { + .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 d26f8aae..26c96a21 100644 --- a/src/renderer/components/TimelineSpace/Contents/Public.vue +++ b/src/renderer/components/TimelineSpace/Contents/Public.vue @@ -44,15 +44,18 @@ export default { } }, computed: { + ...mapState('TimelineSpace/Contents/Public', { + timeline: state => state.timeline, + lazyLoading: state => state.lazyLoading, + heading: state => state.heading, + unread: state => state.unreadTimeline, + filter: state => state.filter + }), ...mapState({ openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar, backgroundColor: state => state.App.theme.background_color, startReload: state => state.TimelineSpace.HeaderMenu.reload, - timeline: state => state.TimelineSpace.Contents.Public.timeline, - lazyLoading: state => state.TimelineSpace.Contents.Public.lazyLoading, - heading: state => state.TimelineSpace.Contents.Public.heading, - unread: state => state.TimelineSpace.Contents.Public.unreadTimeline, - filter: state => state.TimelineSpace.Contents.Public.filter + unreadNotification: state => state.TimelineSpace.unreadNotification }), ...mapGetters('TimelineSpace/Modals', [ 'modalOpened' @@ -69,16 +72,28 @@ export default { return currentIndex === -1 } }, - created () { + async mounted () { this.$store.commit('TimelineSpace/changeLoading', true) - this.initialize() - .finally(() => { - this.$store.commit('TimelineSpace/changeLoading', false) - }) + this.$store.commit('TimelineSpace/SideMenu/changeUnreadPublicTimeline', false) document.getElementById('scrollable').addEventListener('scroll', this.onScroll) + if (!this.unreadNotification.public) { + await this.initialize() + .finally(_ => { + this.$store.commit('TimelineSpace/changeLoading', false) + }) + } + this.$store.commit('TimelineSpace/changeLoading', false) + }, + beforeUpdate () { + if (this.$store.state.TimelineSpace.SideMenu.unreadPublicTimeline && this.heading) { + this.$store.commit('TimelineSpace/SideMenu/changeUnreadPublicTimeline', false) + } }, beforeDestroy () { - this.$store.dispatch('TimelineSpace/Contents/Public/stopPublicStreaming') + if (!this.unreadNotification.public) { + this.$store.dispatch('TimelineSpace/stopPublicStreaming') + this.$store.dispatch('TimelineSpace/unbindPublicStreaming') + } }, destroyed () { this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true) @@ -110,21 +125,15 @@ export default { }, methods: { async initialize () { - try { - await this.$store.dispatch('TimelineSpace/Contents/Public/fetchPublicTimeline') - } catch (err) { - this.$message({ - message: this.$t('message.timeline_fetch_error'), - type: 'error' - }) - } - this.$store.dispatch('TimelineSpace/Contents/Public/startPublicStreaming') - .catch(() => { + await this.$store.dispatch('TimelineSpace/Contents/Public/fetchPublicTimeline') + .catch(_ => { this.$message({ - message: this.$t('message.start_streaming_error'), + message: this.$t('message.timeline_fetch_error'), type: 'error' }) }) + await this.$store.dispatch('TimelineSpace/bindPublicStreaming') + this.$store.dispatch('TimelineSpace/startPublicStreaming') }, updateToot (message) { this.$store.commit('TimelineSpace/Contents/Public/updateToot', message) diff --git a/src/renderer/components/TimelineSpace/SideMenu.vue b/src/renderer/components/TimelineSpace/SideMenu.vue index 43e9facc..a582bdfd 100644 --- a/src/renderer/components/TimelineSpace/SideMenu.vue +++ b/src/renderer/components/TimelineSpace/SideMenu.vue @@ -68,6 +68,8 @@ {{ $t("side_menu.public") }} + + @@ -115,6 +117,7 @@ export default { unreadNotifications: state => state.unreadNotifications, unreadLocalTimeline: state => state.unreadLocalTimeline, unreadDirectMessagesTimeline: state => state.unreadDirectMessagesTimeline, + unreadPublicTimeline: state => state.unreadPublicTimeline, lists: state => state.lists, tags: state => state.tags, collapse: state => state.collapse diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js index 58a87261..0f47f097 100644 --- a/src/renderer/store/TimelineSpace.js +++ b/src/renderer/store/TimelineSpace.js @@ -171,13 +171,18 @@ const TimelineSpace = { if (state.unreadNotification.local) { await dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', {}, { root: true }) } - // TODO: public, favourite + if (state.unreadNotification.public) { + await dispatch('TimelineSpace/Contents/Public/fetchPublicTimeline', {}, { root: true }) + } + // TODO: favourite }, clearContentsTimelines ({ commit }) { commit('TimelineSpace/Contents/Home/clearTimeline', {}, { root: true }) commit('TimelineSpace/Contents/Local/clearTimeline', {}, { root: true }) commit('TimelineSpace/Contents/DirectMessages/clearTimeline', {}, { root: true }) commit('TimelineSpace/Contents/Notifications/clearNotifications', {}, { root: true }) + commit('TimelineSpace/Contents/Public/clearTimeline', {}, { root: true }) + // TODO: favourite }, bindStreamings ({ dispatch, state }, account) { dispatch('bindUserStreaming', account) @@ -187,7 +192,10 @@ const TimelineSpace = { if (state.unreadNotification.local) { dispatch('bindLocalStreaming') } - // TODO: public, favourite + if (state.unreadNotification.public) { + dispatch('bindPublicStreaming') + } + // TODO: favourite }, startStreamings ({ dispatch, state }, account) { dispatch('startUserStreaming', account) @@ -197,15 +205,20 @@ const TimelineSpace = { if (state.unreadNotification.local) { dispatch('startLocalStreaming') } - // TODO: public ,favourite + if (state.unreadNotification.public) { + dispatch('startPublicStreaming') + } + // TODO: favourite }, stopStreamings ({ dispatch }, account) { dispatch('stopUserStreaming') dispatch('stopDirectMessagesStreaming') dispatch('stopLocalStreaming') + dispatch('stopPublicStreaming') dispatch('unbindUserStreaming') dispatch('unbindDirectMessagesStreaming') dispatch('unbindLocalStreaming') + dispatch('unbindPublicStreaming') }, // ------------------------------------------------ // Each streaming methods @@ -258,6 +271,23 @@ const TimelineSpace = { }) }) }, + bindPublicStreaming ({ commit, rootState }) { + 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/SideMenu/changeUnreadPublicTimeline', true, { root: true }) + }, + startPublicStreaming ({ state }) { + return new Promise((resolve, reject) => { + ipcRenderer.send('start-public-streaming', state.account) + ipcRenderer.once('error-start-public-streaming', (event, err) => { + reject(err) + }) + }) + }, bindDirectMessagesStreaming ({ commit, rootState }) { ipcRenderer.on('update-start-directmessages-streaming', (event, update) => { commit('TimelineSpace/Contents/DirectMessages/appendTimeline', update, { root: true }) @@ -290,6 +320,13 @@ const TimelineSpace = { stopLocalStreaming () { ipcRenderer.send('stop-local-streaming') }, + unbindPublicStreaming () { + ipcRenderer.removeAllListeners('error-start-public-streaming') + ipcRenderer.removeAllListeners('update-start-public-streaming') + }, + stopPublicStreaming () { + ipcRenderer.send('stop-public-streaming') + }, unbindDirectMessagesStreaming () { ipcRenderer.removeAllListeners('error-start-directmessages-streaming') ipcRenderer.removeAllListeners('update-start-directmessages-streaming') diff --git a/src/renderer/store/TimelineSpace/Contents/Public.js b/src/renderer/store/TimelineSpace/Contents/Public.js index ceaf828b..1b884cbc 100644 --- a/src/renderer/store/TimelineSpace/Contents/Public.js +++ b/src/renderer/store/TimelineSpace/Contents/Public.js @@ -1,4 +1,3 @@ -import { ipcRenderer } from 'electron' import Mastodon from 'megalodon' const Public = { @@ -81,25 +80,6 @@ const Public = { commit('updateTimeline', res.data) }) }, - startPublicStreaming ({ state, commit, rootState }) { - ipcRenderer.on('update-start-public-streaming', (event, update) => { - commit('appendTimeline', update) - if (state.heading && Math.random() > 0.8) { - commit('archiveTimeline') - } - }) - return new Promise((resolve, reject) => { - ipcRenderer.send('start-public-streaming', rootState.TimelineSpace.account) - ipcRenderer.once('error-start-public-streaming', (event, err) => { - reject(err) - }) - }) - }, - stopPublicStreaming ({ commit }) { - ipcRenderer.removeAllListeners('error-start-public-streaming') - ipcRenderer.removeAllListeners('update-start-public-streaming') - ipcRenderer.send('stop-public-streaming') - }, lazyFetchTimeline ({ state, commit, rootState }, last) { if (last === undefined || last === null) { return Promise.resolve(null) diff --git a/src/renderer/store/TimelineSpace/SideMenu.js b/src/renderer/store/TimelineSpace/SideMenu.js index 4a5d13f2..dbed08f9 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.js +++ b/src/renderer/store/TimelineSpace/SideMenu.js @@ -8,6 +8,7 @@ const SideMenu = { unreadNotifications: false, unreadLocalTimeline: false, unreadDirectMessagesTimeline: false, + unreadPublicTimeline: false, lists: [], tags: [], collapse: false @@ -25,6 +26,9 @@ const SideMenu = { changeUnreadDirectMessagesTimeline (state, value) { state.unreadDirectMessagesTimeline = value }, + changeUnreadPublicTimeline (state, value) { + state.unreadPublicTimeline = value + }, updateLists (state, lists) { state.lists = lists }, From 5ac0f1e2758fa83cb072026767ceceef67460825 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 22:11:51 +0900 Subject: [PATCH 5/8] refs #677 Remove favourite settings --- src/renderer/components/Settings/Timeline.vue | 18 ------------------ src/renderer/store/Settings/Timeline.js | 1 - src/renderer/store/TimelineSpace.js | 5 ----- 3 files changed, 24 deletions(-) diff --git a/src/renderer/components/Settings/Timeline.vue b/src/renderer/components/Settings/Timeline.vue index b61afda7..cfee03fb 100644 --- a/src/renderer/components/Settings/Timeline.vue +++ b/src/renderer/components/Settings/Timeline.vue @@ -13,14 +13,6 @@
- {{ $t('settings.timeline.unread_notification.favourite') }} - - -
{{ $t('settings.timeline.unread_notification.local') }} @@ -57,16 +49,6 @@ export default { }) } }, - favourite: { - get () { - return this.$store.state.Settings.Timeline.unreadNotification.favourite - }, - set (value) { - this.$store.dispatch('Settings/Timeline/changeUnreadNotification', { - favourite: value - }) - } - }, local: { get () { return this.$store.state.Settings.Timeline.unreadNotification.local diff --git a/src/renderer/store/Settings/Timeline.js b/src/renderer/store/Settings/Timeline.js index e0d58d7f..1a5f5349 100644 --- a/src/renderer/store/Settings/Timeline.js +++ b/src/renderer/store/Settings/Timeline.js @@ -5,7 +5,6 @@ export default { state: { unreadNotification: { direct: false, - favourite: false, local: true, public: false } diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js index 0f47f097..d27fe00b 100644 --- a/src/renderer/store/TimelineSpace.js +++ b/src/renderer/store/TimelineSpace.js @@ -25,7 +25,6 @@ const TimelineSpace = { tootMax: 500, unreadNotification: { direct: false, - favourite: false, local: true, public: false } @@ -174,7 +173,6 @@ const TimelineSpace = { if (state.unreadNotification.public) { await dispatch('TimelineSpace/Contents/Public/fetchPublicTimeline', {}, { root: true }) } - // TODO: favourite }, clearContentsTimelines ({ commit }) { commit('TimelineSpace/Contents/Home/clearTimeline', {}, { root: true }) @@ -182,7 +180,6 @@ const TimelineSpace = { commit('TimelineSpace/Contents/DirectMessages/clearTimeline', {}, { root: true }) commit('TimelineSpace/Contents/Notifications/clearNotifications', {}, { root: true }) commit('TimelineSpace/Contents/Public/clearTimeline', {}, { root: true }) - // TODO: favourite }, bindStreamings ({ dispatch, state }, account) { dispatch('bindUserStreaming', account) @@ -195,7 +192,6 @@ const TimelineSpace = { if (state.unreadNotification.public) { dispatch('bindPublicStreaming') } - // TODO: favourite }, startStreamings ({ dispatch, state }, account) { dispatch('startUserStreaming', account) @@ -208,7 +204,6 @@ const TimelineSpace = { if (state.unreadNotification.public) { dispatch('startPublicStreaming') } - // TODO: favourite }, stopStreamings ({ dispatch }, account) { dispatch('stopUserStreaming') From 8934d16cc869a5d82cb109b98d3a4f2e7f62cce1 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 22:32:53 +0900 Subject: [PATCH 6/8] 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 }) From 744c65d9906ddca568ffa7831b202e75259c4633 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 22:44:58 +0900 Subject: [PATCH 7/8] refs #677 Fix default settings of unread notification --- src/constants/unreadNotification.js | 2 +- src/main/index.js | 1 + src/renderer/store/TimelineSpace/SideMenu.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/constants/unreadNotification.js b/src/constants/unreadNotification.js index 1ea5774c..929c744a 100644 --- a/src/constants/unreadNotification.js +++ b/src/constants/unreadNotification.js @@ -6,6 +6,6 @@ export default { default: true }, Public: { - default: true + default: false } } diff --git a/src/main/index.js b/src/main/index.js index 8912dc06..3e734c33 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -779,6 +779,7 @@ ipcMain.on('get-unread-notification', (event, accountID) => { event.sender.send('response-get-unread-notification', doc) }) .catch(err => { + console.warn(err) event.sender.send('error-get-unread-notification', err) }) }) diff --git a/src/renderer/store/TimelineSpace/SideMenu.js b/src/renderer/store/TimelineSpace/SideMenu.js index dbed08f9..dc02e4c9 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.js +++ b/src/renderer/store/TimelineSpace/SideMenu.js @@ -57,6 +57,7 @@ const SideMenu = { commit('changeUnreadNotifications', false) commit('changeUnreadLocalTimeline', false) commit('changeUnreadDirectMessagesTimeline', false) + commit('changeUnreadPublicTimeline', false) }, changeCollapse ({ commit }, value) { commit('changeCollapse', value) From c9a1d68b995f92723ed1ab220dc81db21e6e14ae Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 8 Nov 2018 22:54:36 +0900 Subject: [PATCH 8/8] refs #677 Update translations --- src/config/locales/de/translation.json | 1 + src/config/locales/de/translation.missing.json | 14 +++++++++++++- src/config/locales/en/translation.json | 2 -- src/config/locales/fr/translation.missing.json | 14 +++++++++++++- src/config/locales/ja/translation.json | 12 ++++++++++++ src/config/locales/ko/translation.missing.json | 14 +++++++++++++- src/config/locales/pl/translation.missing.json | 14 +++++++++++++- 7 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/config/locales/de/translation.json b/src/config/locales/de/translation.json index 8188c443..b62b8605 100644 --- a/src/config/locales/de/translation.json +++ b/src/config/locales/de/translation.json @@ -73,6 +73,7 @@ "reload": "Neu laden" }, "settings": { + "title": "Settings", "general": { "title": "Settings", "toot": { diff --git a/src/config/locales/de/translation.missing.json b/src/config/locales/de/translation.missing.json index d99b79c3..72622606 100644 --- a/src/config/locales/de/translation.missing.json +++ b/src/config/locales/de/translation.missing.json @@ -1,5 +1,17 @@ { "side_menu": { "direct": "Direct messages" + }, + "settings": { + "timeline": { + "title": "Timeline", + "unread_notification": { + "title": "Unread Notification", + "description": "Customize unread notifications for each timelines.", + "direct": "Direct Messages", + "local": "Local Timeline", + "public": "Public Timeline" + } + } } -} \ No newline at end of file +} diff --git a/src/config/locales/en/translation.json b/src/config/locales/en/translation.json index 585ea76c..edc62f66 100644 --- a/src/config/locales/en/translation.json +++ b/src/config/locales/en/translation.json @@ -96,9 +96,7 @@ "unread_notification": { "title": "Unread Notification", "description": "Customize unread notifications for each timelines.", - "home": "Home Timeline", "direct": "Direct Messages", - "favourite": "Favourite", "local": "Local Timeline", "public": "Public Timeline" } diff --git a/src/config/locales/fr/translation.missing.json b/src/config/locales/fr/translation.missing.json index d99b79c3..72622606 100644 --- a/src/config/locales/fr/translation.missing.json +++ b/src/config/locales/fr/translation.missing.json @@ -1,5 +1,17 @@ { "side_menu": { "direct": "Direct messages" + }, + "settings": { + "timeline": { + "title": "Timeline", + "unread_notification": { + "title": "Unread Notification", + "description": "Customize unread notifications for each timelines.", + "direct": "Direct Messages", + "local": "Local Timeline", + "public": "Public Timeline" + } + } } -} \ No newline at end of file +} diff --git a/src/config/locales/ja/translation.json b/src/config/locales/ja/translation.json index d2d1cf6f..8521bc5c 100644 --- a/src/config/locales/ja/translation.json +++ b/src/config/locales/ja/translation.json @@ -47,6 +47,7 @@ "expand": "拡大", "home": "ホーム", "notification": "通知", + "direct": "ダイレクトメッセージ", "favourite": "お気に入り", "local": "ローカル", "public": "連合", @@ -75,6 +76,7 @@ "settings": { "title": "設定", "general": { + "title": "一般", "toot": { "title": "トゥート", "visibility": { @@ -88,6 +90,16 @@ "description": "メディアを常に閲覧注意として投稿する" } } + }, + "timeline": { + "title": "タイムライン", + "unread_notification": { + "title": "未読管理", + "description": "未読管理をするタイムラインを設定", + "direct": "ダイレクトメッセージ", + "local": "ローカル", + "public": "連合" + } } }, "preferences": { diff --git a/src/config/locales/ko/translation.missing.json b/src/config/locales/ko/translation.missing.json index d99b79c3..72622606 100644 --- a/src/config/locales/ko/translation.missing.json +++ b/src/config/locales/ko/translation.missing.json @@ -1,5 +1,17 @@ { "side_menu": { "direct": "Direct messages" + }, + "settings": { + "timeline": { + "title": "Timeline", + "unread_notification": { + "title": "Unread Notification", + "description": "Customize unread notifications for each timelines.", + "direct": "Direct Messages", + "local": "Local Timeline", + "public": "Public Timeline" + } + } } -} \ No newline at end of file +} diff --git a/src/config/locales/pl/translation.missing.json b/src/config/locales/pl/translation.missing.json index d99b79c3..72622606 100644 --- a/src/config/locales/pl/translation.missing.json +++ b/src/config/locales/pl/translation.missing.json @@ -1,5 +1,17 @@ { "side_menu": { "direct": "Direct messages" + }, + "settings": { + "timeline": { + "title": "Timeline", + "unread_notification": { + "title": "Unread Notification", + "description": "Customize unread notifications for each timelines.", + "direct": "Direct Messages", + "local": "Local Timeline", + "public": "Public Timeline" + } + } } -} \ No newline at end of file +}