Fix /api/v1/conversations sometimes returning empty accounts (#25499)
parent
036ac5b5c9
commit
4c6c790f80
|
@ -31,14 +31,8 @@ class AccountConversation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def participant_accounts
|
def participant_accounts
|
||||||
@participant_accounts ||= begin
|
@participant_accounts ||= Account.where(id: participant_account_ids).to_a
|
||||||
if participant_account_ids.empty?
|
@participant_accounts.presence || [account]
|
||||||
[account]
|
|
||||||
else
|
|
||||||
participants = Account.where(id: participant_account_ids).to_a
|
|
||||||
participants.empty? ? [account] : participants
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
|
@ -16,6 +16,7 @@ RSpec.describe Api::V1::ConversationsController, type: :controller do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct')
|
PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct')
|
||||||
|
PostStatusService.new.call(user.account, text: 'Hey, nobody here', visibility: 'direct')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
|
@ -31,7 +32,8 @@ RSpec.describe Api::V1::ConversationsController, type: :controller do
|
||||||
it 'returns conversations' do
|
it 'returns conversations' do
|
||||||
get :index
|
get :index
|
||||||
json = body_as_json
|
json = body_as_json
|
||||||
expect(json.size).to eq 1
|
expect(json.size).to eq 2
|
||||||
|
expect(json[0][:accounts].size).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with since_id' do
|
context 'with since_id' do
|
||||||
|
@ -39,7 +41,7 @@ RSpec.describe Api::V1::ConversationsController, type: :controller do
|
||||||
it 'returns conversations' do
|
it 'returns conversations' do
|
||||||
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
|
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
|
||||||
json = body_as_json
|
json = body_as_json
|
||||||
expect(json.size).to eq 1
|
expect(json.size).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in New Issue