fix: issue with is_recorded_audio type
This commit is contained in:
parent
548c0351ec
commit
37c5d31718
@ -79,12 +79,20 @@ class Messages::MessageBuilder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_metadata(attachment)
|
def process_metadata(attachment) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
||||||
# NOTE: `is_recorded_audio` can be either a boolean or an array of file names.
|
# NOTE: `is_recorded_audio` can be either a boolean or an array of file names.
|
||||||
return unless @is_recorded_audio
|
return unless @is_recorded_audio
|
||||||
return { is_recorded_audio: true } if @is_recorded_audio == true
|
return { is_recorded_audio: true } if @is_recorded_audio == true
|
||||||
|
|
||||||
{ is_recorded_audio: true } if @is_recorded_audio.is_a?(Array) && attachment.original_filename.in?(@is_recorded_audio)
|
return { is_recorded_audio: true } if @is_recorded_audio.is_a?(Array) && attachment.original_filename.in?(@is_recorded_audio)
|
||||||
|
|
||||||
|
# FIXME: Remove backwards compatibility with old format.
|
||||||
|
if @is_recorded_audio.is_a?(String)
|
||||||
|
parsed = JSON.parse(@is_recorded_audio)
|
||||||
|
{ is_recorded_audio: true } if parsed.is_a?(Array) && attachment.original_filename.in?(parsed)
|
||||||
|
end
|
||||||
|
rescue JSON::ParserError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_emails
|
def process_emails
|
||||||
|
|||||||
@ -23,7 +23,9 @@ export const buildCreatePayload = ({
|
|||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
payload.append('attachments[]', file);
|
payload.append('attachments[]', file);
|
||||||
});
|
});
|
||||||
payload.append('is_recorded_audio', JSON.stringify(isRecordedAudio));
|
isRecordedAudio?.forEach(filename => {
|
||||||
|
payload.append('is_recorded_audio[]', filename);
|
||||||
|
});
|
||||||
payload.append('private', isPrivate);
|
payload.append('private', isPrivate);
|
||||||
payload.append('echo_id', echoId);
|
payload.append('echo_id', echoId);
|
||||||
payload.append('cc_emails', ccEmails);
|
payload.append('cc_emails', ccEmails);
|
||||||
|
|||||||
@ -135,6 +135,14 @@ describe Messages::MessageBuilder do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'creates attachment with is_recorded_audio metadata' do
|
it 'creates attachment with is_recorded_audio metadata' do
|
||||||
|
params[:is_recorded_audio] = true
|
||||||
|
|
||||||
|
message = message_builder
|
||||||
|
|
||||||
|
expect(message.attachments.first.meta).to eq({ 'is_recorded_audio' => true })
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates attachment with is_recorded_audio metadata when param is array of filenames' do
|
||||||
params[:is_recorded_audio] = ['avatar.png']
|
params[:is_recorded_audio] = ['avatar.png']
|
||||||
|
|
||||||
message = message_builder
|
message = message_builder
|
||||||
@ -142,6 +150,14 @@ describe Messages::MessageBuilder do
|
|||||||
expect(message.attachments.first.meta).to eq({ 'is_recorded_audio' => true })
|
expect(message.attachments.first.meta).to eq({ 'is_recorded_audio' => true })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates attachment with is_recorded_audio metadata when param is string with array' do
|
||||||
|
params[:is_recorded_audio] = '["avatar.png"]'
|
||||||
|
|
||||||
|
message = message_builder
|
||||||
|
|
||||||
|
expect(message.attachments.first.meta).to eq({ 'is_recorded_audio' => true })
|
||||||
|
end
|
||||||
|
|
||||||
context 'when DIRECT_UPLOAD_ENABLED' do
|
context 'when DIRECT_UPLOAD_ENABLED' do
|
||||||
let(:params) do
|
let(:params) do
|
||||||
ActionController::Parameters.new({
|
ActionController::Parameters.new({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user