Commiting
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::BaseController < ApplicationController
|
||||
DEFAULT_STATUSES_LIMIT = 18
|
||||
DEFAULT_ACCOUNTS_LIMIT = 40
|
||||
DEFAULT_STATUSES_LIMIT = 20
|
||||
DEFAULT_ACCOUNTS_LIMIT = 20
|
||||
|
||||
include RateLimitHeaders
|
||||
|
||||
@@ -82,8 +82,8 @@ class Api::BaseController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def render_empty
|
||||
render json: {}, status: 200
|
||||
def render_empty_success(message = nil)
|
||||
render json: { success: true, error: false, message: message }, status: 200
|
||||
end
|
||||
|
||||
def authorize_if_got_token!(*scopes)
|
||||
|
||||
@@ -27,7 +27,7 @@ class Api::V1::FiltersController < Api::BaseController
|
||||
|
||||
def destroy
|
||||
@filter.destroy!
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -14,12 +14,12 @@ class Api::V1::FollowRequestsController < Api::BaseController
|
||||
def authorize
|
||||
AuthorizeFollowService.new.call(account, current_account)
|
||||
NotifyService.new.call(current_account, Follow.find_by(account: account, target_account: current_account))
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def reject
|
||||
RejectFollowService.new.call(account, current_account)
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -19,21 +19,18 @@ class Api::V1::Groups::AccountsController < Api::BaseController
|
||||
def create
|
||||
authorize @group, :join?
|
||||
|
||||
if !@group.password.nil?
|
||||
if @group.has_password?
|
||||
# use the groups/password_controller to join group with password
|
||||
render json: { error: true, message: 'Unable to join group. Incorrect password.' }, status: 422
|
||||
end
|
||||
|
||||
if @group.is_private
|
||||
@group.join_requests << current_account
|
||||
else
|
||||
@group.accounts << current_account
|
||||
|
||||
if current_user.allows_group_in_home_feed?
|
||||
current_user.force_regeneration!
|
||||
if @group.is_private
|
||||
@group.join_requests << current_account
|
||||
else
|
||||
@group.accounts << current_account
|
||||
end
|
||||
end
|
||||
|
||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -41,7 +38,7 @@ class Api::V1::Groups::AccountsController < Api::BaseController
|
||||
|
||||
@account = @group.accounts.find(params[:account_id])
|
||||
GroupAccount.where(group: @group, account: @account).update(group_account_params)
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -51,9 +48,6 @@ class Api::V1::Groups::AccountsController < Api::BaseController
|
||||
else
|
||||
authorize @group, :leave?
|
||||
GroupAccount.where(group: @group, account_id: current_account.id).destroy_all
|
||||
if current_user.allows_group_in_home_feed?
|
||||
current_user.force_regeneration!
|
||||
end
|
||||
end
|
||||
|
||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||
|
||||
@@ -10,25 +10,29 @@ class Api::V1::Groups::PinsController < Api::BaseController
|
||||
|
||||
def create
|
||||
authorize @group, :update?
|
||||
|
||||
GroupPinnedStatus.create!(group: @group, status: @status)
|
||||
render json: @status, serializer: REST::StatusSerializer
|
||||
|
||||
pin = GroupPinnedStatus.find_by(group: @group, status: @status)
|
||||
if pin.nil?
|
||||
GroupPinnedStatus.create!(group: @group, status: @status)
|
||||
render json: @status, serializer: REST::StatusGroupPinnedSerializer, group_id: @group.id
|
||||
else
|
||||
return render json: { error: 'Status is already pinned to group' }, status: 500
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
# is status pinned by user of group?
|
||||
render json: @status, serializer: REST::StatusGroupPinnedSerializer, group_id: @group.id
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize @group, :update?
|
||||
|
||||
pin = GroupPinnedStatus.find_by(group: @group, status: @status)
|
||||
|
||||
if pin
|
||||
pin.destroy!
|
||||
end
|
||||
|
||||
render json: @status, serializer: REST::StatusSerializer
|
||||
render json: @status, serializer: REST::StatusGroupPinnedSerializer, group_id: @group.id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -23,7 +23,7 @@ class Api::V1::Groups::RemovedAccountsController < Api::BaseController
|
||||
@account = @group.accounts.find(params[:account_id])
|
||||
@group.removed_accounts << @account
|
||||
GroupAccount.where(group: @group, account: @account).destroy_all
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -31,7 +31,7 @@ class Api::V1::Groups::RemovedAccountsController < Api::BaseController
|
||||
|
||||
@account = @group.removed_accounts.find(params[:account_id])
|
||||
GroupRemovedAccount.where(group: @group, account: @account).destroy_all
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -16,12 +16,12 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
@groups = Group.where(id: @groupIds).limit(150).all
|
||||
when 'new'
|
||||
if !current_user
|
||||
render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
return render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
end
|
||||
@groups = Group.where(is_archived: false).limit(24).order('created_at DESC').all
|
||||
when 'member'
|
||||
if !current_user
|
||||
render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
return render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
end
|
||||
@groups = Group.joins(:group_accounts).where(is_archived: false, group_accounts: { account: current_account }).order('group_accounts.id DESC').all
|
||||
when 'admin'
|
||||
@@ -36,7 +36,7 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
|
||||
def by_category
|
||||
if !current_user
|
||||
render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
return render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
end
|
||||
|
||||
@groupCategory = nil
|
||||
@@ -54,7 +54,7 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
|
||||
def by_tag
|
||||
if !current_user
|
||||
render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
return render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
end
|
||||
|
||||
@groups = []
|
||||
@@ -94,7 +94,7 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
|
||||
@group.is_archived = true
|
||||
@group.save!
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def destroy_status
|
||||
@@ -102,7 +102,7 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
|
||||
status = Status.find(params[:status_id])
|
||||
GroupUnlinkStatusService.new.call(current_account, @group, status)
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def approve_status
|
||||
@@ -110,7 +110,7 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
|
||||
status = Status.find(params[:status_id])
|
||||
GroupApproveStatusService.new.call(current_account, @group, status)
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -21,12 +21,12 @@ class Api::V1::Lists::AccountsController < Api::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def destroy
|
||||
ListAccount.where(list: @list, account_id: account_ids).destroy_all
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -28,7 +28,7 @@ class Api::V1::ListsController < Api::BaseController
|
||||
|
||||
def destroy
|
||||
@list.destroy!
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
0
app/controllers/api/v1/messages/chats_controller.rb
Normal file
0
app/controllers/api/v1/messages/chats_controller.rb
Normal file
59
app/controllers/api/v1/messages_controller.rb
Normal file
59
app/controllers/api/v1/messages_controller.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::AccountsController < Api::BaseController
|
||||
before_action -> { authorize_if_got_token! :read, :'read:accounts' }, except: [:create, :follow, :unfollow, :block, :unblock, :mute, :unmute]
|
||||
before_action -> { doorkeeper_authorize! :follow, :'write:follows' }, only: [:follow, :unfollow]
|
||||
before_action -> { doorkeeper_authorize! :follow, :'write:mutes' }, only: [:mute, :unmute]
|
||||
before_action -> { doorkeeper_authorize! :follow, :'write:blocks' }, only: [:block, :unblock]
|
||||
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create]
|
||||
|
||||
before_action :require_user!, except: [:show, :create]
|
||||
before_action :set_account, except: [:create]
|
||||
before_action :check_account_suspension, only: [:show]
|
||||
|
||||
def show
|
||||
#
|
||||
end
|
||||
|
||||
def create
|
||||
#
|
||||
end
|
||||
|
||||
def block
|
||||
BlockMessengerService.new.call(current_user.account, @account)
|
||||
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
||||
end
|
||||
|
||||
def mute
|
||||
MuteMessengerService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications))
|
||||
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
||||
end
|
||||
|
||||
def unblock
|
||||
UnblockMessengerService.new.call(current_user.account, @account)
|
||||
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
||||
end
|
||||
|
||||
def unmute
|
||||
UnmuteMessegerService.new.call(current_user.account, @account)
|
||||
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
@account = Account.find(params[:id])
|
||||
end
|
||||
|
||||
def relationships(**options)
|
||||
AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
|
||||
end
|
||||
|
||||
def check_account_suspension
|
||||
gone if @account.suspended?
|
||||
end
|
||||
|
||||
def account_params
|
||||
params.permit(:username, :email, :password, :agreement, :locale)
|
||||
end
|
||||
end
|
||||
@@ -21,12 +21,12 @@ class Api::V1::NotificationsController < Api::BaseController
|
||||
|
||||
def clear
|
||||
current_account.notifications.delete_all
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
def mark_read
|
||||
current_account.notifications.find(params[:id]).mark_read!
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -26,7 +26,7 @@ class Api::V1::ScheduledStatusesController < Api::BaseController
|
||||
|
||||
def destroy
|
||||
@status.destroy!
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -9,14 +9,15 @@ class Api::V1::Statuses::BookmarksController < Api::BaseController
|
||||
def create
|
||||
if current_user.account.is_pro
|
||||
@status = bookmarked_status
|
||||
render json: @status, serializer: REST::StatusSerializer
|
||||
render json: @status, serializer: REST::StatusBookmarkedSerializer
|
||||
else
|
||||
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
# is status bookmarked by user?
|
||||
@status = requested_status
|
||||
render json: @status, serializer: REST::StatusBookmarkedSerializer
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -27,7 +28,7 @@ class Api::V1::Statuses::BookmarksController < Api::BaseController
|
||||
bookmark = StatusBookmark.find_by!(account: current_user.account, status: @status)
|
||||
bookmark.destroy!
|
||||
|
||||
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, bookmarks_map: @bookmarks_map)
|
||||
render json: @status, serializer: REST::StatusBookmarkedSerializer
|
||||
else
|
||||
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController
|
||||
|
||||
def create
|
||||
@status = favourited_status
|
||||
puts "tilly -- status: " + @status.inspect
|
||||
render json: @status, serializer: REST::StatusStatSerializer
|
||||
end
|
||||
|
||||
@@ -18,7 +17,10 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController
|
||||
|
||||
UnfavouriteWorker.perform_async(current_user.account_id, @status.id)
|
||||
|
||||
render json: @status, serializer: REST::StatusStatSerializer, unfavourite: true, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, favourites_map: @favourites_map)
|
||||
render json: @status,
|
||||
serializer: REST::StatusStatSerializer,
|
||||
unfavourite: true,
|
||||
relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, favourites_map: @favourites_map)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -8,12 +8,17 @@ class Api::V1::Statuses::PinsController < Api::BaseController
|
||||
before_action :set_status
|
||||
|
||||
def create
|
||||
StatusPin.create!(account: current_account, status: @status)
|
||||
render json: @status, serializer: REST::StatusSerializer
|
||||
pin = StatusPin.find_by(account: current_account, status: @status)
|
||||
if pin.nil?
|
||||
StatusPin.create!(account: current_account, status: @status)
|
||||
render json: @status, serializer: REST::StatusPinnedSerializer
|
||||
else
|
||||
return render json: { error: 'Status is already pinned' }, status: 500
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
# is status pinned by user?
|
||||
render json: @status, serializer: REST::StatusPinnedSerializer
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -23,7 +28,7 @@ class Api::V1::Statuses::PinsController < Api::BaseController
|
||||
pin.destroy!
|
||||
end
|
||||
|
||||
render json: @status, serializer: REST::StatusSerializer
|
||||
render json: @status, serializer: REST::StatusPinnedSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::Statuses::RepostedByAccountsController < Api::BaseController
|
||||
class Api::V1::Statuses::RebloggedByAccountsController < Api::BaseController
|
||||
include Authorization
|
||||
|
||||
before_action -> { authorize_if_got_token! :read, :'read:accounts' }
|
||||
@@ -36,13 +36,13 @@ class Api::V1::Statuses::RepostedByAccountsController < Api::BaseController
|
||||
|
||||
def next_path
|
||||
if records_continue?
|
||||
api_v1_status_reposted_by_index_url pagination_params(max_id: pagination_max_id)
|
||||
api_v1_status_reblogged_by_index_url pagination_params(max_id: pagination_max_id)
|
||||
end
|
||||
end
|
||||
|
||||
def prev_path
|
||||
unless @accounts.empty?
|
||||
api_v1_status_reposted_by_index_url pagination_params(since_id: pagination_since_id)
|
||||
api_v1_status_reblogged_by_index_url pagination_params(since_id: pagination_since_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,22 +7,25 @@ class Api::V1::Statuses::ReblogsController < Api::BaseController
|
||||
before_action :require_user!
|
||||
|
||||
def create
|
||||
if !current_user.account.local? || !status_for_reblog.local
|
||||
return render json: { error: 'Invalid action' }, status: 422
|
||||
end
|
||||
|
||||
@status = ReblogService.new.call(current_user.account, status_for_reblog, reblog_params)
|
||||
render json: @status, serializer: REST::StatusSerializer
|
||||
@relog = status_for_reblog
|
||||
ReblogService.new.call(current_user.account, @relog, reblog_params)
|
||||
render json: @relog, serializer: REST::StatusStatSerializer
|
||||
end
|
||||
|
||||
def destroy
|
||||
@status = status_for_destroy.reblog
|
||||
@reblogs_map = { @status.id => false }
|
||||
@my_relog = status_for_destroy
|
||||
@original_status = @my_relog.reblog
|
||||
|
||||
authorize status_for_destroy, :unreblog?
|
||||
RemovalWorker.perform_async(status_for_destroy.id)
|
||||
authorize @my_relog, :unreblog?
|
||||
|
||||
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, reblogs_map: @reblogs_map)
|
||||
RemovalWorker.perform_async(@my_relog.id)
|
||||
|
||||
@reblogs_map = { @original_status.id => false }
|
||||
|
||||
render json: @original_status,
|
||||
serializer: REST::StatusStatSerializer,
|
||||
unreblog: true,
|
||||
relationships: StatusRelationshipsPresenter.new([@original_status], current_user&.account_id, reblogs_map: @reblogs_map)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -23,7 +23,7 @@ class Api::V1::SuggestionsController < Api::BaseController
|
||||
|
||||
def destroy
|
||||
PotentialFriendshipTracker.remove(current_account.id, params[:id])
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ class Api::Web::SettingsController < Api::Web::BaseController
|
||||
setting.data = params[:data]
|
||||
setting.save!
|
||||
|
||||
render_empty
|
||||
render_empty_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user