Skip to content

Commit

Permalink
feature: 新增近7天评论标识
Browse files Browse the repository at this point in the history
  • Loading branch information
yangrunkang committed Apr 8, 2023
1 parent 408861a commit df378fe
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

import java.util.Objects;

import static com.upupor.framework.CcConstant.CACHE_COMMENT_TAG_TIME;

/**
* @author Yang Runkang (cruise)
* @createTime 2022-11-27 03:44
Expand Down Expand Up @@ -68,6 +70,11 @@ public class CommentEnhance {

private String createDateDiff;

/**
* 是否是最近新增的
*/
private Boolean latestAdded;

public String getCreateDate() {
return CcDateUtil.timeStamp2Date(comment.getCreateTime());
}
Expand All @@ -79,5 +86,7 @@ public String getCreateDateDiff() {
return CcDateUtil.timeStamp2DateOnly(comment.getCreateTime());
}


public Boolean getLatestAdded() {
return CcDateUtil.getCurrentTime() - comment.getCreateTime() <= CACHE_COMMENT_TAG_TIME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public final class CcConstant {
*/
public static final String HAS_NEW_COMMENT = "hasNewComment";

/**
* 最新评论标识缓存时长,7天
*/
public static final Long CACHE_COMMENT_TAG_TIME = 1 * 60 * 60 * 24 * 7L;

/**
* 根据标签获取对应的数目
*/
Expand Down Expand Up @@ -146,6 +151,7 @@ public final class CcConstant {
public static final String CV_OFF = "0";
public static final String CV_ON = "1";


public static final class UserView {
public static final String BASE_PATH = "user";
public static final String USER_LOGOUT = BASE_PATH + "/logout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@

import com.upupor.data.dao.entity.Comment;
import com.upupor.data.dao.entity.Member;
import com.upupor.framework.BusinessException;
import com.upupor.framework.CcRedis;
import com.upupor.framework.CcResponse;
import com.upupor.framework.ErrorCode;
import com.upupor.framework.*;
import com.upupor.framework.utils.RedisUtil;
import com.upupor.security.limiter.LimitType;
import com.upupor.security.limiter.UpuporLimit;
Expand Down Expand Up @@ -87,7 +84,7 @@ public CcResponse add(@RequestBody AddCommentReq addCommentReq) {
// 添加评论
Comment comment = commentService.create(addCommentReq);
// 缓存有最新评论的标识
RedisUtil.setKeyJust(CcRedis.LATEST_HAS_NEW_COMMENT, 1 * 60 * 60 * 24 * 7L); // 缓存7D
RedisUtil.setKeyJust(CcRedis.LATEST_HAS_NEW_COMMENT, CcConstant.CACHE_COMMENT_TAG_TIME); // 缓存7D
if (StringUtils.isEmpty(addCommentReq.getReplyToUserId())) {
// 常规的评论
normalCommentEvent(addCommentReq.getTargetId(), comment);
Expand Down
2 changes: 1 addition & 1 deletion upupor-web/src/main/resources/templates/comment/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
th:alt="${commentDto.commentEnhance.memberEnhance.member.userName}" /> </i>
<strong>[[${commentDto.commentEnhance.memberEnhance.member.userName}]]</strong>
</a>
<span class="text-black-50 small float-end"><img th:data-src="${ossStatic} + @{/icons/system/content-time.png}" class="lazyload cv-icon-small"/> <strong>[[${commentDto.commentEnhance.createDateDiff}]]</strong></i></span>
<span class="text-black-50 small float-end"><img th:data-src="${ossStatic} + @{/icons/system/content-time.png}" class="lazyload cv-icon-small"/> <strong>[[${commentDto.commentEnhance.createDateDiff}]] <span th:include="fragments/comment::commentLatestAdd(${commentDto.commentEnhance.latestAdded},'近7天新增')"></span></strong></i></span>
</div>
<div>
<a class="text-black-50 small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
</div>


<span th:fragment="commentLatestAdd(latestAdded,text)">
<span th:if="${latestAdded}" class="badge bg-gradient bg-danger fw-light rounded-3 small d-inline-flex text-white">[[${text}]]</span>
</span>
<div th:fragment="commentList(commentEnhance,pageDtoList,total,fromPage,targetUserId,businessDesc)">
<div th:class="${fromPage == 'profile-message'}?'':'card border-0 rounded-3 p-2 my-2'">
<div th:if="${#lists.isEmpty(commentEnhance)}" th:include="fragments/index::empty_content"></div>
Expand All @@ -79,6 +82,7 @@
<a class="text-black-50 cv-link fw-bold" th:href="'/profile/'+${commentEnhance.memberEnhance.member.userId}+'/content'">
[[${commentEnhance.memberEnhance.member.userName}]] <span class="badge rounded-3 fw-normal" style="border: 1px solid #DAEDE4;color: #3f7b5a;background-color: #EFF7ED;" th:if="${commentEnhance.memberEnhance.member.userId == targetUserId}">楼主</span>
<span th:include="fragments/member::memberTag(${commentEnhance.memberEnhance})"></span>
<span th:include="fragments/comment::commentLatestAdd(${commentEnhance.latestAdded},'近7天新增')"></span>
</a>
<span class="badge bg-gradient bg-success" th:if="${commentEnhance.comment.beFloorNum != null}" th:text="'回复 ' + ${commentEnhance.comment.beFloorNum} + '#'+(${commentEnhance.replyMemberEnhance?.member?.userName} == null?'':' · '+${commentEnhance.replyMemberEnhance?.member?.userName})+' 的'+${businessDesc}"></span>
<div class="float-end text-black-50 small">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
</div>
<div class="border-1 border-bottom my-1"></div>
<div class="mt-1 small">
· <a href="/comment" class="text-black-50">全站评论 <i class="bi bi-chat-right-quote"></i> <div th:if="${hasNewComment}" class="badge bg-gradient bg-danger fw-light rounded-3 small d-inline-flex text-white">最近有新的评论</div></a>
· <a href="/comment" class="text-black-50">全站评论 <i class="bi bi-chat-right-quote"></i> <span th:include="fragments/comment::commentLatestAdd(${hasNewComment},'近7天有新的评论')"></span></a>
</div>
<div class="mt-1 small">
· <a class="text-black-50" href="/view/history">浏览记录 <span th:include="fragments/icon::view_record" class="cv-icon-small"></span></a>
Expand Down

0 comments on commit df378fe

Please sign in to comment.