Skip to content

Commit

Permalink
Merge pull request glitch-soc#2713 from ClearlyClaire/glitch-soc/merg…
Browse files Browse the repository at this point in the history
…e-upstream

Merge upstream changes up to de4815a
  • Loading branch information
ClearlyClaire authored May 20, 2024
2 parents 93a6172 + ca5955e commit 7b3eef4
Show file tree
Hide file tree
Showing 115 changed files with 1,333 additions and 593 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/apps/credentials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class Api::V1::Apps::CredentialsController < Api::BaseController
def show
return doorkeeper_render_error unless valid_doorkeeper_token?

render json: doorkeeper_token.application, serializer: REST::ApplicationSerializer, fields: %i(name website vapid_key client_id scopes)
render json: doorkeeper_token.application, serializer: REST::ApplicationSerializer
end
end
4 changes: 2 additions & 2 deletions app/controllers/api/v1/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Api::V1::AppsController < Api::BaseController

def create
@app = Doorkeeper::Application.create!(application_options)
render json: @app, serializer: REST::ApplicationSerializer
render json: @app, serializer: REST::CredentialApplicationSerializer
end

private
Expand All @@ -24,6 +24,6 @@ def app_scopes_or_default
end

def app_params
params.permit(:client_name, :redirect_uris, :scopes, :website)
params.permit(:client_name, :scopes, :website, :redirect_uris, redirect_uris: [])
end
end
12 changes: 5 additions & 7 deletions app/javascript/flavours/glitch/components/column_header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import CloseIcon from '@/material-icons/400-24px/close.svg?react';
import SettingsIcon from '@/material-icons/400-24px/settings.svg?react';
import { Icon } from 'flavours/glitch/components/icon';
import { ButtonInTabsBar } from 'flavours/glitch/features/ui/util/columns_context';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';


import { useAppHistory } from './router';

const messages = defineMessages({
Expand Down Expand Up @@ -51,12 +53,8 @@ BackButton.propTypes = {
};

class ColumnHeader extends PureComponent {

static contextTypes = {
identity: PropTypes.object,
};

static propTypes = {
identity: identityContextPropShape,
intl: PropTypes.object.isRequired,
title: PropTypes.node,
icon: PropTypes.string,
Expand Down Expand Up @@ -171,7 +169,7 @@ class ColumnHeader extends PureComponent {
);
}

if (this.context.identity.signedIn && (children || (multiColumn && this.props.onPin))) {
if (this.props.identity.signedIn && (children || (multiColumn && this.props.onPin))) {
collapseButton = (
<button
className={collapsibleButtonClassName}
Expand Down Expand Up @@ -232,4 +230,4 @@ class ColumnHeader extends PureComponent {

}

export default injectIntl(withRouter(ColumnHeader));
export default injectIntl(withIdentity(withRouter(ColumnHeader)));
11 changes: 4 additions & 7 deletions app/javascript/flavours/glitch/components/poll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CheckIcon from '@/material-icons/400-24px/check.svg?react';
import { Icon } from 'flavours/glitch/components/icon';
import emojify from 'flavours/glitch/features/emoji/emoji';
import Motion from 'flavours/glitch/features/ui/util/optional_motion';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';

import { RelativeTimestamp } from './relative_timestamp';

Expand All @@ -38,12 +39,8 @@ const makeEmojiMap = record => record.get('emojis').reduce((obj, emoji) => {
}, {});

class Poll extends ImmutablePureComponent {

static contextTypes = {
identity: PropTypes.object,
};

static propTypes = {
identity: identityContextPropShape,
poll: ImmutablePropTypes.map,
lang: PropTypes.string,
intl: PropTypes.object.isRequired,
Expand Down Expand Up @@ -235,7 +232,7 @@ class Poll extends ImmutablePureComponent {
</ul>

<div className='poll__footer'>
{!showResults && <button className='button button-secondary' disabled={disabled || !this.context.identity.signedIn} onClick={this.handleVote}><FormattedMessage id='poll.vote' defaultMessage='Vote' /></button>}
{!showResults && <button className='button button-secondary' disabled={disabled || !this.props.identity.signedIn} onClick={this.handleVote}><FormattedMessage id='poll.vote' defaultMessage='Vote' /></button>}
{!showResults && <><button className='poll__link' onClick={this.handleReveal}><FormattedMessage id='poll.reveal' defaultMessage='See results' /></button> · </>}
{showResults && !this.props.disabled && <><button className='poll__link' onClick={this.handleRefresh}><FormattedMessage id='poll.refresh' defaultMessage='Refresh' /></button> · </>}
{votesCount}
Expand All @@ -247,4 +244,4 @@ class Poll extends ImmutablePureComponent {

}

export default injectIntl(Poll);
export default injectIntl(withIdentity(Poll));
17 changes: 7 additions & 10 deletions app/javascript/flavours/glitch/components/status_action_bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import RepeatActiveIcon from '@/svg-icons/repeat_active.svg?react';
import RepeatDisabledIcon from '@/svg-icons/repeat_disabled.svg';
import RepeatPrivateIcon from '@/svg-icons/repeat_private.svg';
import RepeatPrivateActiveIcon from '@/svg-icons/repeat_private_active.svg?react';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
import { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_FEDERATION } from 'flavours/glitch/permissions';
import { accountAdminLink, statusAdminLink } from 'flavours/glitch/utils/backend_links';
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
Expand Down Expand Up @@ -67,12 +68,8 @@ const messages = defineMessages({
});

class StatusActionBar extends ImmutablePureComponent {

static contextTypes = {
identity: PropTypes.object,
};

static propTypes = {
identity: identityContextPropShape,
status: ImmutablePropTypes.map.isRequired,
onReply: PropTypes.func,
onFavourite: PropTypes.func,
Expand Down Expand Up @@ -108,7 +105,7 @@ class StatusActionBar extends ImmutablePureComponent {
];

handleReplyClick = () => {
const { signedIn } = this.context.identity;
const { signedIn } = this.props.identity;

if (signedIn) {
this.props.onReply(this.props.status, this.props.history);
Expand All @@ -124,7 +121,7 @@ class StatusActionBar extends ImmutablePureComponent {
};

handleFavouriteClick = (e) => {
const { signedIn } = this.context.identity;
const { signedIn } = this.props.identity;

if (signedIn) {
this.props.onFavourite(this.props.status, e);
Expand All @@ -134,7 +131,7 @@ class StatusActionBar extends ImmutablePureComponent {
};

handleReblogClick = e => {
const { signedIn } = this.context.identity;
const { signedIn } = this.props.identity;

if (signedIn) {
this.props.onReblog(this.props.status, e);
Expand Down Expand Up @@ -210,7 +207,7 @@ class StatusActionBar extends ImmutablePureComponent {

render () {
const { status, intl, withDismiss, withCounters, showReplyCount, scrollKey } = this.props;
const { permissions, signedIn } = this.context.identity;
const { permissions, signedIn } = this.props.identity;

const mutingConversation = status.get('muted');
const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
Expand Down Expand Up @@ -359,4 +356,4 @@ class StatusActionBar extends ImmutablePureComponent {

}

export default withRouter(injectIntl(StatusActionBar));
export default withRouter(withIdentity(injectIntl(StatusActionBar)));
11 changes: 4 additions & 7 deletions app/javascript/flavours/glitch/components/status_content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import LinkIcon from '@/material-icons/400-24px/link.svg?react';
import MovieIcon from '@/material-icons/400-24px/movie.svg?react';
import MusicNoteIcon from '@/material-icons/400-24px/music_note.svg?react';
import { Icon } from 'flavours/glitch/components/icon';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
import { autoPlayGif, languages as preloadedLanguages } from 'flavours/glitch/initial_state';
import { decode as decodeIDNA } from 'flavours/glitch/utils/idna';

Expand Down Expand Up @@ -126,12 +127,8 @@ const mapStateToProps = state => ({
});

class StatusContent extends PureComponent {

static contextTypes = {
identity: PropTypes.object,
};

static propTypes = {
identity: identityContextPropShape,
status: ImmutablePropTypes.map.isRequired,
statusContent: PropTypes.string,
expanded: PropTypes.bool,
Expand Down Expand Up @@ -349,7 +346,7 @@ class StatusContent extends PureComponent {
const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
const contentLocale = intl.locale.replace(/[_-].*/, '');
const targetLanguages = this.props.languages?.get(status.get('language') || 'und');
const renderTranslate = this.props.onTranslate && this.context.identity.signedIn && ['public', 'unlisted'].includes(status.get('visibility')) && status.get('search_index').trim().length > 0 && targetLanguages?.includes(contentLocale);
const renderTranslate = this.props.onTranslate && this.props.identity.signedIn && ['public', 'unlisted'].includes(status.get('visibility')) && status.get('search_index').trim().length > 0 && targetLanguages?.includes(contentLocale);

const content = { __html: statusContent ?? getStatusContent(status) };
const spoilerContent = { __html: status.getIn(['translation', 'spoilerHtml']) || status.get('spoilerHtml') };
Expand Down Expand Up @@ -503,4 +500,4 @@ class StatusContent extends PureComponent {

}

export default withRouter(connect(mapStateToProps)(injectIntl(StatusContent)));
export default withRouter(withIdentity(connect(mapStateToProps)(injectIntl(StatusContent))));
54 changes: 16 additions & 38 deletions app/javascript/flavours/glitch/containers/mastodon.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { Helmet } from 'react-helmet';
Expand All @@ -15,6 +14,7 @@ import { connectUserStream } from 'flavours/glitch/actions/streaming';
import ErrorBoundary from 'flavours/glitch/components/error_boundary';
import { Router } from 'flavours/glitch/components/router';
import UI from 'flavours/glitch/features/ui';
import { IdentityContext, createIdentityContext } from 'flavours/glitch/identity_context';
import initialState, { title as siteTitle } from 'flavours/glitch/initial_state';
import { IntlProvider } from 'flavours/glitch/locales';
import { store } from 'flavours/glitch/store';
Expand All @@ -33,33 +33,9 @@ if (initialState.meta.me) {
store.dispatch(fetchCustomEmojis());
}

const createIdentityContext = state => ({
signedIn: !!state.meta.me,
accountId: state.meta.me,
disabledAccountId: state.meta.disabled_account_id,
accessToken: state.meta.access_token,
permissions: state.role ? state.role.permissions : 0,
});

export default class Mastodon extends PureComponent {

static childContextTypes = {
identity: PropTypes.shape({
signedIn: PropTypes.bool.isRequired,
accountId: PropTypes.string,
disabledAccountId: PropTypes.string,
accessToken: PropTypes.string,
}).isRequired,
};

identity = createIdentityContext(initialState);

getChildContext() {
return {
identity: this.identity,
};
}

componentDidMount() {
if (this.identity.signedIn) {
this.disconnect = store.dispatch(connectUserStream());
Expand All @@ -79,19 +55,21 @@ export default class Mastodon extends PureComponent {

render () {
return (
<IntlProvider>
<ReduxProvider store={store}>
<ErrorBoundary>
<Router>
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
<Route path='/' component={UI} />
</ScrollContext>
</Router>

<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`} />
</ErrorBoundary>
</ReduxProvider>
</IntlProvider>
<IdentityContext.Provider value={this.identity}>
<IntlProvider>
<ReduxProvider store={store}>
<ErrorBoundary>
<Router>
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
<Route path='/' component={UI} />
</ScrollContext>
</Router>

<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`} />
</ErrorBoundary>
</ReduxProvider>
</IntlProvider>
</IdentityContext.Provider>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Icon } from 'flavours/glitch/components/icon';
import { IconButton } from 'flavours/glitch/components/icon_button';
import { LoadingIndicator } from 'flavours/glitch/components/loading_indicator';
import DropdownMenuContainer from 'flavours/glitch/containers/dropdown_menu_container';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
import { autoPlayGif, me, domain as localDomain } from 'flavours/glitch/initial_state';
import { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_FEDERATION } from 'flavours/glitch/permissions';
import { preferencesLink, profileLink, accountAdminLink } from 'flavours/glitch/utils/backend_links';
Expand Down Expand Up @@ -94,6 +95,7 @@ const dateFormatOptions = {
class Header extends ImmutablePureComponent {

static propTypes = {
identity: identityContextPropShape,
account: ImmutablePropTypes.record,
identity_props: ImmutablePropTypes.list,
onFollow: PropTypes.func.isRequired,
Expand All @@ -117,10 +119,6 @@ class Header extends ImmutablePureComponent {
...WithRouterPropTypes,
};

static contextTypes = {
identity: PropTypes.object,
};

openEditProfile = () => {
window.open(profileLink, '_blank');
};
Expand Down Expand Up @@ -170,7 +168,7 @@ class Header extends ImmutablePureComponent {

render () {
const { account, hidden, intl } = this.props;
const { signedIn, permissions } = this.context.identity;
const { signedIn, permissions } = this.props.identity;

if (!account) {
return null;
Expand Down Expand Up @@ -414,4 +412,4 @@ class Header extends ImmutablePureComponent {

}

export default withRouter(injectIntl(Header));
export default withRouter(withIdentity(injectIntl(Header)));
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { connect } from 'react-redux';

import PeopleIcon from '@/material-icons/400-24px/group.svg?react';
import { DismissableBanner } from 'flavours/glitch/components/dismissable_banner';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
import { domain } from 'flavours/glitch/initial_state';

import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
Expand Down Expand Up @@ -40,16 +41,12 @@ const mapStateToProps = (state, { columnId }) => {
};

class CommunityTimeline extends PureComponent {

static contextTypes = {
identity: PropTypes.object,
};

static defaultProps = {
onlyMedia: false,
};

static propTypes = {
identity: identityContextPropShape,
dispatch: PropTypes.func.isRequired,
columnId: PropTypes.string,
intl: PropTypes.object.isRequired,
Expand Down Expand Up @@ -80,7 +77,7 @@ class CommunityTimeline extends PureComponent {

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

dispatch(expandCommunityTimeline({ onlyMedia }));

Expand All @@ -90,7 +87,7 @@ class CommunityTimeline extends PureComponent {
}

componentDidUpdate (prevProps) {
const { signedIn } = this.context.identity;
const { signedIn } = this.props.identity;

if (prevProps.onlyMedia !== this.props.onlyMedia) {
const { dispatch, onlyMedia } = this.props;
Expand Down Expand Up @@ -165,4 +162,4 @@ class CommunityTimeline extends PureComponent {

}

export default connect(mapStateToProps)(injectIntl(CommunityTimeline));
export default withIdentity(connect(mapStateToProps)(injectIntl(CommunityTimeline)));
Loading

0 comments on commit 7b3eef4

Please sign in to comment.