From e438334c00ebe29c01bfc5b02aa64cffdb43cb46 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 18:00:06 -0400 Subject: [PATCH 1/3] add live updating for tag pages --- plugins/Comet/CometPlugin.php | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index a7a4f4b237..cff0d4c9d6 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -62,6 +62,14 @@ class CometPlugin extends Plugin case 'public': $timeline = '/timelines/public'; break; + case 'tag': + $tag = $action->trimmed('tag'); + if (!empty($tag)) { + $timeline = '/timelines/tag/'.$tag; + } else { + return true; + } + break; default: return true; } @@ -94,6 +102,14 @@ class CometPlugin extends Plugin $timelines[] = '/timelines/public'; } + $tags = $this->getNoticeTags($notice); + + if (!empty($tags)) { + foreach ($tags as $tag) { + $timelines[] = '/timelines/tag/' . $tag; + } + } + if (count($timelines) > 0) { // Require this, since we need it require_once(INSTALLDIR.'/plugins/Comet/bayeux.class.inc.php'); @@ -134,6 +150,26 @@ class CometPlugin extends Plugin return $arr; } + function getNoticeTags($notice) + { + $tags = null; + + $nt = new Notice_tag(); + $nt->notice_id = $notice->id; + + if ($nt->find()) { + $tags = array(); + while ($nt->fetch()) { + $tags[] = $nt->tag; + } + } + + $nt->free(); + $nt = null; + + return $tags; + } + // Push this up to Plugin function log($level, $msg) From db3b56a2fdf51e97e9859aa731674947571667aa Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 20:50:39 -0400 Subject: [PATCH 2/3] Display rendered HTML for a notice Display the rendered HTML for a notice --- plugins/Comet/CometPlugin.php | 1 + plugins/Comet/updatetimeline.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index cff0d4c9d6..2e0bb40a46 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -143,6 +143,7 @@ class CometPlugin extends Plugin $arr = $act->twitter_status_array($notice, true); $arr['url'] = $notice->bestUrl(); + $arr['html'] = htmlspecialchars($notice->rendered); $profile = $notice->getProfile(); $arr['user']['profile_url'] = $profile->profileurl; diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index c6eefb4475..55511d35ff 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -34,6 +34,8 @@ var updater = function() function makeNoticeItem(data) { user = data['user']; + html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); + ni = "
  • "+ "
    "+ ""+ @@ -42,7 +44,7 @@ var updater = function() ""+user['screen_name']+""+ ""+ ""+ - "

    "+data['text']+"

    "+ + "

    "+html+"

    "+ "
    "+ "
    "+ "
    "+ From e97223b2ba3f9f1818ba12b707c53c0ebdcab144 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 21:15:11 -0400 Subject: [PATCH 3/3] Don't add a notice if it already exists on the page Try not to interfere with Ajax posting; don't show something if it's already on the page. --- plugins/Comet/updatetimeline.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index 55511d35ff..de750baba3 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -23,6 +23,14 @@ var updater = function() function receive(message) { + id = message.data.id; + + // Don't add it if it already exists + + if ($("#notice-"+id).length > 0) { + return; + } + var noticeItem = makeNoticeItem(message.data); $("#notices_primary .notices").prepend(noticeItem, true); $("#notices_primary .notice:first").css({display:"none"});