Fix trying to connect to streaming API when logged out in web UI (#19316)

main
Eugen Rochko 2022-10-08 07:15:50 +02:00 committed by GitHub
parent d84c53e769
commit d4b0aa7450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 6 deletions

View File

@ -35,6 +35,7 @@ class CommunityTimeline extends React.PureComponent {
static contextTypes = { static contextTypes = {
router: PropTypes.object, router: PropTypes.object,
identity: PropTypes.object,
}; };
static defaultProps = { static defaultProps = {
@ -71,20 +72,32 @@ class CommunityTimeline extends React.PureComponent {
componentDidMount () { componentDidMount () {
const { dispatch, onlyMedia } = this.props; const { dispatch, onlyMedia } = this.props;
const { signedIn } = this.context.identity;
dispatch(expandCommunityTimeline({ onlyMedia })); dispatch(expandCommunityTimeline({ onlyMedia }));
if (signedIn) {
this.disconnect = dispatch(connectCommunityStream({ onlyMedia })); this.disconnect = dispatch(connectCommunityStream({ onlyMedia }));
} }
}
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
const { signedIn } = this.context.identity;
if (prevProps.onlyMedia !== this.props.onlyMedia) { if (prevProps.onlyMedia !== this.props.onlyMedia) {
const { dispatch, onlyMedia } = this.props; const { dispatch, onlyMedia } = this.props;
if (this.disconnect) {
this.disconnect(); this.disconnect();
}
dispatch(expandCommunityTimeline({ onlyMedia })); dispatch(expandCommunityTimeline({ onlyMedia }));
if (signedIn) {
this.disconnect = dispatch(connectCommunityStream({ onlyMedia })); this.disconnect = dispatch(connectCommunityStream({ onlyMedia }));
} }
} }
}
componentWillUnmount () { componentWillUnmount () {
if (this.disconnect) { if (this.disconnect) {

View File

@ -96,6 +96,12 @@ class HashtagTimeline extends React.PureComponent {
} }
_subscribe (dispatch, id, tags = {}, local) { _subscribe (dispatch, id, tags = {}, local) {
const { signedIn } = this.context.identity;
if (!signedIn) {
return;
}
let any = (tags.any || []).map(tag => tag.value); let any = (tags.any || []).map(tag => tag.value);
let all = (tags.all || []).map(tag => tag.value); let all = (tags.all || []).map(tag => tag.value);
let none = (tags.none || []).map(tag => tag.value); let none = (tags.none || []).map(tag => tag.value);

View File

@ -37,6 +37,7 @@ class PublicTimeline extends React.PureComponent {
static contextTypes = { static contextTypes = {
router: PropTypes.object, router: PropTypes.object,
identity: PropTypes.object,
}; };
static defaultProps = { static defaultProps = {
@ -74,20 +75,32 @@ class PublicTimeline extends React.PureComponent {
componentDidMount () { componentDidMount () {
const { dispatch, onlyMedia, onlyRemote } = this.props; const { dispatch, onlyMedia, onlyRemote } = this.props;
const { signedIn } = this.context.identity;
dispatch(expandPublicTimeline({ onlyMedia, onlyRemote })); dispatch(expandPublicTimeline({ onlyMedia, onlyRemote }));
if (signedIn) {
this.disconnect = dispatch(connectPublicStream({ onlyMedia, onlyRemote })); this.disconnect = dispatch(connectPublicStream({ onlyMedia, onlyRemote }));
} }
}
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
const { signedIn } = this.context.identity;
if (prevProps.onlyMedia !== this.props.onlyMedia || prevProps.onlyRemote !== this.props.onlyRemote) { if (prevProps.onlyMedia !== this.props.onlyMedia || prevProps.onlyRemote !== this.props.onlyRemote) {
const { dispatch, onlyMedia, onlyRemote } = this.props; const { dispatch, onlyMedia, onlyRemote } = this.props;
if (this.disconnect) {
this.disconnect(); this.disconnect();
}
dispatch(expandPublicTimeline({ onlyMedia, onlyRemote })); dispatch(expandPublicTimeline({ onlyMedia, onlyRemote }));
if (signedIn) {
this.disconnect = dispatch(connectPublicStream({ onlyMedia, onlyRemote })); this.disconnect = dispatch(connectPublicStream({ onlyMedia, onlyRemote }));
} }
} }
}
componentWillUnmount () { componentWillUnmount () {
if (this.disconnect) { if (this.disconnect) {