Skip to content

Commit

Permalink
Revert "Include preview cards in status entity in REST API (mastodon#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TheInventrix committed Dec 29, 2018
1 parent 8995fd8 commit 6960cc5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 55 deletions.
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def cache_collection(raw, klass)
def respond_with_error(code)
respond_to do |format|
format.any { head code }

format.html do
set_locale
render "errors/#{code}", layout: 'error', status: code
Expand Down
9 changes: 0 additions & 9 deletions app/javascript/mastodon/components/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import DisplayName from './display_name';
import StatusContent from './status_content';
import StatusActionBar from './status_action_bar';
import AttachmentList from './attachment_list';
import Card from '../features/status/components/card';
import { injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { MediaGallery, Video } from '../features/ui/util/async-components';
Expand Down Expand Up @@ -258,14 +257,6 @@ class Status extends ImmutablePureComponent {
</Bundle>
);
}
} else if (status.get('spoiler_text').length === 0 && status.get('card')) {
media = (
<Card
onOpenMedia={this.props.onOpenMedia}
card={status.get('card')}
compact
/>
);
}

if (otherAccounts) {
Expand Down
15 changes: 7 additions & 8 deletions app/javascript/mastodon/features/status/components/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default class Card extends React.PureComponent {

static defaultProps = {
maxDescription: 50,
compact: false,
};

state = {
Expand Down Expand Up @@ -133,25 +132,25 @@ export default class Card extends React.PureComponent {
}

render () {
const { card, maxDescription, compact } = this.props;
const { width, embedded } = this.state;
const { card, maxDescription } = this.props;
const { width, embedded } = this.state;

if (card === null) {
return null;
}

const provider = card.get('provider_name').length === 0 ? decodeIDNA(getHostname(card.get('url'))) : card.get('provider_name');
const horizontal = (!compact && card.get('width') > card.get('height') && (card.get('width') + 100 >= width)) || card.get('type') !== 'link' || embedded;
const horizontal = card.get('width') > card.get('height') && (card.get('width') + 100 >= width) || card.get('type') !== 'link';
const className = classnames('status-card', { horizontal });
const interactive = card.get('type') !== 'link';
const className = classnames('status-card', { horizontal, compact, interactive });
const title = interactive ? <a className='status-card__title' href={card.get('url')} title={card.get('title')} rel='noopener' target='_blank'><strong>{card.get('title')}</strong></a> : <strong className='status-card__title' title={card.get('title')}>{card.get('title')}</strong>;
const ratio = card.get('width') / card.get('height');
const height = (compact && !embedded) ? (width / (16 / 9)) : (width / ratio);

const description = (
<div className='status-card__content'>
{title}
{!(horizontal || compact) && <p className='status-card__description'>{trim(card.get('description') || '', maxDescription)}</p>}
{!horizontal && <p className='status-card__description'>{trim(card.get('description') || '', maxDescription)}</p>}
<span className='status-card__host'>{provider}</span>
</div>
);
Expand All @@ -176,7 +175,7 @@ export default class Card extends React.PureComponent {
<div className='status-card__actions'>
<div>
<button onClick={this.handleEmbedClick}><i className={`fa fa-${iconVariant}`} /></button>
{horizontal && <a href={card.get('url')} target='_blank' rel='noopener'><i className='fa fa-external-link' /></a>}
<a href={card.get('url')} target='_blank' rel='noopener'><i className='fa fa-external-link' /></a>
</div>
</div>
</div>
Expand All @@ -186,7 +185,7 @@ export default class Card extends React.PureComponent {
return (
<div className={className} ref={this.setRef}>
{embed}
{!compact && description}
{description}
</div>
);
} else if (card.get('image')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { connect } from 'react-redux';
import Card from '../components/card';

const mapStateToProps = (state, { statusId }) => ({
card: state.getIn(['cards', statusId], null),
});

export default connect(mapStateToProps)(Card);
2 changes: 2 additions & 0 deletions app/javascript/mastodon/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import relationships from './relationships';
import settings from './settings';
import push_notifications from './push_notifications';
import status_lists from './status_lists';
import cards from './cards';
import mutes from './mutes';
import reports from './reports';
import contexts from './contexts';
Expand Down Expand Up @@ -45,6 +46,7 @@ const reducers = {
relationships,
settings,
push_notifications,
cards,
mutes,
reports,
contexts,
Expand Down
28 changes: 0 additions & 28 deletions app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2562,9 +2562,6 @@ a.status-card {
display: block;
margin-top: 5px;
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.status-card__image {
Expand All @@ -2589,31 +2586,6 @@ a.status-card {
}
}

.status-card.compact {
border-color: lighten($ui-base-color, 4%);

&.interactive {
border: 0;
}

.status-card__content {
padding: 8px;
padding-top: 10px;
}

.status-card__title {
white-space: nowrap;
}

.status-card__image {
flex: 0 0 60px;
}
}

a.status-card.compact:hover {
background-color: lighten($ui-base-color, 4%);
}

.status-card__image-image {
border-radius: 4px 0 0 4px;
display: block;
Expand Down
6 changes: 0 additions & 6 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,13 @@ class Status < ApplicationRecord
:conversation,
:status_stat,
:tags,
:preview_cards,
:stream_entry,
active_mentions: :account,
reblog: [
:account,
:application,
:stream_entry,
:tags,
:preview_cards,
:media_attachments,
:conversation,
:status_stat,
Expand Down Expand Up @@ -166,10 +164,6 @@ def target
reblog
end

def preview_card
preview_cards.first
end

def title
if destroyed?
"#{account.acct} deleted status"
Expand Down
2 changes: 0 additions & 2 deletions app/serializers/rest/status_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class REST::StatusSerializer < ActiveModel::Serializer
has_many :tags
has_many :emojis, serializer: REST::CustomEmojiSerializer

has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer

def id
object.id.to_s
end
Expand Down
1 change: 0 additions & 1 deletion app/services/fetch_link_card_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def process_url

def attach_card
@status.preview_cards << @card
Rails.cache.delete(@status)
end

def parse_urls
Expand Down

0 comments on commit 6960cc5

Please sign in to comment.