/*
- * Sone - GetTimesAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetTimesAjaxPage.java - Copyright © 2010–2016 David Roden
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
package net.pterodactylus.sone.web.ajax;
+import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
+
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.json.JsonObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Optional;
/**
* {@inheritDoc}
*/
@Override
- protected JsonObject createJsonObject(FreenetRequest request) {
+ protected JsonReturnObject createJsonObject(FreenetRequest request) {
String allIds = request.getHttpRequest().getParam("posts");
- JsonObject postTimes = new JsonObject();
+ ObjectNode postTimes = new ObjectNode(instance);
if (allIds.length() > 0) {
String[] ids = allIds.split(",");
for (String id : ids) {
if (!post.isPresent()) {
continue;
}
- JsonObject postTime = new JsonObject();
+ ObjectNode postTime = new ObjectNode(instance);
Time time = getTime(post.get().getTime());
postTime.put("timeText", time.getText());
postTime.put("refreshTime", TimeUnit.MILLISECONDS.toSeconds(time.getRefresh()));
postTimes.put(id, postTime);
}
}
- JsonObject replyTimes = new JsonObject();
+ ObjectNode replyTimes = new ObjectNode(instance);
allIds = request.getHttpRequest().getParam("replies");
if (allIds.length() > 0) {
String[] ids = allIds.split(",");
if (!reply.isPresent()) {
continue;
}
- JsonObject replyTime = new JsonObject();
+ ObjectNode replyTime = new ObjectNode(instance);
Time time = getTime(reply.get().getTime());
replyTime.put("timeText", time.getText());
replyTime.put("refreshTime", TimeUnit.MILLISECONDS.toSeconds(time.getRefresh()));
String text;
long refresh;
if (age < 0) {
- text = webInterface.getL10n().getDefaultString("View.Time.InTheFuture");
+ text = webInterface.getL10n().getString("View.Time.InTheFuture");
refresh = TimeUnit.MINUTES.toMillis(5);
} else if (age < TimeUnit.SECONDS.toMillis(20)) {
- text = webInterface.getL10n().getDefaultString("View.Time.AFewSecondsAgo");
+ text = webInterface.getL10n().getString("View.Time.AFewSecondsAgo");
refresh = TimeUnit.SECONDS.toMillis(10);
} else if (age < TimeUnit.SECONDS.toMillis(45)) {
text = webInterface.getL10n().getString("View.Time.HalfAMinuteAgo");
text = webInterface.getL10n().getString("View.Time.AWeekAgo");
refresh = TimeUnit.DAYS.toMillis(1);
} else if (age < TimeUnit.DAYS.toMillis(28)) {
- text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / 24));
+ text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / (7 * 24)));
refresh = TimeUnit.DAYS.toMillis(1);
} else if (age < TimeUnit.DAYS.toMillis(42)) {
text = webInterface.getL10n().getString("View.Time.AMonthAgo");