Conflicts: app/models/glitch/keyword_mute.rbclosed-social-glitch-2
@ -1,17 +0,0 @@ | |||
# frozen_string_literal: true | |||
class Api::V1::TrendsController < Api::BaseController | |||
before_action :set_tags | |||
respond_to :json | |||
def index | |||
render json: @tags, each_serializer: REST::TagSerializer | |||
end | |||
private | |||
def set_tags | |||
@tags = TrendingTags.get(limit_param(10)) | |||
end | |||
end |
@ -1,32 +0,0 @@ | |||
import api from '../api'; | |||
export const TRENDS_FETCH_REQUEST = 'TRENDS_FETCH_REQUEST'; | |||
export const TRENDS_FETCH_SUCCESS = 'TRENDS_FETCH_SUCCESS'; | |||
export const TRENDS_FETCH_FAIL = 'TRENDS_FETCH_FAIL'; | |||
export const fetchTrends = () => (dispatch, getState) => { | |||
dispatch(fetchTrendsRequest()); | |||
api(getState) | |||
.get('/api/v1/trends') | |||
.then(({ data }) => dispatch(fetchTrendsSuccess(data))) | |||
.catch(err => dispatch(fetchTrendsFail(err))); | |||
}; | |||
export const fetchTrendsRequest = () => ({ | |||
type: TRENDS_FETCH_REQUEST, | |||
skipLoading: true, | |||
}); | |||
export const fetchTrendsSuccess = trends => ({ | |||
type: TRENDS_FETCH_SUCCESS, | |||
trends, | |||
skipLoading: true, | |||
}); | |||
export const fetchTrendsFail = error => ({ | |||
type: TRENDS_FETCH_FAIL, | |||
error, | |||
skipLoading: true, | |||
skipAlert: true, | |||
}); |
@ -1,14 +1,8 @@ | |||
import { connect } from 'react-redux'; | |||
import SearchResults from '../components/search_results'; | |||
import { fetchTrends } from '../../../actions/trends'; | |||
const mapStateToProps = state => ({ | |||
results: state.getIn(['search', 'results']), | |||
trends: state.getIn(['trends', 'items']), | |||
}); | |||
const mapDispatchToProps = dispatch => ({ | |||
fetchTrends: () => dispatch(fetchTrends()), | |||
}); | |||
export default connect(mapStateToProps, mapDispatchToProps)(SearchResults); | |||
export default connect(mapStateToProps)(SearchResults); |
@ -1,71 +0,0 @@ | |||
import classNames from 'classnames'; | |||
import React from 'react'; | |||
import ImmutablePureComponent from 'react-immutable-pure-component'; | |||
import PropTypes from 'prop-types'; | |||
import ImmutablePropTypes from 'react-immutable-proptypes'; | |||
import { FormattedMessage, defineMessages } from 'react-intl'; | |||
import Hashtag from '../../../components/hashtag'; | |||
import { Link } from 'react-router-dom'; | |||
const messages = defineMessages({ | |||
refresh_trends: { id: 'trends.refresh', defaultMessage: 'Refresh' }, | |||
}); | |||
export default class Trends extends ImmutablePureComponent { | |||
static defaultProps = { | |||
loading: false, | |||
}; | |||
static propTypes = { | |||
trends: ImmutablePropTypes.list, | |||
loading: PropTypes.bool.isRequired, | |||
showTrends: PropTypes.bool.isRequired, | |||
fetchTrends: PropTypes.func.isRequired, | |||
toggleTrends: PropTypes.func.isRequired, | |||
}; | |||
componentDidMount () { | |||
setTimeout(() => this.props.fetchTrends(), 5000); | |||
} | |||
handleRefreshTrends = () => { | |||
this.props.fetchTrends(); | |||
} | |||
handleToggle = () => { | |||
this.props.toggleTrends(!this.props.showTrends); | |||
} | |||
render () { | |||
const { intl, trends, loading, showTrends } = this.props; | |||
if (!trends || trends.size < 1) { | |||
return null; | |||
} | |||
return ( | |||
<div className='getting-started__trends'> | |||
<div className='column-header__wrapper'> | |||
<h1 className='column-header'> | |||
<button> | |||
<i className='fa fa-fire fa-fw' /> | |||
<FormattedMessage id='trends.header' defaultMessage='Trending now' /> | |||
</button> | |||
<div className='column-header__buttons'> | |||
{showTrends && <button onClick={this.handleRefreshTrends} className='column-header__button' title={intl.formatMessage(messages.refresh_trends)} aria-label={intl.formatMessage(messages.refresh_trends)} disabled={loading}><i className={classNames('fa', 'fa-refresh', { 'fa-spin': loading })} /></button>} | |||
<button onClick={this.handleToggle} className='column-header__button'><i className={classNames('fa', showTrends ? 'fa-chevron-down' : 'fa-chevron-up')} /></button> | |||
</div> | |||
</h1> | |||
</div> | |||
{showTrends && <div className='getting-started__scrollable'> | |||
{trends.take(3).map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)} | |||
<Link to='/trends' className='load-more'><FormattedMessage id='status.load_more' defaultMessage='Load more' /></Link> | |||
</div>} | |||
</div> | |||
); | |||
} | |||
} |
@ -1,18 +0,0 @@ | |||
import { connect } from 'react-redux'; | |||
import { injectIntl } from 'react-intl'; | |||
import { fetchTrends } from '../../../actions/trends'; | |||
import Trends from '../components/trends'; | |||
import { changeSetting } from '../../../actions/settings'; | |||
const mapStateToProps = state => ({ | |||
trends: state.getIn(['trends', 'items']), | |||
loading: state.getIn(['trends', 'isLoading']), | |||
showTrends: state.getIn(['settings', 'trends', 'show']), | |||
}); | |||
const mapDispatchToProps = dispatch => ({ | |||
fetchTrends: () => dispatch(fetchTrends()), | |||
toggleTrends: show => dispatch(changeSetting(['trends', 'show'], show)), | |||
}); | |||
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(Trends)); |
@ -1,23 +0,0 @@ | |||
import { TRENDS_FETCH_REQUEST, TRENDS_FETCH_SUCCESS, TRENDS_FETCH_FAIL } from '../actions/trends'; | |||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; | |||
const initialState = ImmutableMap({ | |||
items: ImmutableList(), | |||
isLoading: false, | |||
}); | |||
export default function trendsReducer(state = initialState, action) { | |||
switch(action.type) { | |||
case TRENDS_FETCH_REQUEST: | |||
return state.set('isLoading', true); | |||
case TRENDS_FETCH_SUCCESS: | |||
return state.withMutations(map => { | |||
map.set('items', fromJS(action.trends)); | |||
map.set('isLoading', false); | |||
}); | |||
case TRENDS_FETCH_FAIL: | |||
return state.set('isLoading', false); | |||
default: | |||
return state; | |||
} | |||
}; |
@ -1,6 +1,5 @@ | |||
export const unescapeHTML = (html) => { | |||
const wrapper = document.createElement('div'); | |||
html = html.replace(/<br \/>|<br>|\n/g, ' '); | |||
wrapper.innerHTML = html; | |||
wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, ''); | |||
return wrapper.textContent; | |||
}; |
@ -0,0 +1,10 @@ | |||
import React, { Fragment } from 'react'; | |||
import { FormattedNumber } from 'react-intl'; | |||
export const shortNumberFormat = number => { | |||
if (number < 1000) { | |||
return <FormattedNumber value={number} />; | |||
} else { | |||
return <Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</Fragment>; | |||
} | |||
}; |
@ -0,0 +1,52 @@ | |||
# frozen_string_literal: true | |||
require 'rails_helper' | |||
describe Api::Web::EmbedsController do | |||
render_views | |||
let(:user) { Fabricate(:user) } | |||
before { sign_in user } | |||
describe 'POST #create' do | |||
subject(:response) { post :create, params: { url: url } } | |||
subject(:body) { JSON.parse(response.body, symbolize_names: true) } | |||
context 'when successfully finds status' do | |||
let(:status) { Fabricate(:status) } | |||
let(:url) { "http://#{ Rails.configuration.x.web_domain }/@#{status.account.username}/#{status.id}" } | |||
it 'returns a right response' do | |||
expect(response).to have_http_status :ok | |||
expect(body[:author_name]).to eq status.account.username | |||
end | |||
end | |||
context 'when fails to find status' do | |||
let(:url) { 'https://host.test/oembed.html' } | |||
let(:service_instance) { double('fetch_oembed_service') } | |||
before do | |||
allow(FetchOEmbedService).to receive(:new) { service_instance } | |||
allow(service_instance).to receive(:call) { call_result } | |||
end | |||
context 'when successfully fetching oembed' do | |||
let(:call_result) { { result: :ok } } | |||
it 'returns a right response' do | |||
expect(response).to have_http_status :ok | |||
expect(body[:result]).to eq 'ok' | |||
end | |||
end | |||
context 'when fails to fetch oembed' do | |||
let(:call_result) { nil } | |||
it 'returns a right response' do | |||
expect(response).to have_http_status :not_found | |||
end | |||
end | |||
end | |||
end | |||
end |
@ -0,0 +1,30 @@ | |||
require 'rails_helper' | |||
describe Settings::SessionsController do | |||
render_views | |||
let(:user) { Fabricate(:user) } | |||
let(:session_activation) { Fabricate(:session_activation, user: user) } | |||
before { sign_in user, scope: :user } | |||
describe 'DELETE #destroy' do | |||
subject { delete :destroy, params: { id: id } } | |||
context 'when session activation exists' do | |||
let(:id) { session_activation.id } | |||
it 'destroys session activation' do | |||
is_expected.to redirect_to edit_user_registration_path | |||
expect(SessionActivation.find_by(id: id)).to be_nil | |||
end | |||
end | |||
context 'when session activation does not exist' do | |||
let(:id) { session_activation.id + 1000 } | |||
it 'destroys session activation' do | |||
is_expected.to have_http_status :not_found | |||
end | |||
end | |||
end | |||
end |