]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Realtime/realtimeupdate.js
Merge commit 'refs/merge-requests/182' of gitorious.org:statusnet/mainline into 1.1.x
[quix0rs-gnu-social.git] / plugins / Realtime / realtimeupdate.js
index 59e3fe72d770f19249bd26a99b8a94900eade18a..e044f2f916c0fbe1e8e3bb9b1c37581d97093941 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * StatusNet - a distributed open-source microblogging tool
- * Copyright (C) 2008, StatusNet, Inc.
+ * Copyright (C) 2009-2011, StatusNet, Inc.
  *
  * Add a notice encoded as JSON into the current timeline
  *
@@ -21,7 +21,7 @@
  * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
  * @author    Sarven Capadisli <csarven@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2011 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -45,6 +45,8 @@
 RealtimeUpdate = {
      _userid: 0,
      _showurl: '',
+     _keepaliveurl: '',
+     _closeurl: '',
      _updatecounter: 0,
      _maxnotices: 50,
      _windowhasfocus: true,
@@ -155,6 +157,10 @@ RealtimeUpdate = {
         }
 
         RealtimeUpdate.makeNoticeItem(data, function(noticeItem) {
+            // Check again in case it got shown while we were waiting for data...
+            if (RealtimeUpdate.isNoticeVisible(data.id)) {
+                return;
+            }
             var noticeItemID = $(noticeItem).attr('id');
 
             var list = $("#notices_primary .notices:first")
@@ -177,6 +183,7 @@ RealtimeUpdate = {
                     if (list.length == 0) {
                         list = $('<ul class="notices threaded-replies xoxo"></ul>');
                         parent.append(list);
+                        SN.U.NoticeInlineReplyPlaceholder(parent);
                     }
                     prepend = false;
                 }
@@ -191,7 +198,6 @@ RealtimeUpdate = {
                     newNotice.insertBefore(placeholder)
                 } else {
                     newNotice.appendTo(list);
-                    SN.U.NoticeInlineReplyPlaceholder(parent);
                 }
             }
             newNotice.css({display:"none"}).fadeIn(1000);
@@ -386,11 +392,28 @@ RealtimeUpdate = {
       *
       * @access private
       */
-     initActions: function(url, timeline, path)
+    initActions: function(url, timeline, path, keepaliveurl, closeurl)
      {
         $('#notices_primary').prepend('<ul id="realtime_actions"><li id="realtime_playpause"></li><li id="realtime_timeline"></li></ul>');
 
         RealtimeUpdate._pluginPath = path;
+        RealtimeUpdate._keepaliveurl = keepaliveurl;
+        RealtimeUpdate._closeurl = closeurl;
+
+
+        // On unload, let the server know we're no longer listening
+         $(window).unload(function() {
+            $.ajax({
+                type: 'POST',
+                url: RealtimeUpdate._closeurl});
+        });
+
+       setInterval(function() {
+            $.ajax({
+                type: 'POST',
+                url: RealtimeUpdate._keepaliveurl});
+
+       }, 15 * 60 * 1000 ); // every 15 min; timeout in 30 min
 
         RealtimeUpdate.initPlayPause();
         RealtimeUpdate.initAddPopup(url, timeline, RealtimeUpdate._pluginPath);