Add mutes tab

This commit is contained in:
taehoon 2019-02-13 22:04:28 -05:00
parent 09315b2780
commit e91a94ff9c
7 changed files with 99 additions and 6 deletions

View file

@ -0,0 +1,37 @@
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
const MuteCard = {
props: ['userId'],
data () {
return {
progress: false
}
},
computed: {
user () {
return this.$store.getters.userById(this.userId)
},
muted () {
return this.user.muted
}
},
components: {
BasicUserCard
},
methods: {
unmuteUser () {
this.progress = true
this.$store.dispatch('unmuteUser', this.user.id).then(() => {
this.progress = false
})
},
muteUser () {
this.progress = true
this.$store.dispatch('muteUser', this.user.id).then(() => {
this.progress = false
})
}
}
}
export default MuteCard

View file

@ -0,0 +1,24 @@
<template>
<basic-user-card :user="user">
<template slot="secondary-area">
<button class="btn btn-default" @click="unmuteUser" :disabled="progress" v-if="muted">
<template v-if="progress">
{{ $t('user_card.unmute_progress') }}
</template>
<template v-else>
{{ $t('user_card.unmute') }}
</template>
</button>
<button class="btn btn-default" @click="muteUser" :disabled="progress" v-else>
<template v-if="progress">
{{ $t('user_card.mute_progress') }}
</template>
<template v-else>
{{ $t('user_card.mute') }}
</template>
</button>
</template>
</basic-user-card>
</template>
<script src="./mute_card.js"></script>

View file

@ -6,7 +6,7 @@ import ImageCropper from '../image_cropper/image_cropper.vue'
import StyleSwitcher from '../style_switcher/style_switcher.vue' import StyleSwitcher from '../style_switcher/style_switcher.vue'
import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js'
import BlockCard from '../block_card/block_card.vue' import BlockCard from '../block_card/block_card.vue'
import withLoadMore from '../../hocs/with_load_more/with_load_more' import MuteCard from '../mute_card/mute_card.vue'
import withSubscription from '../../hocs/with_subscription/with_subscription' import withSubscription from '../../hocs/with_subscription/with_subscription'
import withList from '../../hocs/with_list/with_list' import withList from '../../hocs/with_list/with_list'
@ -18,6 +18,14 @@ const BlockListWithSubscription = withSubscription(
'entries' 'entries'
) )
const MuteList = withList(MuteCard, userId => ({ userId }))
const MuteListWithSubscription = withSubscription(
MuteList,
(props, $store) => $store.dispatch('fetchMutes'),
(props, $store) => get($store.state.users.currentUser, 'muteIds', []),
'entries'
)
const UserSettings = { const UserSettings = {
data () { data () {
return { return {
@ -55,7 +63,8 @@ const UserSettings = {
StyleSwitcher, StyleSwitcher,
TabSwitcher, TabSwitcher,
ImageCropper, ImageCropper,
'block-list': BlockListWithSubscription 'block-list': BlockListWithSubscription,
'mute-list': MuteListWithSubscription
}, },
computed: { computed: {
user () { user () {

View file

@ -166,6 +166,10 @@
<div :label="$t('settings.blocks_tab')"> <div :label="$t('settings.blocks_tab')">
<block-list :refresh="true" /> <block-list :refresh="true" />
</div> </div>
<div :label="$t('settings.mutes_tab')">
<mute-list :refresh="true" />
</div>
</tab-switcher> </tab-switcher>
</div> </div>
</div> </div>

View file

@ -165,6 +165,7 @@
"lock_account_description": "Restrict your account to approved followers only", "lock_account_description": "Restrict your account to approved followers only",
"loop_video": "Loop videos", "loop_video": "Loop videos",
"loop_video_silent_only": "Loop only videos without sound (i.e. Mastodon's \"gifs\")", "loop_video_silent_only": "Loop only videos without sound (i.e. Mastodon's \"gifs\")",
"mutes_tab": "Mutes",
"play_videos_in_modal": "Play videos directly in the media viewer", "play_videos_in_modal": "Play videos directly in the media viewer",
"use_contain_fit": "Don't crop the attachment in thumbnails", "use_contain_fit": "Don't crop the attachment in thumbnails",
"name": "Name", "name": "Name",

View file

@ -89,6 +89,10 @@ export const mutations = {
const user = state.currentUser const user = state.currentUser
user.blockIds = union(user.blockIds, blockIds) user.blockIds = union(user.blockIds, blockIds)
}, },
saveMutes (state, ids) {
const user = state.currentUser
user.muteIds = union(user.muteIds, ids)
},
setUserForStatus (state, status) { setUserForStatus (state, status) {
status.user = state.usersObject[status.user.id] status.user = state.usersObject[status.user.id]
}, },
@ -157,6 +161,22 @@ const users = {
return store.rootState.api.backendInteractor.unblockUser(id) return store.rootState.api.backendInteractor.unblockUser(id)
.then((user) => store.commit('addNewUsers', [user])) .then((user) => store.commit('addNewUsers', [user]))
}, },
fetchMutes (store) {
return store.rootState.api.backendInteractor.fetchMutes()
.then((mutedUsers) => {
each(mutedUsers, (user) => { user.muted = true })
store.commit('addNewUsers', mutedUsers)
store.commit('saveMutes', map(mutedUsers, 'id'))
})
},
muteUser (store, id) {
return store.state.api.backendInteractor.setUserMute({ id, muted: true })
.then((user) => store.commit('addNewUsers', [user]))
},
unmuteUser (store, id) {
return store.state.api.backendInteractor.setUserMute({ id, muted: false })
.then((user) => store.commit('addNewUsers', [user]))
},
addFriends ({ rootState, commit }, fetchBy) { addFriends ({ rootState, commit }, fetchBy) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const user = rootState.users.usersObject[fetchBy] const user = rootState.users.usersObject[fetchBy]
@ -300,10 +320,7 @@ const users = {
store.dispatch('startFetching', { timeline: 'friends' }) store.dispatch('startFetching', { timeline: 'friends' })
// Get user mutes and follower info // Get user mutes and follower info
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => { store.dispatch('fetchMutes')
each(mutedUsers, (user) => { user.muted = true })
store.commit('addNewUsers', mutedUsers)
})
// Fetch our friends // Fetch our friends
store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) store.rootState.api.backendInteractor.fetchFriends({ id: user.id })

View file

@ -121,6 +121,7 @@ export const parseUser = (data) => {
output.follow_request_count = data.pleroma.follow_request_count output.follow_request_count = data.pleroma.follow_request_count
} }
output.blockIds = [] output.blockIds = []
output.muteIds = []
return output return output
} }