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.
Add circle posts history support (#18)
* Wip: make web backend * Wip: keep statuses if edit circle * Wip: Add circle history page and record circle posts * Add circle post to history in web ui when post * Add test
- Loading branch information
Showing
19 changed files
with
544 additions
and
15 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
Oops, something went wrong.