refs #673 Set visibility and sync web instance

This commit is contained in:
AkiraFukushima 2018-10-27 00:54:51 +09:00
parent 885a14c5cb
commit e0179a6f87
5 changed files with 73 additions and 14 deletions

View File

@ -34,20 +34,9 @@
<script>
import { mapState } from 'vuex'
import Visibility from '~/src/constants/visibility'
export default {
name: 'Settings',
data () {
return {
visibilities: [
Visibility.Public,
Visibility.Unlisted,
Visibility.Private
],
tootVisibility: Visibility.Public
}
},
computed: {
...mapState({
primaryColor: state => state.App.theme.primary_color,

View File

@ -26,9 +26,21 @@ export default {
Visibility.Public,
Visibility.Unlisted,
Visibility.Private
],
tootVisibility: Visibility.Public.value
]
}
},
computed: {
tootVisibility: {
get () {
return this.$store.state.Settings.General.visibility
},
set (value) {
this.$store.dispatch('Settings/General/setVisibility', value)
}
}
},
created () {
this.$store.dispatch('Settings/General/fetchVisibility')
}
}
</script>

View File

@ -0,0 +1,8 @@
import General from './Settings/General'
export default {
namespaced: true,
modules: {
General
}
}

View File

@ -0,0 +1,48 @@
import Mastodon from 'megalodon'
import Visibility from '~/src/constants/visibility'
export default {
namespaced: true,
state: {
visibility: Visibility.Public.value
},
mutations: {
changeVisibility (state, value) {
state.visibility = value
}
},
actions: {
fetchVisibility ({ state, commit, rootState }) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/accounts/verify_credentials')
.then(res => {
const visibility = Object.values(Visibility).find((v) => {
return v.key === res.data.source.privacy
})
commit('changeVisibility', visibility.value)
return res.data
})
},
setVisibility ({ state, commit, rootState }, value) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const visibility = Object.values(Visibility).find((v) => {
return v.value === value
})
return client.patch('/accounts/update_credentials', {
source: {
privacy: visibility.key
}
})
.then(res => {
commit('changeVisibility', visibility.value)
return res.data
})
}
}
}

View File

@ -8,6 +8,7 @@ import Login from './Login'
import Authorize from './Authorize'
import TimelineSpace from './TimelineSpace'
import Preferences from './Preferences'
import Settings from './Settings'
Vue.use(Vuex)
@ -22,6 +23,7 @@ export default new Vuex.Store({
Login,
Authorize,
TimelineSpace,
Preferences
Preferences,
Settings
}
})