Merge branch 'master' of gitorious.org:statusnet/mainline into 0.9.x

Conflicts:
	actions/newgroup.php
This commit is contained in:
Brion Vibber 2010-11-12 13:32:48 -08:00
commit 65eeb7cba5
3 changed files with 40 additions and 1 deletions

View File

@ -198,10 +198,12 @@ class XmppManager extends IoManager
$this->conn->processTime(0);
return true;
} else {
common_log(LOG_ERR, __METHOD__ . ' failed: 0 bytes sent');
return false;
}
} else {
// Can't send right now...
common_log(LOG_ERR, __METHOD__ . ' failed: XMPP server connection currently down');
return false;
}
}

View File

@ -144,6 +144,7 @@ class Notice_to_status extends Memcached_DataObject
/**
* Save a mapping between a notice and a status
* Warning: status_id values may not fit in 32-bit integers.
*
* @param integer $notice_id ID of the notice in StatusNet
* @param integer $status_id ID of the status in Twitter
@ -153,12 +154,18 @@ class Notice_to_status extends Memcached_DataObject
static function saveNew($notice_id, $status_id)
{
if (empty($notice_id)) {
throw new Exception("Invalid notice_id $notice_id");
}
$n2s = Notice_to_status::staticGet('notice_id', $notice_id);
if (!empty($n2s)) {
return $n2s;
}
if (empty($status_id)) {
throw new Exception("Invalid status_id $status_id");
}
$n2s = Notice_to_status::staticGet('status_id', $status_id);
if (!empty($n2s)) {

View File

@ -128,6 +128,16 @@ function is_twitter_notice($id)
return (!empty($n2s));
}
/**
* Check if we need to broadcast a notice over the Twitter bridge, and
* do so if necessary. Will determine whether to do a straight post or
* a repeat/retweet
*
* This function is meant to be called directly from TwitterQueueHandler.
*
* @param Notice $notice
* @return boolean true if complete or successful, false if we should retry
*/
function broadcast_twitter($notice)
{
$flink = Foreign_link::getByUserID($notice->profile_id,
@ -137,8 +147,13 @@ function broadcast_twitter($notice)
if (!empty($flink) && TwitterOAuthClient::isPackedToken($flink->credentials)) {
if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) {
$retweet = retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of));
if (!empty($retweet)) {
if (is_object($retweet)) {
Notice_to_status::saveNew($notice->id, $retweet->id);
return true;
} else {
// Our error processing will have decided if we need to requeue
// this or can discard safely.
return $retweet;
}
} else if (is_twitter_bound($notice, $flink)) {
return broadcast_oauth($notice, $flink);
@ -148,6 +163,21 @@ function broadcast_twitter($notice)
return true;
}
/**
* Send a retweet to Twitter for a notice that has been previously bridged
* in or out.
*
* Warning: the return value is not guaranteed to be an object; some error
* conditions will return a 'true' which should be passed on to a calling
* queue handler.
*
* No local information about the resulting retweet is saved: it's up to
* caller to save new mappings etc if appropriate.
*
* @param Foreign_link $flink
* @param Notice $notice
* @return mixed object with resulting Twitter status data on success, or true/false/null on error conditions.
*/
function retweet_notice($flink, $notice)
{
$token = TwitterOAuthClient::unpackToken($flink->credentials);