Add REST API for managing and posting to circles
Circles are the conceptual opposite of lists. A list is a subdivision of your follows, a circle is a subdivision of your followers. Posting to a circle means making content available to only some of your followers. Circles have been internally supported in Mastodon for the purposes of federation since #8950, this adds the REST API necessary for making use of them in Mastodon itsef.
This commit is contained in:
parent
a29080256e
commit
6358072bc0
19 changed files with 353 additions and 4 deletions
22
app/models/circle.rb
Normal file
22
app/models/circle.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: circles
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8) not null
|
||||
# title :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class Circle < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
belongs_to :account
|
||||
|
||||
has_many :circle_accounts, inverse_of: :circle, dependent: :destroy
|
||||
has_many :accounts, through: :circle_accounts
|
||||
|
||||
validates :title, presence: true
|
||||
end
|
28
app/models/circle_account.rb
Normal file
28
app/models/circle_account.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: circle_accounts
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# circle_id :bigint(8) not null
|
||||
# account_id :bigint(8) not null
|
||||
# follow_id :bigint(8) not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class CircleAccount < ApplicationRecord
|
||||
belongs_to :circle
|
||||
belongs_to :account
|
||||
belongs_to :follow, optional: true
|
||||
|
||||
validates :account_id, uniqueness: { scope: :circle_id }
|
||||
|
||||
before_validation :set_follow
|
||||
|
||||
private
|
||||
|
||||
def set_follow
|
||||
self.follow = Follow.find_by!(target_account_id: circle.account_id, account_id: account.id)
|
||||
end
|
||||
end
|
|
@ -48,9 +48,12 @@ module AccountAssociations
|
|||
# Lists (that the account is on, not owned by the account)
|
||||
has_many :list_accounts, inverse_of: :account, dependent: :destroy
|
||||
has_many :lists, through: :list_accounts
|
||||
has_many :circle_accounts, inverse_of: :account, dependent: :destroy
|
||||
has_many :circles, through: :circle_accounts
|
||||
|
||||
# Lists (owned by the account)
|
||||
has_many :owned_lists, class_name: 'List', dependent: :destroy, inverse_of: :account
|
||||
has_many :owned_circles, class_name: 'Circle', dependent: :destroy, inverse_of: :account
|
||||
|
||||
# Account migrations
|
||||
belongs_to :moved_to_account, class_name: 'Account', optional: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue