Compare commits
1 Commits
main
...
feature-or
Author | SHA1 | Date |
---|---|---|
Eugen Rochko | 611c063141 |
|
@ -50,7 +50,9 @@ class PreviewCard < ApplicationRecord
|
|||
enum type: { link: 0, photo: 1, video: 2, rich: 3 }
|
||||
enum link_type: { unknown: 0, article: 1 }
|
||||
|
||||
has_and_belongs_to_many :statuses
|
||||
has_many :preview_cards_statuses, dependent: :destroy
|
||||
has_many :statuses, through: :preview_cards_statuses
|
||||
|
||||
has_one :trend, class_name: 'PreviewCardTrend', inverse_of: :preview_card, dependent: :destroy
|
||||
|
||||
has_attached_file :image, processors: [:thumbnail, :blurhash_transcoder], styles: ->(f) { image_styles(f) }, convert_options: { all: '-quality 90 +profile "!icc,*" +set date:modify +set date:create +set date:timestamp' }, validate_media_type: false
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: preview_cards_statuses
|
||||
#
|
||||
# preview_card_id :bigint(8) not null
|
||||
# status_id :bigint(8) not null
|
||||
# url :string
|
||||
#
|
||||
class PreviewCardsStatus < ApplicationRecord
|
||||
# Composite primary keys are not properly supported in Rails. However,
|
||||
# we shouldn't need this anyway...
|
||||
self.primary_key = nil
|
||||
|
||||
belongs_to :preview_card
|
||||
belongs_to :status
|
||||
end
|
|
@ -79,7 +79,9 @@ class Status < ApplicationRecord
|
|||
has_many :local_bookmarked, -> { merge(Account.local) }, through: :bookmarks, source: :account
|
||||
|
||||
has_and_belongs_to_many :tags
|
||||
has_and_belongs_to_many :preview_cards
|
||||
|
||||
has_many :preview_cards_statuses, dependent: :destroy
|
||||
has_many :preview_cards, -> { select('preview_cards.*, preview_cards_statuses.url AS original_url').joins(:preview_cards_statuses) }, through: :preview_cards_statuses
|
||||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
has_one :status_stat, inverse_of: :status
|
||||
|
|
|
@ -8,6 +8,14 @@ class REST::PreviewCardSerializer < ActiveModel::Serializer
|
|||
:provider_url, :html, :width, :height,
|
||||
:image, :image_description, :embed_url, :blurhash, :published_at
|
||||
|
||||
def url
|
||||
if object.respond_to?(:original_url)
|
||||
object.original_url.presence || object.url
|
||||
else
|
||||
object.url
|
||||
end
|
||||
end
|
||||
|
||||
def image
|
||||
object.image? ? full_asset_url(object.image.url(:original)) : nil
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ class FetchLinkCardService < BaseService
|
|||
with_redis_lock("attach_card:#{@status.id}") do
|
||||
return if @status.preview_cards.any?
|
||||
|
||||
@status.preview_cards << @card
|
||||
@status.preview_cards_statuses.create(preview_card: @card, url: @original_url)
|
||||
Rails.cache.delete(@status)
|
||||
Trends.links.register(@status)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddURLToPreviewCardsStatuses < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :preview_cards_statuses, :url, :string
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_09_07_150100) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_10_06_183200) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -811,6 +811,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_07_150100) do
|
|||
create_table "preview_cards_statuses", primary_key: ["status_id", "preview_card_id"], force: :cascade do |t|
|
||||
t.bigint "preview_card_id", null: false
|
||||
t.bigint "status_id", null: false
|
||||
t.string "url"
|
||||
end
|
||||
|
||||
create_table "relays", force: :cascade do |t|
|
||||
|
|
Loading…
Reference in New Issue