Ignore a post if neither sender nor recipient match the currently viewed Sone.
[Sone.git] / src / main / resources / static / javascript / sone.js
index fa2c275..3646f73 100644 (file)
@@ -256,7 +256,7 @@ function getFormPassword() {
 }
 
 function getSoneElement(element) {
-       return $(element).parents(".sone");
+       return $(element).closest(".sone");
 }
 
 /**
@@ -680,7 +680,7 @@ function loadNewPost(postId) {
        loadedPosts[postId] = true;
        $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
                if ((data != null) && data.success) {
-                       if (!isIndexPage() && !(isViewSonePage() && (getShownSoneId() == data.post.sone))) {
+                       if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) {
                                return;
                        }
                        var firstOlderPost = null;
@@ -694,7 +694,7 @@ function loadNewPost(postId) {
                        if (firstOlderPost != null) {
                                newPost.insertBefore(firstOlderPost);
                        } else {
-                               $("#sone .post:last").append(newPost);
+                               $("#sone #posts").append(newPost);
                        }
                        ajaxifyPost(newPost);
                        newPost.slideDown();
@@ -825,6 +825,21 @@ $(document).ready(function() {
                });
        });
 
+       /* ajaxify input field on “view Sone” page. */
+       getTranslation("WebInterface.DefaultText.Message", function(defaultText) {
+               registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false);
+               $("#sone #post-message").submit(function() {
+                       text = $(this).find(":input:enabled").val();
+                       $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "text": text }, function(data, textStatus) {
+                               if ((data != null) && data.success) {
+                                       loadNewPost(data.postId);
+                               }
+                       });
+                       $(this).find(":input:enabled").val("").blur();
+                       return false;
+               });
+       });
+
        /* Ajaxifies all posts. */
        /* calling getTranslation here will cache the necessary values. */
        getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {