Skip to content

Commit

Permalink
Fix /api/v1/conversations sometimes returning empty accounts (#25499)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Jul 6, 2023
1 parent 036ac5b commit 4c6c790
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 2 additions & 8 deletions app/models/account_conversation.rb
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions spec/controllers/api/v1/conversations_controller_spec.rb
Expand Up @@ -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
Expand All @@ -31,15 +32,16 @@
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
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
expect(json.size).to eq 2
end
end

Expand Down

0 comments on commit 4c6c790

Please sign in to comment.