From: Evan Prodromou Date: Sun, 5 Sep 2010 05:17:56 +0000 (-0400) Subject: delete Twitter notice if it was posted from here X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b059a19e0fb82869ab2ac5dbb4ec94348a58aacb;p=quix0rs-gnu-social.git delete Twitter notice if it was posted from here --- diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index f7d3b6659a..bad6a3941b 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -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; diff --git a/plugins/TwitterBridge/twitteroauthclient.php b/plugins/TwitterBridge/twitteroauthclient.php index 22ccaba07e..0f5e4dbda7 100644 --- a/plugins/TwitterBridge/twitteroauthclient.php +++ b/plugins/TwitterBridge/twitteroauthclient.php @@ -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; + } }