forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wip: Add circle history page and record circle posts
- Loading branch information
Showing
14 changed files
with
155 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Circles::StatusesController < Api::BaseController | ||
before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:show] | ||
before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:show] | ||
|
||
before_action :require_user! | ||
before_action :set_circle | ||
|
||
after_action :insert_pagination_headers, only: :show | ||
|
||
def show | ||
@statuses = load_statuses | ||
render json: @statuses, each_serializer: REST::StatusSerializer | ||
end | ||
|
||
private | ||
|
||
def set_circle | ||
@circle = current_account.circles.find(params[:circle_id]) | ||
end | ||
|
||
def load_statuses | ||
if unlimited? | ||
@circle.statuses.includes(:status_stat).all | ||
else | ||
@circle.statuses.includes(:status_stat).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id]) | ||
end | ||
end | ||
|
||
def insert_pagination_headers | ||
set_pagination_headers(next_path, prev_path) | ||
end | ||
|
||
def next_path | ||
return if unlimited? | ||
|
||
api_v1_circle_statuses_url pagination_params(max_id: pagination_max_id) if records_continue? | ||
end | ||
|
||
def prev_path | ||
return if unlimited? | ||
|
||
api_v1_circle_statuses_url pagination_params(since_id: pagination_since_id) unless @statuses.empty? | ||
end | ||
|
||
def pagination_max_id | ||
@statuses.last.id | ||
end | ||
|
||
def pagination_since_id | ||
@statuses.first.id | ||
end | ||
|
||
def records_continue? | ||
@statuses.size == limit_param(DEFAULT_STATUSES_LIMIT) | ||
end | ||
|
||
def pagination_params(core_params) | ||
params.slice(:limit).permit(:limit).merge(core_params) | ||
end | ||
|
||
def unlimited? | ||
params[:limit] == '0' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: circle_statuses | ||
# | ||
# id :bigint(8) not null, primary key | ||
# circle_id :bigint(8) | ||
# status_id :bigint(8) not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class CircleStatus < ApplicationRecord | ||
belongs_to :circle | ||
belongs_to :status | ||
|
||
validates :status, uniqueness: { scope: :circle } | ||
validate :account_own_status | ||
|
||
private | ||
|
||
def account_own_status | ||
errors.add(:status_id, :invalid) unless status.account_id == circle.account_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require Rails.root.join('lib', 'mastodon', 'migration_helpers') | ||
|
||
class CreateCircleStatuses < ActiveRecord::Migration[7.0] | ||
include Mastodon::MigrationHelpers | ||
|
||
disable_ddl_transaction! | ||
|
||
def change | ||
safety_assured do | ||
create_table :circle_statuses do |t| | ||
t.belongs_to :circle, null: true, foreign_key: { on_delete: :cascade } | ||
t.belongs_to :status, null: false, foreign_key: { on_delete: :cascade } | ||
t.datetime :created_at, null: false | ||
t.datetime :updated_at, null: false | ||
end | ||
|
||
add_index :circle_statuses, [:circle_id, :status_id], unique: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters