akkoma-fe/src/components/user_settings/user_settings.js

141 lines
4.2 KiB
JavaScript
Raw Normal View History

import get from 'lodash/get'
import map from 'lodash/map'
import reject from 'lodash/reject'
2020-05-03 14:36:12 +00:00
import Autosuggest from '../autosuggest/autosuggest.vue'
import TabSwitcher from '../tab_switcher/tab_switcher.js'
2019-02-13 19:55:02 +00:00
import BlockCard from '../block_card/block_card.vue'
2019-02-14 03:04:28 +00:00
import MuteCard from '../mute_card/mute_card.vue'
2020-01-15 20:22:54 +00:00
import DomainMuteCard from '../domain_mute_card/domain_mute_card.vue'
import SelectableList from '../selectable_list/selectable_list.vue'
2019-04-04 17:30:34 +00:00
import ProgressButton from '../progress_button/progress_button.vue'
import Importer from '../importer/importer.vue'
2019-03-30 12:03:40 +00:00
import Exporter from '../exporter/exporter.vue'
import withSubscription from '../../hocs/with_subscription/with_subscription'
import Checkbox from '../checkbox/checkbox.vue'
const BlockList = withSubscription({
fetch: (props, $store) => $store.dispatch('fetchBlocks'),
select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []),
childPropName: 'items'
})(SelectableList)
const MuteList = withSubscription({
fetch: (props, $store) => $store.dispatch('fetchMutes'),
select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []),
childPropName: 'items'
})(SelectableList)
2019-02-14 03:04:28 +00:00
2020-01-15 20:22:54 +00:00
const DomainMuteList = withSubscription({
fetch: (props, $store) => $store.dispatch('fetchDomainMutes'),
select: (props, $store) => get($store.state.users.currentUser, 'domainMutes', []),
childPropName: 'items'
})(SelectableList)
const UserSettings = {
data () {
return {
2019-05-25 07:01:02 +00:00
activeTab: 'profile',
2020-01-15 20:22:54 +00:00
newDomainToMute: ''
}
},
created () {
this.$store.dispatch('fetchTokens')
},
components: {
2019-02-07 08:05:59 +00:00
TabSwitcher,
BlockList,
MuteList,
2020-01-15 20:22:54 +00:00
DomainMuteList,
2019-04-02 20:14:45 +00:00
BlockCard,
2019-04-04 17:30:34 +00:00
MuteCard,
2020-01-15 20:22:54 +00:00
DomainMuteCard,
ProgressButton,
2020-05-03 14:36:12 +00:00
Autosuggest,
Checkbox
},
computed: {
user () {
return this.$store.state.users.currentUser
2017-12-23 14:44:22 +00:00
},
pleromaBackend () {
2018-09-09 18:21:23 +00:00
return this.$store.state.instance.pleromaBackend
},
currentSaveStateNotice () {
return this.$store.state.interface.settings.currentSaveStateNotice
2018-06-27 13:28:07 +00:00
}
},
methods: {
2019-03-30 09:10:57 +00:00
importFollows (file) {
return this.$store.state.api.backendInteractor.importFollows({ file })
2019-03-30 09:10:57 +00:00
.then((status) => {
if (!status) {
throw new Error('failed')
}
})
},
2019-03-30 11:27:53 +00:00
importBlocks (file) {
return this.$store.state.api.backendInteractor.importBlocks({ file })
2019-03-30 11:27:53 +00:00
.then((status) => {
if (!status) {
throw new Error('failed')
}
})
},
2019-03-30 12:17:37 +00:00
generateExportableUsersContent (users) {
// Get addresses
return users.map((user) => {
// check is it's a local user
if (user && user.is_local) {
// append the instance address
// eslint-disable-next-line no-undef
return user.screen_name + '@' + location.hostname
}
return user.screen_name
}).join('\n')
},
2018-08-18 23:23:03 +00:00
activateTab (tabName) {
this.activeTab = tabName
2018-11-30 13:30:55 +00:00
},
filterUnblockedUsers (userIds) {
return reject(userIds, (userId) => {
const user = this.$store.getters.findUser(userId)
return !user || user.statusnet_blocking || user.id === this.$store.state.users.currentUser.id
})
},
2019-04-02 20:14:45 +00:00
filterUnMutedUsers (userIds) {
return reject(userIds, (userId) => {
const user = this.$store.getters.findUser(userId)
return !user || user.muted || user.id === this.$store.state.users.currentUser.id
})
},
queryUserIds (query) {
return this.$store.dispatch('searchUsers', query)
.then((users) => map(users, 'id'))
2019-04-04 17:54:52 +00:00
},
blockUsers (ids) {
return this.$store.dispatch('blockUsers', ids)
},
unblockUsers (ids) {
return this.$store.dispatch('unblockUsers', ids)
},
muteUsers (ids) {
return this.$store.dispatch('muteUsers', ids)
},
unmuteUsers (ids) {
return this.$store.dispatch('unmuteUsers', ids)
2019-04-06 18:56:50 +00:00
},
2020-01-15 20:22:54 +00:00
unmuteDomains (domains) {
return this.$store.dispatch('unmuteDomains', domains)
},
muteDomain () {
return this.$store.dispatch('muteDomain', this.newDomainToMute)
.then(() => { this.newDomainToMute = '' })
},
2019-04-06 18:56:50 +00:00
identity (value) {
return value
}
}
}
export default UserSettings