* opts.counter The domid of the node to display chars remaining.
* opts.spinner The domid of the spinner element.
* opts.content The main content area, where the tweets are placed.
+ * opts.mentions The domid of where the mentions stream should be placed.
* opts.endpoint The url endpoint for horde/servcies/twitter.php
* opts.inreplyto
* opts.refreshrate How often to refresh the stream
}.bind(this));
this.instanceid = opts.instanceid;
+
/* Get the first page */
this.getNewEntries();
},
* Get newer entries, or the first page of entries if this is the first
* request.
*/
- getNewEntries: function() {
- var params = {
+ getNewEntries: function(type) {
+ var callback, params = {
actionID: 'getPage',
i: this.instanceid
};
-
- if (this.newestId) {
+ if (type == 'mentions') {
+ params.mentions = 1;
+ callback = this._getNewMentionsCallback.bind(this);
+ } else {
+ callback = this._getNewEntriesCallback.bind(this);
+ }
+ if (this.newestId && type !== 'mentions') {
params.since_id = this.newestId;
} else {
params.page = 1;
}
+
new Ajax.Request(this.opts.endpoint, {
method: 'post',
parameters: params,
- onSuccess: this._getNewEntriesCallback.bind(this),
+ onSuccess: callback,
onFailure: function() {
$(this.opts.spinner).toggle();
}
*/
_getNewEntriesCallback: function(response) {
var content = response.responseJSON.c;
+
if (response.responseJSON.n != this.newestId) {
var h = $(this.opts.content).scrollHeight
$(this.opts.content).insert({ 'top': content });
},
/**
+ * Callback for retrieving new mentions.
+ *
+ * @TODO: Implement paging, separate oldestId etc...
+ */
+ _getNewMentionsCallback: function(response) {
+ var content = response.responseJSON.c;
+ //if (response.responseJSON.n != this.newestId) {
+ var h = $(this.opts.mentions).scrollHeight
+ $(this.opts.mentions).insert({ 'top': content });
+ // Don't scroll if it's the first request.
+ if (this.newestId) {
+ $(this.opts.mentions).scrollTop = h;
+ } else {
+ $(this.opts.mentions).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;
+ //}
+ //}
+ //new PeriodicalExecuter(function(pe) { this.getNewMentions(); pe.stop(); }.bind(this), this.opts.refreshrate );
+ },
+
+ /**
* Build the reply structure
*/
buildReply: function(id, userid, usertext) {
$(this.opts.content).insert({top:tweet});
},
+ showMentions: function()
+ {
+ $(this.opts.content).hide();
+ this.getNewEntries('mentions');
+ $(this.opts.mentions).show();
+ },
+
+ showStream: function()
+ {
+ $(this.opts.mentions).hide();
+ $(this.opts.content).show();
+ },
+
/**
* Clear the input field.
*/
$params['since_id'] = $since;
}
$instance = Horde_Util::getPost('i');
- $stream = Horde_Serialize::unserialize($twitter->statuses->homeTimeline($params), Horde_Serialize::JSON);
+ if (Horde_Util::getPost('mentions', null)) {
+ $stream = Horde_Serialize::unserialize($twitter->statuses->mentions($params), Horde_Serialize::JSON);
+ } else {
+ $stream = Horde_Serialize::unserialize($twitter->statuses->homeTimeline($params), Horde_Serialize::JSON);
+ }
} catch (Horde_Service_Twitter_Exception $e) {
echo sprintf(_("Unable to contact Twitter. Please try again later. Error returned: %s"), $e->getMessage());
exit;
<?php echo $this->loadingImg ?>
<div id="currentStatus" class="" style="margin:10px;"><strong>'<?php echo _("Latest") ?></strong><?php echo $this->latestStatus ?> - <span class="fbstreaminfo"><?php echo $this->latestDate ?></span></div>
</div>
- <div style="height:<?php echo $this->bodyHeight ?>px; overflow-y:auto;" id="<?php echo $this->instance ?>_twitter_body"></div>
+ <div>
+ <a href="#" onclick="Horde['twitter<?php echo $this->instance ?>'].showStream();"><?php echo _("Stream")?></a>
+ <a href="#" onclick="Horde['twitter<?php echo $this->instance ?>'].showMentions();"><?php echo _("Mentions") ?></a>
+ </div>
+ <div style="height:<?php echo $this->bodyHeight ?>px; overflow-y:auto;" id="<?php echo $this->instance ?>_twitter_body">
+ <div id="<?php echo $this->instance ?>_stream"></div>
+ <div id="<?php echo $this->instance ?>_mentions"></div>
+ </div>
<div class="hordeSmGetmore"><input type="button" class="button" id="<?php echo $this->instance ?>_getmore" value="<?php echo _("Get More") ?>"></div>
</div>
\ No newline at end of file