Add protocol handler. Handle follow intents (#4511)
* Add protocol handler. Handle follow intents * Add share intent * Improve code in intents controller * Adjust share form CSSth-downstream
parent
ffc125c953
commit
0e5c8372e7
@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class IntentsController < ApplicationController
|
||||||
|
def show
|
||||||
|
uri = Addressable::URI.parse(params[:uri])
|
||||||
|
|
||||||
|
if uri.scheme == 'web+mastodon'
|
||||||
|
case uri.host
|
||||||
|
when 'follow'
|
||||||
|
return redirect_to authorize_follow_path(acct: uri.query_values['uri'].gsub(/\Aacct:/, ''))
|
||||||
|
when 'share'
|
||||||
|
return redirect_to share_path(text: uri.query_values['text'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
not_found
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,25 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SharesController < ApplicationController
|
||||||
|
layout 'public'
|
||||||
|
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def show
|
||||||
|
serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
|
||||||
|
@initial_state_json = serializable_resource.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def initial_state_params
|
||||||
|
{
|
||||||
|
settings: Web::Setting.find_by(user: current_user)&.data || {},
|
||||||
|
push_subscription: current_account.user.web_push_subscription(current_session),
|
||||||
|
current_account: current_account,
|
||||||
|
token: current_session.token,
|
||||||
|
admin: Account.find_local(Setting.site_contact_username),
|
||||||
|
text: params[:text],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import configureStore from '../store/configureStore';
|
||||||
|
import { hydrateStore } from '../actions/store';
|
||||||
|
import { IntlProvider, addLocaleData } from 'react-intl';
|
||||||
|
import { getLocale } from '../locales';
|
||||||
|
import Compose from '../features/standalone/compose';
|
||||||
|
|
||||||
|
const { localeData, messages } = getLocale();
|
||||||
|
addLocaleData(localeData);
|
||||||
|
|
||||||
|
const store = configureStore();
|
||||||
|
const initialStateContainer = document.getElementById('initial-state');
|
||||||
|
|
||||||
|
if (initialStateContainer !== null) {
|
||||||
|
const initialState = JSON.parse(initialStateContainer.textContent);
|
||||||
|
store.dispatch(hydrateStore(initialState));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class TimelineContainer extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
locale: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { locale } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IntlProvider locale={locale} messages={messages}>
|
||||||
|
<Provider store={store}>
|
||||||
|
<Compose />
|
||||||
|
</Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ComposeFormContainer from '../../compose/containers/compose_form_container';
|
||||||
|
import NotificationsContainer from '../../ui/containers/notifications_container';
|
||||||
|
import LoadingBarContainer from '../../ui/containers/loading_bar_container';
|
||||||
|
|
||||||
|
export default class Compose extends React.PureComponent {
|
||||||
|
|
||||||
|
render () {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<ComposeFormContainer />
|
||||||
|
<NotificationsContainer />
|
||||||
|
<LoadingBarContainer className='loading-bar' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
import loadPolyfills from '../mastodon/load_polyfills';
|
||||||
|
|
||||||
|
require.context('../images/', true);
|
||||||
|
|
||||||
|
function loaded() {
|
||||||
|
const ComposeContainer = require('../mastodon/containers/compose_container').default;
|
||||||
|
const React = require('react');
|
||||||
|
const ReactDOM = require('react-dom');
|
||||||
|
const mountNode = document.getElementById('mastodon-compose');
|
||||||
|
|
||||||
|
if (mountNode !== null) {
|
||||||
|
const props = JSON.parse(mountNode.getAttribute('data-props'));
|
||||||
|
ReactDOM.render(<ComposeContainer {...props} />, mountNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
const ready = require('../mastodon/ready').default;
|
||||||
|
ready(loaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadPolyfills().then(main).catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
@ -1,5 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class InitialStatePresenter < ActiveModelSerializers::Model
|
class InitialStatePresenter < ActiveModelSerializers::Model
|
||||||
attributes :settings, :push_subscription, :token, :current_account, :admin
|
attributes :settings, :push_subscription, :token,
|
||||||
|
:current_account, :admin, :text
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
- content_for :header_tags do
|
||||||
|
%script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json)
|
||||||
|
= javascript_pack_tag 'share', integrity: true, crossorigin: 'anonymous'
|
||||||
|
|
||||||
|
#mastodon-compose{ data: { props: Oj.dump(default_props) } }
|
Loading…
Reference in new issue