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