// into the columns
const insertIfOnline = timelineId => {
- if (getState().getIn(['timelines', timelineId, 'items', 0]) !== null) {
+ const timeline = getState().getIn(['timelines', timelineId]);
+
+ if (timeline && timeline.get('items').size > 0 && timeline.getIn(['items', 0]) !== null && timeline.get('online')) {
dispatch(updateTimeline(timelineId, { ...response.data }));
}
};
updateTimeline,
deleteFromTimelines,
expandHomeTimeline,
+ connectTimeline,
disconnectTimeline,
} from './timelines';
import { updateNotifications, expandNotifications } from './notifications';
return connectStream (path, pollingRefresh, (dispatch, getState) => {
const locale = getState().getIn(['meta', 'locale']);
+
return {
+ onConnect() {
+ dispatch(connectTimeline(timelineId));
+ },
+
onDisconnect() {
dispatch(disconnectTimeline(timelineId));
},
export const TIMELINE_SCROLL_TOP = 'TIMELINE_SCROLL_TOP';
+export const TIMELINE_CONNECT = 'TIMELINE_CONNECT';
export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT';
export function updateTimeline(timeline, status, accept) {
};
};
+export function connectTimeline(timeline) {
+ return {
+ type: TIMELINE_CONNECT,
+ timeline,
+ };
+};
+
export function disconnectTimeline(timeline) {
return {
type: TIMELINE_DISCONNECT,
TIMELINE_EXPAND_REQUEST,
TIMELINE_EXPAND_FAIL,
TIMELINE_SCROLL_TOP,
+ TIMELINE_CONNECT,
TIMELINE_DISCONNECT,
} from '../actions/timelines';
import {
const initialTimeline = ImmutableMap({
unread: 0,
+ online: false,
top: true,
isLoading: false,
hasMore: true,
return filterTimeline('home', state, action.relationship, action.statuses);
case TIMELINE_SCROLL_TOP:
return updateTop(state, action.timeline, action.top);
+ case TIMELINE_CONNECT:
+ return state.update(action.timeline, initialTimeline, map => map.set('online', true));
case TIMELINE_DISCONNECT:
return state.update(
action.timeline,
initialTimeline,
- map => map.update(
- 'items',
- items => items.first() ? items.unshift(null) : items
- )
+ map => map.set('online', false).update('items', items => items.first() ? items.unshift(null) : items)
);
default:
return state;
const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max));
-export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onDisconnect() {}, onReceive() {} })) {
+export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) {
return (dispatch, getState) => {
const streamingAPIBaseURL = getState().getIn(['meta', 'streaming_api_base_url']);
const accessToken = getState().getIn(['meta', 'access_token']);
- const { onDisconnect, onReceive } = callbacks(dispatch, getState);
+ const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState);
let polling = null;
if (pollingRefresh) {
clearPolling();
}
+
+ onConnect();
},
disconnected () {
clearPolling();
pollingRefresh(dispatch);
}
+
+ onConnect();
},
});