Allow deletion of forum replies #111
@ -23,4 +23,8 @@ public interface BasicForumService extends Serializable {
|
|||||||
ForumThread createThread(String subject);
|
ForumThread createThread(String subject);
|
||||||
|
|
||||||
long countUnreadThreads(List<ForumThread> forumThreadList, User user);
|
long countUnreadThreads(List<ForumThread> forumThreadList, User user);
|
||||||
|
|
||||||
|
ForumPost getLastPost(ForumThread forumThread);
|
||||||
|
|
||||||
|
boolean hasAttachments(ForumThread forumThread);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class BasicForumServiceImpl implements BasicForumService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isThreadRead(User user, ForumThread forumThread) {
|
public boolean isThreadRead(User user, ForumThread forumThread) {
|
||||||
for (ForumPost post : forumThread.getPosts()) {
|
for (ForumPost post : getPosts(forumThread)) {
|
||||||
if (!getReadState(user, post).isRead()) {
|
if (!getReadState(user, post).isRead()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -133,4 +133,22 @@ public class BasicForumServiceImpl implements BasicForumService {
|
|||||||
|
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ForumPost getLastPost(ForumThread forumThread) {
|
||||||
|
return Collections.max(
|
||||||
|
getPosts(forumThread),
|
||||||
|
Comparator.comparing(ForumPost::getDateCreated).thenComparing(ForumPost::getId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasAttachments(ForumThread forumThread) {
|
||||||
|
for (ForumPost post : getPosts(forumThread)) {
|
||||||
|
if (!post.getAttachments().isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,13 +116,4 @@ public class ForumThread extends LazyDeletableDomainObject {
|
|||||||
public User getCreatedBy() {
|
public User getCreatedBy() {
|
||||||
return getPosts().get(0).getPostedBy();
|
return getPosts().get(0).getPostedBy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAttachments() {
|
|
||||||
for (ForumPost post : posts) {
|
|
||||||
if (!post.getAttachments().isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package se.su.dsv.scipro.forum.panels.threaded;
|
package se.su.dsv.scipro.forum.panels.threaded;
|
||||||
|
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||||
import org.apache.wicket.markup.html.basic.Label;
|
import org.apache.wicket.markup.html.basic.Label;
|
||||||
@ -15,6 +14,7 @@ import org.apache.wicket.model.LambdaModel;
|
|||||||
import org.apache.wicket.model.LoadableDetachableModel;
|
import org.apache.wicket.model.LoadableDetachableModel;
|
||||||
import se.su.dsv.scipro.components.DateLabel;
|
import se.su.dsv.scipro.components.DateLabel;
|
||||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||||
|
import se.su.dsv.scipro.forum.BasicForumService;
|
||||||
import se.su.dsv.scipro.forum.Discussable;
|
import se.su.dsv.scipro.forum.Discussable;
|
||||||
import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
||||||
import se.su.dsv.scipro.forum.dataobjects.ForumThread;
|
import se.su.dsv.scipro.forum.dataobjects.ForumThread;
|
||||||
@ -23,6 +23,9 @@ import se.su.dsv.scipro.system.User;
|
|||||||
|
|
||||||
public class ThreadsOverviewPanel<A> extends Panel {
|
public class ThreadsOverviewPanel<A> extends Panel {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BasicForumService basicForumService;
|
||||||
|
|
||||||
public ThreadsOverviewPanel(
|
public ThreadsOverviewPanel(
|
||||||
final String id,
|
final String id,
|
||||||
final IModel<List<A>> model,
|
final IModel<List<A>> model,
|
||||||
@ -41,7 +44,7 @@ public class ThreadsOverviewPanel<A> extends Panel {
|
|||||||
@Override
|
@Override
|
||||||
protected void onConfigure() {
|
protected void onConfigure() {
|
||||||
super.onConfigure();
|
super.onConfigure();
|
||||||
setVisibilityAllowed(discussion.getObject().hasAttachments());
|
setVisibilityAllowed(basicForumService.hasAttachments(discussion.getObject()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -80,7 +83,7 @@ public class ThreadsOverviewPanel<A> extends Panel {
|
|||||||
BookmarkablePageLink<Void> newThreadLink(String id, IModel<A> thread);
|
BookmarkablePageLink<Void> newThreadLink(String id, IModel<A> thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LastPostColumn extends WebMarkupContainer {
|
private class LastPostColumn extends WebMarkupContainer {
|
||||||
|
|
||||||
public LastPostColumn(String id, final IModel<ForumThread> model) {
|
public LastPostColumn(String id, final IModel<ForumThread> model) {
|
||||||
super(id);
|
super(id);
|
||||||
@ -110,10 +113,7 @@ public class ThreadsOverviewPanel<A> extends Panel {
|
|||||||
return new LoadableDetachableModel<>() {
|
return new LoadableDetachableModel<>() {
|
||||||
@Override
|
@Override
|
||||||
protected ForumPost load() {
|
protected ForumPost load() {
|
||||||
return Collections.max(
|
return basicForumService.getLastPost(model.getObject());
|
||||||
model.getObject().getPosts(),
|
|
||||||
Comparator.comparing(ForumPost::getDateCreated).thenComparing(ForumPost::getId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.apache.wicket.model.Model;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import se.su.dsv.scipro.SciProTest;
|
import se.su.dsv.scipro.SciProTest;
|
||||||
import se.su.dsv.scipro.forum.Discussable;
|
import se.su.dsv.scipro.forum.Discussable;
|
||||||
@ -20,11 +21,13 @@ import se.su.dsv.scipro.system.User;
|
|||||||
public class ThreadsOverviewPanelTest extends SciProTest {
|
public class ThreadsOverviewPanelTest extends SciProTest {
|
||||||
|
|
||||||
private List<ForumThread> threads;
|
private List<ForumThread> threads;
|
||||||
|
private ForumPost post;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
ForumThread forumThread = createThread();
|
ForumThread forumThread = createThread();
|
||||||
threads = Arrays.asList(forumThread);
|
threads = Arrays.asList(forumThread);
|
||||||
|
Mockito.when(basicForumService.getLastPost(forumThread)).thenReturn(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -54,7 +57,7 @@ public class ThreadsOverviewPanelTest extends SciProTest {
|
|||||||
|
|
||||||
private ForumThread createThread() {
|
private ForumThread createThread() {
|
||||||
User bob = User.builder().firstName("Bob").lastName("the Builder").emailAddress("bob@building.com").build();
|
User bob = User.builder().firstName("Bob").lastName("the Builder").emailAddress("bob@building.com").build();
|
||||||
ForumPost post = new ForumPost();
|
post = new ForumPost();
|
||||||
post.setPostedBy(bob);
|
post.setPostedBy(bob);
|
||||||
ForumThread groupForumThread = new ForumThread();
|
ForumThread groupForumThread = new ForumThread();
|
||||||
groupForumThread.addPost(post);
|
groupForumThread.addPost(post);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user