From a4811dab7c9a8674ddbae06e11481e7be5e10006 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sat, 1 Jan 2022 22:41:28 +0900 Subject: [PATCH] Change use-marker config under the Settings from Preferences --- .../store/Preferences/General.spec.ts | 3 +- .../integration/store/TimelineSpace.spec.ts | 4 +++ .../store/TimelineSpace/Contents/Home.spec.ts | 9 ++++-- .../Contents/Notifications.spec.ts | 6 ++++ .../unit/store/Preferences/General.spec.ts | 3 +- .../renderer/unit/store/TimelineSpace.spec.ts | 4 +-- src/config/locales/en/translation.json | 8 +++-- src/constants/initializer/preferences.ts | 3 +- src/constants/initializer/setting.ts | 14 ++++++--- src/main/settings.ts | 13 ++++---- .../components/Preferences/General.vue | 17 ----------- src/renderer/components/Settings/Timeline.vue | 30 +++++++++++++++++++ src/renderer/store/App.ts | 11 ++----- src/renderer/store/Preferences/General.ts | 3 +- src/renderer/store/Settings/Timeline.ts | 19 ++++++++++-- src/renderer/store/TimelineSpace.ts | 4 +-- .../store/TimelineSpace/Contents/Home.ts | 4 +-- .../TimelineSpace/Contents/Notifications.ts | 4 +-- src/types/setting.ts | 6 ++++ src/types/timeline.ts | 1 - 20 files changed, 105 insertions(+), 61 deletions(-) diff --git a/spec/renderer/integration/store/Preferences/General.spec.ts b/spec/renderer/integration/store/Preferences/General.spec.ts index a11916b5..8bdc50f2 100644 --- a/spec/renderer/integration/store/Preferences/General.spec.ts +++ b/spec/renderer/integration/store/Preferences/General.spec.ts @@ -16,8 +16,7 @@ const state = (): GeneralState => { timeline: { cw: false, nsfw: false, - hideAllAttachments: false, - useMarkerTimeline: [] + hideAllAttachments: false }, other: { launch: false diff --git a/spec/renderer/integration/store/TimelineSpace.spec.ts b/spec/renderer/integration/store/TimelineSpace.spec.ts index a08dd363..06cc2c98 100644 --- a/spec/renderer/integration/store/TimelineSpace.spec.ts +++ b/spec/renderer/integration/store/TimelineSpace.spec.ts @@ -83,6 +83,10 @@ const state = (): TimelineSpaceState => { direct: true, local: true, public: true + }, + useMarker: { + home: false, + notifications: true } }, sns: 'mastodon', diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/Home.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/Home.spec.ts index 2b1710b1..343acbd6 100644 --- a/spec/renderer/integration/store/TimelineSpace/Contents/Home.spec.ts +++ b/spec/renderer/integration/store/TimelineSpace/Contents/Home.spec.ts @@ -141,6 +141,12 @@ const timelineState = { account: { accessToken: 'token', baseURL: 'http://localhost' + }, + timelineSetting: { + useMarker: { + home: false, + notifications: false + } } } } @@ -148,8 +154,7 @@ const timelineState = { const appState = { namespaced: true, state: { - proxyConfiguration: false, - useMarkerTimeline: [] + proxyConfiguration: false } } diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/Notifications.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/Notifications.spec.ts index b0df9f8e..d794543c 100644 --- a/spec/renderer/integration/store/TimelineSpace/Contents/Notifications.spec.ts +++ b/spec/renderer/integration/store/TimelineSpace/Contents/Notifications.spec.ts @@ -215,6 +215,12 @@ const timelineState = { account: { accessToken: 'token', baseURL: 'http://localhost' + }, + timelineSetting: { + useMarker: { + home: false, + notifications: false + } } } } diff --git a/spec/renderer/unit/store/Preferences/General.spec.ts b/spec/renderer/unit/store/Preferences/General.spec.ts index d7502fd2..d4db7079 100644 --- a/spec/renderer/unit/store/Preferences/General.spec.ts +++ b/spec/renderer/unit/store/Preferences/General.spec.ts @@ -12,8 +12,7 @@ describe('Preferences/General', () => { timeline: { cw: false, nsfw: false, - hideAllAttachments: false, - useMarkerTimeline: [] + hideAllAttachments: false }, other: { launch: false diff --git a/spec/renderer/unit/store/TimelineSpace.spec.ts b/spec/renderer/unit/store/TimelineSpace.spec.ts index f3df2032..e016dc5f 100644 --- a/spec/renderer/unit/store/TimelineSpace.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace.spec.ts @@ -1,5 +1,5 @@ import TimelineSpace, { TimelineSpaceState, blankAccount, MUTATION_TYPES } from '~/src/renderer/store/TimelineSpace' -import { Base } from '~/src/constants/initializer/setting' +import { DefaultSetting } from '~/src/constants/initializer/setting' describe('TimelineSpace', () => { describe('mutations', () => { @@ -11,7 +11,7 @@ describe('TimelineSpace', () => { loading: false, emojis: [], tootMax: 500, - timelineSetting: Base.timeline, + timelineSetting: DefaultSetting.timeline, sns: 'mastodon', filters: [] } diff --git a/src/config/locales/en/translation.json b/src/config/locales/en/translation.json index 7a6a558a..117c9761 100644 --- a/src/config/locales/en/translation.json +++ b/src/config/locales/en/translation.json @@ -111,6 +111,11 @@ "direct": "Direct Messages", "local": "Local Timeline", "public": "Public Timeline" + }, + "use_marker": { + "title": "Load the timeline from the last reading position", + "home": "Home", + "notifications": "Notifications" } }, "filters": { @@ -162,8 +167,7 @@ "description": "Customize view in your timelines.", "cw": "Always ignore contents warnings", "nsfw": "Always ignore NSFW of medias", - "hideAllAttachments": "Hide all medias", - "useMarker": "Load timeline from the last reading position" + "hideAllAttachments": "Hide all medias" }, "other": { "title": "Other options", diff --git a/src/constants/initializer/preferences.ts b/src/constants/initializer/preferences.ts index 6731257b..b4a55b83 100644 --- a/src/constants/initializer/preferences.ts +++ b/src/constants/initializer/preferences.ts @@ -20,8 +20,7 @@ const sound: Sound = { const timeline: Timeline = { cw: false, nsfw: false, - hideAllAttachments: false, - useMarkerTimeline: ['notifications'] + hideAllAttachments: false } const other: Other = { diff --git a/src/constants/initializer/setting.ts b/src/constants/initializer/setting.ts index fab19a08..563f803c 100644 --- a/src/constants/initializer/setting.ts +++ b/src/constants/initializer/setting.ts @@ -1,4 +1,4 @@ -import { Setting, Timeline, UnreadNotification } from '~/src/types/setting' +import { Setting, Timeline, UnreadNotification, UseMarker } from '~/src/types/setting' const unreadNotification: UnreadNotification = { direct: false, @@ -6,11 +6,17 @@ const unreadNotification: UnreadNotification = { public: false } -const timeline: Timeline = { - unreadNotification: unreadNotification +const useMarker: UseMarker = { + home: false, + notifications: true } -export const Base: Setting = { +const timeline: Timeline = { + unreadNotification: unreadNotification, + useMarker: useMarker +} + +export const DefaultSetting: Setting = { accountID: '', timeline: timeline } diff --git a/src/main/settings.ts b/src/main/settings.ts index 7a3b9171..c4c1025e 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -2,7 +2,7 @@ import storage from 'electron-json-storage' import log from 'electron-log' import objectAssignDeep from 'object-assign-deep' import { BaseSettings, Setting } from '~/src/types/setting' -import { Base } from '~/src/constants/initializer/setting' +import { DefaultSetting } from '~/src/constants/initializer/setting' import { isEmpty } from 'lodash' export default class Settings { @@ -12,7 +12,7 @@ export default class Settings { this.path = path } - public async load(): Promise { + public async _load(): Promise { try { const settings = await this._get() if (isEmpty(settings)) { @@ -26,17 +26,16 @@ export default class Settings { } public async get(accountID: string): Promise { - const current = await this.load() + const current = await this._load() const find: Setting | undefined = current.find(d => { return d.accountID === accountID }) if (find) { - return find + return objectAssignDeep({}, DefaultSetting, find) } - const base = objectAssignDeep({}, Base, { + return objectAssignDeep({}, DefaultSetting, { accountID: accountID }) - return base } private _get(): Promise { @@ -58,7 +57,7 @@ export default class Settings { } public async update(obj: Setting): Promise { - const current = await this.load() + const current = await this._load() const find = current.find(d => { return d.accountID === obj.accountID }) diff --git a/src/renderer/components/Preferences/General.vue b/src/renderer/components/Preferences/General.vue index f9ce208d..097ea611 100644 --- a/src/renderer/components/Preferences/General.vue +++ b/src/renderer/components/Preferences/General.vue @@ -23,12 +23,6 @@ - - - - - -

{{ $t('preferences.general.other.title') }}

@@ -105,17 +99,6 @@ export default { }) } }, - timeline_use_marker: { - get() { - return this.$store.state.Preferences.General.general.timeline.useMarkerTimeline - }, - set(value) { - console.log(value) - this.$store.dispatch('Preferences/General/updateTimeline', { - useMarkerTimeline: value - }) - } - }, other_launch: { get() { return this.$store.state.Preferences.General.general.other.launch diff --git a/src/renderer/components/Settings/Timeline.vue b/src/renderer/components/Settings/Timeline.vue index 802c5564..c9c7c97a 100644 --- a/src/renderer/components/Settings/Timeline.vue +++ b/src/renderer/components/Settings/Timeline.vue @@ -15,6 +15,16 @@
+ + +

{{ $t('settings.timeline.use_marker.title') }}

+ + + + + + +
@@ -51,6 +61,26 @@ export default { public: value }) } + }, + marker_home: { + get() { + return this.$store.state.Settings.Timeline.setting.useMarker.home + }, + set(value) { + this.$store.dispatch('Settings/Timeline/changeUseMarker', { + home: value + }) + } + }, + marker_notifications: { + get() { + return this.$store.state.Settings.Timeline.setting.useMarker.notifications + }, + set(value) { + this.$store.dispatch('Settings/Timeline/changeUseMarker', { + notifications: value + }) + } } }, async created() { diff --git a/src/renderer/store/App.ts b/src/renderer/store/App.ts index 68497141..ede7535a 100644 --- a/src/renderer/store/App.ts +++ b/src/renderer/store/App.ts @@ -27,7 +27,6 @@ export type AppState = { hideAllAttachments: boolean tootPadding: number userAgent: string - useMarkerTimeline: Array } const state = (): AppState => ({ @@ -52,8 +51,7 @@ const state = (): AppState => ({ ignoreCW: false, ignoreNSFW: false, hideAllAttachments: false, - userAgent: 'Whalebird', - useMarkerTimeline: ['notifications'] + userAgent: 'Whalebird' }) const MUTATION_TYPES = { @@ -67,8 +65,7 @@ const MUTATION_TYPES = { ADD_FONT: 'addFont', UPDATE_IGNORE_CW: 'updateIgnoreCW', UPDATE_IGNORE_NSFW: 'updateIgnoreNSFW', - UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments', - UPDATE_USE_MARKER: 'updateUseMarker' + UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments' } const mutations: MutationTree = { @@ -105,9 +102,6 @@ const mutations: MutationTree = { }, [MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS]: (state: AppState, hideAllAttachments: boolean) => { state.hideAllAttachments = hideAllAttachments - }, - [MUTATION_TYPES.UPDATE_USE_MARKER]: (state: AppState, useMarkerTimeline: Array) => { - state.useMarkerTimeline = useMarkerTimeline } } @@ -133,7 +127,6 @@ const actions: ActionTree = { commit(MUTATION_TYPES.UPDATE_IGNORE_CW, conf.general.timeline.cw) commit(MUTATION_TYPES.UPDATE_IGNORE_NSFW, conf.general.timeline.nsfw) commit(MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS, conf.general.timeline.hideAllAttachments) - commit(MUTATION_TYPES.UPDATE_USE_MARKER, conf.general.timeline.useMarkerTimeline) return conf }, updateTheme: async ({ commit }, appearance: Appearance) => { diff --git a/src/renderer/store/Preferences/General.ts b/src/renderer/store/Preferences/General.ts index 6f37dcb5..b38231f7 100644 --- a/src/renderer/store/Preferences/General.ts +++ b/src/renderer/store/Preferences/General.ts @@ -21,8 +21,7 @@ const state = (): GeneralState => ({ timeline: { cw: false, nsfw: false, - hideAllAttachments: false, - useMarkerTimeline: ['notifications'] + hideAllAttachments: false }, other: { launch: false diff --git a/src/renderer/store/Settings/Timeline.ts b/src/renderer/store/Settings/Timeline.ts index 20b176f3..5860b6cb 100644 --- a/src/renderer/store/Settings/Timeline.ts +++ b/src/renderer/store/Settings/Timeline.ts @@ -1,8 +1,8 @@ import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { MyWindow } from '~/src/types/global' -import { Setting, UnreadNotification, Timeline as TimelineSetting } from '~src/types/setting' -import { Base } from '~/src/constants/initializer/setting' +import { Setting, UnreadNotification, Timeline as TimelineSetting, UseMarker } from '~src/types/setting' +import { DefaultSetting } from '~/src/constants/initializer/setting' const win = (window as any) as MyWindow @@ -11,7 +11,7 @@ export type TimelineState = { } const state = (): TimelineState => ({ - setting: Base.timeline + setting: DefaultSetting.timeline }) export const MUTATION_TYPES = { @@ -42,6 +42,19 @@ const actions: ActionTree = { await win.ipcRenderer.invoke('update-account-setting', setting) dispatch('loadTimelineSetting') return true + }, + changeUseMarker: async ({ dispatch, state, rootState }, timeline: { key: boolean }) => { + const marker: UseMarker = Object.assign({}, state.setting.useMarker, timeline) + const tl: TimelineSetting = Object.assign({}, state.setting, { + useMarker: marker + }) + const setting: Setting = { + accountID: rootState.Settings.accountID!, + timeline: tl + } + await win.ipcRenderer.invoke('update-account-setting', setting) + dispatch('loadTimelineSetting') + return true } } diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index 63b0bf7e..62d417b7 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -10,7 +10,7 @@ import { AccountLoadError } from '@/errors/load' import { TimelineFetchError } from '@/errors/fetch' import { MyWindow } from '~/src/types/global' import { Timeline, Setting } from '~src/types/setting' -import { Base } from '~/src/constants/initializer/setting' +import { DefaultSetting } from '~/src/constants/initializer/setting' const win = (window as any) as MyWindow @@ -45,7 +45,7 @@ const state = (): TimelineSpaceState => ({ loading: false, emojis: [], tootMax: 500, - timelineSetting: Base.timeline, + timelineSetting: DefaultSetting.timeline, sns: 'mastodon', filters: [] }) diff --git a/src/renderer/store/TimelineSpace/Contents/Home.ts b/src/renderer/store/TimelineSpace/Contents/Home.ts index 6f114046..c458b8fe 100644 --- a/src/renderer/store/TimelineSpace/Contents/Home.ts +++ b/src/renderer/store/TimelineSpace/Contents/Home.ts @@ -134,7 +134,7 @@ const actions: ActionTree = { console.error(err) }) - if (rootState.App.useMarkerTimeline.includes('home') && localMarker !== null) { + if (rootState.TimelineSpace.timelineSetting.useMarker.home && localMarker !== null) { const last = await client.getStatus(localMarker.last_read_id) const lastReadStatus = last.data @@ -240,7 +240,7 @@ const actions: ActionTree = { return res.data }, getMarker: async ({ rootState }): Promise => { - if (!rootState.App.useMarkerTimeline.includes('home')) { + if (!rootState.TimelineSpace.timelineSetting.useMarker.home) { return null } const client = generator( diff --git a/src/renderer/store/TimelineSpace/Contents/Notifications.ts b/src/renderer/store/TimelineSpace/Contents/Notifications.ts index e325db39..6e0f9178 100644 --- a/src/renderer/store/TimelineSpace/Contents/Notifications.ts +++ b/src/renderer/store/TimelineSpace/Contents/Notifications.ts @@ -120,7 +120,7 @@ const actions: ActionTree = { console.error(err) }) - if (rootState.App.useMarkerTimeline.includes('notifications') && localMarker !== null) { + if (rootState.TimelineSpace.timelineSetting.useMarker.notifications && localMarker !== null) { // The result does not contain max_id's notification, when we specify max_id parameter in get notifications. // So we need to get max_id's notification. const last = await client.getNotification(localMarker.last_read_id) @@ -224,7 +224,7 @@ const actions: ActionTree = { win.ipcRenderer.send('reset-badge') }, getMarker: async ({ rootState }): Promise => { - if (!rootState.App.useMarkerTimeline.includes('notifications')) { + if (!rootState.TimelineSpace.timelineSetting.useMarker.notifications) { return null } const client = generator( diff --git a/src/types/setting.ts b/src/types/setting.ts index fa68b23b..07c24ea6 100644 --- a/src/types/setting.ts +++ b/src/types/setting.ts @@ -4,8 +4,14 @@ export type UnreadNotification = { public: boolean } +export type UseMarker = { + home: boolean + notifications: boolean +} + export type Timeline = { unreadNotification: UnreadNotification + useMarker: UseMarker } export type Setting = { accountID: string diff --git a/src/types/timeline.ts b/src/types/timeline.ts index 1a8d9282..2be8cd16 100644 --- a/src/types/timeline.ts +++ b/src/types/timeline.ts @@ -2,5 +2,4 @@ export type Timeline = { cw: boolean nsfw: boolean hideAllAttachments: boolean - useMarkerTimeline: Array }