forked from mstdn/mastodon
cdb101340a
* Add keyword filtering GET|POST /api/v1/filters GET|PUT|DELETE /api/v1/filters/:id - Irreversible filters can drop toots from home or notifications - Other filters can hide toots through the client app - Filters use a phrase valid in particular contexts, expiration * Make sure expired filters don't get applied client-side * Add missing API methods * Remove "regex filter" from column settings * Add tests * Add test for FeedManager * Add CustomFilter test * Add UI for managing filters * Add streaming API event to allow syncing filters * Fix tests
49 lines
1.1 KiB
Ruby
49 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::FiltersController < Api::BaseController
|
|
before_action -> { doorkeeper_authorize! :read }, only: [:index, :show]
|
|
before_action -> { doorkeeper_authorize! :write }, except: [:index, :show]
|
|
before_action :require_user!
|
|
before_action :set_filters, only: :index
|
|
before_action :set_filter, only: [:show, :update, :destroy]
|
|
|
|
respond_to :json
|
|
|
|
def index
|
|
render json: @filters, each_serializer: REST::FilterSerializer
|
|
end
|
|
|
|
def create
|
|
@filter = current_account.custom_filters.create!(resource_params)
|
|
render json: @filter, serializer: REST::FilterSerializer
|
|
end
|
|
|
|
def show
|
|
render json: @filter, serializer: REST::FilterSerializer
|
|
end
|
|
|
|
def update
|
|
@filter.update!(resource_params)
|
|
render json: @filter, serializer: REST::FilterSerializer
|
|
end
|
|
|
|
def destroy
|
|
@filter.destroy!
|
|
render_empty
|
|
end
|
|
|
|
private
|
|
|
|
def set_filters
|
|
@filters = current_account.custom_filters
|
|
end
|
|
|
|
def set_filter
|
|
@filter = current_account.custom_filters.find(params[:id])
|
|
end
|
|
|
|
def resource_params
|
|
params.permit(:phrase, :expires_at, :irreversible, context: [])
|
|
end
|
|
end
|