From 2ecdede351429232a5b44297773aaaa1ee4224fc Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Mon, 20 Apr 2026 15:26:48 +0100 Subject: [PATCH] Implement web notifications for diary comments --- app/models/user_notifications.rb | 23 +++++++++ .../notifications/_diary_comment.html.erb | 48 +++++++++++++++++++ config/locales/en.yml | 3 ++ .../notifications/diary_comment_view_test.rb | 19 ++++++++ 4 files changed, 93 insertions(+) create mode 100644 app/views/notifications/_diary_comment.html.erb create mode 100644 test/controllers/notifications/diary_comment_view_test.rb diff --git a/app/models/user_notifications.rb b/app/models/user_notifications.rb index 723e5c72e..d6fc5156c 100644 --- a/app/models/user_notifications.rb +++ b/app/models/user_notifications.rb @@ -50,6 +50,28 @@ class UserNotifications end end + class DiaryCommentNotification < Notification + delegate :body, :to => :record + delegate :diary_entry, :to => :record + delegate :title, :to => :diary_entry, :prefix => true + + def commenter + record.user + end + + def comment_id + record.id + end + + def comment_body + record.body + end + + def diary_author + diary_entry.user + end + end + class NoteCommentNotification < Notification delegate :note, :to => :record delegate :event, :to => :record @@ -76,6 +98,7 @@ class UserNotifications LISTABLE_NOTIFICATIONS = %w[ ChangesetCommentNotifier::Notification + DiaryCommentNotifier::Notification NoteCommentNotifier::Notification ].freeze diff --git a/app/views/notifications/_diary_comment.html.erb b/app/views/notifications/_diary_comment.html.erb new file mode 100644 index 000000000..03e41c556 --- /dev/null +++ b/app/views/notifications/_diary_comment.html.erb @@ -0,0 +1,48 @@ +<%# locals: (notification:) %> + +
+
+

+ <%= link_to( + t(".headline"), + diary_entry_path( + notification.diary_author, + notification.diary_entry, + :anchor => "c#{notification.comment_id}" + ) + ) %> +

+

<%= friendly_date_ago(notification.timestamp) %>

+
+ +
+
+ <%= link_to( + user_thumbnail(notification.commenter, :class => "img-fluid"), + user_url(notification.commenter), + :target => "_blank", :rel => "noopener" + ) %> +
+
+

+ <%= t( + ".description_html", + :commenter_name_with_link => link_to( + notification.commenter.display_name, + notification.commenter + ), + :diary_entry_title_with_link => link_to( + notification.diary_entry_title, + diary_entry_path( + notification.diary_author, + notification.diary_entry + ) + ) + ) %> +

+
+ <%= notification.comment_body.to_html %> +
+
+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index 3b2cba40e..2112ee7ac 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -624,6 +624,9 @@ en: commented_html: "User %{commenter_name_with_link} left a comment on note %{note_id_with_link} (\"%{note_text}\")" closed_html: "User %{commenter_name_with_link} resolved note %{note_id_with_link} (\"%{note_text}\")" reopened_html: "User %{commenter_name_with_link} reopened note %{note_id_with_link} (\"%{note_text}\")" + diary_comment: + headline: Diary comment + description_html: "User %{commenter_name_with_link} left a comment on diary entry \"%{diary_entry_title_with_link}\"" diary_entries: new: title: New Diary Entry diff --git a/test/controllers/notifications/diary_comment_view_test.rb b/test/controllers/notifications/diary_comment_view_test.rb new file mode 100644 index 000000000..749ccb4bf --- /dev/null +++ b/test/controllers/notifications/diary_comment_view_test.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "test_helper" + +module Notifications + class DiaryCommentViewTest < ActionView::TestCase + def test_render + diary_comment = build_stubbed(:diary_comment) + notification = build_stubbed(:notification, :record => diary_comment) + notification_wrapper = UserNotifications::DiaryCommentNotification.new(notification) + + render "notifications/diary_comment", :notification => notification_wrapper + + assert_dom ".user-notification h2", "Diary comment" + assert_dom ".user-notification time", "less than 1 minute ago" + assert_dom ".user-notification blockquote", diary_comment.body + end + end +end -- 2.47.3