Implement Retweet function in twitter client
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 30 Jun 2010 22:05:28 +0000 (18:05 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 1 Jul 2010 00:11:39 +0000 (20:11 -0400)
horde/lib/Block/twitter_timeline.php
horde/services/twitter.php

index 3895459..306dbd2 100644 (file)
@@ -175,6 +175,7 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block
             $html .=  $body;
             $html .= '<div class="fbstreaminfo">' . sprintf(_("Posted %s via %s"), Horde_Date_Utils::relativeDateTime(strtotime($tweet->created_at), $GLOBALS['prefs']->getValue('date_format')), $appText) . '</div>';
             $html .= '<div class="fbstreaminfo">' . Horde::link('#', '', '', '', 'Horde.twitter.buildReply(\'' . $tweet->id . '\', \'' . $tweet->user->screen_name . '\', \'' . $tweet->user->name . '\')') .  _("Reply") . '</a>';
+            $html .= '&nbsp;|&nbsp;' . Horde::link('#', '', '', '', 'Horde.twitter.retweet(\'' . $tweet->id . '\')') . _("Retweet") . '</a>';
             $html .= '</div><div class="clear">&nbsp;</div></div>';
         }
         $html .= '</div>';
@@ -198,7 +199,25 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block
                 params = new Object();
                 params.actionID = 'updateStatus';
                 params.statusText = statusText;
-                params.inReplyTo = this.inReplyTo;
+                params.params = { 'in_reply_to_status_id': this.inReplyTo };
+                new Ajax.Request('$endpoint', {
+                    method: 'post',
+                    parameters: params,
+                    onComplete: function(response) {
+                        this.updateCallback(response.responseJSON);
+                    }.bind(this),
+                    onFailure: function() {
+                        {$spinner}.toggle();
+                        this.inReplyTo = '';
+                    }
+                });
+            },
+
+            retweet: function(id) {
+                params = {
+                    actionID: 'retweet',
+                    tweetId: id
+                };
                 new Ajax.Request('$endpoint', {
                     method: 'post',
                     parameters: params,
index f505353..fb886aa 100644 (file)
@@ -74,6 +74,12 @@ case 'updateStatus':
     header('Content-Type: application/json');
     echo $result;
     exit;
+
+case 'retweet':
+    $result = $twitter->statuses->retweet(Horde_Util::getPost('tweetId'));
+    header('Content-Type: application/json');
+    echo $result;
+    exit;
 }
 
 /* No requested action, check to see if we have a valid token */