From 85bc737dee2523d0c880fc14280d2e1955cc447c Mon Sep 17 00:00:00 2001
From: Nenad Vujicic
Date: Tue, 4 Feb 2025 16:36:58 +0100
Subject: [PATCH 1/2] Switches from comments to all_comments
Switches from using note's .comments to .all_comments. Fixes bug with notes of deleted users without comments, which are filtered out, but the code tries to access the first comment.
---
app/models/note.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/models/note.rb b/app/models/note.rb
index d37b863e5..807ee9ec8 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -94,7 +94,7 @@ class Note < ApplicationRecord
# Return the note's description, derived from the first comment
def description
if user_ip.nil? && user_id.nil?
- comments.first.body
+ all_comments.first.body
else
RichText.new("text", super)
end
@@ -103,7 +103,7 @@ class Note < ApplicationRecord
# Return the note's author object, derived from the first comment
def author
if user_ip.nil? && user_id.nil?
- comments.first.author
+ all_comments.first.author
else
super
end
From 592b28fd23534946b92ace7858287727e4afc169 Mon Sep 17 00:00:00 2001
From: Nenad Vujicic
Date: Tue, 4 Feb 2025 17:30:10 +0100
Subject: [PATCH 2/2] Removes dropping note's first comment
Removes dropping note's first visible comment in case of deleted note's author. After adding displaying "deleted" as note's description, first visible comment is now displayed as note's comment. Moves logic of calculating which note comments will be displayed and if note contains anonymous author / comments to the controller.
---
app/controllers/notes_controller.rb | 4 ++++
app/views/notes/show.html.erb | 6 +++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index 4b4f3d651..574c9b8b7 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -40,6 +40,10 @@ class NotesController < ApplicationController
@note = Note.visible.find(params[:id])
@note_comments = @note.comments
end
+
+ @note_includes_anonymous = @note.author.nil? || @note_comments.find { |comment| comment.author.nil? }
+
+ @note_comments = @note_comments.drop(1) unless !@note.author.nil? && @note.author.status == "deleted"
rescue ActiveRecord::RecordNotFound
render :template => "browse/not_found", :status => :not_found
end
diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb
index 4f20cdd44..b65926b5f 100644
--- a/app/views/notes/show.html.erb
+++ b/app/views/notes/show.html.erb
@@ -22,7 +22,7 @@
- <% if @note_comments.find { |comment| comment.author.nil? } -%>
+ <% if @note_includes_anonymous -%>
<%= t ".anonymous_warning" %>
<% end -%>
@@ -52,10 +52,10 @@
<% end %>
- <% if @note_comments.length > 1 %>
+ <% if @note_comments.length > 0 %>
- <% @note_comments.drop(1).each do |comment| %> + <% @note_comments.each do |comment| %>-
<%= note_event(comment.event, comment.created_at, comment.author) %>