]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/actions/timelines.js
1 import api
, { getLinks
} from '../api';
2 import Immutable
from 'immutable';
4 export const TIMELINE_UPDATE
= 'TIMELINE_UPDATE';
5 export const TIMELINE_DELETE
= 'TIMELINE_DELETE';
7 export const TIMELINE_REFRESH_REQUEST
= 'TIMELINE_REFRESH_REQUEST';
8 export const TIMELINE_REFRESH_SUCCESS
= 'TIMELINE_REFRESH_SUCCESS';
9 export const TIMELINE_REFRESH_FAIL
= 'TIMELINE_REFRESH_FAIL';
11 export const TIMELINE_EXPAND_REQUEST
= 'TIMELINE_EXPAND_REQUEST';
12 export const TIMELINE_EXPAND_SUCCESS
= 'TIMELINE_EXPAND_SUCCESS';
13 export const TIMELINE_EXPAND_FAIL
= 'TIMELINE_EXPAND_FAIL';
15 export const TIMELINE_SCROLL_TOP
= 'TIMELINE_SCROLL_TOP';
17 export const TIMELINE_CONNECT
= 'TIMELINE_CONNECT';
18 export const TIMELINE_DISCONNECT
= 'TIMELINE_DISCONNECT';
20 export function refreshTimelineSuccess(timeline
, statuses
, skipLoading
, next
) {
22 type: TIMELINE_REFRESH_SUCCESS
,
30 export function updateTimeline(timeline
, status
) {
31 return (dispatch
, getState
) => {
32 const references
= status
.reblog
? getState().get('statuses').filter((item
, itemId
) => (itemId
=== status
.reblog
.id
|| item
.get('reblog') === status
.reblog
.id
)).map((_
, itemId
) => itemId
) : [];
35 type: TIMELINE_UPDATE
,
43 export function deleteFromTimelines(id
) {
44 return (dispatch
, getState
) => {
45 const accountId
= getState().getIn(['statuses', id
, 'account']);
46 const references
= getState().get('statuses').filter(status
=> status
.get('reblog') === id
).map(status
=> [status
.get('id'), status
.get('account')]);
47 const reblogOf
= getState().getIn(['statuses', id
, 'reblog'], null);
50 type: TIMELINE_DELETE
,
59 export function refreshTimelineRequest(timeline
, id
, skipLoading
) {
61 type: TIMELINE_REFRESH_REQUEST
,
68 export function refreshTimeline(timeline
, id
= null) {
69 return function (dispatch
, getState
) {
70 if (getState().getIn(['timelines', timeline
, 'isLoading'])) {
74 const ids
= getState().getIn(['timelines', timeline
, 'items'], Immutable
.List());
75 const newestId
= ids
.size
> 0 ? ids
.first() : null;
76 let params
= getState().getIn(['timelines', timeline
, 'params'], {});
77 const path
= getState().getIn(['timelines', timeline
, 'path'])(id
);
79 let skipLoading
= false;
81 if (newestId
!== null && getState().getIn(['timelines', timeline
, 'loaded']) && (id
=== null || getState().getIn(['timelines', timeline
, 'id']) === id
)) {
82 if (id
=== null && getState().getIn(['timelines', timeline
, 'online'])) {
83 // Skip refreshing when timeline is live anyway
87 params
= { ...params
, since_id: newestId
};
89 } else if (getState().getIn(['timelines', timeline
, 'loaded'])) {
93 dispatch(refreshTimelineRequest(timeline
, id
, skipLoading
));
95 api(getState
).get(path
, { params
}).then(response
=> {
96 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
97 dispatch(refreshTimelineSuccess(timeline
, response
.data
, skipLoading
, next
? next
.uri : null));
99 dispatch(refreshTimelineFail(timeline
, error
, skipLoading
));
104 export function refreshTimelineFail(timeline
, error
, skipLoading
) {
106 type: TIMELINE_REFRESH_FAIL
,
113 export function expandTimeline(timeline
) {
114 return (dispatch
, getState
) => {
115 if (getState().getIn(['timelines', timeline
, 'isLoading'])) {
119 if (getState().getIn(['timelines', timeline
, 'items']).size
=== 0) {
123 const path
= getState().getIn(['timelines', timeline
, 'path'])(getState().getIn(['timelines', timeline
, 'id']));
124 const params
= getState().getIn(['timelines', timeline
, 'params'], {});
125 const lastId
= getState().getIn(['timelines', timeline
, 'items']).last();
127 dispatch(expandTimelineRequest(timeline
));
129 api(getState
).get(path
, {
135 }).then(response
=> {
136 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
137 dispatch(expandTimelineSuccess(timeline
, response
.data
, next
? next
.uri : null));
139 dispatch(expandTimelineFail(timeline
, error
));
144 export function expandTimelineRequest(timeline
) {
146 type: TIMELINE_EXPAND_REQUEST
,
151 export function expandTimelineSuccess(timeline
, statuses
, next
) {
153 type: TIMELINE_EXPAND_SUCCESS
,
160 export function expandTimelineFail(timeline
, error
) {
162 type: TIMELINE_EXPAND_FAIL
,
168 export function scrollTopTimeline(timeline
, top
) {
170 type: TIMELINE_SCROLL_TOP
,
176 export function connectTimeline(timeline
) {
178 type: TIMELINE_CONNECT
,
183 export function disconnectTimeline(timeline
) {
185 type: TIMELINE_DISCONNECT
,
This page took 0.10154 seconds and 5 git commands to generate.