]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/twitter.php
Fix for failure edge case in TwitterBridge outgoing repeat/retweets.
[quix0rs-gnu-social.git] / plugins / TwitterBridge / twitter.php
index cd1ad70b9b8369fe9b512afd8d18cb5b1d4ff10e..b34488069aaa2e2e1255433f3dfa104b8c49bbe2 100644 (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);