From 420980f0e0cd1023902b23d4082a0734d16c67a5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 14 Jul 2009 17:06:29 -0400 Subject: changes to make realtime work for Meteor --- plugins/Realtime/RealtimePlugin.php | 14 ++++++------- plugins/Realtime/realtimeupdate.js | 39 ++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 21 deletions(-) (limited to 'plugins/Realtime') diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index c9483f991..d01da5a50 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -65,12 +65,12 @@ class RealtimePlugin extends Plugin switch ($action->trimmed('action')) { case 'public': - $timeline = '/timelines/public'; + $timeline = 'timelines-public'; break; case 'tag': $tag = $action->trimmed('tag'); if (!empty($tag)) { - $timeline = '/timelines/tag/'.$tag; + $timeline = 'timelines-tag-'.$tag; } else { return true; } @@ -112,14 +112,14 @@ class RealtimePlugin extends Plugin if ($notice->is_local || ($notice->is_local == 0 && !common_config('public', 'localonly'))) { - $timelines[] = '/timelines/public'; + $timelines[] = 'timelines-public'; } $tags = $this->getNoticeTags($notice); if (!empty($tags)) { foreach ($tags as $tag) { - $timelines[] = '/timelines/tag/' . $tag; + $timelines[] = 'timelines-tag-' . $tag; } } @@ -198,13 +198,13 @@ class RealtimePlugin extends Plugin function _getScripts() { - return array(common_local_path('plugins/Realtime/realtimeupdater.js'), - common_local_path('plugins/Realtime/json2.js')); + return array(common_path('plugins/Realtime/realtimeupdate.js'), + common_path('plugins/Realtime/json2.js')); } function _updateInitialize($timeline, $user_id) { - return '; '; + return "RealtimeUpdate.init($user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->deleteurl\"); "; } function _connect() diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index 9ad808740..d55db5859 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -3,7 +3,20 @@ RealtimeUpdate = { - receive: function(message) + _userid: 0, + _replyurl: '', + _favorurl: '', + _deleteurl: '', + + init: function(userid, replyurl, favorurl, deleteurl) + { + RealtimeUpdate._userid = userid; + RealtimeUpdate._replyurl = replyurl; + RealtimeUpdate._favorurl = favorurl; + RealtimeUpdate._deleteurl = deleteurl; + }, + + receive: function(data) { id = data.id; @@ -17,9 +30,8 @@ RealtimeUpdate = { $("#notices_primary .notices").prepend(noticeItem, true); $("#notices_primary .notice:first").css({display:"none"}); $("#notices_primary .notice:first").fadeIn(1000); - NoticeHover(); NoticeReply(); - } + }, makeNoticeItem: function(data) { @@ -63,12 +75,12 @@ RealtimeUpdate = { ni = ni+""+ "
"; - if (_userid != 0) { + if (RealtimeUpdate._userid != 0) { var input = $("form#form_notice fieldset input#token"); var session_key = input.val(); ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key); ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']); - if (_userid == data['user']['id']) { + if (RealtimeUpdate._userid == data['user']['id']) { ni = ni+RealtimeUpdate.makeDeleteLink(data['id']); } } @@ -76,13 +88,13 @@ RealtimeUpdate = { ni = ni+"
"+ ""; return ni; - } + }, makeFavoriteForm: function(id, session_key) { var ff; - ff = "
"+ + ff = ""+ "
"+ "Favor this notice"+ // XXX: i18n ""+ @@ -91,7 +103,7 @@ RealtimeUpdate = { "
"+ "
"; return ff; - } + }, makeReplyLink: function(id, nickname) { @@ -99,17 +111,17 @@ RealtimeUpdate = { rl = "
"+ "
Reply to this notice
"+ "
"+ - "Reply "+id+""+ + "Reply "+id+""+ ""+ "
"+ "
"; return rl; - } + }, makeDeleteLink: function(id) { var dl, delurl; - delurl = _deleteurl.replace("0000000000", id); + delurl = RealtimeUpdate._deleteurl.replace("0000000000", id); dl = "
"+ "
Delete this notice
"+ @@ -119,6 +131,5 @@ RealtimeUpdate = { "
"; return dl; - } -}; - + }, +} -- cgit v1.2.3-54-g00ecf