Skip to content

Commit b285817

Browse files
authored
Fix public timelines being broken by new toots when they are not mounted (mastodon#10131)
1 parent 9f079c2 commit b285817

5 files changed

Lines changed: 28 additions & 7 deletions

File tree

app/javascript/mastodon/actions/compose.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ export function submitCompose(routerHistory) {
158158
// into the columns
159159

160160
const insertIfOnline = timelineId => {
161-
if (getState().getIn(['timelines', timelineId, 'items', 0]) !== null) {
161+
const timeline = getState().getIn(['timelines', timelineId]);
162+
163+
if (timeline && timeline.get('items').size > 0 && timeline.getIn(['items', 0]) !== null && timeline.get('online')) {
162164
dispatch(updateTimeline(timelineId, { ...response.data }));
163165
}
164166
};

app/javascript/mastodon/actions/streaming.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
updateTimeline,
44
deleteFromTimelines,
55
expandHomeTimeline,
6+
connectTimeline,
67
disconnectTimeline,
78
} from './timelines';
89
import { updateNotifications, expandNotifications } from './notifications';
@@ -16,7 +17,12 @@ export function connectTimelineStream (timelineId, path, pollingRefresh = null,
1617

1718
return connectStream (path, pollingRefresh, (dispatch, getState) => {
1819
const locale = getState().getIn(['meta', 'locale']);
20+
1921
return {
22+
onConnect() {
23+
dispatch(connectTimeline(timelineId));
24+
},
25+
2026
onDisconnect() {
2127
dispatch(disconnectTimeline(timelineId));
2228
},

app/javascript/mastodon/actions/timelines.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const TIMELINE_EXPAND_FAIL = 'TIMELINE_EXPAND_FAIL';
1212

1313
export const TIMELINE_SCROLL_TOP = 'TIMELINE_SCROLL_TOP';
1414

15+
export const TIMELINE_CONNECT = 'TIMELINE_CONNECT';
1516
export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT';
1617

1718
export function updateTimeline(timeline, status, accept) {
@@ -143,6 +144,13 @@ export function scrollTopTimeline(timeline, top) {
143144
};
144145
};
145146

147+
export function connectTimeline(timeline) {
148+
return {
149+
type: TIMELINE_CONNECT,
150+
timeline,
151+
};
152+
};
153+
146154
export function disconnectTimeline(timeline) {
147155
return {
148156
type: TIMELINE_DISCONNECT,

app/javascript/mastodon/reducers/timelines.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TIMELINE_EXPAND_REQUEST,
77
TIMELINE_EXPAND_FAIL,
88
TIMELINE_SCROLL_TOP,
9+
TIMELINE_CONNECT,
910
TIMELINE_DISCONNECT,
1011
} from '../actions/timelines';
1112
import {
@@ -20,6 +21,7 @@ const initialState = ImmutableMap();
2021

2122
const initialTimeline = ImmutableMap({
2223
unread: 0,
24+
online: false,
2325
top: true,
2426
isLoading: false,
2527
hasMore: true,
@@ -142,14 +144,13 @@ export default function timelines(state = initialState, action) {
142144
return filterTimeline('home', state, action.relationship, action.statuses);
143145
case TIMELINE_SCROLL_TOP:
144146
return updateTop(state, action.timeline, action.top);
147+
case TIMELINE_CONNECT:
148+
return state.update(action.timeline, initialTimeline, map => map.set('online', true));
145149
case TIMELINE_DISCONNECT:
146150
return state.update(
147151
action.timeline,
148152
initialTimeline,
149-
map => map.update(
150-
'items',
151-
items => items.first() ? items.unshift(null) : items
152-
)
153+
map => map.set('online', false).update('items', items => items.first() ? items.unshift(null) : items)
153154
);
154155
default:
155156
return state;

app/javascript/mastodon/stream.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import WebSocketClient from 'websocket.js';
22

33
const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max));
44

5-
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onDisconnect() {}, onReceive() {} })) {
5+
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) {
66
return (dispatch, getState) => {
77
const streamingAPIBaseURL = getState().getIn(['meta', 'streaming_api_base_url']);
88
const accessToken = getState().getIn(['meta', 'access_token']);
9-
const { onDisconnect, onReceive } = callbacks(dispatch, getState);
9+
const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState);
1010

1111
let polling = null;
1212

@@ -28,6 +28,8 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
2828
if (pollingRefresh) {
2929
clearPolling();
3030
}
31+
32+
onConnect();
3133
},
3234

3335
disconnected () {
@@ -47,6 +49,8 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
4749
clearPolling();
4850
pollingRefresh(dispatch);
4951
}
52+
53+
onConnect();
5054
},
5155

5256
});

0 commit comments

Comments
 (0)