Commit 6f12f94c authored by mgabdev's avatar mgabdev

Updated fetchRelationships for accounts and importing

• Updated:
- fetchRelationships for accounts and importing relationships on timeline fetches
parent 4ca59477
......@@ -577,7 +577,10 @@ export function fetchRelationships(accountIds) {
if (!me) return;
const loadedRelationships = getState().get('relationships');
const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
let newAccountIds = accountIds.filter((id) => {
if (id === me) return false
return loadedRelationships.get(id, null) === null
})
if (newAccountIds.length === 0) {
return;
......@@ -586,6 +589,9 @@ export function fetchRelationships(accountIds) {
if (me === firstId) return;
}
// Unique
newAccountIds = Array.from(new Set(newAccountIds))
dispatch(fetchRelationshipsRequest(newAccountIds));
api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
......
import { Map as ImmutableMap, List as ImmutableList, toJS } from 'immutable';
import { importFetchedStatus, importFetchedStatuses } from './importer';
import api, { getLinks } from '../api';
import { Map as ImmutableMap, List as ImmutableList, toJS } from 'immutable';
import { fetchRelationships } from './accounts'
export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
export const TIMELINE_DELETE = 'TIMELINE_DELETE';
......@@ -18,6 +19,13 @@ export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT';
export const MAX_QUEUED_ITEMS = 40;
const fetchStatusesAccountsRelationships = (dispatch, statuses) => {
const accountIds = statuses.map(item => item.account.id)
if (accountIds.length > 0) {
dispatch(fetchRelationships(accountIds));
}
}
export function updateTimeline(timeline, status, accept) {
return dispatch => {
if (typeof accept === 'function' && !accept(status)) {
......@@ -148,6 +156,7 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedStatuses(response.data));
dispatch(expandTimelineSuccess(timelineId, response.data, next ? next.uri : null, response.code === 206, isLoadingRecent, isLoadingMore));
fetchStatusesAccountsRelationships(dispatch, response.data)
done();
}).catch(error => {
dispatch(expandTimelineFail(timelineId, error, isLoadingMore));
......
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