parent
d51efdd1dc
commit
c3f5dfeabb
@ -0,0 +1,103 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
import StatusList from '../../components/status_list';
|
||||||
|
import Column from '../ui/components/column';
|
||||||
|
import Immutable from 'immutable';
|
||||||
|
import { selectStatus } from '../../reducers/timelines';
|
||||||
|
import {
|
||||||
|
updateTimeline,
|
||||||
|
refreshTimeline,
|
||||||
|
expandTimeline
|
||||||
|
} from '../../actions/timelines';
|
||||||
|
import { deleteStatus } from '../../actions/statuses';
|
||||||
|
import { replyCompose } from '../../actions/compose';
|
||||||
|
import {
|
||||||
|
favourite,
|
||||||
|
reblog,
|
||||||
|
unreblog,
|
||||||
|
unfavourite
|
||||||
|
} from '../../actions/interactions';
|
||||||
|
|
||||||
|
function selectStatuses(state) {
|
||||||
|
return state.getIn(['timelines', 'public'], Immutable.List()).map(id => selectStatus(state, id)).filterNot(status => status === null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
statuses: selectStatuses(state),
|
||||||
|
me: state.getIn(['timelines', 'me'])
|
||||||
|
});
|
||||||
|
|
||||||
|
const PublicTimeline = React.createClass({
|
||||||
|
|
||||||
|
propTypes: {
|
||||||
|
statuses: ImmutablePropTypes.list.isRequired,
|
||||||
|
me: React.PropTypes.number.isRequired,
|
||||||
|
dispatch: React.PropTypes.func.isRequired
|
||||||
|
},
|
||||||
|
|
||||||
|
mixins: [PureRenderMixin],
|
||||||
|
|
||||||
|
componentWillMount () {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
|
dispatch(refreshTimeline('public'));
|
||||||
|
|
||||||
|
if (typeof App !== 'undefined') {
|
||||||
|
this.subscription = App.cable.subscriptions.create('PublicChannel', {
|
||||||
|
|
||||||
|
received (data) {
|
||||||
|
dispatch(updateTimeline('public', JSON.parse(data.message)));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
if (typeof this.subscription !== 'undefined') {
|
||||||
|
this.subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handleReply (status) {
|
||||||
|
this.props.dispatch(replyCompose(status));
|
||||||
|
},
|
||||||
|
|
||||||
|
handleReblog (status) {
|
||||||
|
if (status.get('reblogged')) {
|
||||||
|
this.props.dispatch(unreblog(status));
|
||||||
|
} else {
|
||||||
|
this.props.dispatch(reblog(status));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handleFavourite (status) {
|
||||||
|
if (status.get('favourited')) {
|
||||||
|
this.props.dispatch(unfavourite(status));
|
||||||
|
} else {
|
||||||
|
this.props.dispatch(favourite(status));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handleDelete (status) {
|
||||||
|
this.props.dispatch(deleteStatus(status.get('id')));
|
||||||
|
},
|
||||||
|
|
||||||
|
handleScrollToBottom () {
|
||||||
|
this.props.dispatch(expandTimeline('public'));
|
||||||
|
},
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { statuses, me } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Column icon='globe' heading='Public'>
|
||||||
|
<StatusList statuses={statuses} me={me} onScrollToBottom={this.handleScrollToBottom} onReply={this.handleReply} onReblog={this.handleReblog} onFavourite={this.handleFavourite} onDelete={this.handleDelete} />
|
||||||
|
</Column>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(PublicTimeline);
|
@ -0,0 +1,19 @@
|
|||||||
|
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
|
||||||
|
class PublicChannel < ApplicationCable::Channel
|
||||||
|
def subscribed
|
||||||
|
stream_from 'timeline:public', -> (encoded_message) do
|
||||||
|
message = ActiveSupport::JSON.decode(encoded_message)
|
||||||
|
|
||||||
|
status = Status.find_by(id: message['id'])
|
||||||
|
next if status.nil?
|
||||||
|
|
||||||
|
message['message'] = FeedManager.instance.inline_render(current_user.account, status)
|
||||||
|
|
||||||
|
transmit message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unsubscribed
|
||||||
|
# Any cleanup needed when channel is unsubscribed
|
||||||
|
end
|
||||||
|
end
|
@ -1,2 +0,0 @@
|
|||||||
collection @statuses
|
|
||||||
extends('api/v1/statuses/show')
|
|
Loading…
Reference in new issue