Skip to content
Merged
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
7 changes: 7 additions & 0 deletions app/assets/stylesheets/components/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@
flex-shrink: 0;
}

.settings-page .radio-group input[type="checkbox"] {
width: auto;
margin: var(--spacing-1) 0 0 0;
padding: 0;
flex-shrink: 0;
}

.settings-page .radio-group .radio-text {
flex: 1;
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def update
private

def preferences_params
params.require(:user).permit(:mention_restriction)
params.require(:user).permit(:mention_restriction, :open_threads_at_first_unread)
end
end
end
11 changes: 9 additions & 2 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1008,15 +1008,16 @@ def topics_page_cache_key

latest_topic = @topics.first
watermark = "#{latest_topic.last_activity.to_i}_#{latest_topic.id}"
[ "topics-index", watermark ]
[ "topics-index", watermark, topic_link_pref_cache_key ]
end

def topics_turbo_stream_cache_key
[
"topics-index-turbo",
params[:filter],
params[:team_id],
params[:cursor].presence || "root"
params[:cursor].presence || "root",
topic_link_pref_cache_key
]
end

Expand All @@ -1030,6 +1031,12 @@ def topics_turbo_stream_cache_fetch
Rails.cache.fetch(topics_turbo_stream_cache_key, expires_in: 10.minutes) { yield }
end

def topic_link_pref_cache_key
return "top" unless user_signed_in?

current_user.open_threads_at_first_unread? ? "first-unread" : "top"
end

def require_team_membership
team_id = params[:team_id].presence&.to_i
return unless team_id
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/topics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,12 @@ def team_readers_icon_html(topic:, readers:)
safe_join(parts)
end
end

def topic_title_link(topic)
if user_signed_in? && current_user.open_threads_at_first_unread?
topic_path(topic, anchor: "first-unread")
else
topic_path(topic)
end
end
end
9 changes: 9 additions & 0 deletions app/views/settings/profiles/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@
span.radio-text
strong Teammates only
span.radio-description Only users who share a team with you can @mention you
h2 Thread Navigation
p.settings-hint Control where thread titles open.
.form-group
.radio-group
label
= f.check_box :open_threads_at_first_unread
span.radio-text
strong Open at first unread
span.radio-description Jump to first unread message in the thread if the title was clicked
= f.submit "Save", class: "button-primary"
4 changes: 2 additions & 2 deletions app/views/topics/_status_cell.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ td.topic-title.status-border class=status_class id=dom_id(topic, "status_cell")
.topic-title-main
.topic-title-icons
== icons_html
= link_to topic.title, topic_path(topic), class: "topic-link"
= link_to topic.title, topic_title_link(topic), class: "topic-link"
.topic-title-mobile
= link_to topic.title, topic_path(topic), class: "topic-link"
= link_to topic.title, topic_title_link(topic), class: "topic-link"
- if creator || last_sender
.topic-byline
- if creator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddOpenThreadsAtFirstUnreadToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :open_threads_at_first_unread, :boolean, default: false, null: false
end
end