From af9492977aaa10903d54add3187b5cf9d9a00d6c Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 24 Apr 2020 18:53:17 +0300 Subject: [PATCH] add back mute prediction, add getter for relationships --- src/components/block_card/block_card.js | 2 +- src/components/follow_card/follow_card.js | 2 +- src/components/mute_card/mute_card.js | 2 +- src/components/notification/notification.js | 2 +- src/components/status/status.js | 2 +- src/components/user_card/user_card.js | 2 +- src/components/user_settings/user_settings.js | 4 ++-- src/modules/users.js | 12 ++++++++++++ test/unit/specs/components/user_profile.spec.js | 1 + 9 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/components/block_card/block_card.js b/src/components/block_card/block_card.js index 659c75d8..0bf4e37b 100644 --- a/src/components/block_card/block_card.js +++ b/src/components/block_card/block_card.js @@ -12,7 +12,7 @@ const BlockCard = { return this.$store.getters.findUser(this.userId) }, relationship () { - return this.$store.state.users.relationships[this.userId] || {} + return this.$store.getters.relationship(this.userId) }, blocked () { return this.relationship.blocking diff --git a/src/components/follow_card/follow_card.js b/src/components/follow_card/follow_card.js index 620ae7fd..6dcb6d47 100644 --- a/src/components/follow_card/follow_card.js +++ b/src/components/follow_card/follow_card.js @@ -20,7 +20,7 @@ const FollowCard = { return this.$store.state.users.currentUser }, relationship () { - return this.$store.state.users.relationships[this.user.id] + return this.$store.getters.relationship(this.user.id) } } } diff --git a/src/components/mute_card/mute_card.js b/src/components/mute_card/mute_card.js index be528d37..cbec0e9b 100644 --- a/src/components/mute_card/mute_card.js +++ b/src/components/mute_card/mute_card.js @@ -12,7 +12,7 @@ const MuteCard = { return this.$store.getters.findUser(this.userId) }, relationship () { - return this.$store.state.users.relationships[this.userId] + return this.$store.getters.relationship(this.userId) }, muted () { return this.relationship.muting diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 09554f54..ff1c2817 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -56,7 +56,7 @@ const Notification = { return this.generateUserProfileLink(this.targetUser) }, needMute () { - return (this.$store.state.users.relationships[this.user.id] || {}).muting + return this.$store.getters.relationship(this.user.id).muting } } } diff --git a/src/components/status/status.js b/src/components/status/status.js index a73e3ae2..a36de028 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -119,7 +119,7 @@ const Status = { return hits }, muted () { - const relationship = this.$store.state.users.relationships[this.status.user.id] || {} + const relationship = this.$store.getters.relationship(this.userId) return !this.unmuted && ( (!(this.inProfile && this.status.user.id === this.profileUserId) && relationship.muting) || (!this.inConversation && this.status.thread_muted) || diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index fb3cfebc..8e6b9d7f 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -25,7 +25,7 @@ export default { return this.$store.getters.findUser(this.userId) }, relationship () { - return this.$store.state.users.relationships[this.userId] || {} + return this.$store.getters.relationship(this.userId) }, classes () { return [{ diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index adfab8fa..5338c974 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -351,13 +351,13 @@ const UserSettings = { }, filterUnblockedUsers (userIds) { 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 }) }, filterUnMutedUsers (userIds) { 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 }) }, diff --git a/src/modules/users.js b/src/modules/users.js index 6b19fc97..fb04ebd3 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -48,6 +48,11 @@ const unblockUser = (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 }) .then((relationship) => { store.commit('updateUserRelationship', [relationship]) @@ -56,6 +61,10 @@ const muteUser = (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 }) .then((relationship) => store.commit('updateUserRelationship', [relationship])) } @@ -227,6 +236,9 @@ export const getters = { return state.usersObject[query.toLowerCase()] } return result + }, + relationship: state => id => { + return state.relationships[id] || { id, loading: true } } } diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 0a3f2d27..dcf066f9 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -19,6 +19,7 @@ const actions = { const testGetters = { findUser: state => getters.findUser(state.users), + relationship: state => getters.relationship(state.users), mergedConfig: state => ({ colors: '', highlight: {},