From 865e6fea272d68e1f4937dd0ecc044e76749a1fa Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 12 Aug 2010 13:43:14 -0400 Subject: [PATCH] Don't assume we will always have updates. --- horde/js/twitterclient.js | 31 ++++++++++++++++--------------- horde/services/twitter.php | 7 ++++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/horde/js/twitterclient.js b/horde/js/twitterclient.js index 20ff458eb..2829c84d4 100644 --- a/horde/js/twitterclient.js +++ b/horde/js/twitterclient.js @@ -41,7 +41,7 @@ var Horde_Twitter = Class.create({ $(this.opts.input).observe('keyup', function() { $(this.opts.counter).update(140 - $F(this.opts.input).length); }.bind(this)); - + /* Get the first page */ this.getNewEntries(); }, @@ -152,25 +152,26 @@ var Horde_Twitter = Class.create({ /** * Callback for retrieving new entries. Updates the display and remembers * the newest id, and possible the older id as well. - * + * */ _getNewEntriesCallback: function(response) { var content = response.responseJSON.c; - var h = $(this.opts.content).scrollHeight - $(this.opts.content).insert({ 'top': content }); - // Don't scroll if it's the first request. - if (this.newestId) { - $(this.opts.content).scrollTop = h; - } else { - $(this.opts.content).scrollTop = 0; - } - this.newestId = response.responseJSON.n; + if (response.responseJSON.n != this.newestId) { + var h = $(this.opts.content).scrollHeight + $(this.opts.content).insert({ 'top': content }); + // Don't scroll if it's the first request. + if (this.newestId) { + $(this.opts.content).scrollTop = h; + } else { + $(this.opts.content).scrollTop = 0; + } + this.newestId = response.responseJSON.n; - // First time we've been called, record the oldest one as well.' - if (!this.oldestId) { - this.oldestId = response.responseJSON.o; + // First time we've been called, record the oldest one as well.' + if (!this.oldestId) { + this.oldestId = response.responseJSON.o; + } } - new PeriodicalExecuter(function(pe) { this.getNewEntries(); pe.stop(); }.bind(this), this.opts.refreshrate ); }, diff --git a/horde/services/twitter.php b/horde/services/twitter.php index cda42c71c..99fcd8e23 100644 --- a/horde/services/twitter.php +++ b/horde/services/twitter.php @@ -63,7 +63,12 @@ case 'getPage': exit; } $html = ''; - $newest = $stream[0]->id; + if (count($stream)) { + $newest = $stream[0]->id; + } else { + $newest = $params['since_id']; + $oldest = 0; + } foreach ($stream as $tweet) { $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block')); $view->addHelper('Tag'); -- 2.11.0