Skip to content

Commit 22b823b

Browse files
committed
Create detached comment threads
1 parent c3d481a commit 22b823b

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

app/helpers/categories_helper.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ def active?(category)
77

88
def expandable?
99
(defined?(@category) && !@category.nil? && !@category.id.nil? && !current_page?(new_category_url)) ||
10-
(defined?(@post) && !@post.category.nil?) ||
11-
(defined?(@question) && !@question.category.nil?) ||
12-
(defined?(@article) && !@article.category.nil?)
10+
(defined?(@post) && !@post&.category.nil?) ||
11+
(defined?(@question) && !@question&.category.nil?) ||
12+
(defined?(@article) && !@article&.category.nil?)
1313
end
1414

1515
def current_category
1616
@current_category ||= if defined?(@category) && !@category.nil? && !@category.id.nil?
1717
@category
18-
elsif defined?(@post) && !@post.category.nil?
18+
elsif defined?(@post) && !@post&.category.nil?
1919
@post.category
20-
elsif defined?(@question) && !@question.category.nil?
20+
elsif defined?(@question) && !@question&.category.nil?
2121
@question.category
22-
elsif defined?(@article) && !@article.category.nil?
22+
elsif defined?(@article) && !@article&.category.nil?
2323
@article.category
2424
end
2525
end

app/helpers/comments_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def render_comment_helpers(comment_text, user = current_user)
5555

5656
def get_pingable(thread)
5757
post = thread.post
58+
return [] unless post.present? # Detached threads do not support individual pings
5859

5960
# post author +
6061
# answer authors +

app/views/comments/thread.html.erb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<% pingable = get_pingable(@comment_thread) %>
22

3+
<% if @post.present? %>
34
<% if @post.parent.present? %>
45
<details>
56
<summary>Parent</summary>
@@ -15,6 +16,9 @@
1516
<h1>Comments on
1617
<a href="<%= generic_share_link(@post) %>"><%= @post.title.blank? && @post.parent.present? ? @post.parent.title : @post.title %></a>
1718
</h1>
19+
<% else %>
20+
<h1>Private Notification</h1>
21+
<% end %>
1822

1923
<!-- THREAD STARTS BELOW -->
2024
<div class="<%= @comment_thread.deleted ? 'h-bg-red-050' : '' %> <%= params[:inline] == 'true' ? 'post--comments-thread is-embedded' : '' %>">
@@ -115,27 +119,27 @@
115119
<% unless current_user.nil? || params[:inline] == 'true' %>
116120
<div class="widget--footer">
117121
<% if !@comment_thread.read_only? %>
118-
<% if @post.locked? && !moderator? && !admin? %>
122+
<% if @post.present? && @post.locked? && !moderator? && !admin? %>
119123
<p class="has-color-tertiary-500">Comments are disabled on locked posts.</p>
120-
<% elsif @post.deleted %>
124+
<% elsif @post.present? && @post.deleted %>
121125
<p class="has-color-tertiary-500">Comments are disabled on deleted posts.</p>
122-
<% elsif @post.comments_disabled && !moderator? && !admin? %>
126+
<% elsif @post.present? && @post.comments_disabled && !moderator? && !admin? %>
123127
<p class="has-color-red-500"><i class="fa fa-lock"></i> Comments have been disabled on the parent post.</p>
124128
<% else %>
125-
<% if @post.locked? %>
129+
<% if @post.present? && @post.locked? %>
126130
<p class="has-color-red-500"><i class="fa fa-lock"></i> Comments are disabled on locked posts, but as a moderator you are exempt from that block.</p>
127-
<% elsif @post.comments_disabled %>
131+
<% elsif @post.present? && @post.comments_disabled %>
128132
<p class="has-color-red-500"><i class="fa fa-lock"></i> Comments have been disabled on this post, but as a moderator you are exempt from that block.</p>
129133
<% end %>
130134
<h4>Reply to this thread</h4>
131135
<%= form_tag create_comment_path(@comment_thread.id) do %>
132-
<%= hidden_field_tag :post_id, @post.id %>
136+
<%= hidden_field_tag :post_id, @post&.id %>
133137

134138
<%= label_tag :content, 'Your message', class: 'form-element' %>
135139
<%= text_area_tag :content, '', class: 'form-element js-comment-field',
136-
data: { thread: @comment_thread.id, post: @comment_thread.post_id,
137-
character_count: ".js-character-count-#{@post.id}" } %>
138-
<span class="has-float-right has-font-size-caption js-character-count-<%= @post.id %>"
140+
data: { thread: @comment_thread.id, post: @post&.id,
141+
character_count: ".js-character-count-#{@post&.id}" } %>
142+
<span class="has-float-right has-font-size-caption js-character-count-<%= @post&.id %>"
139143
data-max="1000" data-min="15">
140144
<i class="fas fa-ellipsis-h js-character-count__icon"></i>
141145
<span class="js-character-count__count">0 / 1000</span>

0 commit comments

Comments
 (0)