/** The logger. */
private static final Logger logger = Logging.getLogger(SoneDownloader.class);
+ /** The maximum protocol version. */
+ private static final int MAX_PROTOCOL_VERSION = 0;
+
/** The core. */
private final Core core;
return null;
}
+ Integer protocolVersion = null;
+ String soneProtocolVersion = soneXml.getValue("protocol-version", null);
+ if (soneProtocolVersion != null) {
+ protocolVersion = Numbers.safeParseInteger(soneProtocolVersion);
+ }
+ if (protocolVersion == null) {
+ logger.log(Level.INFO, "No protocol version found, assuming 0.");
+ protocolVersion = 0;
+ }
+
+ if (protocolVersion < 0) {
+ logger.log(Level.WARNING, "Invalid protocol version: " + protocolVersion + "! Not parsing Sone.");
+ return null;
+ }
+
+ /* check for valid versions. */
+ if (protocolVersion > MAX_PROTOCOL_VERSION) {
+ logger.log(Level.WARNING, "Unknown protocol version: " + protocolVersion + "! Not parsing Sone.");
+ return null;
+ }
+
String soneTime = soneXml.getValue("time", null);
if (soneTime == null) {
/* TODO - mark Sone as bad. */
public ListNotification(String id, String key, Template template) {
super(id, template);
template.set(key, elements);
+ template.set("notification", this);
}
//
@Override
protected void processTemplate(Request request, Template template) throws RedirectException {
super.processTemplate(request, template);
- template.set("currentSone", getCurrentSone(request.getToadletContext()));
+ template.set("currentSone", getCurrentSone(request.getToadletContext(), false));
template.set("request", request);
}
*/
@Override
protected String getRedirectTarget(Page.Request request) {
- if (requiresLogin() && (getCurrentSone(request.getToadletContext()) == null)) {
+ if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) {
return "login.html";
}
return null;
protected JsonObject createJsonObject(Request request) {
/* load Sones. */
boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "true"));
- Set<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext())));
+ Set<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext(), false)));
if (loadAllSones) {
sones.addAll(webInterface.getCore().getSones());
}
JsonArray jsonSones = new JsonArray();
for (Sone sone : sones) {
+ if (sone == null) {
+ continue;
+ }
JsonObject jsonSone = createJsonSone(sone);
jsonSones.add(jsonSone);
}
package net.pterodactylus.sone.web.ajax;
-import java.util.UUID;
-
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.Page;
* session
*/
protected Session getCurrentSession(ToadletContext toadletContenxt) {
- return getCurrentSession(toadletContenxt, true);
+ return webInterface.getCurrentSession(toadletContenxt);
}
/**
* session
*/
protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
- Session session = webInterface.getSessionManager().useSession(toadletContenxt);
- if (create && (session == null)) {
- session = webInterface.getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
- }
- return session;
+ return webInterface.getCurrentSession(toadletContenxt, create);
}
/**
* currently logged in
*/
protected Sone getCurrentSone(ToadletContext toadletContext) {
- Session session = getCurrentSession(toadletContext);
- if (session == null) {
- return null;
- }
- String soneId = (String) session.getAttribute("Sone.CurrentSone");
- if (soneId == null) {
- return null;
- }
- return webInterface.getCore().getLocalSone(soneId, false);
+ return webInterface.getCurrentSone(toadletContext);
+ }
+
+ /**
+ * Returns the currently logged in Sone.
+ *
+ * @param toadletContext
+ * The toadlet context
+ * @param create
+ * {@code true} to create a new session if no session exists,
+ * {@code false} to not create a new session
+ * @return The currently logged in Sone, or {@code null} if no Sone is
+ * currently logged in
+ */
+ protected Sone getCurrentSone(ToadletContext toadletContext, boolean create) {
+ return webInterface.getCurrentSone(toadletContext, create);
}
//
WebInterface.SelectBox.No=No
WebInterface.ClickToShow.Replies=Click here to show hidden replies.
+Notification.ClickHereToRead=Click here to read the full text of the notification.
Notification.FirstStart.Text=This seems to be the first time you start Sone. To start, create a new Sone from a web of trust identity and start following other Sones.
Notification.Startup.Text=Sone is currently starting up. It may take a while to retrieve all identities and Sones from the web of trust. If you are missing some elements, please be patient, they will probably reappear very soon.
Notification.ConfigNotRead.Text=The configuration file “sone.properties” could not be read, probably because it was not saved correctly. This can happen on versions prior to Sone 0.3.3 and there is nothing you can do about it.
Notification.Button.Dismiss=Dismiss
Notification.NewSone.Text=New Sones have been discovered:
+Notification.NewPost.ShortText=New posts have been discovered.
Notification.NewPost.Text=New posts have been discovered by the following Sones:
+Notification.NewReply.ShortText=New replies have been discovered.
Notification.NewReply.Text=New replies have been discovered by the following Sones:
Notification.SoneIsBeingRescued.Text=The following Sones are currently being rescued:
Notification.SoneRescued.Text=The following Sones have been rescued:
float: right;
}
-#sone #notification-area .notification > div {
- display: inline;
-}
-
#sone #notification-area .notification .post-count {
margin-left: 1ex;
}
return notification;
}
+/**
+ * Shows the details of the notification with the given ID.
+ *
+ * @param notificationId
+ * The ID of the notification
+ */
+function showNotificationDetails(notificationId) {
+ $("#sone .notification#" + notificationId + " .text").show();
+ $("#sone .notification#" + notificationId + " .short-text").hide();
+}
+
//
// EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE
//
<sone>
<time><% currentSone.time></time>
+ <protocol-version>0</protocol-version>
<client>
<name>Sone</name>
<%include include/head.html>
+
+ <div class="page-id hidden">login</div>
+
<%if !sones.empty>
<h1><%= Page.Login.Page.Title|l10n|html></h1>
<form method="post">
-<div class="text">
+<div class="short-text">
+ <%= Notification.NewPost.ShortText|l10n|html>
+ <a href="javascript:showNotificationDetails('<%notification.id|html>'); return false;"><%= Notification.ClickHereToRead|l10n|html></a>
+</div>
+<div class="text hidden">
<%= Notification.NewPost.Text|l10n|html>
<%foreach posts post>
<a href="viewPost.html?post=<% post.id|html>"><% post.sone.niceName|html></a><%notlast>,<%/notlast><%last>.<%/last>
-<div class="text">
+<div class="short-text">
+ <%= Notification.NewReply.ShortText|l10n|html>
+ <a href="javascript:showNotificationDetails('<%notification.id|html>'); return false;"><%= Notification.ClickHereToRead|l10n|html></a>
+</div>
+<div class="text hidden">
<%= Notification.NewReply.Text|l10n|html>
<%foreach replies reply>
<a href="viewPost.html?post=<% reply.post.id|html>"><% reply.sone.niceName|html></a><%notlast>,<%/notlast><%last>.<%/last>