Feed: Add generated titles to lazy chat messages.

Change-Id: I691cbc0a1440960a5dc8a46863d7291927ff3390
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index 035e47b..e5a0e7f 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -32,6 +32,7 @@
 import java.time.format.DateTimeFormatter;
 import java.time.format.FormatStyle;
 import java.time.temporal.TemporalAccessor;
+import java.util.Arrays;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.List;
@@ -58,6 +59,7 @@
 import org.eclipse.microprofile.config.inject.ConfigProperty;
 import org.hibernate.Session;
 import org.jboss.logging.Logger;
+import org.jsoup.Jsoup;
 
 public abstract class PostResource {
 
@@ -76,6 +78,8 @@
 
   private static final int pageKeyBytes = 32;
 
+  private static final int AUTOTITLE_WORDS = 10;
+
   protected static final JsonProvider jsonProvider = JsonProvider.provider();
 
   @ConfigProperty(name = "mulkcms.posts.default-max-results")
@@ -315,6 +319,14 @@
                     title.setType("text");
                     title.setValue(post.getTitle());
                     entry.setTitleEx(title);
+                  } else if (post.getDescriptionHtml() != null) {
+                    var title = new Content();
+                    title.setType("text");
+                    var words =
+                        Jsoup.parse(post.getDescriptionHtml()).text().split("\\s", AUTOTITLE_WORDS);
+                    var titleWords = Arrays.asList(words).subList(0, words.length - 1);
+                    title.setValue(String.join(" ", titleWords) + " ...");
+                    entry.setTitleEx(title);
                   }
 
                   if (post.getDescriptionHtml() != null) {