~cytrogen/masto-fe

ebfeaebedbc43526116fc5c0abe82f3d8745c927 — Claire 2 years ago ec91ea4
Fix /api/v1/conversations sometimes returning empty accounts (#25499)

M app/models/account_conversation.rb => app/models/account_conversation.rb +2 -8
@@ 32,14 32,8 @@ class AccountConversation < ApplicationRecord
  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

M spec/controllers/api/v1/conversations_controller_spec.rb => spec/controllers/api/v1/conversations_controller_spec.rb +4 -2
@@ 18,6 18,7 @@ RSpec.describe Api::V1::ConversationsController do

    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


@@ 33,7 34,8 @@ RSpec.describe Api::V1::ConversationsController do
    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


@@ 41,7 43,7 @@ RSpec.describe Api::V1::ConversationsController 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