Commit eaea8f98 authored by Liang Ding's avatar Liang Ding

🎨 #12509 评论时间

parent 351612c3
......@@ -55,7 +55,7 @@ import java.util.Date;
* Comment receiver (from B3log Symphony).
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.15, Aug 2, 2018
* @version 1.1.1.16, Sep 16, 2018
* @since 0.5.5
*/
@RequestProcessor
......@@ -202,8 +202,8 @@ public class CommentReceiver {
comment.put(Comment.COMMENT_CONTENT, commentContent);
final Date date = new Date();
comment.put(Comment.COMMENT_DATE, date);
ret.put(Comment.COMMENT_DATE, DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
comment.put(Comment.COMMENT_CREATED, date.getTime());
ret.put(Comment.COMMENT_T_DATE, DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
if (StringUtils.isNotBlank(originalCommentId)) {
originalComment = commentRepository.get(originalCommentId);
if (null != originalComment) {
......
......@@ -22,7 +22,7 @@ package org.b3log.solo.model;
* This class defines all comment model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.7, Jan 18, 2013
* @version 1.1.0.0, Sep 16, 2018
* @since 0.3.1
*/
public final class Comment {
......@@ -62,10 +62,15 @@ public final class Comment {
*/
public static final String COMMENT_SHARP_URL = "commentSharpURL";
/**
* Key of comment created at.
*/
public static final String COMMENT_CREATED = "commentCreated";
/**
* Key of comment date.
*/
public static final String COMMENT_DATE = "commentDate";
public static final String COMMENT_T_DATE = "commentDate";
/**
* Key of comment time.
......@@ -100,5 +105,6 @@ public final class Comment {
/**
* Private constructor.
*/
private Comment() {}
private Comment() {
}
}
......@@ -66,7 +66,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.6.16.5, Sep 2, 2018
* @version 1.6.16.6, Sep 16, 2018
* @since 0.3.1
*/
@Service
......@@ -549,7 +549,7 @@ public class Filler {
comment.put(Comment.COMMENT_URL, comment.getString(Comment.COMMENT_URL));
comment.put(Common.IS_REPLY, false);
comment.remove(Comment.COMMENT_EMAIL); // Erases email for security reason
comment.put("commentDate2", comment.opt(Comment.COMMENT_DATE));
comment.put("commentDate2", new Date(comment.optLong(Comment.COMMENT_CREATED)));
final String email = comment.optString(Comment.COMMENT_EMAIL);
final String thumbnailURL = comment.optString(Comment.COMMENT_THUMBNAIL_URL);
......
......@@ -57,7 +57,7 @@ import java.util.Date;
* Comment management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.3.1, Aug 2, 2018
* @version 1.3.3.2, Sep 16, 2018
* @since 0.3.5
*/
@Service
......@@ -426,8 +426,8 @@ public class CommentMgmtService {
final JSONObject preference = preferenceQueryService.getPreference();
final Date date = new Date();
comment.put(Comment.COMMENT_DATE, date);
ret.put(Comment.COMMENT_DATE, DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
comment.put(Comment.COMMENT_CREATED, date.getTime());
ret.put(Comment.COMMENT_T_DATE, DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
ret.put("commentDate2", date);
ret.put(Common.COMMENTABLE, preference.getBoolean(Option.ID_C_COMMENTABLE) && page.getBoolean(Page.PAGE_COMMENTABLE));
......@@ -562,8 +562,8 @@ public class CommentMgmtService {
final JSONObject preference = preferenceQueryService.getPreference();
final Date date = new Date();
comment.put(Comment.COMMENT_DATE, date);
ret.put(Comment.COMMENT_DATE, DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
comment.put(Comment.COMMENT_CREATED, date.getTime());
ret.put(Comment.COMMENT_T_DATE, DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
ret.put("commentDate2", date);
ret.put(Common.COMMENTABLE, preference.getBoolean(Option.ID_C_COMMENTABLE) && article.getBoolean(Article.ARTICLE_COMMENTABLE));
......
......@@ -53,7 +53,7 @@ import java.util.List;
* Comment query service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.2.0, Aug 31, 2017
* @version 1.3.2.1, Sep 16, 2018
* @since 0.3.5
*/
@Service
......@@ -163,8 +163,8 @@ public class CommentQueryService {
final int pageSize = requestJSONObject.getInt(Pagination.PAGINATION_PAGE_SIZE);
final int windowSize = requestJSONObject.getInt(Pagination.PAGINATION_WINDOW_SIZE);
final Query query = new Query().setCurrentPageNum(currentPageNum).setPageSize(pageSize).addSort(Comment.COMMENT_DATE,
SortDirection.DESCENDING);
final Query query = new Query().setCurrentPageNum(currentPageNum).setPageSize(pageSize).
addSort(Comment.COMMENT_CREATED, SortDirection.DESCENDING);
final JSONObject result = commentRepository.get(query);
final JSONArray comments = result.getJSONArray(Keys.RESULTS);
......@@ -196,8 +196,8 @@ public class CommentQueryService {
commentContent = Jsoup.clean(commentContent, Whitelist.relaxed());
comment.put(Comment.COMMENT_CONTENT, commentContent);
comment.put(Comment.COMMENT_TIME, ((Date) comment.get(Comment.COMMENT_DATE)).getTime());
comment.remove(Comment.COMMENT_DATE);
comment.put(Comment.COMMENT_TIME, comment.optLong(Comment.COMMENT_CREATED));
comment.remove(Comment.COMMENT_CREATED);
}
final int pageCount = result.getJSONObject(Pagination.PAGINATION).getInt(Pagination.PAGINATION_PAGE_COUNT);
......@@ -232,8 +232,8 @@ public class CommentQueryService {
final List<JSONObject> comments = commentRepository.getComments(onId, 1, Integer.MAX_VALUE);
for (final JSONObject comment : comments) {
comment.put(Comment.COMMENT_TIME, ((Date) comment.get(Comment.COMMENT_DATE)).getTime());
comment.put("commentDate2", comment.get(Comment.COMMENT_DATE)); // 1.9.0 向后兼容
comment.put(Comment.COMMENT_TIME, comment.optLong(Comment.COMMENT_CREATED));
comment.put("commentDate2", new Date(comment.optLong(Comment.COMMENT_CREATED))); // 1.9.0 向后兼容
comment.put(Comment.COMMENT_NAME, comment.getString(Comment.COMMENT_NAME));
String url = comment.getString(Comment.COMMENT_URL);
if (StringUtils.contains(url, "<")) { // legacy issue https://github.com/b3log/solo/issues/12091
......
......@@ -57,7 +57,7 @@ import java.util.Set;
* Solo initialization service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.2.21, Aug 2, 2018
* @version 1.5.2.22, Sep 16, 2018
* @since 0.4.0
*/
@Service
......@@ -305,7 +305,6 @@ public class InitService {
final String articleId = addHelloWorldArticle(article);
final JSONObject comment = new JSONObject();
comment.put(Keys.OBJECT_ID, articleId);
comment.put(Comment.COMMENT_NAME, "Daniel");
comment.put(Comment.COMMENT_EMAIL, "d@b3log.org");
......@@ -314,7 +313,7 @@ public class InitService {
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_ID, "");
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, "");
comment.put(Comment.COMMENT_THUMBNAIL_URL, Solos.GRAVATAR + "59a5e8209c780307dbe9c9ba728073f5??s=60&r=G");
comment.put(Comment.COMMENT_DATE, date);
comment.put(Comment.COMMENT_CREATED, date.getTime());
comment.put(Comment.COMMENT_ON_ID, articleId);
comment.put(Comment.COMMENT_ON_TYPE, Article.ARTICLE);
final String commentId = Ids.genTimeMillisId();
......
{
"description": "Description of repository structures, for generation of the relational database table and persistence validation.",
"version": "3.2.1.0, Apr 18, 2018",
"version": "3.2.1.1, Sep 16, 2018",
"authors": [
"Liang Ding"
],
......@@ -138,9 +138,9 @@
"length": 2000
},
{
"name": "commentDate",
"description": "评论时间",
"type": "Date"
"name": "commentCreated",
"description": "评论时间",
"type": "long"
},
{
"name": "commentEmail",
......
......@@ -17,8 +17,6 @@
*/
package org.b3log.solo.repository.impl;
import java.util.Date;
import java.util.List;
import org.b3log.latke.repository.Transaction;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.model.Comment;
......@@ -27,11 +25,14 @@ import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Date;
import java.util.List;
/**
* {@link ArticleRepositoryImpl} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Jan 7, 2012
* @version 1.0.0.2, Sep 16, 2018
*/
@Test(suiteName = "repository")
public class CommentRepositoryImplTestCase extends AbstractTestCase {
......@@ -48,7 +49,7 @@ public class CommentRepositoryImplTestCase extends AbstractTestCase {
final JSONObject comment = new JSONObject();
comment.put(Comment.COMMENT_CONTENT, "comment1 content");
comment.put(Comment.COMMENT_DATE, new Date());
comment.put(Comment.COMMENT_CREATED, new Date().getTime());
comment.put(Comment.COMMENT_EMAIL, "test@gmail.com");
comment.put(Comment.COMMENT_NAME, "comment1 name");
comment.put(Comment.COMMENT_ON_ID, "comment1 on id");
......@@ -63,15 +64,11 @@ public class CommentRepositoryImplTestCase extends AbstractTestCase {
commentRepository.add(comment);
transaction.commit();
final List<JSONObject> comments =
commentRepository.getComments("comment1 on id", 1,
Integer.MAX_VALUE);
final List<JSONObject> comments = commentRepository.getComments("comment1 on id", 1, Integer.MAX_VALUE);
Assert.assertNotNull(comments);
Assert.assertEquals(comments.size(), 1);
Assert.assertEquals(
commentRepository.getComments("not found", 1, Integer.MAX_VALUE).
size(), 0);
Assert.assertEquals(commentRepository.getComments("not found", 1, Integer.MAX_VALUE).size(), 0);
Assert.assertEquals(commentRepository.getRecentComments(3).size(), 1);
}
......
......@@ -33,7 +33,7 @@ import org.testng.annotations.Test;
* {@link CommentMgmtService} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Sep 11, 2012
* @version 1.0.0.3, Sep 16, 2018
*/
@Test(suiteName = "service")
public class CommentMgmtServiceTestCase extends AbstractTestCase {
......@@ -91,7 +91,7 @@ public class CommentMgmtServiceTestCase extends AbstractTestCase {
final JSONObject addResult = commentMgmtService.addArticleComment(requestJSONObject);
Assert.assertNotNull(addResult);
Assert.assertNotNull(addResult.getString(Keys.OBJECT_ID));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_DATE));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_T_DATE));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_THUMBNAIL_URL));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_SHARP_URL));
......@@ -140,7 +140,7 @@ public class CommentMgmtServiceTestCase extends AbstractTestCase {
final JSONObject addResult = commentMgmtService.addPageComment(requestJSONObject);
Assert.assertNotNull(addResult);
Assert.assertNotNull(addResult.getString(Keys.OBJECT_ID));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_DATE));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_T_DATE));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_THUMBNAIL_URL));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_SHARP_URL));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment