summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-09 20:02:20 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-09 20:02:20 +0100
commit94b5e7b4c85a4bde4848bf3d85c1adc7cd73acc6 (patch)
tree4d6ddb89267a18bf935acc195fe0ca1922835ab5 /src/main/java
parent62416de64d7fa2dda4dd12777a7698a7a5d0c199 (diff)
Lafargue: Implement basic viewer.
Change-Id: If24f58aa069a14139454708d02ac40109c2181ef
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java1
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java7
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java78
-rw-r--r--src/main/java/eu/mulk/mulkcms2/common/markdown/MarkdownConverter.java (renamed from src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java)4
4 files changed, 88 insertions, 2 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
index 6bbd3a6..503f551 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
@@ -10,6 +10,7 @@ import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;
+import eu.mulk.mulkcms2.common.markdown.MarkdownConverter;
@Entity
@Table(name = "bookmarks", schema = "benki")
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
index de1e0cc..0afc294 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
@@ -1,5 +1,6 @@
package eu.mulk.mulkcms2.benki.lazychat;
+import eu.mulk.mulkcms2.common.markdown.MarkdownConverter;
import eu.mulk.mulkcms2.benki.generic.Post;
import java.util.Collection;
import javax.persistence.Column;
@@ -7,6 +8,7 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
+import javax.persistence.Transient;
@Entity
@Table(name = "lazychat_messages", schema = "benki")
@@ -20,4 +22,9 @@ public class LazychatMessage extends Post {
@OneToMany(mappedBy = "referrer", fetch = FetchType.LAZY)
public Collection<LazychatReference> references;
+
+ @Transient
+ public String getContentHtml() {
+ return new MarkdownConverter().htmlify(content);
+ }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
new file mode 100644
index 0000000..8be3d4a
--- /dev/null
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
@@ -0,0 +1,78 @@
+package eu.mulk.mulkcms2.benki.lazychat;
+
+import static javax.ws.rs.core.MediaType.TEXT_HTML;
+
+import eu.mulk.mulkcms2.benki.accesscontrol.Role;
+import eu.mulk.mulkcms2.benki.bookmarks.Bookmark;
+import eu.mulk.mulkcms2.benki.users.User;
+import io.quarkus.panache.common.Sort;
+import io.quarkus.qute.Template;
+import io.quarkus.qute.TemplateExtension;
+import io.quarkus.qute.TemplateInstance;
+import io.quarkus.qute.api.ResourcePath;
+import io.quarkus.security.identity.SecurityIdentity;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
+import java.time.temporal.TemporalAccessor;
+import java.util.List;
+import javax.inject.Inject;
+import javax.json.spi.JsonProvider;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import org.jboss.logging.Logger;
+
+@Path("/lazychat")
+public class LazychatResource {
+
+ private static Logger log = Logger.getLogger(LazychatResource.class);
+
+ private static DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+
+ private static DateTimeFormatter humanDateFormatter =
+ DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
+
+ private static JsonProvider jsonProvider = JsonProvider.provider();
+
+ @ResourcePath("benki/lazychat/lazychatList.html")
+ @Inject
+ Template lazychatList;
+
+ @Inject SecurityIdentity identity;
+
+ @GET
+ @Produces(TEXT_HTML)
+ public TemplateInstance getPage() {
+ List<LazychatMessage> lazychatMessages;
+ if (identity.isAnonymous()) {
+ Role world = Role.find("from Role r join r.tags tag where tag = 'world'").singleResult();
+ lazychatMessages =
+ Bookmark.find(
+ "select bm from LazychatMessage lm join lm.targets target left join fetch lm.owner where target = ?1",
+ Sort.by("date").descending(),
+ world)
+ .list();
+ } else {
+ var userName = identity.getPrincipal().getName();
+ User user =
+ User.find("from BenkiUser u join u.nicknames n where ?1 = n", userName).singleResult();
+ lazychatMessages =
+ Bookmark.find(
+ "select lm from BenkiUser u inner join u.visibleLazychatMessages lm left join fetch lm.owner where u.id = ?1",
+ Sort.by("date").descending(),
+ user.id)
+ .list();
+ }
+ return lazychatList.data("lazychatMessages", lazychatMessages);
+ }
+
+ @TemplateExtension
+ static String humanDateTime(TemporalAccessor x) {
+ return humanDateFormatter.format(x);
+ }
+
+ @TemplateExtension
+ static String htmlDateTime(TemporalAccessor x) {
+ return htmlDateFormatter.format(x);
+ }
+}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java b/src/main/java/eu/mulk/mulkcms2/common/markdown/MarkdownConverter.java
index 1fae62c..68f7a18 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java
+++ b/src/main/java/eu/mulk/mulkcms2/common/markdown/MarkdownConverter.java
@@ -1,4 +1,4 @@
-package eu.mulk.mulkcms2.benki.bookmarks;
+package eu.mulk.mulkcms2.common.markdown;
import com.vladsch.flexmark.ext.abbreviation.AbbreviationExtension;
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
@@ -18,7 +18,7 @@ public class MarkdownConverter {
private final Parser parser;
private final HtmlRenderer renderer;
- MarkdownConverter() {
+ public MarkdownConverter() {
var options = new MutableDataSet();
options.set(
Parser.EXTENSIONS,