summaryrefslogtreecommitdiff
path: root/plugins/Realtime/realtimeupdate.js
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-07-14 15:26:39 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-07-14 15:26:39 -0400
commit86533d99d760b7d6b3a6a047898eec5e25497138 (patch)
tree887b44d4197af7ce13932e4d075e34179c3c015b /plugins/Realtime/realtimeupdate.js
parent7a84b349a2f6ee36f4813bf2828c5bf2399d1614 (diff)
make RealtimePlugin work correctly
Diffstat (limited to 'plugins/Realtime/realtimeupdate.js')
-rw-r--r--plugins/Realtime/realtimeupdate.js56
1 files changed, 13 insertions, 43 deletions
diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js
index 170949e9b..9ad808740 100644
--- a/plugins/Realtime/realtimeupdate.js
+++ b/plugins/Realtime/realtimeupdate.js
@@ -1,41 +1,11 @@
-// update the local timeline from a Comet server
+// add a notice encoded as JSON into the current timeline
//
-var updater = function()
-{
- var _server;
- var _timeline;
- var _userid;
- var _replyurl;
- var _favorurl;
- var _deleteurl;
- var _cometd;
-
- return {
- init: function(server, timeline, userid, replyurl, favorurl, deleteurl)
- {
- _cometd = $.cometd; // Uses the default Comet object
- _cometd.setLogLevel('debug');
- _cometd.init(server);
- _server = server;
- _timeline = timeline;
- _userid = userid;
- _favorurl = favorurl;
- _replyurl = replyurl;
- _deleteurl = deleteurl;
- _cometd.subscribe(timeline, receive);
- $(window).unload(leave);
- }
- }
-
- function leave()
- {
- _cometd.disconnect();
- }
+RealtimeUpdate = {
- function receive(message)
+ receive: function(message)
{
- id = message.data.id;
+ id = data.id;
// Don't add it if it already exists
@@ -43,7 +13,7 @@ var updater = function()
return;
}
- var noticeItem = makeNoticeItem(message.data);
+ var noticeItem = RealtimeUpdate.makeNoticeItem(data);
$("#notices_primary .notices").prepend(noticeItem, true);
$("#notices_primary .notice:first").css({display:"none"});
$("#notices_primary .notice:first").fadeIn(1000);
@@ -51,7 +21,7 @@ var updater = function()
NoticeReply();
}
- function makeNoticeItem(data)
+ makeNoticeItem: function(data)
{
user = data['user'];
html = data['html'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');
@@ -96,10 +66,10 @@ var updater = function()
if (_userid != 0) {
var input = $("form#form_notice fieldset input#token");
var session_key = input.val();
- ni = ni+makeFavoriteForm(data['id'], session_key);
- ni = ni+makeReplyLink(data['id'], data['user']['screen_name']);
+ ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
+ ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
if (_userid == data['user']['id']) {
- ni = ni+makeDeleteLink(data['id']);
+ ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
}
}
@@ -108,7 +78,7 @@ var updater = function()
return ni;
}
- function makeFavoriteForm(id, session_key)
+ makeFavoriteForm: function(id, session_key)
{
var ff;
@@ -123,7 +93,7 @@ var updater = function()
return ff;
}
- function makeReplyLink(id, nickname)
+ makeReplyLink: function(id, nickname)
{
var rl;
rl = "<dl class=\"notice_reply\">"+
@@ -136,7 +106,7 @@ var updater = function()
return rl;
}
- function makeDeleteLink(id)
+ makeDeleteLink: function(id)
{
var dl, delurl;
delurl = _deleteurl.replace("0000000000", id);
@@ -150,5 +120,5 @@ var updater = function()
return dl;
}
-}();
+};