Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def sound
end
end

def thread_has_unread_for?(user, thread)
return false unless thread.present?

membership = thread.memberships.active.visible.find_by(user: user)
return false unless membership

membership.unread?
end

private

def involve_mentionees_in_room(unread:)
Expand Down
3 changes: 2 additions & 1 deletion app/views/messages/_threads.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<% participants = User.where(id: participant_users).index_by(&:id) %>
<% ordered_participants = participant_users.map { |id| participants[id] }.compact %>
<% reply_count = thread.messages_count || thread.messages.active.count %>
<% has_unread = Current.user.present? && message.thread_has_unread_for?(Current.user, thread) %>

<%= link_to room_path(thread), class: "thread__link flex-inline align-center gap", data: { turbo_frame: "_top", updated_at: thread.last_active_at.iso8601 } do %>
<div class="thread__avatars flex-inline gap">
Expand All @@ -22,7 +23,7 @@
</div>
<%= pluralize(reply_count, 'reply', 'replies') %>
<% if reply_count > 0 %>
<span class="txt-muted">Last reply <%= local_datetime_tag thread.last_active_at, style: :relative %></span>
<span class="txt-muted" style="<%= 'font-weight: 800; color: var(--color-text);' if has_unread %>">Last reply <%= local_datetime_tag thread.last_active_at, style: :relative %></span>
<% end %>
<% end %>
<% end %>
Expand Down