forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp notification policy options (mastodon#31343)
- Loading branch information
1 parent
e29c401
commit cbdd8ed
Showing
16 changed files
with
442 additions
and
109 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
38 changes: 38 additions & 0 deletions
38
app/controllers/api/v2/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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V2::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( | ||
:for_not_following, | ||
:for_not_followers, | ||
:for_new_accounts, | ||
:for_private_mentions, | ||
:for_limited_accounts | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class REST::V1::NotificationPolicySerializer < ActiveModel::Serializer | ||
attributes :filter_not_following, | ||
:filter_not_followers, | ||
:filter_new_accounts, | ||
:filter_private_mentions, | ||
:summary | ||
|
||
def summary | ||
{ | ||
pending_requests_count: object.pending_requests_count.to_i, | ||
pending_notifications_count: object.pending_notifications_count.to_i, | ||
} | ||
end | ||
|
||
def filter_not_following | ||
!object.accept_not_following? | ||
end | ||
|
||
def filter_not_followers | ||
!object.accept_not_followers? | ||
end | ||
|
||
def filter_new_accounts | ||
!object.accept_new_accounts? | ||
end | ||
|
||
def filter_private_mentions | ||
!object.accept_private_mentions? | ||
end | ||
end |
Oops, something went wrong.