add back mute prediction, add getter for relationships

This commit is contained in:
Shpuld Shpuldson 2020-04-24 18:53:17 +03:00
parent f6fce92cf7
commit af9492977a
9 changed files with 21 additions and 8 deletions

View file

@ -12,7 +12,7 @@ const BlockCard = {
return this.$store.getters.findUser(this.userId) return this.$store.getters.findUser(this.userId)
}, },
relationship () { relationship () {
return this.$store.state.users.relationships[this.userId] || {} return this.$store.getters.relationship(this.userId)
}, },
blocked () { blocked () {
return this.relationship.blocking return this.relationship.blocking

View file

@ -20,7 +20,7 @@ const FollowCard = {
return this.$store.state.users.currentUser return this.$store.state.users.currentUser
}, },
relationship () { relationship () {
return this.$store.state.users.relationships[this.user.id] return this.$store.getters.relationship(this.user.id)
} }
} }
} }

View file

@ -12,7 +12,7 @@ const MuteCard = {
return this.$store.getters.findUser(this.userId) return this.$store.getters.findUser(this.userId)
}, },
relationship () { relationship () {
return this.$store.state.users.relationships[this.userId] return this.$store.getters.relationship(this.userId)
}, },
muted () { muted () {
return this.relationship.muting return this.relationship.muting

View file

@ -56,7 +56,7 @@ const Notification = {
return this.generateUserProfileLink(this.targetUser) return this.generateUserProfileLink(this.targetUser)
}, },
needMute () { needMute () {
return (this.$store.state.users.relationships[this.user.id] || {}).muting return this.$store.getters.relationship(this.user.id).muting
} }
} }
} }

View file

@ -119,7 +119,7 @@ const Status = {
return hits return hits
}, },
muted () { muted () {
const relationship = this.$store.state.users.relationships[this.status.user.id] || {} const relationship = this.$store.getters.relationship(this.userId)
return !this.unmuted && ( return !this.unmuted && (
(!(this.inProfile && this.status.user.id === this.profileUserId) && relationship.muting) || (!(this.inProfile && this.status.user.id === this.profileUserId) && relationship.muting) ||
(!this.inConversation && this.status.thread_muted) || (!this.inConversation && this.status.thread_muted) ||

View file

@ -25,7 +25,7 @@ export default {
return this.$store.getters.findUser(this.userId) return this.$store.getters.findUser(this.userId)
}, },
relationship () { relationship () {
return this.$store.state.users.relationships[this.userId] || {} return this.$store.getters.relationship(this.userId)
}, },
classes () { classes () {
return [{ return [{

View file

@ -351,13 +351,13 @@ const UserSettings = {
}, },
filterUnblockedUsers (userIds) { filterUnblockedUsers (userIds) {
return reject(userIds, (userId) => { return reject(userIds, (userId) => {
const relationship = this.$store.state.users.relationships[userId] || {} const relationship = this.$store.getters.relationship(this.userId)
return relationship.blocking || userId === this.$store.state.users.currentUser.id return relationship.blocking || userId === this.$store.state.users.currentUser.id
}) })
}, },
filterUnMutedUsers (userIds) { filterUnMutedUsers (userIds) {
return reject(userIds, (userId) => { return reject(userIds, (userId) => {
const relationship = this.$store.state.users.relationships[userId] || {} const relationship = this.$store.getters.relationship(this.userId)
return relationship.muting || userId === this.$store.state.users.currentUser.id return relationship.muting || userId === this.$store.state.users.currentUser.id
}) })
}, },

View file

@ -48,6 +48,11 @@ const unblockUser = (store, id) => {
} }
const muteUser = (store, id) => { const muteUser = (store, id) => {
const predictedRelationship = store.state.relationships[id] || { id }
predictedRelationship.muting = true
store.commit('updateUserRelationship', [predictedRelationship])
store.commit('addMuteId', id)
return store.rootState.api.backendInteractor.muteUser({ id }) return store.rootState.api.backendInteractor.muteUser({ id })
.then((relationship) => { .then((relationship) => {
store.commit('updateUserRelationship', [relationship]) store.commit('updateUserRelationship', [relationship])
@ -56,6 +61,10 @@ const muteUser = (store, id) => {
} }
const unmuteUser = (store, id) => { const unmuteUser = (store, id) => {
const predictedRelationship = store.state.relationships[id] || { id }
predictedRelationship.muting = false
store.commit('updateUserRelationship', [predictedRelationship])
return store.rootState.api.backendInteractor.unmuteUser({ id }) return store.rootState.api.backendInteractor.unmuteUser({ id })
.then((relationship) => store.commit('updateUserRelationship', [relationship])) .then((relationship) => store.commit('updateUserRelationship', [relationship]))
} }
@ -227,6 +236,9 @@ export const getters = {
return state.usersObject[query.toLowerCase()] return state.usersObject[query.toLowerCase()]
} }
return result return result
},
relationship: state => id => {
return state.relationships[id] || { id, loading: true }
} }
} }

View file

@ -19,6 +19,7 @@ const actions = {
const testGetters = { const testGetters = {
findUser: state => getters.findUser(state.users), findUser: state => getters.findUser(state.users),
relationship: state => getters.relationship(state.users),
mergedConfig: state => ({ mergedConfig: state => ({
colors: '', colors: '',
highlight: {}, highlight: {},