From 576ad9750be4a76df7f7cc4d7062aa4546d7f61f Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 22 Apr 2020 00:07:01 +0300 Subject: make tests not fail --- test/unit/specs/components/user_profile.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 1b6a47d7..0a3f2d27 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -96,7 +96,8 @@ const externalProfileStore = new Vuex.Store({ credentials: '' }, usersObject: { 100: extUser }, - users: [extUser] + users: [extUser], + relationships: {} } } }) @@ -164,7 +165,8 @@ const localProfileStore = new Vuex.Store({ credentials: '' }, usersObject: { 100: localUser, 'testuser': localUser }, - users: [localUser] + users: [localUser], + relationships: {} } } }) -- cgit v1.2.3-70-g09d2 From cda298c8223851d50edcd2761391d4ddb8932ed1 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 23 Apr 2020 11:17:52 +0300 Subject: remove unused mutation and test for it --- src/modules/users.js | 4 ---- .../entity_normalizer/entity_normalizer.service.js | 9 --------- test/unit/specs/modules/users.spec.js | 14 -------------- 3 files changed, 27 deletions(-) (limited to 'test') diff --git a/src/modules/users.js b/src/modules/users.js index 591d4634..6b19fc97 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -83,10 +83,6 @@ const unmuteDomain = (store, domain) => { } export const mutations = { - setMuted (state, { user: { id }, muted }) { - const user = state.usersObject[id] - set(user, 'muted', muted) - }, tagUser (state, { user: { id }, tag }) { const user = state.usersObject[id] const tags = user.tags || [] diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 66a7a8b7..7237fdfc 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -73,15 +73,6 @@ export const parseUser = (data) => { output.background_image = data.pleroma.background_image output.token = data.pleroma.chat_token - if (relationship && !relationship) { - output.follows_you = relationship.followed_by - output.requested = relationship.requested - output.following = relationship.following - output.statusnet_blocking = relationship.blocking - output.muted = relationship.muting - output.showing_reblogs = relationship.showing_reblogs - output.subscribed = relationship.subscribing - } if (relationship) { output.relationship = relationship } diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index eeb7afef..670acfc8 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -18,20 +18,6 @@ describe('The users module', () => { expect(state.users).to.eql([user]) expect(state.users[0].name).to.eql('Dude') }) - - it('sets a mute bit on users', () => { - const state = cloneDeep(defaultState) - const user = { id: '1', name: 'Guy' } - - mutations.addNewUsers(state, [user]) - mutations.setMuted(state, { user, muted: true }) - - expect(user.muted).to.eql(true) - - mutations.setMuted(state, { user, muted: false }) - - expect(user.muted).to.eql(false) - }) }) describe('findUser', () => { -- cgit v1.2.3-70-g09d2 From af9492977aaa10903d54add3187b5cf9d9a00d6c Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 24 Apr 2020 18:53:17 +0300 Subject: 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(-) (limited to 'test') 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: {}, -- cgit v1.2.3-70-g09d2