]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
delete Twitter notice if it was posted from here
authorEvan Prodromou <evan@status.net>
Sun, 5 Sep 2010 05:17:56 +0000 (01:17 -0400)
committerEvan Prodromou <evan@status.net>
Tue, 7 Sep 2010 08:00:59 +0000 (04:00 -0400)
plugins/TwitterBridge/TwitterBridgePlugin.php
plugins/TwitterBridge/twitteroauthclient.php

index f7d3b6659a5c400780a326d613739b7cc1bc56ba..bad6a3941b8b46e784a5a54ee4765fed3b8244b5 100644 (file)
@@ -423,7 +423,33 @@ class TwitterBridgePlugin extends Plugin
     function onNoticeDeleteRelated($notice)
     {
         $n2s = Notice_to_status::staticGet('notice_id', $notice->id);
+
         if (!empty($n2s)) {
+
+            $user = common_current_user();
+
+            if (empty($user) || $user->id != $notice->profile_id) {
+                $this->log(LOG_INFO, "Skipping deleting notice for {$notice->id} since it doesn't seem to be by the author.");
+                return true;
+            }
+
+            $flink = Foreign_link::getByUserID($notice->profile_id,
+                                               TWITTER_SERVICE); // twitter service
+
+            if (empty($flink)) {
+                return true;
+            }
+
+            if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
+                $this->log(LOG_INFO, "Skipping deleting notice for {$notice->id} since link is not OAuth.");
+                return true;
+            }
+
+            $token = TwitterOAuthClient::unpackToken($flink->credentials);
+            $client = new TwitterOAuthClient($token->key, $token->secret);
+
+            $client->statusesDestroy($n2s->status_id);
+
             $n2s->delete();
         }
         return true;
index 22ccaba07eda907ec34706c5ed44468e8872570d..0f5e4dbda795957c5b9fce5bbabab7547aebcf4f 100644 (file)
@@ -324,4 +324,20 @@ class TwitterOAuthClient extends OAuthClient
         $status = json_decode($response);
         return $status;
     }
+
+    /**
+     * Calls Twitter's /statuses/destroy API method
+     *
+     * @param int $id ID of the status to destroy
+     *
+     * @return object destroyed
+     */
+
+    function statusesDestroy($id)
+    {
+        $url = "http://api.twitter.com/1/statuses/destroy/$id.json";
+        $response = $this->oAuthPost($url);
+        $status = json_decode($response);
+        return $status;
+    }
 }