Merge branch 'fix/profile-with-no-statuses-not-loading' into 'develop'

Fix profiles without statuses not loading

See merge request pleroma/pleroma-fe!445
This commit is contained in:
HJ 2018-12-31 01:57:22 +00:00
commit 7aa42c01eb
4 changed files with 100 additions and 126 deletions

View file

@ -6,7 +6,7 @@ const UserProfile = {
created () { created () {
this.$store.commit('clearTimeline', { timeline: 'user' }) this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.dispatch('startFetching', ['user', this.fetchBy]) this.$store.dispatch('startFetching', ['user', this.fetchBy])
if (!this.user) { if (!this.user.id) {
this.$store.dispatch('fetchUser', this.fetchBy) this.$store.dispatch('fetchUser', this.fetchBy)
} }
}, },
@ -29,14 +29,20 @@ const UserProfile = {
followers () { followers () {
return this.user.followers return this.user.followers
}, },
userInStore () {
if (this.isExternal) {
return this.$store.getters.userById(this.userId)
}
return this.$store.getters.userByName(this.userName)
},
user () { user () {
if (this.timeline.statuses[0]) { if (this.timeline.statuses[0]) {
return this.timeline.statuses[0].user return this.timeline.statuses[0].user
} else {
return Object.values(this.$store.state.users.usersObject).filter(user => {
return (this.isExternal ? user.id === this.userId : user.screen_name === this.userName)
})[0] || {}
} }
if (this.userInStore) {
return this.userInStore
}
return {}
}, },
fetchBy () { fetchBy () {
return this.isExternal ? this.userId : this.userName return this.isExternal ? this.userId : this.userName

View file

@ -86,6 +86,13 @@ export const mutations = {
} }
} }
export const getters = {
userById: state => id =>
state.users.find(user => user.id === id),
userByName: state => name =>
state.users.find(user => user.screen_name === name)
}
export const defaultState = { export const defaultState = {
loggingIn: false, loggingIn: false,
lastLoginName: false, lastLoginName: false,
@ -99,6 +106,7 @@ export const defaultState = {
const users = { const users = {
state: defaultState, state: defaultState,
mutations, mutations,
getters,
actions: { actions: {
fetchUser (store, id) { fetchUser (store, id) {
store.rootState.api.backendInteractor.fetchUser({ id }) store.rootState.api.backendInteractor.fetchUser({ id })

View file

@ -2,6 +2,7 @@ import { mount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import UserProfile from 'src/components/user_profile/user_profile.vue' import UserProfile from 'src/components/user_profile/user_profile.vue'
import backendInteractorService from 'src/services/backend_interactor_service/backend_interactor_service.js' import backendInteractorService from 'src/services/backend_interactor_service/backend_interactor_service.js'
import { getters } from 'src/modules/users.js'
const localVue = createLocalVue() const localVue = createLocalVue()
localVue.use(Vuex) localVue.use(Vuex)
@ -10,8 +11,26 @@ const mutations = {
clearTimeline: () => {} clearTimeline: () => {}
} }
const testGetters = {
userByName: state => getters.userByName(state.users),
userById: state => getters.userById(state.users)
}
const localUser = {
id: 100,
is_local: true,
screen_name: 'testUser'
}
const extUser = {
id: 100,
is_local: false,
screen_name: 'testUser@test.instance'
}
const externalProfileStore = new Vuex.Store({ const externalProfileStore = new Vuex.Store({
mutations, mutations,
getters: testGetters,
state: { state: {
api: { api: {
backendInteractor: backendInteractorService('') backendInteractor: backendInteractorService('')
@ -44,7 +63,7 @@ const externalProfileStore = new Vuex.Store({
followers: [], followers: [],
friends: [], friends: [],
viewing: 'statuses', viewing: 'statuses',
userId: 701, userId: 100,
flushMarker: 0 flushMarker: 0
} }
} }
@ -53,58 +72,15 @@ const externalProfileStore = new Vuex.Store({
currentUser: { currentUser: {
credentials: '' credentials: ''
}, },
usersObject: [ usersObject: [extUser],
{ users: [extUser]
background_image: null,
cover_photo: 'https://playvicious.social/system/accounts/headers/000/000/001/original/7dae4fc0e8330e83.jpg?1507329206',
created_at: 'Mon Dec 18 16:01:35 +0000 2017',
default_scope: 'public',
description: "Your favorite person's favorite person.",
description_html: "<p>Your favorite person's favorite person.</p>",
favourites_count: 0,
fields: [
{
name: '✌🏾',
value: '<a href="https://thetwelfth.house" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">thetwelfth.house</span><span class="invisible"></span></a>'
},
{
name: '🚧',
value: '<a href="https://code.playvicio.us" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">code.playvicio.us</span><span class="invisible"></span></a>'
},
{
name: '❤️',
value: '<a href="https://www.patreon.com/Are0h" rel="me nofollow noopener" target="_blank"><span class="invisible">https://www.</span><span class="">patreon.com/Are0h</span><span class="invisible"></span></a>'
}
],
followers_count: 2,
following: false,
follows_you: false,
friends_count: 0,
id: 701,
is_local: false,
locked: false,
name: 'Are0h',
name_html: 'Are0h',
no_rich_text: false,
profile_image_url: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
profile_image_url_https: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
profile_image_url_original: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
profile_image_url_profile_size: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
rights: {
delete_others_notice: false
},
screen_name: 'Are0h@playvicious.social',
statuses_count: 6727,
statusnet_blocking: false,
statusnet_profile_url: 'https://playvicious.social/users/Are0h'
}
]
} }
} }
}) })
const localProfileStore = new Vuex.Store({ const localProfileStore = new Vuex.Store({
mutations, mutations,
getters: testGetters,
state: { state: {
api: { api: {
backendInteractor: backendInteractorService('') backendInteractor: backendInteractorService('')
@ -137,7 +113,7 @@ const localProfileStore = new Vuex.Store({
followers: [], followers: [],
friends: [], friends: [],
viewing: 'statuses', viewing: 'statuses',
userId: 701, userId: 100,
flushMarker: 0 flushMarker: 0
} }
} }
@ -146,52 +122,8 @@ const localProfileStore = new Vuex.Store({
currentUser: { currentUser: {
credentials: '' credentials: ''
}, },
usersObject: [ usersObject: [localUser],
{ users: [localUser]
background_image: null,
cover_photo: 'https://playvicious.social/system/accounts/headers/000/000/001/original/7dae4fc0e8330e83.jpg?1507329206',
created_at: 'Mon Dec 18 16:01:35 +0000 2017',
default_scope: 'public',
description: "Your favorite person's favorite person.",
description_html: "<p>Your favorite person's favorite person.</p>",
favourites_count: 0,
fields: [
{
name: '✌🏾',
value: '<a href="https://thetwelfth.house" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">thetwelfth.house</span><span class="invisible"></span></a>'
},
{
name: '🚧',
value: '<a href="https://code.playvicio.us" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">code.playvicio.us</span><span class="invisible"></span></a>'
},
{
name: '❤️',
value: '<a href="https://www.patreon.com/Are0h" rel="me nofollow noopener" target="_blank"><span class="invisible">https://www.</span><span class="">patreon.com/Are0h</span><span class="invisible"></span></a>'
}
],
followers_count: 2,
following: false,
follows_you: false,
friends_count: 0,
id: 701,
is_local: false,
locked: false,
name: 'Are0h',
name_html: 'Are0h',
no_rich_text: false,
profile_image_url: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
profile_image_url_https: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
profile_image_url_original: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
profile_image_url_profile_size: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
rights: {
delete_others_notice: false
},
screen_name: 'Are0h',
statuses_count: 6727,
statusnet_blocking: false,
statusnet_profile_url: 'https://playvicious.social/users/Are0h'
}
]
} }
} }
}) })
@ -203,14 +135,14 @@ describe('UserProfile', () => {
store: externalProfileStore, store: externalProfileStore,
mocks: { mocks: {
$route: { $route: {
params: { id: 701 }, params: { id: 100 },
name: 'external-user-profile' name: 'external-user-profile'
}, },
$t: (msg) => msg $t: (msg) => msg
} }
}) })
expect(wrapper.find('.user-screen-name').text()).to.eql('@Are0h@playvicious.social') expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser@test.instance')
}) })
it('renders local profile', () => { it('renders local profile', () => {
@ -219,13 +151,13 @@ describe('UserProfile', () => {
store: localProfileStore, store: localProfileStore,
mocks: { mocks: {
$route: { $route: {
params: { name: 'Are0h' }, params: { name: 'testUser' },
name: 'user-profile' name: 'user-profile'
}, },
$t: (msg) => msg $t: (msg) => msg
} }
}) })
expect(wrapper.find('.user-screen-name').text()).to.eql('@Are0h') expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser')
}) })
}) })

View file

@ -1,8 +1,9 @@
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { defaultState, mutations } from '../../../../src/modules/users.js' import { defaultState, mutations, getters } from '../../../../src/modules/users.js'
describe('The users module', () => { describe('The users module', () => {
describe('mutations', () => {
it('adds new users to the set, merging in new information for old users', () => { it('adds new users to the set, merging in new information for old users', () => {
const state = cloneDeep(defaultState) const state = cloneDeep(defaultState)
const user = { id: 1, name: 'Guy' } const user = { id: 1, name: 'Guy' }
@ -32,3 +33,30 @@ describe('The users module', () => {
expect(user.muted).to.eql(false) expect(user.muted).to.eql(false)
}) })
}) })
describe('getUserByName', () => {
it('returns user with matching screen_name', () => {
const state = {
users: [
{ screen_name: 'Guy', id: 1 }
]
}
const name = 'Guy'
const expected = { screen_name: 'Guy', id: 1 }
expect(getters.userByName(state)(name)).to.eql(expected)
})
})
describe('getUserById', () => {
it('returns user with matching id', () => {
const state = {
users: [
{ screen_name: 'Guy', id: 1 }
]
}
const id = 1
const expected = { screen_name: 'Guy', id: 1 }
expect(getters.userById(state)(id)).to.eql(expected)
})
})
})