aboutsummaryrefslogtreecommitdiff
path: root/juick-core
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-03-02 17:24:39 +0300
committerGravatar Vitaly Takmazov2017-03-02 17:24:39 +0300
commitc2f4735877781313ef0d0960ac3c0403944a495c (patch)
tree6faf327903145713c9b91dc8b07f61fbf52430c1 /juick-core
parent434ea38eeb489f5c095ce55a16ef6dcca9489335 (diff)
juick-server: protocol refactoring
Diffstat (limited to 'juick-core')
-rw-r--r--juick-core/build.gradle1
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java18
2 files changed, 19 insertions, 0 deletions
diff --git a/juick-core/build.gradle b/juick-core/build.gradle
index 58d8eec3..772818e4 100644
--- a/juick-core/build.gradle
+++ b/juick-core/build.gradle
@@ -8,6 +8,7 @@ dependencies {
compile 'org.apache.commons:commons-lang3:3.5'
compile 'org.apache.commons:commons-collections4:4.1'
compile 'commons-io:commons-io:2.5'
+ compile 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
testCompile "junit:junit:${rootProject.junitVersion}"
testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}"
diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
index c6e9022a..d75365e0 100644
--- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -1,9 +1,16 @@
package com.juick.formatters;
+import org.apache.commons.lang3.StringUtils;
+import org.ocpsoft.prettytime.PrettyTime;
+
+import java.util.Locale;
+
/**
* Created by vitalyster on 12.10.2016.
*/
public class PlainTextFormatter {
+ static PrettyTime pt = new PrettyTime(new Locale("ru"));
+
public static String formatPost(com.juick.Message jmsg) {
StringBuilder sb = new StringBuilder();
boolean isReply = jmsg.getRid() > 0;
@@ -17,6 +24,17 @@ public class PlainTextFormatter {
return sb.toString();
}
+ public static String formatPostSummary(com.juick.Message m) {
+ int cropLength = 384;
+ String timeAgo = pt.format(m.getDate());
+ String repliesCount = m.getReplies() == 1 ? "; 1 reply" : m.getReplies() == 0 ? ""
+ : String.format("; %d replies", m.getReplies());
+ String txt = m.getText().length() >= cropLength ?
+ StringUtils.substring(m.getText(), 0, cropLength) + " [...]" : m.getText();
+ return String.format("@%s:%s\n%s\n#%d (%s%s) http://juick.com/%d",
+ m.getUser().getName(), m.getTagsString(), txt, m.getMid(), timeAgo, repliesCount, m.getMid());
+ }
+
public static String formatUrl(com.juick.Message jmsg) {
if (jmsg.getRid() > 0) {
return String.format("https://juick.com/%d#%d", jmsg.getMid(), jmsg.getRid());