From 7055bc7cfdfb3c35bee3a5ec0f0478d80902c3c1 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 12 Feb 2024 16:23:30 +0100 Subject: [PATCH] Fix faulty file type determination logic - Previously we assumed that all files attached to a message were the same mime/content type. For some messengers, grouped files are received as one message and can have different mime/content types. We now check if any files attached to a message are of a certain type and then display all these file types correctly. --- .../chat_message/chat_message.html.erb | 40 ++++++++++--------- app/components/chat_message/chat_message.rb | 18 ++++++--- .../chat_message_audio.html.erb | 10 +++-- .../chat_message_audio/chat_message_audio.rb | 6 +-- spec/components/chat_message_voice_spec.rb | 4 +- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/app/components/chat_message/chat_message.html.erb b/app/components/chat_message/chat_message.html.erb index d6771a947..e8e938daa 100644 --- a/app/components/chat_message/chat_message.html.erb +++ b/app/components/chat_message/chat_message.html.erb @@ -59,34 +59,36 @@ <% end %> <% end %> - <% if image? %> - <% if message.text.blank? %> + <% unless files.empty? %> + <% if image? %> + <% if message.text.blank? %> +
+ <% if message.sender %> + <%= c 'avatar', record: message.sender, style: :small, class: "ChatMessage-avatar" %> + <% else %> + <%= c 'avatar', style: :small, class: "ChatMessage-avatar" %> + <% end %> + <%= c 'chat_message_photos', photos: image_files %> +
+ <% else %> + <%= c 'chat_message_photos', photos: image_files %> + <% end %> + <% end %> + + <% if audio? %>
<% if message.sender %> <%= c 'avatar', record: message.sender, style: :small, class: "ChatMessage-avatar" %> <% else %> <%= c 'avatar', style: :small, class: "ChatMessage-avatar" %> <% end %> - <%= c 'chat_message_photos', photos: files %> + <%= c 'chat_message_audio', audios: audio_files %>
- <% else %> - <%= c 'chat_message_photos', photos: files %> <% end %> - <% end %> - - <% if audio? %> -
- <% if message.sender %> - <%= c 'avatar', record: message.sender, style: :small, class: "ChatMessage-avatar" %> - <% else %> - <%= c 'avatar', style: :small, class: "ChatMessage-avatar" %> - <% end %> - <%= c 'chat_message_audio', audio: audio %> -
- <% end %> - <% if video? %> - <%= c 'chat_message_video', videos: files %> + <% if video? %> + <%= c 'chat_message_video', videos: video_files %> + <% end %> <% end %>