Browse Source

use news bot for explore news timeline

closed-social-glitch-2
欧醚 1 year ago
parent
commit
c19eddb1d4
5 changed files with 76 additions and 5 deletions
  1. +15
    -5
      app/javascript/flavours/glitch/features/explore/index.jsx
  2. +55
    -0
      app/javascript/flavours/glitch/features/explore/news_bot_statuses.jsx
  3. +4
    -0
      app/javascript/flavours/glitch/initial_state.js
  4. +1
    -0
      app/serializers/initial_state_serializer.rb
  5. +1
    -0
      config/initializers/new_feature.rb

+ 15
- 5
app/javascript/flavours/glitch/features/explore/index.jsx View File

@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import Column from 'flavours/glitch/components/column';
import ColumnHeader from 'flavours/glitch/components/column_header';
import { NavLink, Switch, Route } from 'react-router-dom';
import Links from './links';
import NewsBotStatuses from './news_bot_statuses';
import Tags from './tags';
import Statuses from './statuses';
import Suggestions from './suggestions';
@ -13,6 +13,7 @@ import Search from 'flavours/glitch/features/compose/containers/search_container
import SearchResults from './results';
import { showTrends } from 'flavours/glitch/initial_state';
import { Helmet } from 'react-helmet';
import { newsBotId } from '../../initial_state'
const messages = defineMessages({
title: { id: 'explore.title', defaultMessage: 'Explore' },
@ -74,9 +75,11 @@ class Explore extends React.PureComponent {
<NavLink exact to='/explore/tags'>
<FormattedMessage tagName='div' id='explore.trending_tags' defaultMessage='Hashtags' />
</NavLink>
<NavLink exact to='/explore/links'>
<FormattedMessage tagName='div' id='explore.trending_links' defaultMessage='News' />
</NavLink>
{newsBotId ? (
<NavLink exact to='/explore/links'>
<FormattedMessage tagName='div' id='explore.trending_links' defaultMessage='News' />
</NavLink>
) : null}
{signedIn && (
<NavLink exact to='/explore/suggestions'>
<FormattedMessage tagName='div' id='explore.suggested_follows' defaultMessage='For you' />
@ -86,7 +89,14 @@ class Explore extends React.PureComponent {
<Switch>
<Route path='/explore/tags' component={Tags} />
<Route path='/explore/links' component={Links} />
{newsBotId ? (
<Route path='/explore/links'>
<NewsBotStatuses
accountId={newsBotId}
multiColumn={multiColumn}
/>
</Route>
) : null}
<Route path='/explore/suggestions' component={Suggestions} />
<Route exact path={['/explore', '/explore/posts', '/search']} component={Statuses} componentParams={{ multiColumn }} />
</Switch>

+ 55
- 0
app/javascript/flavours/glitch/features/explore/news_bot_statuses.jsx View File

@ -0,0 +1,55 @@
import React from 'react';
import { connect } from 'react-redux';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { expandAccountTimeline } from 'flavours/glitch/actions/timelines';
import StatusList from '../../components/status_list';
import { List as ImmutableList } from 'immutable';
const mapStateToProps = (state, { accountId }) => {
return {
statusIds: state.getIn(['timelines', `account:${accountId}`, 'items'], ImmutableList()),
isLoading: state.getIn(['timelines', `account:${accountId}`, 'isLoading']),
hasMore: state.getIn(['timelines', `account:${accountId}`, 'hasMore']),
};
};
export default @connect(mapStateToProps)
class NewsBotStatuses extends React.PureComponent {
static propTypes = {
accountId: PropTypes.string.isRequired,
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list,
isLoading: PropTypes.bool,
hasMore: PropTypes.bool,
multiColumn: PropTypes.bool,
};
componentDidMount () {
this.props.dispatch(expandAccountTimeline(this.props.accountId));
}
handleLoadMore = maxId => {
this.props.dispatch(expandAccountTimeline(this.props.accountId, { maxId }));
};
render () {
const { statusIds, isLoading, hasMore, multiColumn } = this.props;
return (
<StatusList
scrollKey='news_bot_timeline'
statusIds={statusIds}
isLoading={isLoading}
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
timelineId='news_bot'
bindToDocument={!multiColumn}
/>
);
}
}

+ 4
- 0
app/javascript/flavours/glitch/initial_state.js View File

@ -82,6 +82,7 @@
* @property {string} version
* @property {boolean} translation_enabled
* @property {object} local_settings
* @property {string} news_bot_id
*/
/**
@ -150,4 +151,7 @@ export const pollLimits = (initialState && initialState.poll_limits);
export const defaultContentType = getMeta('default_content_type');
export const useSystemEmojiFont = getMeta('system_emoji_font');
// Closed-social-specific settings
export const newsBotId = getMeta('news_bot_id');
export default initialState;

+ 1
- 0
app/serializers/initial_state_serializer.rb View File

@ -46,6 +46,7 @@ class InitialStateSerializer < ActiveModel::Serializer
single_user_mode: Rails.configuration.x.single_user_mode,
trends_as_landing_page: Setting.trends_as_landing_page,
status_page_url: Setting.status_page_url,
news_bot_id: Rails.configuration.x.news_bot_id,
}
if object.current_account

+ 1
- 0
config/initializers/new_feature.rb View File

@ -7,4 +7,5 @@ Rails.application.configure do
config.x.anon.acc = ENV.fetch('ANON_ACC', nil)
config.x.anon.namelist = ENV['ANON_NAME_LIST'] ? File.readlines(ENV['ANON_NAME_LIST']).collect(&:strip) : ['Alice', 'Bob', 'Carol', 'Dave']
config.x.anon.salt = (1..42).map { ('a'..'z').to_a.sample }.join
config.x.news_bot_id = ENV.fetch('NEWS_BOT', nil)
end

Loading…
Cancel
Save