Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include preview cards in status entity in REST API #9120

Merged
merged 3 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ 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
8 changes: 8 additions & 0 deletions app/javascript/mastodon/components/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -256,6 +257,13 @@ 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')}
/>
);
}

if (otherAccounts) {
Expand Down
6 changes: 6 additions & 0 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ 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 @@ -163,6 +165,10 @@ def target
reblog
end

def preview_card
preview_cards.first
end

def title
if destroyed?
"#{account.acct} deleted status"
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/rest/status_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ 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: 1 addition & 0 deletions app/services/fetch_link_card_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def process_url

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

def parse_urls
Expand Down