Merge remote-tracking branch 'personal/merge/tootsuite/master' into gs-master

This commit is contained in:
David Yip 2017-12-06 22:34:42 -06:00
commit ddb61decce
No known key found for this signature in database
GPG Key ID: 7DA0036508FCC0CC
9 changed files with 39 additions and 20 deletions

View File

@ -68,7 +68,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onReblogToggle (account) { onReblogToggle (account) {
if (account.getIn(['relationship', 'show_reblogs'])) { if (account.getIn(['relationship', 'showing_reblogs'])) {
dispatch(followAccount(account.get('id'), false)); dispatch(followAccount(account.get('id'), false));
} else { } else {
dispatch(followAccount(account.get('id'), true)); dispatch(followAccount(account.get('id'), true));

View File

@ -101,7 +101,7 @@ export default class Card extends React.PureComponent {
onClick={this.handlePhotoClick} onClick={this.handlePhotoClick}
role='button' role='button'
tabIndex='0' tabIndex='0'
src={card.get('url')} src={card.get('embed_url')}
alt={card.get('title')} alt={card.get('title')}
width={card.get('width')} width={card.get('width')}
height={card.get('height')} height={card.get('height')}

View File

@ -21,6 +21,7 @@
# height :integer default(0), not null # height :integer default(0), not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# embed_url :string default(""), not null
# #
class PreviewCard < ApplicationRecord class PreviewCard < ApplicationRecord

View File

@ -14,16 +14,6 @@
# web_push_subscription_id :integer # web_push_subscription_id :integer
# #
# id :bigint not null, primary key
# user_id :bigint not null
# session_id :string not null
# created_at :datetime not null
# updated_at :datetime not null
# user_agent :string default(""), not null
# ip :inet
# access_token_id :bigint
#
class SessionActivation < ApplicationRecord class SessionActivation < ApplicationRecord
belongs_to :user, inverse_of: :session_activations, required: true belongs_to :user, inverse_of: :session_activations, required: true
belongs_to :access_token, class_name: 'Doorkeeper::AccessToken', dependent: :destroy belongs_to :access_token, class_name: 'Doorkeeper::AccessToken', dependent: :destroy

View File

@ -6,7 +6,7 @@ class REST::PreviewCardSerializer < ActiveModel::Serializer
attributes :url, :title, :description, :type, attributes :url, :title, :description, :type,
:author_name, :author_url, :provider_name, :author_name, :author_url, :provider_name,
:provider_url, :html, :width, :height, :provider_url, :html, :width, :height,
:image :image, :embed_url
def image def image
object.image? ? full_asset_url(object.image.url(:original)) : nil object.image? ? full_asset_url(object.image.url(:original)) : nil

View File

@ -74,9 +74,6 @@ class FetchLinkCardService < BaseService
return false unless response.respond_to?(:type) return false unless response.respond_to?(:type)
# The photo will change the URL. So, to avoid duplication of URLs, PreviewCard needs to be checked again.
@card = PreviewCard.find_by(url: response.url) || @card if response.type == 'photo'
@card.type = response.type @card.type = response.type
@card.title = response.respond_to?(:title) ? response.title : '' @card.title = response.respond_to?(:title) ? response.title : ''
@card.author_name = response.respond_to?(:author_name) ? response.author_name : '' @card.author_name = response.respond_to?(:author_name) ? response.author_name : ''
@ -90,9 +87,9 @@ class FetchLinkCardService < BaseService
when 'link' when 'link'
@card.image = URI.parse(response.thumbnail_url) if response.respond_to?(:thumbnail_url) @card.image = URI.parse(response.thumbnail_url) if response.respond_to?(:thumbnail_url)
when 'photo' when 'photo'
@card.url = response.url @card.embed_url = response.url
@card.width = response.width.presence || 0 @card.width = response.width.presence || 0
@card.height = response.height.presence || 0 @card.height = response.height.presence || 0
when 'video' when 'video'
@card.width = response.width.presence || 0 @card.width = response.width.presence || 0
@card.height = response.height.presence || 0 @card.height = response.height.presence || 0

View File

@ -0,0 +1,18 @@
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class AddEmbedUrlToPreviewCards < ActiveRecord::Migration[5.1]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
def up
safety_assured do
add_column_with_default :preview_cards, :embed_url, :string, default: '', allow_null: false
end
end
def down
execute "UPDATE preview_cards SET url=embed_url WHERE embed_url!=''"
remove_column :preview_cards, :embed_url
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171129172043) do ActiveRecord::Schema.define(version: 20171130000000) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -334,6 +334,7 @@ ActiveRecord::Schema.define(version: 20171129172043) do
t.integer "height", default: 0, null: false t.integer "height", default: 0, null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "embed_url", default: "", null: false
t.index ["url"], name: "index_preview_cards_on_url", unique: true t.index ["url"], name: "index_preview_cards_on_url", unique: true
end end

View File

@ -326,5 +326,17 @@ namespace :mastodon do
end end
end end
end end
desc 'Migrate photo preview cards made before 2.1'
task migrate_photo_preview_cards: :environment do
status_ids = Status.joins(:preview_cards)
.where(preview_cards: { embed_url: '', type: :photo })
.reorder(nil)
.group(:id)
.pluck(:id)
PreviewCard.where(embed_url: '', type: :photo).delete_all
LinkCrawlWorker.push_bulk status_ids
end
end end
end end