diff options
3 files changed, 31 insertions, 10 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java index 3cb1204..fa2da99 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java @@ -49,7 +49,7 @@ public class LazychatResource extends PostResource { @POST @Transactional @Authenticated - @Path("/p/{id}/edit") + @Path("{id}/edit") public Response patchMessage( @PathParam("id") int id, @FormParam("text") String text, 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 03447ad..9c871d3 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java @@ -283,7 +283,7 @@ public abstract class PostResource { } @CheckForNull - protected User getCurrentUser() { + protected final User getCurrentUser() { if (identity.isAnonymous()) { return null; } @@ -292,13 +292,8 @@ public abstract class PostResource { return User.findByNickname(userName); } - @GET - @Produces(APPLICATION_JSON) - @Path("/p/{id}") - public Post getPost(@PathParam("id") int id) { - + protected final Post getPostIfVisible(int id) { var user = getCurrentUser(); - var message = getSession().byId(Post.class).load(id); if (!message.isVisibleTo(user)) { @@ -307,4 +302,30 @@ public abstract class PostResource { return message; } + + @GET + @Produces(APPLICATION_JSON) + @Path("{id}") + public Post getPostJson(@PathParam("id") int id) { + return getPostIfVisible(id); + } + + @GET + @Produces(TEXT_HTML) + @Path("{id}") + public TemplateInstance getPostHtml(@PathParam("id") int id) { + var post = getPostIfVisible(id); + + return postList + .data("posts", List.of(post)) + .data("feedUri", "/bookmarks/feed") + .data("pageTitle", pageTitle) + .data("showBookmarkForm", false) + .data("showLazychatForm", false) + .data("hasPreviousPage", false) + .data("hasNextPage", false) + .data("previousCursor", null) + .data("nextCursor", null) + .data("pageSize", null); + } } diff --git a/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js b/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js index 5b67cee..e43e135 100644 --- a/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js +++ b/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js @@ -71,7 +71,7 @@ export class MlkLazychatSubmissionForm extends HTMLElement { connectedCallback() { if (this.editedId !== null) { this.mainForm.method = "post"; - this.mainForm.action = `/lazychat/p/${this.editedId}/edit`; + this.mainForm.action = `/lazychat/${this.editedId}/edit`; } } @@ -89,7 +89,7 @@ export class MlkLazychatSubmissionForm extends HTMLElement { return; } - let fetchUrl = new URL(`/lazychat/p/${this.editedId}`, document.URL); + let fetchUrl = new URL(`/posts/${this.editedId}`, document.URL); let r = await fetch(fetchUrl); if (!r.ok) { |