Commit 858f3bc1 authored by Nastassia Danilova's avatar Nastassia Danilova

fetch users from every statuses lists which were received

parent a0bdf1bf
Pipeline #27882 passed with stages
in 7 minutes and 18 seconds
......@@ -6,10 +6,9 @@ import Users from '../reducers/users.js'
import Api from '../reducers/api.js'
import Conversations from '../thunks/conversations_thunks'
import { apiErrorCatcher, getConfig } from '../utils/api_utils'
import map from 'lodash/map'
import last from 'lodash/last'
import has from 'lodash/has'
import { getUsersFromStatusesList } from '../utils/users_utils.js'
const fetchTimeline = async ({ type, config, queries, fullUrl }) => {
if (fullUrl) {
......@@ -71,8 +70,7 @@ const statusesThunks = {
stopLoading(dispatch, timelineName, older)
await dispatch(Statuses.actions.addStatusesToTimeline({ statuses: result.data, timelineName }))
const users = map(result.data, 'account')
await dispatch(Users.actions.addUsers({ users }))
await dispatch(Users.actions.addUsers({ users: getUsersFromStatusesList(result.data) }))
if (result.links) {
const timeline = getState().api.timelines[timelineName] || {}
......
......@@ -4,6 +4,7 @@ import Users from '../reducers/users'
import Statuses from '../reducers/statuses'
import { apiErrorCatcher, getConfig } from '../utils/api_utils'
import { updateLinks, startLoading, stopLoading } from './api_thunks'
import { getUsersFromStatusesList } from '../utils/users_utils'
const usersThunks = {
fetchUser: ({ config, params }) => {
......@@ -35,6 +36,8 @@ const usersThunks = {
stopLoading({ dispatch, entity: 'userStatuses', older })
await dispatch(Users.actions.addUserStatuses({ userId: params.id, statuses: result.data }))
await dispatch(Statuses.actions.addStatuses({ statuses: result.data }))
await dispatch(Users.actions.addUsers({ users: getUsersFromStatusesList(result.data) }))
if (result.links) {
const statuses = getState().api.userStatuses
await updateLinks({ dispatch, statuses, entity: 'userStatuses', links: result.links, older })
......
import forEach from 'lodash/forEach'
export const getUsersFromStatusesList = (statuses) => {
const users = []
forEach(statuses, status => {
users.push(status.account)
if (status.reblog) {
users.push(status.reblog.account)
}
})
return users
}
......@@ -57,6 +57,53 @@ describe('Users thunks', () => {
.toEqual({ 1: expectedResult })
})
it(`fetch user's statuses`, async () => {
const store = { state: undefined }
const dispatch = (action) => {
store.state = reducer(store.state, action)
}
const getState = () => store.state
const user = {
id: '1',
username: 'username'
}
const account2 = {
id: '2',
username: 'username1'
}
const statuses = [
{ id: 1, content: 'second status', spoiler_text: '', account: user, reblog: { account: account2 } },
{ id: 0, content: 'test status', spoiler_text: '', account: user },
]
fetch.mockReset()
fetch
.mockImplementationOnce(fetchMocker(
statuses,
{ expectedUrl: `https://pleroma.soykaf.com/api/v1/accounts/1/statuses` }
))
let state = await usersThunks.fetchUserStatuses({ config, params: { id: '1' } })(dispatch, getState)
const expectedResult = {
'1': {
id: '1',
username: 'username',
display_name: "",
note: undefined,
statuses
},
'2': {
id: '2',
username: 'username1',
display_name: "",
note: undefined,
}
}
expect(state.users.usersByIds)
.toEqual(expectedResult)
})
it('follow user', async () => {
const store = { state: {
users: {
......
import * as UsersUtils from '../../src/utils/users_utils'
describe('users utils', () => {
describe('get users from statuses list', () => {
it('should add ids and reverse sort them', () => {
const statuses = [
{ id: 0, account: { id: 0 } },
{ id: 1, account: { id: 1 }, reblog: { account: { id: 2} } }
]
const expected = [{ id: 0 }, { id: 1 }, { id: 2 }]
expect(UsersUtils.getUsersFromStatusesList(statuses)).toEqual(expected)
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment