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
1 change: 1 addition & 0 deletions app/assets/stylesheets/application/utilities.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.txt-tight-lines { line-height: 1.2; }
.txt-normal { font-weight: 400; font-style: normal; }
.txt-medium { font-weight: 500; }
.fw-800 { font-weight: 800; }
.txt-nowrap { white-space: nowrap; }

.inline { display: inline }
Expand Down
35 changes: 35 additions & 0 deletions app/models/rooms/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,39 @@ def default_involvement(user: nil)
"invisible"
end
end

# Check if a user is participating in this thread
# A user participates if they:
# - Created the parent message (the original message being threaded)
# - Created the thread (first commenter)
# - Have a visible membership (not "invisible" involvement)
# - Were mentioned in the thread (which gives them "mentions" involvement)
def participating?(user)
return false unless user

user_id = user.id

# Parent message creator is always a participant
return true if parent_message&.creator_id == user_id

# Thread creator is always a participant
return true if creator_id == user_id

# Check if user has a visible membership (not "invisible")
membership = memberships.active.find_by(user_id: user_id)
return false unless membership

# User is participating if they have a visible involvement (not "invisible")
membership.involved_in_invisible? ? false : true
end

# Check if a participating user has unread messages in this thread
def unread_for_participating?(user)
return false unless user

membership = memberships.active.find_by(user_id: user.id)
return false unless membership

membership.unread?
end
end
5 changes: 4 additions & 1 deletion app/views/messages/_threads.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<% 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 %>
<% is_participating = thread.participating?(Current.user) %>
<% has_unread = is_participating && thread.unread_for_participating?(Current.user) %>

<%= 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 +24,8 @@
</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>
<% timestamp_class = has_unread ? "txt-primary fw-800" : "txt-muted" %>
<span class="<%= timestamp_class %>">Last reply <%= local_datetime_tag thread.last_active_at, style: :relative %></span>
<% end %>
<% end %>
<% end %>
Expand Down