Instead of using spoiler boolean and spoiler_text, simply check for non-blank spoiler_text
Federate spoiler_text using warning attribute on <content /> instead of a <category term="spoiler" /> Clean up schema file from accidental development migrations
This commit is contained in:
parent
f8da0dd490
commit
999cde94a6
|
@ -70,7 +70,6 @@ export function submitCompose() {
|
||||||
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
|
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
|
||||||
media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')),
|
media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')),
|
||||||
sensitive: getState().getIn(['compose', 'sensitive']),
|
sensitive: getState().getIn(['compose', 'sensitive']),
|
||||||
spoiler: getState().getIn(['compose', 'spoiler']),
|
|
||||||
spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''),
|
spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''),
|
||||||
visibility: getState().getIn(['compose', 'private']) ? 'private' : (getState().getIn(['compose', 'unlisted']) ? 'unlisted' : 'public')
|
visibility: getState().getIn(['compose', 'private']) ? 'private' : (getState().getIn(['compose', 'unlisted']) ? 'unlisted' : 'public')
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
import emojify from '../emoji';
|
import emojify from '../emoji';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
const StatusContent = React.createClass({
|
const StatusContent = React.createClass({
|
||||||
|
|
||||||
|
@ -13,17 +14,17 @@ const StatusContent = React.createClass({
|
||||||
onClick: React.PropTypes.func
|
onClick: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState () {
|
||||||
|
return {
|
||||||
|
hidden: true
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const node = ReactDOM.findDOMNode(this);
|
const node = ReactDOM.findDOMNode(this);
|
||||||
const links = node.querySelectorAll('a');
|
const links = node.querySelectorAll('a');
|
||||||
const spoilers = node.querySelectorAll('.spoiler');
|
|
||||||
|
|
||||||
for (var i = 0; i < spoilers.length; ++i) {
|
|
||||||
let spoiler = spoilers[i];
|
|
||||||
spoiler.addEventListener('click', this.onSpoilerClick.bind(this, spoiler), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < links.length; ++i) {
|
for (var i = 0; i < links.length; ++i) {
|
||||||
let link = links[i];
|
let link = links[i];
|
||||||
|
@ -56,18 +57,6 @@ const StatusContent = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onSpoilerClick (spoiler, e) {
|
|
||||||
if (e.button === 0) {
|
|
||||||
//only toggle if we're not clicking a visible link
|
|
||||||
var hasClass = $(spoiler).hasClass('spoiler-on');
|
|
||||||
if (hasClass || e.target === spoiler) {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
$(spoiler).siblings(".spoiler").andSelf().toggleClass('spoiler-on', !hasClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleMouseDown (e) {
|
handleMouseDown (e) {
|
||||||
this.startXY = [e.clientX, e.clientY];
|
this.startXY = [e.clientX, e.clientY];
|
||||||
},
|
},
|
||||||
|
@ -87,20 +76,40 @@ const StatusContent = React.createClass({
|
||||||
this.startXY = null;
|
this.startXY = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleSpoilerClick () {
|
||||||
|
this.setState({ hidden: !this.state.hidden });
|
||||||
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { status } = this.props;
|
const { status } = this.props;
|
||||||
|
const { hidden } = this.state;
|
||||||
|
|
||||||
const content = { __html: emojify(status.get('content')) };
|
const content = { __html: emojify(status.get('content')) };
|
||||||
|
const spoilerContent = { __html: emojify(status.get('spoiler_text')) };
|
||||||
|
|
||||||
return (
|
if (status.get('spoiler_text').length > 0) {
|
||||||
<div
|
const toggleText = hidden ? <FormattedMessage id='status.show_more' defaultMessage='Show more' /> : <FormattedMessage id='status.show_less' defaultMessage='Show less' />;
|
||||||
className='status__content'
|
|
||||||
style={{ cursor: 'pointer' }}
|
return (
|
||||||
dangerouslySetInnerHTML={content}
|
<div className='status__content' style={{ cursor: 'pointer' }} onMouseDown={this.handleMouseDown} onMouseUp={this.handleMouseUp}>
|
||||||
onMouseDown={this.handleMouseDown}
|
<p>
|
||||||
onMouseUp={this.handleMouseUp}
|
<span dangerouslySetInnerHTML={spoilerContent} /> <a onClick={this.handleSpoilerClick}>{toggleText}</a>
|
||||||
/>
|
</p>
|
||||||
);
|
|
||||||
|
<div style={{ display: hidden ? 'none' : 'block' }} dangerouslySetInnerHTML={content} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className='status__content'
|
||||||
|
style={{ cursor: 'pointer' }}
|
||||||
|
onMouseDown={this.handleMouseDown}
|
||||||
|
onMouseUp={this.handleMouseUp}
|
||||||
|
dangerouslySetInnerHTML={content}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -155,7 +155,7 @@ const ComposeForm = React.createClass({
|
||||||
|
|
||||||
<div style={{ marginTop: '10px', overflow: 'hidden' }}>
|
<div style={{ marginTop: '10px', overflow: 'hidden' }}>
|
||||||
<div style={{ float: 'right' }}><Button text={intl.formatMessage(messages.publish)} onClick={this.handleSubmit} disabled={disabled} /></div>
|
<div style={{ float: 'right' }}><Button text={intl.formatMessage(messages.publish)} onClick={this.handleSubmit} disabled={disabled} /></div>
|
||||||
<div style={{ float: 'right', marginRight: '16px', lineHeight: '36px' }}><CharacterCounter max={500} text={this.props.spoiler ? (this.props.spoiler_text + "\n" + this.props.text) : this.props.text} /></div>
|
<div style={{ float: 'right', marginRight: '16px', lineHeight: '36px' }}><CharacterCounter max={500} text={[this.props.spoiler_text, this.props.text].join('')} /></div>
|
||||||
<UploadButtonContainer style={{ paddingTop: '4px' }} />
|
<UploadButtonContainer style={{ paddingTop: '4px' }} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ const UploadForm = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
media: ImmutablePropTypes.list.isRequired,
|
media: ImmutablePropTypes.list.isRequired,
|
||||||
is_uploading: React.PropTypes.bool,
|
is_uploading: React.PropTypes.bool,
|
||||||
onRemoveFile: React.PropTypes.func.isRequired
|
onRemoveFile: React.PropTypes.func.isRequired,
|
||||||
|
intl: React.PropTypes.object.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
|
|
@ -96,68 +96,68 @@ const insertSuggestion = (state, position, token, completion) => {
|
||||||
|
|
||||||
export default function compose(state = initialState, action) {
|
export default function compose(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case STORE_HYDRATE:
|
case STORE_HYDRATE:
|
||||||
return state.merge(action.state.get('compose'));
|
return state.merge(action.state.get('compose'));
|
||||||
case COMPOSE_MOUNT:
|
case COMPOSE_MOUNT:
|
||||||
return state.set('mounted', true);
|
return state.set('mounted', true);
|
||||||
case COMPOSE_UNMOUNT:
|
case COMPOSE_UNMOUNT:
|
||||||
return state.set('mounted', false);
|
return state.set('mounted', false);
|
||||||
case COMPOSE_SENSITIVITY_CHANGE:
|
case COMPOSE_SENSITIVITY_CHANGE:
|
||||||
return state.set('sensitive', action.checked);
|
return state.set('sensitive', action.checked);
|
||||||
case COMPOSE_SPOILERNESS_CHANGE:
|
case COMPOSE_SPOILERNESS_CHANGE:
|
||||||
return state.set('spoiler', action.checked);
|
return (action.checked ? state : state.set('spoiler_text', '')).set('spoiler', action.checked);
|
||||||
case COMPOSE_SPOILER_TEXT_CHANGE:
|
case COMPOSE_SPOILER_TEXT_CHANGE:
|
||||||
return state.set('spoiler_text', action.text);
|
return state.set('spoiler_text', action.text);
|
||||||
case COMPOSE_VISIBILITY_CHANGE:
|
case COMPOSE_VISIBILITY_CHANGE:
|
||||||
return state.set('private', action.checked);
|
return state.set('private', action.checked);
|
||||||
case COMPOSE_LISTABILITY_CHANGE:
|
case COMPOSE_LISTABILITY_CHANGE:
|
||||||
return state.set('unlisted', action.checked);
|
return state.set('unlisted', action.checked);
|
||||||
case COMPOSE_CHANGE:
|
case COMPOSE_CHANGE:
|
||||||
return state.set('text', action.text);
|
return state.set('text', action.text);
|
||||||
case COMPOSE_REPLY:
|
case COMPOSE_REPLY:
|
||||||
return state.withMutations(map => {
|
return state.withMutations(map => {
|
||||||
map.set('in_reply_to', action.status.get('id'));
|
map.set('in_reply_to', action.status.get('id'));
|
||||||
map.set('text', statusToTextMentions(state, action.status));
|
map.set('text', statusToTextMentions(state, action.status));
|
||||||
});
|
});
|
||||||
case COMPOSE_REPLY_CANCEL:
|
case COMPOSE_REPLY_CANCEL:
|
||||||
return state.withMutations(map => {
|
return state.withMutations(map => {
|
||||||
map.set('in_reply_to', null);
|
map.set('in_reply_to', null);
|
||||||
map.set('text', '');
|
map.set('text', '');
|
||||||
});
|
});
|
||||||
case COMPOSE_SUBMIT_REQUEST:
|
case COMPOSE_SUBMIT_REQUEST:
|
||||||
return state.set('is_submitting', true);
|
return state.set('is_submitting', true);
|
||||||
case COMPOSE_SUBMIT_SUCCESS:
|
case COMPOSE_SUBMIT_SUCCESS:
|
||||||
return clearAll(state);
|
return clearAll(state);
|
||||||
case COMPOSE_SUBMIT_FAIL:
|
case COMPOSE_SUBMIT_FAIL:
|
||||||
return state.set('is_submitting', false);
|
return state.set('is_submitting', false);
|
||||||
case COMPOSE_UPLOAD_REQUEST:
|
case COMPOSE_UPLOAD_REQUEST:
|
||||||
return state.withMutations(map => {
|
return state.withMutations(map => {
|
||||||
map.set('is_uploading', true);
|
map.set('is_uploading', true);
|
||||||
map.set('fileDropDate', new Date());
|
map.set('fileDropDate', new Date());
|
||||||
});
|
});
|
||||||
case COMPOSE_UPLOAD_SUCCESS:
|
case COMPOSE_UPLOAD_SUCCESS:
|
||||||
return appendMedia(state, Immutable.fromJS(action.media));
|
return appendMedia(state, Immutable.fromJS(action.media));
|
||||||
case COMPOSE_UPLOAD_FAIL:
|
case COMPOSE_UPLOAD_FAIL:
|
||||||
return state.set('is_uploading', false);
|
return state.set('is_uploading', false);
|
||||||
case COMPOSE_UPLOAD_UNDO:
|
case COMPOSE_UPLOAD_UNDO:
|
||||||
return removeMedia(state, action.media_id);
|
return removeMedia(state, action.media_id);
|
||||||
case COMPOSE_UPLOAD_PROGRESS:
|
case COMPOSE_UPLOAD_PROGRESS:
|
||||||
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
||||||
case COMPOSE_MENTION:
|
case COMPOSE_MENTION:
|
||||||
return state.update('text', text => `${text}@${action.account.get('acct')} `);
|
return state.update('text', text => `${text}@${action.account.get('acct')} `);
|
||||||
case COMPOSE_SUGGESTIONS_CLEAR:
|
case COMPOSE_SUGGESTIONS_CLEAR:
|
||||||
return state.update('suggestions', Immutable.List(), list => list.clear()).set('suggestion_token', null);
|
return state.update('suggestions', Immutable.List(), list => list.clear()).set('suggestion_token', null);
|
||||||
case COMPOSE_SUGGESTIONS_READY:
|
case COMPOSE_SUGGESTIONS_READY:
|
||||||
return state.set('suggestions', Immutable.List(action.accounts.map(item => item.id))).set('suggestion_token', action.token);
|
return state.set('suggestions', Immutable.List(action.accounts.map(item => item.id))).set('suggestion_token', action.token);
|
||||||
case COMPOSE_SUGGESTION_SELECT:
|
case COMPOSE_SUGGESTION_SELECT:
|
||||||
return insertSuggestion(state, action.position, action.token, action.completion);
|
return insertSuggestion(state, action.position, action.token, action.completion);
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
if (action.id === state.get('in_reply_to')) {
|
if (action.id === state.get('in_reply_to')) {
|
||||||
return state.set('in_reply_to', null);
|
return state.set('in_reply_to', null);
|
||||||
} else {
|
} else {
|
||||||
return state;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return state;
|
return state;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,16 +14,6 @@ $(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each($('.spoiler'), (_, content) => {
|
|
||||||
$(content).on('click', e => {
|
|
||||||
var hasClass = $(content).hasClass('spoiler-on');
|
|
||||||
if (hasClass || e.target === content) {
|
|
||||||
e.preventDefault();
|
|
||||||
$(content).siblings(".spoiler").andSelf().toggleClass('spoiler-on', !hasClass);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.media-spoiler').on('click', e => {
|
$('.media-spoiler').on('click', e => {
|
||||||
$(e.target).hide();
|
$(e.target).hide();
|
||||||
});
|
});
|
||||||
|
|
|
@ -249,6 +249,7 @@
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 100px;
|
border-radius: 100px;
|
||||||
color: rgba($color5, 0.8);
|
color: rgba($color5, 0.8);
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +264,7 @@
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
transition: all 100ms linear;
|
transition: all 100ms linear;
|
||||||
|
z-index: 2;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: darken($color3, 5%);
|
background: darken($color3, 5%);
|
||||||
|
|
|
@ -57,7 +57,12 @@ class Api::V1::StatusesController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids], sensitive: params[:sensitive], spoiler: params[:spoiler], spoiler_text: params[:spoiler_text], visibility: params[:visibility], application: doorkeeper_token.application)
|
@status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids],
|
||||||
|
sensitive: params[:sensitive],
|
||||||
|
spoiler_text: params[:spoiler_text],
|
||||||
|
visibility: params[:visibility],
|
||||||
|
application: doorkeeper_token.application)
|
||||||
|
|
||||||
render action: :show
|
render action: :show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,10 @@ module AtomBuilderHelper
|
||||||
xml['activity'].send('verb', TagManager::VERBS[verb])
|
xml['activity'].send('verb', TagManager::VERBS[verb])
|
||||||
end
|
end
|
||||||
|
|
||||||
def content(xml, content)
|
def content(xml, content, warning = nil)
|
||||||
xml.content({ type: 'html' }, content) unless content.blank?
|
extra = { type: 'html' }
|
||||||
|
extra[:warning] = warning unless warning.blank?
|
||||||
|
xml.content(extra, content) unless content.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def title(xml, title)
|
def title(xml, title)
|
||||||
|
@ -153,12 +155,20 @@ module AtomBuilderHelper
|
||||||
portable_contact xml, account
|
portable_contact xml, account
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rich_content(xml, activity)
|
||||||
|
if activity.is_a?(Status)
|
||||||
|
content xml, conditionally_formatted(activity), activity.spoiler_text
|
||||||
|
else
|
||||||
|
content xml, conditionally_formatted(activity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def include_entry(xml, stream_entry)
|
def include_entry(xml, stream_entry)
|
||||||
unique_id xml, stream_entry.created_at, stream_entry.activity_id, stream_entry.activity_type
|
unique_id xml, stream_entry.created_at, stream_entry.activity_id, stream_entry.activity_type
|
||||||
published_at xml, stream_entry.created_at
|
published_at xml, stream_entry.created_at
|
||||||
updated_at xml, stream_entry.updated_at
|
updated_at xml, stream_entry.updated_at
|
||||||
title xml, stream_entry.title
|
title xml, stream_entry.title
|
||||||
content xml, conditionally_formatted(stream_entry.activity)
|
rich_content xml, stream_entry.activity
|
||||||
verb xml, stream_entry.verb
|
verb xml, stream_entry.verb
|
||||||
link_self xml, account_stream_entry_url(stream_entry.account, stream_entry, format: 'atom')
|
link_self xml, account_stream_entry_url(stream_entry.account, stream_entry, format: 'atom')
|
||||||
link_alternate xml, account_stream_entry_url(stream_entry.account, stream_entry)
|
link_alternate xml, account_stream_entry_url(stream_entry.account, stream_entry)
|
||||||
|
@ -207,7 +217,6 @@ module AtomBuilderHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
category(xml, 'nsfw') if stream_entry.target.sensitive?
|
category(xml, 'nsfw') if stream_entry.target.sensitive?
|
||||||
category(xml, 'spoiler') if stream_entry.target.spoiler?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -229,7 +238,6 @@ module AtomBuilderHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
category(xml, 'nsfw') if stream_entry.activity.sensitive?
|
category(xml, 'nsfw') if stream_entry.activity.sensitive?
|
||||||
category(xml, 'spoiler') if stream_entry.activity.spoiler?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -14,15 +14,7 @@ class Formatter
|
||||||
|
|
||||||
html = status.text
|
html = status.text
|
||||||
html = encode(html)
|
html = encode(html)
|
||||||
|
html = simple_format(html, {}, sanitize: false)
|
||||||
if (status.spoiler?)
|
|
||||||
spoilerhtml = status.spoiler_text
|
|
||||||
spoilerhtml = encode(spoilerhtml)
|
|
||||||
html = wrap_spoilers(html, spoilerhtml)
|
|
||||||
else
|
|
||||||
html = simple_format(html, sanitize: false)
|
|
||||||
end
|
|
||||||
|
|
||||||
html = html.gsub(/\n/, '')
|
html = html.gsub(/\n/, '')
|
||||||
html = link_urls(html)
|
html = link_urls(html)
|
||||||
html = link_mentions(html, status.mentions)
|
html = link_mentions(html, status.mentions)
|
||||||
|
@ -51,13 +43,6 @@ class Formatter
|
||||||
HTMLEntities.new.encode(html)
|
HTMLEntities.new.encode(html)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_spoilers(html, spoilerhtml)
|
|
||||||
spoilerhtml = simple_format(spoilerhtml, {class: "spoiler-helper"}, {sanitize: false})
|
|
||||||
html = simple_format(html, {class: ["spoiler", "spoiler-on"]}, {sanitize: false})
|
|
||||||
|
|
||||||
spoilerhtml + html
|
|
||||||
end
|
|
||||||
|
|
||||||
def link_urls(html)
|
def link_urls(html)
|
||||||
html.gsub(URI.regexp(%w(http https))) do |match|
|
html.gsub(URI.regexp(%w(http https))) do |match|
|
||||||
link_html(match)
|
link_html(match)
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class StatusLengthValidator < ActiveModel::Validator
|
||||||
|
MAX_CHARS = 500
|
||||||
|
|
||||||
|
def validate(status)
|
||||||
|
return unless status.local? && !status.reblog?
|
||||||
|
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: MAX_CHARS)) if [status.text, status.spoiler_text].join.length > MAX_CHARS
|
||||||
|
end
|
||||||
|
end
|
|
@ -28,9 +28,8 @@ class Status < ApplicationRecord
|
||||||
|
|
||||||
validates :account, presence: true
|
validates :account, presence: true
|
||||||
validates :uri, uniqueness: true, unless: 'local?'
|
validates :uri, uniqueness: true, unless: 'local?'
|
||||||
validates :text, presence: true, if: proc { |s| s.local? && !s.reblog? }
|
validates :text, presence: true, unless: 'reblog?'
|
||||||
validates_with StatusLengthValidator
|
validates_with StatusLengthValidator
|
||||||
validates :text, presence: true, if: proc { |s| !s.local? && !s.reblog? }
|
|
||||||
validates :reblog, uniqueness: { scope: :account, message: 'of status already exists' }, if: 'reblog?'
|
validates :reblog, uniqueness: { scope: :account, message: 'of status already exists' }, if: 'reblog?'
|
||||||
|
|
||||||
default_scope { order('id desc') }
|
default_scope { order('id desc') }
|
||||||
|
@ -176,6 +175,7 @@ class Status < ApplicationRecord
|
||||||
|
|
||||||
before_validation do
|
before_validation do
|
||||||
text.strip!
|
text.strip!
|
||||||
|
spoiler_text&.strip!
|
||||||
|
|
||||||
self.reblog = reblog.reblog if reblog? && reblog.reblog?
|
self.reblog = reblog.reblog if reblog? && reblog.reblog?
|
||||||
self.in_reply_to_account_id = (thread.account_id == account_id && thread.reply? ? thread.in_reply_to_account_id : thread.account_id) if reply?
|
self.in_reply_to_account_id = (thread.account_id == account_id && thread.reply? ? thread.in_reply_to_account_id : thread.account_id) if reply?
|
||||||
|
|
|
@ -9,7 +9,7 @@ class FetchLinkCardService < BaseService
|
||||||
|
|
||||||
response = http_client.get(url)
|
response = http_client.get(url)
|
||||||
|
|
||||||
return if response.code != 200
|
return if response.code != 200 || response.mime_type != 'text/html'
|
||||||
|
|
||||||
page = Nokogiri::HTML(response.to_s)
|
page = Nokogiri::HTML(response.to_s)
|
||||||
card = PreviewCard.where(status: status).first_or_initialize(status: status, url: url)
|
card = PreviewCard.where(status: status).first_or_initialize(status: status, url: url)
|
||||||
|
@ -18,6 +18,8 @@ class FetchLinkCardService < BaseService
|
||||||
card.description = meta_property(page, 'og:description') || meta_property(page, 'description')
|
card.description = meta_property(page, 'og:description') || meta_property(page, 'description')
|
||||||
card.image = URI.parse(meta_property(page, 'og:image')) if meta_property(page, 'og:image')
|
card.image = URI.parse(meta_property(page, 'og:image')) if meta_property(page, 'og:image')
|
||||||
|
|
||||||
|
return if card.title.blank?
|
||||||
|
|
||||||
card.save_with_optional_image!
|
card.save_with_optional_image!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,16 @@ class PostStatusService < BaseService
|
||||||
# @param [Hash] options
|
# @param [Hash] options
|
||||||
# @option [Boolean] :sensitive
|
# @option [Boolean] :sensitive
|
||||||
# @option [String] :visibility
|
# @option [String] :visibility
|
||||||
# @option [Boolean] :spoiler
|
|
||||||
# @option [String] :spoiler_text
|
# @option [String] :spoiler_text
|
||||||
# @option [Enumerable] :media_ids Optional array of media IDs to attach
|
# @option [Enumerable] :media_ids Optional array of media IDs to attach
|
||||||
# @option [Doorkeeper::Application] :application
|
# @option [Doorkeeper::Application] :application
|
||||||
# @return [Status]
|
# @return [Status]
|
||||||
def call(account, text, in_reply_to = nil, options = {})
|
def call(account, text, in_reply_to = nil, options = {})
|
||||||
status = account.statuses.create!(text: text,
|
status = account.statuses.create!(text: text,
|
||||||
thread: in_reply_to,
|
thread: in_reply_to,
|
||||||
sensitive: options[:sensitive],
|
sensitive: options[:sensitive],
|
||||||
spoiler: options[:spoiler],
|
spoiler_text: options[:spoiler_text],
|
||||||
spoiler_text: options[:spoiler_text],
|
visibility: options[:visibility],
|
||||||
visibility: options[:visibility],
|
|
||||||
application: options[:application])
|
application: options[:application])
|
||||||
|
|
||||||
attach_media(status, options[:media_ids])
|
attach_media(status, options[:media_ids])
|
||||||
|
|
|
@ -103,6 +103,7 @@ class ProcessFeedService < BaseService
|
||||||
url: url(entry),
|
url: url(entry),
|
||||||
account: account,
|
account: account,
|
||||||
text: content(entry),
|
text: content(entry),
|
||||||
|
spoiler_text: content_warning(entry),
|
||||||
created_at: published(entry)
|
created_at: published(entry)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -223,6 +224,10 @@ class ProcessFeedService < BaseService
|
||||||
xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content
|
xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content_warning(xml = @xml)
|
||||||
|
xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS)['warning']
|
||||||
|
end
|
||||||
|
|
||||||
def published(xml = @xml)
|
def published(xml = @xml)
|
||||||
xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content
|
xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,5 @@ class ProcessHashtagsService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
status.update(sensitive: true) if tags.include?('nsfw')
|
status.update(sensitive: true) if tags.include?('nsfw')
|
||||||
status.update(spoiler: true) if tags.include?('spoiler')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
class StatusLengthValidator < ActiveModel::Validator
|
|
||||||
def validate(status)
|
|
||||||
if status.local? && !status.reblog?
|
|
||||||
combinedText = status.text
|
|
||||||
if (status.spoiler? && status.spoiler_text.present?)
|
|
||||||
combinedText = status.spoiler_text + "\n" + status.text
|
|
||||||
end
|
|
||||||
|
|
||||||
maxChars = 500
|
|
||||||
unless combinedText.length <= maxChars
|
|
||||||
status.errors[:text] << "is too long (maximum is #{maxChars})"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,4 +1,4 @@
|
||||||
attributes :id, :created_at, :in_reply_to_id, :sensitive, :spoiler, :visibility
|
attributes :id, :created_at, :in_reply_to_id, :sensitive, :spoiler_text, :visibility
|
||||||
|
|
||||||
node(:uri) { |status| TagManager.instance.uri_for(status) }
|
node(:uri) { |status| TagManager.instance.uri_for(status) }
|
||||||
node(:content) { |status| Formatter.instance.format(status) }
|
node(:content) { |status| Formatter.instance.format(status) }
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
%strong.p-name.emojify= display_name(status.account)
|
%strong.p-name.emojify= display_name(status.account)
|
||||||
%span.p-nickname= acct(status.account)
|
%span.p-nickname= acct(status.account)
|
||||||
|
|
||||||
.status__content.e-content.p-name.emojify= Formatter.instance.format(status)
|
.status__content.e-content.p-name.emojify<
|
||||||
|
- unless status.spoiler_text.blank?
|
||||||
|
%p= status.spoiler_text
|
||||||
|
= Formatter.instance.format(status)
|
||||||
|
|
||||||
- unless status.media_attachments.empty?
|
- unless status.media_attachments.empty?
|
||||||
- if status.media_attachments.first.video?
|
- if status.media_attachments.first.video?
|
||||||
|
|
|
@ -12,7 +12,10 @@
|
||||||
%strong.p-name.emojify= display_name(status.account)
|
%strong.p-name.emojify= display_name(status.account)
|
||||||
%span.p-nickname= acct(status.account)
|
%span.p-nickname= acct(status.account)
|
||||||
|
|
||||||
.status__content.e-content.p-name.emojify= Formatter.instance.format(status)
|
.status__content.e-content.p-name.emojify<
|
||||||
|
- unless status.spoiler_text.blank?
|
||||||
|
%p= status.spoiler_text
|
||||||
|
= Formatter.instance.format(status)
|
||||||
|
|
||||||
- unless status.media_attachments.empty?
|
- unless status.media_attachments.empty?
|
||||||
.status__attachments
|
.status__attachments
|
||||||
|
|
|
@ -93,6 +93,8 @@ en:
|
||||||
back: Back to Mastodon
|
back: Back to Mastodon
|
||||||
edit_profile: Edit profile
|
edit_profile: Edit profile
|
||||||
preferences: Preferences
|
preferences: Preferences
|
||||||
|
statuses:
|
||||||
|
over_character_limit: character limit of %{max} exceeded
|
||||||
stream_entries:
|
stream_entries:
|
||||||
click_to_show: Click to show
|
click_to_show: Click to show
|
||||||
favourited: favourited a post by
|
favourited: favourited a post by
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
class AddSpoilerToStatuses < ActiveRecord::Migration[5.0]
|
|
||||||
def change
|
|
||||||
add_column :statuses, :spoiler, :boolean, default: false
|
|
||||||
end
|
|
||||||
end
|
|
15
db/schema.rb
15
db/schema.rb
|
@ -173,19 +173,6 @@ ActiveRecord::Schema.define(version: 20170123203248) do
|
||||||
t.index ["status_id"], name: "index_preview_cards_on_status_id", unique: true, using: :btree
|
t.index ["status_id"], name: "index_preview_cards_on_status_id", unique: true, using: :btree
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "pubsubhubbub_subscriptions", force: :cascade do |t|
|
|
||||||
t.string "topic", default: "", null: false
|
|
||||||
t.string "callback", default: "", null: false
|
|
||||||
t.string "mode", default: "", null: false
|
|
||||||
t.string "challenge", default: "", null: false
|
|
||||||
t.string "secret"
|
|
||||||
t.boolean "confirmed", default: false, null: false
|
|
||||||
t.datetime "expires_at", null: false
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.index ["topic", "callback"], name: "index_pubsubhubbub_subscriptions_on_topic_and_callback", unique: true, using: :btree
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "settings", force: :cascade do |t|
|
create_table "settings", force: :cascade do |t|
|
||||||
t.string "var", null: false
|
t.string "var", null: false
|
||||||
t.text "value"
|
t.text "value"
|
||||||
|
@ -208,8 +195,6 @@ ActiveRecord::Schema.define(version: 20170123203248) do
|
||||||
t.boolean "sensitive", default: false
|
t.boolean "sensitive", default: false
|
||||||
t.integer "visibility", default: 0, null: false
|
t.integer "visibility", default: 0, null: false
|
||||||
t.integer "in_reply_to_account_id"
|
t.integer "in_reply_to_account_id"
|
||||||
t.string "conversation_uri"
|
|
||||||
t.boolean "spoiler", default: false
|
|
||||||
t.text "spoiler_text", default: ""
|
t.text "spoiler_text", default: ""
|
||||||
t.integer "application_id"
|
t.integer "application_id"
|
||||||
t.index ["account_id"], name: "index_statuses_on_account_id", using: :btree
|
t.index ["account_id"], name: "index_statuses_on_account_id", using: :btree
|
||||||
|
|
Loading…
Reference in New Issue