From f386bc1a420831a0945e21b81dec832645749064 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 20 Jun 2023 18:32:26 +0200 Subject: [PATCH] Fix /api/v1/conversations sometimes returning empty accounts (#25499) --- app/models/account_conversation.rb | 10 ++-------- .../api/v1/conversations_controller_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/models/account_conversation.rb b/app/models/account_conversation.rb index 78cc05614cc6ed..38ee247cfdc206 100644 --- a/app/models/account_conversation.rb +++ b/app/models/account_conversation.rb @@ -31,14 +31,8 @@ def participant_account_ids=(arr) end def participant_accounts - @participant_accounts ||= begin - if participant_account_ids.empty? - [account] - else - participants = Account.where(id: participant_account_ids).to_a - participants.empty? ? [account] : participants - end - end + @participant_accounts ||= Account.where(id: participant_account_ids).to_a + @participant_accounts.presence || [account] end class << self diff --git a/spec/controllers/api/v1/conversations_controller_spec.rb b/spec/controllers/api/v1/conversations_controller_spec.rb index c5d604e053bb51..1ec26d52036fa6 100644 --- a/spec/controllers/api/v1/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/conversations_controller_spec.rb @@ -16,6 +16,7 @@ before do PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct') + PostStatusService.new.call(user.account, text: 'Hey, nobody here', visibility: 'direct') end it 'returns http success' do @@ -31,7 +32,8 @@ it 'returns conversations' do get :index 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 context 'with since_id' do @@ -39,7 +41,7 @@ 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 + expect(json.size).to eq 2 end end