refactor(voice): drop content_attributes.data from voice_call messages
Nothing reads it anymore — frontend uses message.call, CallMessageBuilder
uses call.message (the FK), and the jsonb fallback finder was dead code
(call.message_id is always linked immediately after message creation, in
the same transaction).
New voice_call messages are now created with blank content_attributes.
Existing rows keep their legacy payload; nothing reads it, so it's inert.
Safe to backfill with `Message.voice_calls.update_all(content_attributes: {})`
if you want a tidy table.
This commit is contained in:
@@ -8,26 +8,18 @@ class Voice::CallMessageBuilder
|
||||
end
|
||||
|
||||
def perform!
|
||||
find_message || create_message!
|
||||
call.message || create_message!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :call
|
||||
|
||||
def find_message
|
||||
return call.message if call.message_id.present?
|
||||
|
||||
call.conversation.messages.voice_calls
|
||||
.find_by("content_attributes -> 'data' ->> 'call_sid' = ?", call.provider_call_id)
|
||||
end
|
||||
|
||||
def create_message!
|
||||
params = {
|
||||
content: 'Voice Call',
|
||||
message_type: call.outgoing? ? 'outgoing' : 'incoming',
|
||||
content_type: 'voice_call',
|
||||
content_attributes: { 'data' => { 'call_sid' => call.provider_call_id } }
|
||||
content_type: 'voice_call'
|
||||
}
|
||||
Messages::MessageBuilder.new(sender, call.conversation, params).perform
|
||||
end
|
||||
|
||||
@@ -48,7 +48,6 @@ RSpec.describe Voice::InboundCallBuilder do
|
||||
expect(voice_message).to be_present
|
||||
expect(voice_message.message_type).to eq('incoming')
|
||||
expect(call.message_id).to eq(voice_message.id)
|
||||
expect(voice_message.content_attributes['data']['call_sid']).to eq(call_sid)
|
||||
expect(voice_message.call).to eq(call)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,6 @@ RSpec.describe Voice::OutboundCallBuilder do
|
||||
voice_message = call.conversation.messages.voice_calls.last
|
||||
expect(call.message_id).to eq(voice_message.id)
|
||||
expect(voice_message.message_type).to eq('outgoing')
|
||||
expect(voice_message.content_attributes['data']['call_sid']).to eq(call_sid)
|
||||
expect(voice_message.call).to eq(call)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user