Skip to content

Commit

Permalink
Fix public timelines being broken by new toots when they are not moun…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Mar 7, 2019
1 parent 9f079c2 commit b285817
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/javascript/mastodon/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export function submitCompose(routerHistory) {
// 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 }));
}
};
Expand Down
6 changes: 6 additions & 0 deletions app/javascript/mastodon/actions/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
updateTimeline,
deleteFromTimelines,
expandHomeTimeline,
connectTimeline,
disconnectTimeline,
} from './timelines';
import { updateNotifications, expandNotifications } from './notifications';
Expand All @@ -16,7 +17,12 @@ export function connectTimelineStream (timelineId, path, pollingRefresh = null,

return connectStream (path, pollingRefresh, (dispatch, getState) => {
const locale = getState().getIn(['meta', 'locale']);

return {
onConnect() {
dispatch(connectTimeline(timelineId));
},

onDisconnect() {
dispatch(disconnectTimeline(timelineId));
},
Expand Down
8 changes: 8 additions & 0 deletions app/javascript/mastodon/actions/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const TIMELINE_EXPAND_FAIL = 'TIMELINE_EXPAND_FAIL';

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) {
Expand Down Expand Up @@ -143,6 +144,13 @@ export function scrollTopTimeline(timeline, top) {
};
};

export function connectTimeline(timeline) {
return {
type: TIMELINE_CONNECT,
timeline,
};
};

export function disconnectTimeline(timeline) {
return {
type: TIMELINE_DISCONNECT,
Expand Down
9 changes: 5 additions & 4 deletions app/javascript/mastodon/reducers/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TIMELINE_EXPAND_REQUEST,
TIMELINE_EXPAND_FAIL,
TIMELINE_SCROLL_TOP,
TIMELINE_CONNECT,
TIMELINE_DISCONNECT,
} from '../actions/timelines';
import {
Expand All @@ -20,6 +21,7 @@ const initialState = ImmutableMap();

const initialTimeline = ImmutableMap({
unread: 0,
online: false,
top: true,
isLoading: false,
hasMore: true,
Expand Down Expand Up @@ -142,14 +144,13 @@ export default function timelines(state = initialState, action) {
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;
Expand Down
8 changes: 6 additions & 2 deletions app/javascript/mastodon/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import WebSocketClient from 'websocket.js';

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;

Expand All @@ -28,6 +28,8 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
if (pollingRefresh) {
clearPolling();
}

onConnect();
},

disconnected () {
Expand All @@ -47,6 +49,8 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
clearPolling();
pollingRefresh(dispatch);
}

onConnect();
},

});
Expand Down

0 comments on commit b285817

Please sign in to comment.