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 %>