From 498e1f2c3b3c85a01003385b69cd100fb0bdafa6 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 30 Jun 2025 16:45:23 +0000 Subject: [PATCH] Add plugin --- plugin.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plugin.rb diff --git a/plugin.rb b/plugin.rb new file mode 100644 index 0000000..f1c7c52 --- /dev/null +++ b/plugin.rb @@ -0,0 +1,33 @@ +# name: custom-digest-posts +# about: Removes score threshold for popular posts in Discourse digest emails +# version: 0.1 +# authors: David Szekeres +# url: https://git.stonecarterstudios.com/StoneCarterStudios/custom-digest-posts + +after_initialize do + module CustomUserNotifications + def digest(user, opts = {}) + super(user, opts).tap do + @popular_posts = + if SiteSetting.digest_posts > 0 + Post + .order("posts.score DESC") + .for_mailing_list(user, @since) + .where("posts.post_type = ?", Post.types[:regular]) + .where( + "posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false", + ) + .where("posts.post_number > ?", 1) + .where("posts.created_at < ?", (SiteSetting.editing_grace_period || 0).seconds.ago) + .limit(SiteSetting.digest_posts) + else + [] + end + end + end + end + + class ::UserNotifications + prepend CustomUserNotifications + end +end \ No newline at end of file