comment period
This commit is contained in:
@@ -42,49 +42,26 @@ public class CommentManager {
|
||||
private QVote qVote = QVote.vote;
|
||||
private QEntry qEntry = QEntry.entry;
|
||||
|
||||
/**
|
||||
* Fetch by ranking.
|
||||
*
|
||||
* @param target the target
|
||||
* @param parent the parent
|
||||
* @param date the date
|
||||
* @param gravity the gravity
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @return the page
|
||||
*/
|
||||
|
||||
public Page<Comment> fetchByRanking(Long target, Long parent, Instant date, double gravity,
|
||||
int page, int size) {
|
||||
if (parent == null) {
|
||||
return commentRepository.findAllByRankingAndParent(target, date, gravity,
|
||||
PageRequest.of(page, size));
|
||||
}
|
||||
|
||||
return commentRepository.findAllByRankingAndParent(target, parent, date, gravity,
|
||||
PageRequest.of(page, size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch by date.
|
||||
*
|
||||
* @param username the username
|
||||
* @param target the target
|
||||
* @param parent the parent
|
||||
* @param date the date
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param desc the desc
|
||||
* @param date the date
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param desc the desc
|
||||
* @return the page
|
||||
*/
|
||||
public Page<Comment> fetchByDate(Long target, Long parent, Instant date, int page, int size,
|
||||
boolean desc) {
|
||||
public Page<Comment> fetchByDate(String username, Long target, Long parent, Instant date,
|
||||
int page, int size, boolean desc) {
|
||||
Sort sort = Sort.by(desc ? Order.desc("created") : Order.asc("created"));
|
||||
if (parent == null) {
|
||||
return commentRepository
|
||||
.findAll(
|
||||
qComment.target.eq(target).and(qComment.parent.isNull())
|
||||
.and(qComment.created.before(date)),
|
||||
PageRequest.of(page, size, sort));
|
||||
return commentRepository.findAll(
|
||||
qComment.target.eq(target).and(qComment.parent.isNull())
|
||||
.and(qComment.created.before(date).or(qComment.author.eq(username))),
|
||||
PageRequest.of(page, size, sort));
|
||||
}
|
||||
|
||||
return commentRepository.findAll(qComment.target.eq(target).and(qComment.parent.eq(parent))
|
||||
@@ -95,11 +72,11 @@ public class CommentManager {
|
||||
* Fetch by username.
|
||||
*
|
||||
* @param username the username
|
||||
* @param orElse the or else
|
||||
* @param date the date
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param asc the asc
|
||||
* @param orElse the or else
|
||||
* @param date the date
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param asc the asc
|
||||
* @return the page
|
||||
*/
|
||||
public Page<Comment> fetchByUsername(String username, Long orElse, Instant date, int page,
|
||||
@@ -139,8 +116,8 @@ public class CommentManager {
|
||||
* Apply metadata.
|
||||
*
|
||||
* @param username the username
|
||||
* @param comment the comment
|
||||
* @param ignore the ignore
|
||||
* @param comment the comment
|
||||
* @param ignore the ignore
|
||||
*/
|
||||
public void applyMetadata(String username, Comment comment, List<String> ignore) {
|
||||
|
||||
@@ -191,8 +168,8 @@ public class CommentManager {
|
||||
* Apply metadata.
|
||||
*
|
||||
* @param username the username
|
||||
* @param entries the entries
|
||||
* @param ignore the ignore
|
||||
* @param entries the entries
|
||||
* @param ignore the ignore
|
||||
*/
|
||||
public void applyMetadata(String username, List<Comment> entries, List<String> ignore) {
|
||||
for (Comment comment : entries) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -42,14 +41,13 @@ public class EntryManager {
|
||||
private VoteRepository voteRepository;
|
||||
@Autowired
|
||||
private BookmarksManager bookmarksManager;
|
||||
@Autowired
|
||||
private SettingsManager settingsManager;
|
||||
|
||||
private QEntry qEntry = QEntry.entry;
|
||||
|
||||
private QVote qVote = QVote.vote;
|
||||
|
||||
@Value("${bstly.board.unvoteThresh:10}")
|
||||
private long UNVOTE_THRESH;
|
||||
|
||||
/**
|
||||
* Fetch by ranking.
|
||||
*
|
||||
@@ -187,7 +185,7 @@ public class EntryManager {
|
||||
entry.getMetadata().put("vote", true);
|
||||
}
|
||||
|
||||
if (!ignore.contains("downvote") && karma >= UNVOTE_THRESH) {
|
||||
if (!ignore.contains("downvote") && karma >= settingsManager.getUnvoteThresh()) {
|
||||
entry.getMetadata().put("downvote", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.bstly.board.businesslogic;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* The Class SettingsManager.
|
||||
*/
|
||||
@Component
|
||||
public class SettingsManager {
|
||||
|
||||
@Value("${bstly.board.ranking.gravity:1.2}")
|
||||
private double GRAVITY;
|
||||
@Value("${bstly.board.size:30}")
|
||||
private int SIZE;
|
||||
@Value("${bstly.board.comment.changePeriod:1}")
|
||||
private long COMMENT_CHANGE_PERIDO;
|
||||
@Value("${bstly.board.unvoteThresh:10}")
|
||||
private long UNVOTE_THRESH;
|
||||
|
||||
/**
|
||||
* Gets the gravity.
|
||||
*
|
||||
* @return the gravity
|
||||
*/
|
||||
public double getGravity() {
|
||||
return GRAVITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page size.
|
||||
*
|
||||
* @return the page size
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the comment delay.
|
||||
*
|
||||
* @return the comment delay
|
||||
*/
|
||||
public long getCommentDelay() {
|
||||
return COMMENT_CHANGE_PERIDO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unvote thresh.
|
||||
*
|
||||
* @return the unvote thresh
|
||||
*/
|
||||
public long getUnvoteThresh() {
|
||||
return UNVOTE_THRESH;
|
||||
}
|
||||
}
|
||||
@@ -54,9 +54,20 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
|
||||
@Value("${admin.password:}")
|
||||
private String adminPassword;
|
||||
@Value("${bstly.board.ranking.gravity:1.2}")
|
||||
private double GRAVITY;
|
||||
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#
|
||||
* loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
@@ -89,6 +100,19 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
*/
|
||||
@@ -207,7 +231,6 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
if (user.getUsername().equalsIgnoreCase(username)
|
||||
&& !user.getMetadata().containsKey("self")) {
|
||||
user.getMetadata().put("self", true);
|
||||
user.getMetadata().put("defaultGravity", GRAVITY);
|
||||
}
|
||||
|
||||
if (!user.getMetadata().containsKey("points")) {
|
||||
|
||||
Reference in New Issue
Block a user