diff --git a/app/controllers/api/v1/accounts/relationships_controller.rb b/app/controllers/api/v1/accounts/relationships_controller.rb index 1d3992a2..6325a2c6 100644 --- a/app/controllers/api/v1/accounts/relationships_controller.rb +++ b/app/controllers/api/v1/accounts/relationships_controller.rb @@ -4,21 +4,22 @@ class Api::V1::Accounts::RelationshipsController < Api::BaseController before_action -> { doorkeeper_authorize! :read, :'read:follows' } before_action :require_user! - def index + def relationships accounts = Account.where(id: account_ids).select('id') # .where doesn't guarantee that our results are in the same order # we requested them, so return the "right" order to the requestor. @accounts = accounts.index_by(&:id).values_at(*account_ids).compact - render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: relationships + render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: get_relationships end private - def relationships + def get_relationships AccountRelationshipsPresenter.new(@accounts, current_user.account_id) end def account_ids - Array(params[:id]).map(&:to_i) + the_take = current_user.staff? ? 100 : 25 + params[:accountIds].map(&:to_i).take(the_take) end end diff --git a/app/controllers/api/v1/groups/relationships_controller.rb b/app/controllers/api/v1/group_relationships_controller.rb similarity index 72% rename from app/controllers/api/v1/groups/relationships_controller.rb rename to app/controllers/api/v1/group_relationships_controller.rb index 3bbad6aa..47e56822 100644 --- a/app/controllers/api/v1/groups/relationships_controller.rb +++ b/app/controllers/api/v1/group_relationships_controller.rb @@ -1,24 +1,25 @@ # frozen_string_literal: true -class Api::V1::Groups::RelationshipsController < Api::BaseController +class Api::V1::GroupRelationshipsController < Api::BaseController before_action -> { doorkeeper_authorize! :read, :'read:groups' } before_action :require_user! - def index + def relationships groups = Group.where(id: group_ids, is_archived: false).select('id') # .where doesn't guarantee that our results are in the same order # we requested them, so return the "right" order to the requestor. @groups = groups.index_by(&:id).values_at(*group_ids).compact - render json: @groups, each_serializer: REST::GroupRelationshipSerializer, relationships: relationships + render json: @groups, each_serializer: REST::GroupRelationshipSerializer, relationships: get_relationships end private - def relationships + def get_relationships GroupRelationshipsPresenter.new(@groups, current_user.account_id) end def group_ids - Array(params[:id]).map(&:to_i) + the_take = current_user.staff? ? 100 : 25 + params[:groupIds].map(&:to_i).take(the_take) end end diff --git a/app/javascript/gabsocial/actions/accounts.js b/app/javascript/gabsocial/actions/accounts.js index 90a498a6..b02e857b 100644 --- a/app/javascript/gabsocial/actions/accounts.js +++ b/app/javascript/gabsocial/actions/accounts.js @@ -542,7 +542,9 @@ export const fetchRelationships = (accountIds) => (dispatch, getState) => { dispatch(fetchRelationshipsRequest(newAccountIds)) - api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then((response) => { + api(getState).post('/api/v1/accounts/relationships', { + accountIds: newAccountIds, + }).then((response) => { dispatch(fetchRelationshipsSuccess(response.data)) }).catch((error) => { dispatch(fetchRelationshipsFail(error)) diff --git a/app/javascript/gabsocial/actions/groups.js b/app/javascript/gabsocial/actions/groups.js index 87187dac..1b11e936 100644 --- a/app/javascript/gabsocial/actions/groups.js +++ b/app/javascript/gabsocial/actions/groups.js @@ -182,13 +182,18 @@ export const fetchGroupRelationships = (groupIds) => (dispatch, getState) => { if (!me || !Array.isArray(groupIds)) return const loadedRelationships = getState().get('group_relationships') - const newGroupIds = groupIds.filter((id) => loadedRelationships.get(id, null) === null) + let newGroupIds = groupIds.filter((id) => loadedRelationships.get(id, null) === null) if (newGroupIds.length === 0) return + // Unique + newGroupIds = Array.from(new Set(newGroupIds)) + dispatch(fetchGroupRelationshipsRequest(newGroupIds)) - api(getState).get(`/api/v1/groups/${newGroupIds[0]}/relationships?${newGroupIds.map(id => `id[]=${id}`).join('&')}`).then((response) => { + api(getState).post('/api/v1/group_relationships', { + groupIds: newGroupIds, + }).then((response) => { dispatch(fetchGroupRelationshipsSuccess(response.data)) }).catch((error) => { dispatch(fetchGroupRelationshipsFail(error)) diff --git a/config/routes.rb b/config/routes.rb index 3d954ffd..93e3957c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -320,7 +320,7 @@ Rails.application.routes.draw do patch :update_credentials, to: 'credentials#update' post :resend_email_confirmation, to: 'credentials#resend_email_confirmation' resource :search, only: :show, controller: :search - resources :relationships, only: :index + post :relationships, to: 'relationships#relationships' end resources :accounts, only: [:create, :show] do @@ -355,7 +355,6 @@ Rails.application.routes.draw do get '/category/:category', to: 'groups#by_category' get '/tag/:tag', to: 'groups#by_tag' - resources :relationships, only: :index, controller: 'groups/relationships' resource :accounts, only: [:show, :create, :update, :destroy], controller: 'groups/accounts' resource :removed_accounts, only: [:show, :create, :destroy], controller: 'groups/removed_accounts' resource :password, only: [:create], controller: 'groups/password' @@ -367,6 +366,8 @@ Rails.application.routes.draw do post :unpin, to: 'groups/pins#destroy' end + post :group_relationships, to: 'group_relationships#relationships' + resources :polls, only: [:create, :show] do resources :votes, only: :create, controller: 'polls/votes' end