0
0
Fork 0

Pinned statuses (#4675)

* Pinned statuses

* yarn manage:translations
This commit is contained in:
Eugen Rochko 2017-08-25 01:41:18 +02:00 committed by GitHub
parent c5157ef07b
commit 9caa90025f
59 changed files with 493 additions and 29 deletions

View file

@ -77,6 +77,10 @@ class Account < ApplicationRecord
has_many :mentions, inverse_of: :account, dependent: :destroy
has_many :notifications, inverse_of: :account, dependent: :destroy
# Pinned statuses
has_many :status_pins, inverse_of: :account, dependent: :destroy
has_many :pinned_statuses, through: :status_pins, class_name: 'Status', source: :status
# Media
has_many :media_attachments, dependent: :destroy

View file

@ -138,4 +138,8 @@ module AccountInteractions
def reblogged?(status)
status.proper.reblogs.where(account: self).exists?
end
def pinned?(status)
status_pins.where(status: status).exists?
end
end

View file

@ -164,6 +164,10 @@ class Status < ApplicationRecord
ConversationMute.select('conversation_id').where(conversation_id: conversation_ids).where(account_id: account_id).map { |m| [m.conversation_id, true] }.to_h
end
def pins_map(status_ids, account_id)
StatusPin.select('status_id').where(status_id: status_ids).where(account_id: account_id).map { |p| [p.status_id, true] }.to_h
end
def reload_stale_associations!(cached_items)
account_ids = []

16
app/models/status_pin.rb Normal file
View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: status_pins
#
# id :integer not null, primary key
# account_id :integer not null
# status_id :integer not null
#
class StatusPin < ApplicationRecord
belongs_to :account, required: true
belongs_to :status, required: true
validates_with StatusPinValidator
end