mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-10 01:25:15 +00:00
Fix ArgumentError when loading newer Private Mentions (#25399)
This commit is contained in:
parent
bca649ba79
commit
ec59166844
|
@ -45,7 +45,7 @@ class Api::V1::ConversationsController < Api::BaseController
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.to_a_paginated_by_id(limit_param(LIMIT), **params_slice(:max_id, :since_id, :min_id))
|
.to_a_paginated_by_id(limit_param(LIMIT), params_slice(:max_id, :since_id, :min_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert_pagination_headers
|
def insert_pagination_headers
|
||||||
|
|
|
@ -43,23 +43,22 @@ class AccountConversation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def to_a_paginated_by_id(limit, min_id: nil, max_id: nil, since_id: nil, preload_participants: true)
|
def to_a_paginated_by_id(limit, options = {})
|
||||||
array = begin
|
array = begin
|
||||||
if min_id
|
if options[:min_id]
|
||||||
paginate_by_min_id(limit, min_id, max_id).reverse
|
paginate_by_min_id(limit, options[:min_id], options[:max_id]).reverse
|
||||||
else
|
else
|
||||||
paginate_by_max_id(limit, max_id, since_id).to_a
|
paginate_by_max_id(limit, options[:max_id], options[:since_id]).to_a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if preload_participants
|
# Preload participants
|
||||||
participant_ids = array.flat_map(&:participant_account_ids)
|
participant_ids = array.flat_map(&:participant_account_ids)
|
||||||
accounts_by_id = Account.where(id: participant_ids).index_by(&:id)
|
accounts_by_id = Account.where(id: participant_ids).index_by(&:id)
|
||||||
|
|
||||||
array.each do |conversation|
|
array.each do |conversation|
|
||||||
conversation.participant_accounts = conversation.participant_account_ids.filter_map { |id| accounts_by_id[id] }
|
conversation.participant_accounts = conversation.participant_account_ids.filter_map { |id| accounts_by_id[id] }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
array
|
array
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,5 +35,23 @@ RSpec.describe Api::V1::ConversationsController do
|
||||||
json = body_as_json
|
json = body_as_json
|
||||||
expect(json.size).to eq 1
|
expect(json.size).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with since_id' do
|
||||||
|
context 'when requesting old posts' do
|
||||||
|
it 'returns conversations' do
|
||||||
|
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
|
||||||
|
json = body_as_json
|
||||||
|
expect(json.size).to eq 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when requesting posts in the future' do
|
||||||
|
it 'returns no conversation' do
|
||||||
|
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.from_now, with_random: false) }
|
||||||
|
json = body_as_json
|
||||||
|
expect(json.size).to eq 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue