Skip to content

Commit

Permalink
Merge pull request mastodon#499 from ThibG/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes
  • Loading branch information
ClearlyClaire authored May 21, 2018
2 parents 98ecadb + a4c9bda commit 162f186
Show file tree
Hide file tree
Showing 69 changed files with 412 additions and 120 deletions.
10 changes: 8 additions & 2 deletions app/controllers/api/v1/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ class Api::V1::StatusesController < Api::BaseController

respond_to :json

# This API was originally unlimited, pagination cannot be introduced without
# breaking backwards-compatibility. Arbitrarily high number to cover most
# conversations as quasi-unlimited, it would be too much work to render more
# than this anyway
CONTEXT_LIMIT = 4_096

def show
cached = Rails.cache.read(@status.cache_key)
@status = cached unless cached.nil?
render json: @status, serializer: REST::StatusSerializer
end

def context
ancestors_results = @status.in_reply_to_id.nil? ? [] : @status.ancestors(DEFAULT_STATUSES_LIMIT, current_account)
descendants_results = @status.descendants(DEFAULT_STATUSES_LIMIT, current_account)
ancestors_results = @status.in_reply_to_id.nil? ? [] : @status.ancestors(CONTEXT_LIMIT, current_account)
descendants_results = @status.descendants(CONTEXT_LIMIT, current_account)
loaded_ancestors = cache_collection(ancestors_results, Status)
loaded_descendants = cache_collection(descendants_results, Status)

Expand Down
13 changes: 6 additions & 7 deletions app/javascript/mastodon/actions/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ const refreshHomeTimelineAndNotification = (dispatch, done) => {
dispatch(expandHomeTimeline({}, () => dispatch(expandNotifications({}, done))));
};

export const connectUserStream = () => connectTimelineStream('home', 'user', refreshHomeTimelineAndNotification);
export const connectCommunityStream = () => connectTimelineStream('community', 'public:local');
export const connectMediaStream = () => connectTimelineStream('community', 'public:local');
export const connectPublicStream = () => connectTimelineStream('public', 'public');
export const connectHashtagStream = (tag) => connectTimelineStream(`hashtag:${tag}`, `hashtag&tag=${tag}`);
export const connectDirectStream = () => connectTimelineStream('direct', 'direct');
export const connectListStream = (id) => connectTimelineStream(`list:${id}`, `list&list=${id}`);
export const connectUserStream = () => connectTimelineStream('home', 'user', refreshHomeTimelineAndNotification);
export const connectCommunityStream = ({ onlyMedia } = {}) => connectTimelineStream(`community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`);
export const connectPublicStream = ({ onlyMedia } = {}) => connectTimelineStream(`public${onlyMedia ? ':media' : ''}`, `public${onlyMedia ? ':media' : ''}`);
export const connectHashtagStream = tag => connectTimelineStream(`hashtag:${tag}`, `hashtag&tag=${tag}`);
export const connectDirectStream = () => connectTimelineStream('direct', 'direct');
export const connectListStream = id => connectTimelineStream(`list:${id}`, `list&list=${id}`);
16 changes: 8 additions & 8 deletions app/javascript/mastodon/actions/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
};
};

export const expandHomeTimeline = ({ maxId } = {}, done = noOp) => expandTimeline('home', '/api/v1/timelines/home', { max_id: maxId }, done);
export const expandPublicTimeline = ({ maxId } = {}, done = noOp) => expandTimeline('public', '/api/v1/timelines/public', { max_id: maxId }, done);
export const expandCommunityTimeline = ({ maxId } = {}, done = noOp) => expandTimeline('community', '/api/v1/timelines/public', { local: true, max_id: maxId }, done);
export const expandDirectTimeline = ({ maxId } = {}, done = noOp) => expandTimeline('direct', '/api/v1/timelines/direct', { max_id: maxId }, done);
export const expandAccountTimeline = (accountId, { maxId, withReplies } = {}) => expandTimeline(`account:${accountId}${withReplies ? ':with_replies' : ''}`, `/api/v1/accounts/${accountId}/statuses`, { exclude_replies: !withReplies, max_id: maxId });
export const expandHomeTimeline = ({ maxId } = {}, done = noOp) => expandTimeline('home', '/api/v1/timelines/home', { max_id: maxId }, done);
export const expandPublicTimeline = ({ maxId, onlyMedia } = {}, done = noOp) => expandTimeline(`public${onlyMedia ? ':media' : ''}`, '/api/v1/timelines/public', { max_id: maxId, only_media: !!onlyMedia }, done);
export const expandCommunityTimeline = ({ maxId, onlyMedia } = {}, done = noOp) => expandTimeline(`community${onlyMedia ? ':media' : ''}`, '/api/v1/timelines/public', { local: true, max_id: maxId, only_media: !!onlyMedia }, done);
export const expandDirectTimeline = ({ maxId } = {}, done = noOp) => expandTimeline('direct', '/api/v1/timelines/direct', { max_id: maxId }, done);
export const expandAccountTimeline = (accountId, { maxId, withReplies } = {}) => expandTimeline(`account:${accountId}${withReplies ? ':with_replies' : ''}`, `/api/v1/accounts/${accountId}/statuses`, { exclude_replies: !withReplies, max_id: maxId });
export const expandAccountFeaturedTimeline = accountId => expandTimeline(`account:${accountId}:pinned`, `/api/v1/accounts/${accountId}/statuses`, { pinned: true });
export const expandAccountMediaTimeline = (accountId, { maxId } = {}) => expandTimeline(`account:${accountId}:media`, `/api/v1/accounts/${accountId}/statuses`, { max_id: maxId, only_media: true });
export const expandHashtagTimeline = (hashtag, { maxId } = {}, done = noOp) => expandTimeline(`hashtag:${hashtag}`, `/api/v1/timelines/tag/${hashtag}`, { max_id: maxId }, done);
export const expandListTimeline = (id, { maxId } = {}, done = noOp) => expandTimeline(`list:${id}`, `/api/v1/timelines/list/${id}`, { max_id: maxId }, done);
export const expandAccountMediaTimeline = (accountId, { maxId } = {}) => expandTimeline(`account:${accountId}:media`, `/api/v1/accounts/${accountId}/statuses`, { max_id: maxId, only_media: true });
export const expandHashtagTimeline = (hashtag, { maxId } = {}, done = noOp) => expandTimeline(`hashtag:${hashtag}`, `/api/v1/timelines/tag/${hashtag}`, { max_id: maxId }, done);
export const expandListTimeline = (id, { maxId } = {}, done = noOp) => expandTimeline(`list:${id}`, `/api/v1/timelines/list/${id}`, { max_id: maxId }, done);

export function expandTimelineRequest(timeline) {
return {
Expand Down
9 changes: 5 additions & 4 deletions app/javascript/mastodon/components/media_gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Item extends React.PureComponent {
index: PropTypes.number.isRequired,
size: PropTypes.number.isRequired,
onClick: PropTypes.func.isRequired,
displayWidth: PropTypes.number,
};

static defaultProps = {
Expand Down Expand Up @@ -58,7 +59,7 @@ class Item extends React.PureComponent {
}

render () {
const { attachment, index, size, standalone } = this.props;
const { attachment, index, size, standalone, displayWidth } = this.props;

let width = 50;
let height = 100;
Expand Down Expand Up @@ -121,7 +122,7 @@ class Item extends React.PureComponent {
const hasSize = typeof originalWidth === 'number' && typeof previewWidth === 'number';

const srcSet = hasSize ? `${originalUrl} ${originalWidth}w, ${previewUrl} ${previewWidth}w` : null;
const sizes = hasSize ? `(min-width: 1025px) ${320 * (width / 100)}px, ${width}vw` : null;
const sizes = hasSize ? `${displayWidth * (width / 100)}px` : null;

const focusX = attachment.getIn(['meta', 'focus', 'x']) || 0;
const focusY = attachment.getIn(['meta', 'focus', 'y']) || 0;
Expand Down Expand Up @@ -263,9 +264,9 @@ export default class MediaGallery extends React.PureComponent {
const size = media.take(4).size;

if (this.isStandaloneEligible()) {
children = <Item standalone onClick={this.handleClick} attachment={media.get(0)} />;
children = <Item standalone onClick={this.handleClick} attachment={media.get(0)} displayWidth={width} />;
} else {
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} onClick={this.handleClick} attachment={attachment} index={i} size={size} />);
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} onClick={this.handleClick} attachment={attachment} index={i} size={size} displayWidth={width} />);
}
}

Expand Down
34 changes: 25 additions & 9 deletions app/javascript/mastodon/features/community_timeline/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import React from 'react';
import { connect } from 'react-redux';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { NavLink } from 'react-router-dom';
import PropTypes from 'prop-types';
import StatusListContainer from '../ui/containers/status_list_container';
import Column from '../../components/column';
import ColumnHeader from '../../components/column_header';
import { expandCommunityTimeline } from '../../actions/timelines';
import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ColumnSettingsContainer from './containers/column_settings_container';
import { connectCommunityStream } from '../../actions/streaming';

const messages = defineMessages({
title: { id: 'column.community', defaultMessage: 'Local timeline' },
});

const mapStateToProps = state => ({
hasUnread: state.getIn(['timelines', 'community', 'unread']) > 0,
const mapStateToProps = (state, { onlyMedia }) => ({
hasUnread: state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`, 'unread']) > 0,
});

@connect(mapStateToProps)
@injectIntl
export default class CommunityTimeline extends React.PureComponent {

static defaultProps = {
onlyMedia: false,
};

static propTypes = {
dispatch: PropTypes.func.isRequired,
columnId: PropTypes.string,
intl: PropTypes.object.isRequired,
hasUnread: PropTypes.bool,
multiColumn: PropTypes.bool,
onlyMedia: PropTypes.bool,
};

handlePin = () => {
Expand All @@ -50,10 +56,10 @@ export default class CommunityTimeline extends React.PureComponent {
}

componentDidMount () {
const { dispatch } = this.props;
const { dispatch, onlyMedia } = this.props;

dispatch(expandCommunityTimeline());
this.disconnect = dispatch(connectCommunityStream());
dispatch(expandCommunityTimeline({ onlyMedia }));
this.disconnect = dispatch(connectCommunityStream({ onlyMedia }));
}

componentWillUnmount () {
Expand All @@ -68,13 +74,22 @@ export default class CommunityTimeline extends React.PureComponent {
}

handleLoadMore = maxId => {
this.props.dispatch(expandCommunityTimeline({ maxId }));
const { dispatch, onlyMedia } = this.props;

dispatch(expandCommunityTimeline({ maxId, onlyMedia }));
}

render () {
const { intl, hasUnread, columnId, multiColumn } = this.props;
const { intl, hasUnread, columnId, multiColumn, onlyMedia } = this.props;
const pinned = !!columnId;

const headline = (
<div className='community-timeline__section-headline'>
<NavLink exact to='/timelines/public/local' replace><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></NavLink>
<NavLink exact to='/timelines/public/local/media' replace><FormattedMessage id='timeline.media' defaultMessage='Media' /></NavLink>
</div>
);

return (
<Column ref={this.setRef}>
<ColumnHeader
Expand All @@ -91,9 +106,10 @@ export default class CommunityTimeline extends React.PureComponent {
</ColumnHeader>

<StatusListContainer
prepend={headline}
trackScroll={!pinned}
scrollKey={`community_timeline-${columnId}`}
timelineId='community'
timelineId={`community${onlyMedia ? ':media' : ''}`}
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
/>
Expand Down
34 changes: 25 additions & 9 deletions app/javascript/mastodon/features/public_timeline/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import React from 'react';
import { connect } from 'react-redux';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { NavLink } from 'react-router-dom';
import PropTypes from 'prop-types';
import StatusListContainer from '../ui/containers/status_list_container';
import Column from '../../components/column';
import ColumnHeader from '../../components/column_header';
import { expandPublicTimeline } from '../../actions/timelines';
import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ColumnSettingsContainer from './containers/column_settings_container';
import { connectPublicStream } from '../../actions/streaming';

const messages = defineMessages({
title: { id: 'column.public', defaultMessage: 'Federated timeline' },
});

const mapStateToProps = state => ({
hasUnread: state.getIn(['timelines', 'public', 'unread']) > 0,
const mapStateToProps = (state, { onlyMedia }) => ({
hasUnread: state.getIn(['timelines', `public${onlyMedia ? ':media' : ''}`, 'unread']) > 0,
});

@connect(mapStateToProps)
@injectIntl
export default class PublicTimeline extends React.PureComponent {

static defaultProps = {
onlyMedia: false,
};

static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
columnId: PropTypes.string,
multiColumn: PropTypes.bool,
hasUnread: PropTypes.bool,
onlyMedia: PropTypes.bool,
};

handlePin = () => {
Expand All @@ -50,10 +56,10 @@ export default class PublicTimeline extends React.PureComponent {
}

componentDidMount () {
const { dispatch } = this.props;
const { dispatch, onlyMedia } = this.props;

dispatch(expandPublicTimeline());
this.disconnect = dispatch(connectPublicStream());
dispatch(expandPublicTimeline({ onlyMedia }));
this.disconnect = dispatch(connectPublicStream({ onlyMedia }));
}

componentWillUnmount () {
Expand All @@ -68,13 +74,22 @@ export default class PublicTimeline extends React.PureComponent {
}

handleLoadMore = maxId => {
this.props.dispatch(expandPublicTimeline({ maxId }));
const { dispatch, onlyMedia } = this.props;

dispatch(expandPublicTimeline({ maxId, onlyMedia }));
}

render () {
const { intl, columnId, hasUnread, multiColumn } = this.props;
const { intl, columnId, hasUnread, multiColumn, onlyMedia } = this.props;
const pinned = !!columnId;

const headline = (
<div className='public-timeline__section-headline'>
<NavLink exact to='/timelines/public' replace><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></NavLink>
<NavLink exact to='/timelines/public/media' replace><FormattedMessage id='timeline.media' defaultMessage='Media' /></NavLink>
</div>
);

return (
<Column ref={this.setRef}>
<ColumnHeader
Expand All @@ -91,7 +106,8 @@ export default class PublicTimeline extends React.PureComponent {
</ColumnHeader>

<StatusListContainer
timelineId='public'
prepend={headline}
timelineId={`public${onlyMedia ? ':media' : ''}`}
onLoadMore={this.handleLoadMore}
trackScroll={!pinned}
scrollKey={`public_timeline-${columnId}`}
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/mastodon/features/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class SwitchingColumnsArea extends React.PureComponent {
<WrappedRoute path='/keyboard-shortcuts' component={KeyboardShortcuts} content={children} />
<WrappedRoute path='/timelines/home' component={HomeTimeline} content={children} />
<WrappedRoute path='/timelines/public' exact component={PublicTimeline} content={children} />
<WrappedRoute path='/timelines/public/local' component={CommunityTimeline} content={children} />
<WrappedRoute path='/timelines/public/media' component={PublicTimeline} content={children} componentParams={{ onlyMedia: true }} />
<WrappedRoute path='/timelines/public/local' exact component={CommunityTimeline} content={children} />
<WrappedRoute path='/timelines/public/local/media' component={CommunityTimeline} content={children} componentParams={{ onlyMedia: true }} />
<WrappedRoute path='/timelines/direct' component={DirectTimeline} content={children} />
<WrappedRoute path='/timelines/tag/:id' component={HashtagTimeline} content={children} />
<WrappedRoute path='/timelines/list/:id' component={ListTimeline} content={children} />
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
"tabs_bar.local_timeline": "المحلي",
"tabs_bar.notifications": "الإخطارات",
"tabs_bar.search": "البحث",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "سوف تفقد مسودتك إن تركت ماستدون.",
"upload_area.title": "إسحب ثم أفلت للرفع",
"upload_button.label": "إضافة وسائط",
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
"tabs_bar.local_timeline": "Local",
"tabs_bar.notifications": "Известия",
"tabs_bar.search": "Search",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "Your draft will be lost if you leave Mastodon.",
"upload_area.title": "Drag & drop to upload",
"upload_button.label": "Добави медия",
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
"tabs_bar.local_timeline": "Local",
"tabs_bar.notifications": "Notificacions",
"tabs_bar.search": "Cerca",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "El vostre esborrany es perdrà si sortiu de Mastodon.",
"upload_area.title": "Arrossega i deixa anar per carregar",
"upload_button.label": "Afegir multimèdia",
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/co.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
"tabs_bar.local_timeline": "Lucale",
"tabs_bar.notifications": "Nutificazione",
"tabs_bar.search": "Cercà",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "A bruttacopia sarà persa s'ellu hè chjosu Mastodon.",
"upload_area.title": "Drag & drop per caricà un fugliale",
"upload_button.label": "Aghjunghje un media",
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
"tabs_bar.local_timeline": "Lokal",
"tabs_bar.notifications": "Mitteilungen",
"tabs_bar.search": "Suchen",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "Dein Entwurf geht verloren, wenn du Mastodon verlässt.",
"upload_area.title": "Zum Hochladen hereinziehen",
"upload_button.label": "Mediendatei hinzufügen",
Expand Down
16 changes: 16 additions & 0 deletions app/javascript/mastodon/locales/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@
"defaultMessage": "Local timeline",
"id": "column.community"
},
{
"defaultMessage": "Toots",
"id": "timeline.posts"
},
{
"defaultMessage": "Media",
"id": "timeline.media"
},
{
"defaultMessage": "The local timeline is empty. Write something publicly to get the ball rolling!",
"id": "empty_column.community"
Expand Down Expand Up @@ -1393,6 +1401,14 @@
"defaultMessage": "Federated timeline",
"id": "column.public"
},
{
"defaultMessage": "Toots",
"id": "timeline.posts"
},
{
"defaultMessage": "Media",
"id": "timeline.media"
},
{
"defaultMessage": "There is nothing here! Write something publicly, or manually follow users from other instances to fill it up",
"id": "empty_column.public"
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
"tabs_bar.local_timeline": "Local",
"tabs_bar.notifications": "Notifications",
"tabs_bar.search": "Search",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "Your draft will be lost if you leave Mastodon.",
"upload_area.title": "Drag & drop to upload",
"upload_button.label": "Add media",
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@
"tabs_bar.local_timeline": "Local",
"tabs_bar.notifications": "Notifications",
"tabs_bar.search": "Search",
"timeline.media": "Media",
"timeline.posts": "Toots",
"ui.beforeunload": "Your draft will be lost if you leave Mastodon.",
"upload_area.title": "Drag & drop to upload",
"upload_button.label": "Add media",
Expand Down
Loading

0 comments on commit 162f186

Please sign in to comment.