From df5002abc778dfcbac2195f94b9f209681f9746f 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 new followers --- app/models/user_notifications.rb | 5 +++ .../notifications/_new_follower.html.erb | 33 +++++++++++++++++++ config/locales/en.yml | 4 +++ .../notifications/new_follower_view_test.rb | 21 ++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 app/views/notifications/_new_follower.html.erb create mode 100644 test/controllers/notifications/new_follower_view_test.rb diff --git a/app/models/user_notifications.rb b/app/models/user_notifications.rb index d6fc5156c..719501044 100644 --- a/app/models/user_notifications.rb +++ b/app/models/user_notifications.rb @@ -72,6 +72,10 @@ class UserNotifications end end + class NewFollowerNotification < Notification + delegate :follower, :to => :record + end + class NoteCommentNotification < Notification delegate :note, :to => :record delegate :event, :to => :record @@ -99,6 +103,7 @@ class UserNotifications LISTABLE_NOTIFICATIONS = %w[ ChangesetCommentNotifier::Notification DiaryCommentNotifier::Notification + NewFollowerNotifier::Notification NoteCommentNotifier::Notification ].freeze diff --git a/app/views/notifications/_new_follower.html.erb b/app/views/notifications/_new_follower.html.erb new file mode 100644 index 000000000..bade0a97f --- /dev/null +++ b/app/views/notifications/_new_follower.html.erb @@ -0,0 +1,33 @@ +<%# locals: (notification:) %> + +
+
+

<%= t(".headline") %>

+

<%= friendly_date_ago(notification.timestamp) %>

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

+ <%= t( + ".description_html", + :follower_name_with_link => link_to( + notification.follower.display_name, + notification.follower + ), + :link => link_to( + t(".link_text"), + follow_url(notification.follower) + ) + ) %> +

+
+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index 2112ee7ac..0398b8cb5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -615,6 +615,10 @@ en: headline: Changeset comment description_with_summary_html: "User %{commenter_name_with_link} left a comment on changeset %{changeset_id_with_link} (\"%{changeset_summary}\")" description_without_summary_html: "User %{commenter_name_with_link} left a comment on changeset %{changeset_id_with_link}" + new_follower: + headline: New follower + description_html: "User %{follower_name_with_link} started following you. You can %{link} if you wish." + link_text: follow them back note_comment: headline: commented: Note comment diff --git a/test/controllers/notifications/new_follower_view_test.rb b/test/controllers/notifications/new_follower_view_test.rb new file mode 100644 index 000000000..535e4f9f5 --- /dev/null +++ b/test/controllers/notifications/new_follower_view_test.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require "test_helper" + +module Notifications + class NewFollowerViewTest < ActionView::TestCase + def test_render + follower = build_stubbed(:user, :display_name => "Follower") + follow = build_stubbed(:follow, :follower => follower) + + notification = build_stubbed(:notification, :record => follow, :notifier_class => NewFollowerNotifier) + notification_wrapper = UserNotifications::NewFollowerNotification.new(notification) + + render "notifications/new_follower", :notification => notification_wrapper + + assert_dom ".user-notification h2", "New follower" + assert_dom ".user-notification time", "less than 1 minute ago" + assert_dom ".user-notification p", "User Follower started following you. You can follow them back if you wish." + end + end +end -- 2.47.3