<% new_message ||= false %> <% current_author = defined?(current_user) ? current_user : send(BulletTrain::Conversations.current_participant_helper_method) %> <% current_user_message = message.author == current_author %> <% avatar = capture do %> <% if message.membership %> <%= message.user_name %> <% elsif message.participant %>
<% if BulletTrain::Conversations.respond_to?(:participant_avatar_partial) && BulletTrain::Conversations.participant_avatar_partial %> <%= render BulletTrain::Conversations.participant_avatar_partial, participant: message.participant %> <% end %>
<% end %> <% end %> <% next_message ||= message.next_message %> <%# A message series is a series of messages by the same user, each message within 5 minutes of the previous message. It has nothing to do with replies and message threads %> <% next_message_in_series = (message.author == next_message&.author) && (message.created_at > next_message.created_at - 5.minutes) && (message.parent_message_id == next_message&.parent_message_id || message.id == next_message.parent_message_id)%> <% if next_message_in_series %> <% avatar = nil %> <% end %> <%# We set this to true when rendering the messages for the reply view. All messages in the thread are shown in order without any other messages from the conversation %> <% show_as_thread ||= false %> <%# placeholder messages are used when displaying a reply to a message that we need to show out of order with the rest %> <% placeholder_message ||= false %> <% if avatar.nil? %> <% avatar = capture do %>
<% end %> <% end %> <% rounding_modifier = message_corner_class(next_message_in_series, current_user_message) %> <% timestamp = next_message_in_series || show_as_thread ? '' : time_ago_in_words(message.created_at) + " ago" %> <% threaded_message = message.threaded? %> <% thread_started_by_current_user = message.thread_origin_user == current_author %> <% last_message_in_thread = !placeholder_message && threaded_message && (message.next_message.nil? || message.next_message.thread_id != message.thread_id)%> <% out_of_thread_message = !show_as_thread && threaded_message && message.reply? && message.previous_message != message.previous_message_in_thread %> <% has_replies = message.replies.any? && message.next_message == message.next_message_in_thread %> <% border_side = thread_started_by_current_user ? :left : :right %> <% show_borders = !show_as_thread && threaded_message %> <% if out_of_thread_message %> <%= render 'account/shared/message', message: message.thread_origin_message, next_message: message, placeholder_message: true, show_as_thread: show_as_thread %> <% end %>
data-reply-target="message" data-user="<%= message.author.label_string %>" data-message-id="<%= message.parent_message_id || message.id %>" data-action="mouseleave->reply#hideReplyButton" <% end %> >
<% if show_borders %> <% if (has_replies || placeholder_message) %> <%= message_thread_border(side: border_side, position: :start) unless show_as_thread %> <% end %> <% if message.reply? && ((current_user_message && thread_started_by_current_user) || (!current_user_message && !thread_started_by_current_user) ) %> <%= message_thread_border(side: border_side, position: (last_message_in_thread ? :end : :middle)) %> <% end %> <% end %>
<% if placeholder_message %>
<%= Nokogiri::HTML.fragment(trix_sanitize(message.body)).text.truncate(80) %>
<% else %>
<%= trix_sanitize(message.body) %>
<% end %>
<%= avatar %> <% unless placeholder_message || show_as_thread %>
<% end %>
<% if message.replies.any? && !show_as_thread %>
<% end %>
<% unless next_message_in_series || placeholder_message %>
<% if show_borders && !last_message_in_thread %> <% if (thread_started_by_current_user && current_user_message) || (!thread_started_by_current_user && !current_user_message) %> <%= message_thread_border(side: border_side, position: :middle) %> <% end %> <% end %>
<%= message.author.name %> <%= timestamp %>
<% end %> <% if message.replies.any? && false %>
<% message.replies.each do |reply| %>
<%= reply.membership.label_string %> reply:
<%= reply.body.html_safe %>
<% end %>
<% end %>