Merge branch 'release-0.4.3' 0.4.3
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Jan 2011 09:22:01 +0000 (10:22 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Jan 2011 09:22:01 +0000 (10:22 +0100)
17 files changed:
pom.xml
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
src/main/java/net/pterodactylus/sone/core/UpdateChecker.java
src/main/java/net/pterodactylus/sone/core/UpdateListener.java
src/main/java/net/pterodactylus/sone/core/UpdateListenerManager.java
src/main/java/net/pterodactylus/sone/data/Sone.java
src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/static/javascript/sone.js
src/main/resources/templates/notify/newVersionNotification.html
src/main/resources/templates/viewSone.html

diff --git a/pom.xml b/pom.xml
index 4a5a06e..3546ccc 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
        <modelVersion>4.0.0</modelVersion>
        <groupId>net.pterodactylus</groupId>
        <artifactId>sone</artifactId>
-       <version>0.4.2</version>
+       <version>0.4.3</version>
        <dependencies>
                <dependency>
                        <groupId>net.pterodactylus</groupId>
index dbda28d..99a119b 100644 (file)
@@ -996,7 +996,7 @@ public class Core implements IdentityListener, UpdateListener {
                                                }
                                        }
                                }
-                               Set<Reply> storedReplies = sone.getReplies();
+                               Set<Reply> storedReplies = storedSone.getReplies();
                                synchronized (newReplies) {
                                        for (Reply reply : sone.getReplies()) {
                                                reply.setSone(storedSone);
@@ -1771,8 +1771,8 @@ public class Core implements IdentityListener, UpdateListener {
         * {@inheritDoc}
         */
        @Override
-       public void updateFound(Version version, long releaseTime) {
-               coreListenerManager.fireUpdateFound(version, releaseTime);
+       public void updateFound(Version version, long releaseTime, long latestEdition) {
+               coreListenerManager.fireUpdateFound(version, releaseTime, latestEdition);
        }
 
 }
index 5fbb333..fb83c9f 100644 (file)
@@ -135,7 +135,9 @@ public interface CoreListener extends EventListener {
         *            The version that was found
         * @param releaseTime
         *            The release time of the new version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       public void updateFound(Version version, long releaseTime);
+       public void updateFound(Version version, long releaseTime, long latestEdition);
 
 }
index 4fc9532..6dbdc58 100644 (file)
@@ -201,15 +201,17 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        /**
         * Notifies all listeners that a new version was found.
         *
-        * @see CoreListener#updateFound(Version, long)
+        * @see CoreListener#updateFound(Version, long, long)
         * @param version
         *            The new version
         * @param releaseTime
         *            The release time of the new version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       void fireUpdateFound(Version version, long releaseTime) {
+       void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
                for (CoreListener coreListener : getListeners()) {
-                       coreListener.updateFound(version, releaseTime);
+                       coreListener.updateFound(version, releaseTime, latestEdition);
                }
        }
 
index c31be8a..b16d374 100644 (file)
@@ -204,7 +204,7 @@ public class SoneInserter extends AbstractService {
                                        core.setSoneStatus(sone, SoneStatus.inserting);
                                        long insertTime = System.currentTimeMillis();
                                        insertInformation.setTime(insertTime);
-                                       FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html");
+                                       FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri(), insertInformation.generateManifestEntries(), "index.html");
                                        /* at this point we might already be stopped. */
                                        if (shouldStop()) {
                                                /* if so, bail out, don’t change anything. */
@@ -212,6 +212,7 @@ public class SoneInserter extends AbstractService {
                                        }
                                        sone.setTime(insertTime);
                                        sone.setLatestEdition(finalUri.getEdition());
+                                       core.saveSone(sone);
                                        success = true;
                                        logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri });
                                } catch (SoneException se1) {
index 51e8df4..e07e160 100644 (file)
@@ -60,6 +60,9 @@ public class UpdateChecker {
        /** The current URI of the homepage. */
        private FreenetURI currentUri;
 
+       /** The latest known edition. */
+       private long latestEdition;
+
        /** The current latest known version. */
        private Version currentLatestVersion = SonePlugin.VERSION;
 
@@ -135,6 +138,15 @@ public class UpdateChecker {
                return latestVersionDate;
        }
 
+       /**
+        * Returns the latest known edition of the Sone homepage.
+        *
+        * @return The latest edition of the Sone homepage
+        */
+       public long getLatestEdition() {
+               return latestEdition;
+       }
+
        //
        // ACTIONS
        //
@@ -163,7 +175,8 @@ public class UpdateChecker {
                                        }
                                        Bucket resultBucket = uriResult.getRight().asBucket();
                                        try {
-                                               parseProperties(resultBucket.getInputStream());
+                                               parseProperties(resultBucket.getInputStream(), edition);
+                                               latestEdition = edition;
                                        } catch (IOException ioe1) {
                                                logger.log(Level.WARNING, "Could not parse sone.properties of " + uri, ioe1);
                                        } finally {
@@ -189,14 +202,16 @@ public class UpdateChecker {
         * Parses the properties of the latest version and fires events, if
         * necessary.
         *
-        * @see UpdateListener#updateFound(Version, long)
-        * @see UpdateListenerManager#fireUpdateFound(Version, long)
+        * @see UpdateListener#updateFound(Version, long, long)
+        * @see UpdateListenerManager#fireUpdateFound(Version, long, long)
         * @param propertiesInputStream
         *            The input stream to parse
+        * @param edition
+        *            The latest edition of the Sone homepage
         * @throws IOException
         *             if an I/O error occured
         */
-       private void parseProperties(InputStream propertiesInputStream) throws IOException {
+       private void parseProperties(InputStream propertiesInputStream, long edition) throws IOException {
                Properties properties = new Properties();
                InputStreamReader inputStreamReader = null;
                try {
@@ -226,7 +241,7 @@ public class UpdateChecker {
                        currentLatestVersion = version;
                        latestVersionDate = releaseTime;
                        logger.log(Level.INFO, "Found new version: %s (%tc)", new Object[] { version, new Date(releaseTime) });
-                       updateListenerManager.fireUpdateFound(version, releaseTime);
+                       updateListenerManager.fireUpdateFound(version, releaseTime, edition);
                }
        }
 
index 1469afa..18f4b88 100644 (file)
@@ -36,7 +36,9 @@ public interface UpdateListener extends EventListener {
         *            The version that was found
         * @param releaseTime
         *            The release time of the version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       public void updateFound(Version version, long releaseTime);
+       public void updateFound(Version version, long releaseTime, long latestEdition);
 
 }
index 3f3b21f..cddf8db 100644 (file)
@@ -45,10 +45,12 @@ public class UpdateListenerManager extends AbstractListenerManager<Void, UpdateL
         *            The new version
         * @param releaseTime
         *            The release time of the new version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       void fireUpdateFound(Version version, long releaseTime) {
+       void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
                for (UpdateListener updateListener : getListeners()) {
-                       updateListener.updateFound(version, releaseTime);
+                       updateListener.updateFound(version, releaseTime, latestEdition);
                }
        }
 
index 03dff75..f183b39 100644 (file)
@@ -176,7 +176,7 @@ public class Sone implements Fingerprintable {
         */
        public Sone setRequestUri(FreenetURI requestUri) {
                if (this.requestUri == null) {
-                       this.requestUri = requestUri.setDocName("Sone").setMetaString(new String[0]);
+                       this.requestUri = requestUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
                        return this;
                }
                if (!this.requestUri.equalsKeypair(requestUri)) {
@@ -204,7 +204,7 @@ public class Sone implements Fingerprintable {
         */
        public Sone setInsertUri(FreenetURI insertUri) {
                if (this.insertUri == null) {
-                       this.insertUri = insertUri.setDocName("Sone").setMetaString(new String[0]);
+                       this.insertUri = insertUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
                        return this;
                }
                if (!this.insertUri.equalsKeypair(insertUri)) {
index 68a10f4..26dc449 100644 (file)
@@ -72,8 +72,6 @@ public interface OwnIdentity extends Identity {
 
        /**
         * Sets the property with the given name to the given value.
-        * <p>
-        * This method is only called by the {@link IdentityManager}.
         *
         * @param name
         *            The name of the property
index 4be076d..e51f9a1 100644 (file)
@@ -78,7 +78,7 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
        }
 
        /** The version. */
-       public static final Version VERSION = new Version(0, 4, 2);
+       public static final Version VERSION = new Version(0, 4, 3);
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(SonePlugin.class);
index fa43945..a7df9c2 100644 (file)
@@ -193,6 +193,7 @@ public class SoneTemplatePage extends TemplatePage {
                templateContext.set("request", request);
                templateContext.set("currentVersion", SonePlugin.VERSION);
                templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
+               templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
                templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
                templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
        }
index 0df6d79..9023ccf 100644 (file)
@@ -765,8 +765,9 @@ public class WebInterface implements CoreListener {
         * {@inheritDoc}
         */
        @Override
-       public void updateFound(Version version, long releaseTime) {
-               newVersionNotification.getTemplateContext().set("version", version);
+       public void updateFound(Version version, long releaseTime, long latestEdition) {
+               newVersionNotification.getTemplateContext().set("latestVersion", version);
+               newVersionNotification.getTemplateContext().set("latestEdition", latestEdition);
                newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
                notificationManager.addNotification(newVersionNotification);
        }
index 50dab27..35bc436 100644 (file)
@@ -245,4 +245,4 @@ Notification.SoneIsBeingRescued.Text=The following Sones are currently being res
 Notification.SoneRescued.Text=The following Sones have been rescued:
 Notification.SoneRescued.Text.RememberToUnlock=Please remember to control the posts and replies you have given and don’t forget to unlock your Sones!
 Notification.LockedSones.Text=The following Sones have been locked for more than 5 minutes. Please check if you really want to keep these Sones locked:
-Notification.NewVersion.Text=A new version of the Sone plugin was found: Version {version}.
+Notification.NewVersion.Text=Version {version} of the Sone plugin was found. Download it from USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/{edition}​!
index 6ff4ceb..251105a 100644 (file)
@@ -71,7 +71,6 @@ function addCommentLink(postId, element, insertAfterThisElement) {
        commentElement = (function(postId) {
                separator = $("<span> · </span>").addClass("separator");
                var commentElement = $("<div><span>Comment</span></div>").addClass("show-reply-form").click(function() {
-                       markPostAsKnown(getPostElement(this));
                        replyElement = $("#sone .post#" + postId + " .create-reply");
                        replyElement.removeClass("hidden");
                        replyElement.removeClass("light");
@@ -606,7 +605,6 @@ function ajaxifyPost(postElement) {
                                if (success) {
                                        $(inputField).val("");
                                        loadNewReply(replyId, soneId, postId);
-                                       markPostAsKnown(getPostElement(inputField));
                                        $("#sone .post#" + postId + " .create-reply").addClass("hidden");
                                        $("#sone .post#" + postId + " .create-reply .sender").hide();
                                        $("#sone .post#" + postId + " .create-reply .select-sender").show();
@@ -630,12 +628,10 @@ function ajaxifyPost(postElement) {
        /* convert all “like” buttons to javascript functions. */
        $(postElement).find(".like-post").submit(function() {
                likePost(getPostId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
        $(postElement).find(".unlike-post").submit(function() {
                unlikePost(getPostId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
 
@@ -698,12 +694,10 @@ function ajaxifyPost(postElement) {
 function ajaxifyReply(replyElement) {
        $(replyElement).find(".like-reply").submit(function() {
                likeReply(getReplyId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
        $(replyElement).find(".unlike-reply").submit(function() {
                unlikeReply(getReplyId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
        (function(replyElement) {
@@ -728,11 +722,6 @@ function ajaxifyReply(replyElement) {
                untrustSone(getReplyAuthor(this));
                return false;
        });
-
-       /* mark post and all replies as known on click. */
-       $(replyElement).click(function() {
-               markPostAsKnown(getPostElement(this));
-       });
 }
 
 /**
@@ -1013,10 +1002,9 @@ function markPostAsKnown(postElements) {
                postElement = this;
                if ($(postElement).hasClass("new")) {
                        (function(postElement) {
-                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}, function(data, textStatus) {
-                                       $(postElement).removeClass("new");
-                                       $(".click-to-show", postElement).removeClass("new");
-                               });
+                               $(postElement).removeClass("new");
+                               $(".click-to-show", postElement).removeClass("new");
+                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)});
                        })(postElement);
                }
        });
@@ -1028,9 +1016,8 @@ function markReplyAsKnown(replyElements) {
                replyElement = this;
                if ($(replyElement).hasClass("new")) {
                        (function(replyElement) {
-                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)}, function(data, textStatus) {
-                                       $(replyElement).removeClass("new");
-                               });
+                               $(replyElement).removeClass("new");
+                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)});
                        })(replyElement);
                }
        });
index 23a5855..fdb8b2a 100644 (file)
@@ -1 +1 @@
-<div class="text"><%= Notification.NewVersion.Text|l10n|html|replace needle="{version}" replacementKey=version></div>
+<div class="text"><%= Notification.NewVersion.Text|l10n|replace needle="{version}" replacementKey=latestVersion|replace needle="{edition}" replacementKey=latestEdition|parse sone=currentSone></div>
index fac920b..4b2502a 100644 (file)
                                </div>
                        <%/foreach>
 
-               <%if ! sone.current>
-                       <p><%= Page.ViewSone.WriteAMessage|l10n|html></p>
-
-                       <form action="createPost.html" id="post-message" method="post">
-                               <input type="hidden" name="formPassword" value="<% formPassword|html>" />
-                               <input type="hidden" name="returnPage" value="<% request.uri|html>" />
-                               <input type="hidden" name="recipient" value="<% sone.id|html>" />
-                               <input type="text" name="text" value="" />
-                               <button type="submit"><%= Page.CreatePost.Button.Post|l10n|html></button>
-                       </form>
+               <%ifnull ! currentSone>
+                       <%if ! sone.current>
+                               <p><%= Page.ViewSone.WriteAMessage|l10n|html></p>
+
+                               <form action="createPost.html" id="post-message" method="post">
+                                       <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+                                       <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+                                       <input type="hidden" name="recipient" value="<% sone.id|html>" />
+                                       <input type="text" name="text" value="" />
+                                       <button type="submit"><%= Page.CreatePost.Button.Post|l10n|html></button>
+                               </form>
+                       <%/if>
                <%/if>
 
                <h1><%= Page.ViewSone.PostList.Title|l10n|replace needle="{sone}" replacementKey=sone.niceName|html></h1>