Skip to content

Commit 01dee86

Browse files
committed
added profile setting to configre thread title click behavior - jump to first unread
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent addfecb commit 01dee86

7 files changed

Lines changed: 43 additions & 5 deletions

File tree

app/assets/stylesheets/components/settings.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,13 @@
444444
flex-shrink: 0;
445445
}
446446

447+
.settings-page .radio-group input[type="checkbox"] {
448+
width: auto;
449+
margin: var(--spacing-1) 0 0 0;
450+
padding: 0;
451+
flex-shrink: 0;
452+
}
453+
447454
.settings-page .radio-group .radio-text {
448455
flex: 1;
449456
}

app/controllers/settings/preferences_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def update
1313
private
1414

1515
def preferences_params
16-
params.require(:user).permit(:mention_restriction)
16+
params.require(:user).permit(:mention_restriction, :open_threads_at_first_unread)
1717
end
1818
end
1919
end

app/controllers/topics_controller.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,15 +1008,16 @@ def topics_page_cache_key
10081008

10091009
latest_topic = @topics.first
10101010
watermark = "#{latest_topic.last_activity.to_i}_#{latest_topic.id}"
1011-
[ "topics-index", watermark ]
1011+
["topics-index", watermark, topic_link_pref_cache_key]
10121012
end
10131013

10141014
def topics_turbo_stream_cache_key
10151015
[
10161016
"topics-index-turbo",
10171017
params[:filter],
10181018
params[:team_id],
1019-
params[:cursor].presence || "root"
1019+
params[:cursor].presence || "root",
1020+
topic_link_pref_cache_key
10201021
]
10211022
end
10221023

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

1034+
def topic_link_pref_cache_key
1035+
return "top" unless user_signed_in?
1036+
1037+
current_user.open_threads_at_first_unread? ? "first-unread" : "top"
1038+
end
1039+
10331040
def require_team_membership
10341041
team_id = params[:team_id].presence&.to_i
10351042
return unless team_id

app/helpers/topics_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,12 @@ def team_readers_icon_html(topic:, readers:)
226226
safe_join(parts)
227227
end
228228
end
229+
230+
def topic_title_link(topic)
231+
if user_signed_in? && current_user.open_threads_at_first_unread?
232+
topic_path(topic, anchor: "first-unread")
233+
else
234+
topic_path(topic)
235+
end
236+
end
229237
end

app/views/settings/profiles/show.html.slim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,13 @@
4040
span.radio-text
4141
strong Teammates only
4242
span.radio-description Only users who share a team with you can @mention you
43+
h2 Thread Navigation
44+
p.settings-hint Control where thread titles open.
45+
.form-group
46+
.radio-group
47+
label
48+
= f.check_box :open_threads_at_first_unread
49+
span.radio-text
50+
strong Open at first unread
51+
span.radio-description Jump to first unread message in the thread if the title was clicked
4352
= f.submit "Save", class: "button-primary"

app/views/topics/_status_cell.html.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ td.topic-title.status-border class=status_class id=dom_id(topic, "status_cell")
2727
.topic-title-main
2828
.topic-title-icons
2929
== icons_html
30-
= link_to topic.title, topic_path(topic), class: "topic-link"
30+
= link_to topic.title, topic_title_link(topic), class: "topic-link"
3131
.topic-title-mobile
32-
= link_to topic.title, topic_path(topic), class: "topic-link"
32+
= link_to topic.title, topic_title_link(topic), class: "topic-link"
3333
- if creator || last_sender
3434
.topic-byline
3535
- if creator
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddOpenThreadsAtFirstUnreadToUsers < ActiveRecord::Migration[7.1]
4+
def change
5+
add_column :users, :open_threads_at_first_unread, :boolean, default: false, null: false
6+
end
7+
end

0 commit comments

Comments
 (0)