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.
Merge pull request #649 from kmycode/upstream-20240308
Upstream 20240308
- Loading branch information
Showing
237 changed files
with
6,222 additions
and
2,254 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
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
37 changes: 37 additions & 0 deletions
37
app/controllers/api/v1/notifications/policies_controller.rb
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Notifications::PoliciesController < Api::BaseController | ||
before_action -> { doorkeeper_authorize! :read, :'read:notifications' }, only: :show | ||
before_action -> { doorkeeper_authorize! :write, :'write:notifications' }, only: :update | ||
|
||
before_action :require_user! | ||
before_action :set_policy | ||
|
||
def show | ||
render json: @policy, serializer: REST::NotificationPolicySerializer | ||
end | ||
|
||
def update | ||
@policy.update!(resource_params) | ||
render json: @policy, serializer: REST::NotificationPolicySerializer | ||
end | ||
|
||
private | ||
|
||
def set_policy | ||
@policy = NotificationPolicy.find_or_initialize_by(account: current_account) | ||
|
||
with_read_replica do | ||
@policy.summarize! | ||
end | ||
end | ||
|
||
def resource_params | ||
params.permit( | ||
:filter_not_following, | ||
:filter_not_followers, | ||
:filter_new_accounts, | ||
:filter_private_mentions | ||
) | ||
end | ||
end |
79 changes: 79 additions & 0 deletions
79
app/controllers/api/v1/notifications/requests_controller.rb
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,79 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Notifications::RequestsController < Api::BaseController | ||
before_action -> { doorkeeper_authorize! :read, :'read:notifications' }, only: :index | ||
before_action -> { doorkeeper_authorize! :write, :'write:notifications' }, except: :index | ||
|
||
before_action :require_user! | ||
before_action :set_request, except: :index | ||
|
||
after_action :insert_pagination_headers, only: :index | ||
|
||
def index | ||
with_read_replica do | ||
@requests = load_requests | ||
@relationships = relationships | ||
end | ||
|
||
render json: @requests, each_serializer: REST::NotificationRequestSerializer, relationships: @relationships | ||
end | ||
|
||
def show | ||
render json: @request, serializer: REST::NotificationRequestSerializer | ||
end | ||
|
||
def accept | ||
AcceptNotificationRequestService.new.call(@request) | ||
render_empty | ||
end | ||
|
||
def dismiss | ||
@request.update!(dismissed: true) | ||
render_empty | ||
end | ||
|
||
private | ||
|
||
def load_requests | ||
requests = NotificationRequest.where(account: current_account).where(dismissed: truthy_param?(:dismissed) || false).includes(:last_status, from_account: [:account_stat, :user]).to_a_paginated_by_id( | ||
limit_param(DEFAULT_ACCOUNTS_LIMIT), | ||
params_slice(:max_id, :since_id, :min_id) | ||
) | ||
|
||
NotificationRequest.preload_cache_collection(requests) do |statuses| | ||
cache_collection(statuses, Status) | ||
end | ||
end | ||
|
||
def relationships | ||
StatusRelationshipsPresenter.new(@requests.map(&:last_status), current_user&.account_id) | ||
end | ||
|
||
def set_request | ||
@request = NotificationRequest.where(account: current_account).find(params[:id]) | ||
end | ||
|
||
def insert_pagination_headers | ||
set_pagination_headers(next_path, prev_path) | ||
end | ||
|
||
def next_path | ||
api_v1_notifications_requests_url pagination_params(max_id: pagination_max_id) unless @requests.empty? | ||
end | ||
|
||
def prev_path | ||
api_v1_notifications_requests_url pagination_params(min_id: pagination_since_id) unless @requests.empty? | ||
end | ||
|
||
def pagination_max_id | ||
@requests.last.id | ||
end | ||
|
||
def pagination_since_id | ||
@requests.first.id | ||
end | ||
|
||
def pagination_params(core_params) | ||
params.slice(:dismissed).permit(:dismissed).merge(core_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
Oops, something went wrong.