From 2082d9ac9c6027bce55d8c943277cbe2bab52b2b Mon Sep 17 00:00:00 2001 From: dendianugerah Date: Thu, 16 Oct 2025 02:15:22 +0700 Subject: [PATCH] feat: add unread indicators to thread replies --- app/models/message.rb | 9 +++++++++ app/views/messages/_threads.html.erb | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/message.rb b/app/models/message.rb index d25721be..0366449d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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:) diff --git a/app/views/messages/_threads.html.erb b/app/views/messages/_threads.html.erb index 7900a85a..90527802 100644 --- a/app/views/messages/_threads.html.erb +++ b/app/views/messages/_threads.html.erb @@ -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 %>
@@ -22,7 +23,7 @@
<%= pluralize(reply_count, 'reply', 'replies') %> <% if reply_count > 0 %> - Last reply <%= local_datetime_tag thread.last_active_at, style: :relative %> + Last reply <%= local_datetime_tag thread.last_active_at, style: :relative %> <% end %> <% end %> <% end %>