forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base class for
api/v1/timelines/*
controllers (mastodon#27840)
- Loading branch information
1 parent
b2c5b20
commit 7e1a77e
Showing
5 changed files
with
52 additions
and
80 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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Timelines::BaseController < Api::BaseController | ||
after_action :insert_pagination_headers, unless: -> { @statuses.empty? } | ||
|
||
private | ||
|
||
def insert_pagination_headers | ||
set_pagination_headers(next_path, prev_path) | ||
end | ||
|
||
def pagination_max_id | ||
@statuses.last.id | ||
end | ||
|
||
def pagination_since_id | ||
@statuses.first.id | ||
end | ||
|
||
def next_path_params | ||
permitted_params.merge(max_id: pagination_max_id) | ||
end | ||
|
||
def prev_path_params | ||
permitted_params.merge(min_id: pagination_since_id) | ||
end | ||
|
||
def permitted_params | ||
params | ||
.slice(*self.class::PERMITTED_PARAMS) | ||
.permit(*self.class::PERMITTED_PARAMS) | ||
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