Add conversation-based forwarding for limited visibility statuses through bearcaps
This commit is contained in:
parent
52157fdcba
commit
7cd4ed7d42
26 changed files with 430 additions and 78 deletions
|
@ -3,18 +3,44 @@
|
|||
#
|
||||
# Table name: conversations
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# uri :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# id :bigint(8) not null, primary key
|
||||
# uri :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# parent_status_id :bigint(8)
|
||||
# parent_account_id :bigint(8)
|
||||
# inbox_url :string
|
||||
#
|
||||
|
||||
class Conversation < ApplicationRecord
|
||||
validates :uri, uniqueness: true, if: :uri?
|
||||
|
||||
has_many :statuses
|
||||
belongs_to :parent_status, class_name: 'Status', optional: true, inverse_of: :conversation
|
||||
belongs_to :parent_account, class_name: 'Account', optional: true
|
||||
|
||||
has_many :statuses, inverse_of: :conversation
|
||||
|
||||
scope :local, -> { where(uri: nil) }
|
||||
|
||||
before_validation :set_parent_account, on: :create
|
||||
|
||||
after_create :set_conversation_on_parent_status
|
||||
|
||||
def local?
|
||||
uri.nil?
|
||||
end
|
||||
|
||||
def object_type
|
||||
:conversation
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_parent_account
|
||||
self.parent_account = parent_status.account if parent_status.present?
|
||||
end
|
||||
|
||||
def set_conversation_on_parent_status
|
||||
parent_status.update_column(:conversation_id, id) if parent_status.present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,9 +50,11 @@ class Status < ApplicationRecord
|
|||
|
||||
belongs_to :account, inverse_of: :statuses
|
||||
belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account', optional: true
|
||||
belongs_to :conversation, optional: true
|
||||
belongs_to :conversation, optional: true, inverse_of: :statuses
|
||||
belongs_to :preloadable_poll, class_name: 'Poll', foreign_key: 'poll_id', optional: true
|
||||
|
||||
has_one :owned_conversation, class_name: 'Conversation', foreign_key: 'parent_status_id', inverse_of: :parent_status
|
||||
|
||||
belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true
|
||||
belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true
|
||||
|
||||
|
@ -63,6 +65,7 @@ class Status < ApplicationRecord
|
|||
has_many :mentions, dependent: :destroy, inverse_of: :status
|
||||
has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status
|
||||
has_many :media_attachments, dependent: :nullify
|
||||
has_many :capability_tokens, class_name: 'StatusCapabilityToken', inverse_of: :status, dependent: :destroy
|
||||
|
||||
has_and_belongs_to_many :tags
|
||||
has_and_belongs_to_many :preview_cards
|
||||
|
@ -205,7 +208,9 @@ class Status < ApplicationRecord
|
|||
public_visibility? || unlisted_visibility?
|
||||
end
|
||||
|
||||
alias sign? distributable?
|
||||
def sign?
|
||||
distributable? || limited_visibility?
|
||||
end
|
||||
|
||||
def with_media?
|
||||
media_attachments.any?
|
||||
|
@ -264,11 +269,11 @@ class Status < ApplicationRecord
|
|||
|
||||
around_create Mastodon::Snowflake::Callbacks
|
||||
|
||||
before_validation :prepare_contents, if: :local?
|
||||
before_validation :set_reblog
|
||||
before_validation :set_visibility
|
||||
before_validation :set_conversation
|
||||
before_validation :set_local
|
||||
before_validation :prepare_contents, on: :create, if: :local?
|
||||
before_validation :set_reblog, on: :create
|
||||
before_validation :set_visibility, on: :create
|
||||
before_validation :set_conversation, on: :create
|
||||
before_validation :set_local, on: :create
|
||||
|
||||
after_create :set_poll_id
|
||||
|
||||
|
@ -464,7 +469,7 @@ class Status < ApplicationRecord
|
|||
self.in_reply_to_account_id = carried_over_reply_to_account_id
|
||||
self.conversation_id = thread.conversation_id if conversation_id.nil?
|
||||
elsif conversation_id.nil?
|
||||
self.conversation = Conversation.new
|
||||
build_owned_conversation
|
||||
end
|
||||
end
|
||||
|
||||
|
|
25
app/models/status_capability_token.rb
Normal file
25
app/models/status_capability_token.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: status_capability_tokens
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# status_id :bigint(8)
|
||||
# token :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class StatusCapabilityToken < ApplicationRecord
|
||||
belongs_to :status
|
||||
|
||||
validates :token, presence: true
|
||||
|
||||
before_validation :generate_token, on: :create
|
||||
|
||||
private
|
||||
|
||||
def generate_token
|
||||
self.token = Doorkeeper::OAuth::Helpers::UniqueToken.generate
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue