Commit eaea8f98 authored by Liang Ding's avatar Liang Ding

🎨 #12509 评论时间

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