2020-05-03 14:36:12 +00:00
|
|
|
import get from 'lodash/get'
|
|
|
|
import map from 'lodash/map'
|
|
|
|
import reject from 'lodash/reject'
|
2020-05-10 03:46:06 +00:00
|
|
|
import Autosuggest from 'src/components/autosuggest/autosuggest.vue'
|
|
|
|
import TabSwitcher from 'src/components/tab_switcher/tab_switcher.js'
|
|
|
|
import BlockCard from 'src/components/block_card/block_card.vue'
|
|
|
|
import MuteCard from 'src/components/mute_card/mute_card.vue'
|
|
|
|
import DomainMuteCard from 'src/components/domain_mute_card/domain_mute_card.vue'
|
|
|
|
import SelectableList from 'src/components/selectable_list/selectable_list.vue'
|
|
|
|
import ProgressButton from 'src/components/progress_button/progress_button.vue'
|
|
|
|
import withSubscription from 'src/components/../hocs/with_subscription/with_subscription'
|
|
|
|
import Checkbox from 'src/components/checkbox/checkbox.vue'
|
2020-05-03 14:36:12 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
const DomainMuteList = withSubscription({
|
|
|
|
fetch: (props, $store) => $store.dispatch('fetchDomainMutes'),
|
|
|
|
select: (props, $store) => get($store.state.users.currentUser, 'domainMutes', []),
|
|
|
|
childPropName: 'items'
|
|
|
|
})(SelectableList)
|
|
|
|
|
|
|
|
const MutesAndBlocks = {
|
|
|
|
data () {
|
|
|
|
return {
|
2020-05-10 10:54:55 +00:00
|
|
|
activeTab: 'profile'
|
2020-05-03 14:36:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.$store.dispatch('fetchTokens')
|
2020-05-10 10:54:55 +00:00
|
|
|
this.$store.dispatch('getKnownDomains')
|
2020-05-03 14:36:12 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
TabSwitcher,
|
|
|
|
BlockList,
|
|
|
|
MuteList,
|
|
|
|
DomainMuteList,
|
|
|
|
BlockCard,
|
|
|
|
MuteCard,
|
|
|
|
DomainMuteCard,
|
|
|
|
ProgressButton,
|
|
|
|
Autosuggest,
|
|
|
|
Checkbox
|
|
|
|
},
|
2020-05-10 10:54:55 +00:00
|
|
|
computed: {
|
|
|
|
knownDomains () {
|
|
|
|
return this.$store.state.instance.knownDomains
|
|
|
|
},
|
|
|
|
user () {
|
|
|
|
return this.$store.state.users.currentUser
|
|
|
|
}
|
|
|
|
},
|
2020-05-03 14:36:12 +00:00
|
|
|
methods: {
|
|
|
|
importFollows (file) {
|
|
|
|
return this.$store.state.api.backendInteractor.importFollows({ file })
|
|
|
|
.then((status) => {
|
|
|
|
if (!status) {
|
|
|
|
throw new Error('failed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
importBlocks (file) {
|
|
|
|
return this.$store.state.api.backendInteractor.importBlocks({ file })
|
|
|
|
.then((status) => {
|
|
|
|
if (!status) {
|
|
|
|
throw new Error('failed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
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')
|
|
|
|
},
|
|
|
|
activateTab (tabName) {
|
|
|
|
this.activeTab = tabName
|
|
|
|
},
|
|
|
|
filterUnblockedUsers (userIds) {
|
|
|
|
return reject(userIds, (userId) => {
|
2020-05-25 00:29:48 +00:00
|
|
|
const relationship = this.$store.getters.relationship(this.userId)
|
2020-05-10 10:54:55 +00:00
|
|
|
return relationship.blocking || userId === this.user.id
|
2020-05-03 14:36:12 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
filterUnMutedUsers (userIds) {
|
|
|
|
return reject(userIds, (userId) => {
|
2020-05-25 00:29:48 +00:00
|
|
|
const relationship = this.$store.getters.relationship(this.userId)
|
2020-05-10 10:54:55 +00:00
|
|
|
return relationship.muting || userId === this.user.id
|
2020-05-03 14:36:12 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
queryUserIds (query) {
|
2020-05-25 00:29:48 +00:00
|
|
|
return this.$store.dispatch('searchUsers', { query })
|
2020-05-03 14:36:12 +00:00
|
|
|
.then((users) => map(users, 'id'))
|
|
|
|
},
|
|
|
|
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)
|
|
|
|
},
|
2020-05-10 10:54:55 +00:00
|
|
|
filterUnMutedDomains (urls) {
|
|
|
|
return urls.filter(url => !this.user.domainMutes.includes(url))
|
|
|
|
},
|
|
|
|
queryKnownDomains (query) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(this.knownDomains.filter(url => url.toLowerCase().includes(query)))
|
|
|
|
})
|
|
|
|
},
|
2020-05-03 14:36:12 +00:00
|
|
|
unmuteDomains (domains) {
|
|
|
|
return this.$store.dispatch('unmuteDomains', domains)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MutesAndBlocks
|