delete Twitter notice if it was posted from here

This commit is contained in:
Evan Prodromou 2010-09-05 01:17:56 -04:00
parent 4deea8e2db
commit 32f3332007
2 changed files with 42 additions and 0 deletions

View 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;

View 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;
}
}