});
/* process new posts. */
$.each(data.newPosts, function(index, value) {
- loadNewPost(value);
+ loadNewPost(value.id, value.sone, value.recipient);
});
/* process new replies. */
$.each(data.newReplies, function(index, value) {
}
/**
+ * Returns the ID of the currently logged in Sone.
+ *
+ * @return The ID of the current Sone, or an empty string if no Sone is logged
+ * in
+ */
+function getCurrentSoneId() {
+ return $("#currentSoneId").text();
+}
+
+/**
* Returns the content of the page-id attribute.
*
* @returns The page ID
return getPageId() == "known-sones";
}
-var loadedPosts = {};
-var loadedReplies = {};
+/**
+ * Returns whether a post with the given ID exists on the current page.
+ *
+ * @param postId
+ * The post ID to check for
+ * @returns {Boolean} <code>true</code> if a post with the given ID already
+ * exists on the page, <code>false</code> otherwise
+ */
+function hasPost(postId) {
+ return $(".post#" + postId).length > 0;
+}
-function loadNewPost(postId) {
- if (postId in loadedPosts) {
+/**
+ * Returns whether a reply with the given ID exists on the current page.
+ *
+ * @param replyId
+ * The reply ID to check for
+ * @returns {Boolean} <code>true</code> if a reply with the given ID already
+ * exists on the page, <code>false</code> otherwise
+ */
+function hasReply(replyId) {
+ return $("#sone .reply#" + replyId).length > 0;
+}
+
+function loadNewPost(postId, soneId, recipientId) {
+ if (hasPost(postId)) {
+ return;
+ }
+ if (!isIndexPage() && (!isViewPostPage() || (getShownPostId() != postId))) {
return;
}
$.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
if ((data != null) && data.success) {
- if (data.post.id in loadedPosts) {
+ if (hasPost(data.post.id)) {
return;
}
- loadedPosts[data.post.id] = true;
if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) {
return;
}
}
function loadNewReply(replyId) {
- if (replyId in loadedReplies) {
+ if (hasReply(replyId)) {
return;
}
$.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
/* find post. */
if ((data != null) && data.success) {
- if (data.reply.id in loadedReplies) {
+ if (hasReply(data.reply.id)) {
return;
}
- loadedReplies[data.reply.id] = true;
$("#sone .post#" + data.reply.postId).each(function() {
var firstNewerReply = null;
$(this).find(".replies .reply").each(function() {
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
//
getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) {
registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false);
$("#sone #update-status").submit(function() {
+ if ($(this).find(":input.default:enabled").length > 0) {
+ return false;
+ }
text = $(this).find(":input:enabled").val();
$.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
if ((data != null) && data.success) {