From 5000f9a3b87bf7689cba3e03dca4ec8260d56fae Mon Sep 17 00:00:00 2001
From: Matthias Andreas Benkard <code@mail.matthias.benkard.de>
Date: Tue, 3 Nov 2020 07:09:42 +0100
Subject: KB68 Only put public posts into the newsletter.

Change-Id: Iee7f4dfd14820c19179c43be71759f209caa9989
---
 .../eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java    | 10 +++++++++-
 .../benki/newsletter/NewsletterSubscriptionExpirer.java        |  3 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

(limited to 'src/main')

diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
index 59ab37c..7a52d32 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
@@ -50,7 +50,15 @@ public class NewsletterSender {
   void run() throws InterruptedException, TimeoutException, ExecutionException {
     var session = em.unwrap(Session.class);
 
-    List<Post<?>> posts = Post.list("newsletter IS NULL", Sort.ascending("date"));
+    List<Post<?>> posts =
+        Post.list(
+            ""
+                + "SELECT p FROM Post p"
+                + "  JOIN p.targets r"
+                + "  JOIN r.tags tag"
+                + " WHERE newsletter IS NULL"
+                + "   AND tag = 'world'",
+            Sort.ascending("date"));
     Post.fetchTexts(posts);
 
     if (posts.isEmpty()) {
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
index 43787dc..a9dda9c 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
@@ -16,8 +16,7 @@ public class NewsletterSubscriptionExpirer {
   void run() {
     var subscriptionsDeleted =
         NewsletterSubscription.delete(
-            "registrationKey IS NOT NULL AND startDate < ?1",
-            OffsetDateTime.now().minusWeeks(1));
+            "registrationKey IS NOT NULL AND startDate < ?1", OffsetDateTime.now().minusWeeks(1));
     if (subscriptionsDeleted > 0) {
       log.infof("%d expired newsletter subscriptions deleted.", subscriptionsDeleted);
     }
-- 
cgit v1.2.3