]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/daemons/twitterstatusfetcher.php
if something's a retweet, save it as a repeat in bridge
[quix0rs-gnu-social.git] / plugins / TwitterBridge / daemons / twitterstatusfetcher.php
index 7c624fdb3bacc605f823f847611fc943dff32b96..848e866697be897f9cfbd006001e798031539f2b 100755 (executable)
@@ -215,6 +215,13 @@ class TwitterStatusFetcher extends ParallelizingDaemon
                 continue;
             }
 
+            // Don't save it if the user is protected
+            // FIXME: save it but treat it as private
+
+            if ($status->user->protected) {
+                continue;
+            }
+
             $this->saveStatus($status, $flink);
         }
 
@@ -224,20 +231,17 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         $flink->update();
     }
 
-    function saveStatus($status, $flink)
+    function saveStatus($status, $flink=null)
     {
         $profile = $this->ensureProfile($status->user);
 
         if (empty($profile)) {
             common_log(LOG_ERR, $this->name() .
                 ' - Problem saving notice. No associated Profile.');
-            return;
+            return null;
         }
 
-        $statusUri = 'http://twitter.com/'
-            . $status->user->screen_name
-            . '/status/'
-            . $status->id;
+        $statusUri = $this->makeStatusURI($status->user->screen_name, $status->id);
 
         // check to see if we've already imported the status
 
@@ -249,7 +253,14 @@ class TwitterStatusFetcher extends ParallelizingDaemon
                 $this->name() .
                 " - Ignoring duplicate import: $statusUri"
             );
-            return;
+            return $dupe;
+        }
+
+        // If it's a retweet, save it as a repeat!
+
+        if (!empty($status->retweeted_status)) {
+            $original = $this->saveStatus($status->retweeted_status);
+            return $original->repeat($profile->id, 'twitter');
         }
 
         $notice = new Notice();
@@ -263,7 +274,23 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         );
 
         $notice->source     = 'twitter';
+
         $notice->reply_to   = null;
+
+        if (!empty($status->in_reply_to_status_id)) {
+            $replyUri = $this->makeStatusURI($status->in_reply_to_screen_name, $status->in_reply_to_status_id);
+            $reply = Notice::staticGet('uri', $replyUri);
+            if (!empty($reply)) {
+                $notice->reply_to     = $reply->id;
+                $notice->conversation = $reply->conversation;
+            }
+        }
+
+        if (empty($notice->conversation)) {
+            $conv = Conversation::create();
+            $notice->conversation = $conv->id;
+        }
+
         $notice->is_local   = Notice::GATEWAY;
 
         $notice->content    = common_shorten_links($status->text);
@@ -285,23 +312,30 @@ class TwitterStatusFetcher extends ParallelizingDaemon
             Event::handle('EndNoticeSave', array($notice));
         }
 
-        $orig = clone($notice);
-        $conv = Conversation::create();
-
-        $notice->conversation = $conv->id;
-
-        if (!$notice->update($orig)) {
-            common_log_db_error($notice, 'UPDATE', __FILE__);
-            common_log(LOG_ERR, $this->name() .
-                ' - Problem saving notice.');
+        if (!empty($flink)) {
+            Inbox::insertNotice($flink->user_id, $notice->id);
         }
-
-        Inbox::insertNotice($flink->user_id, $notice->id);
         $notice->blowOnInsert();
 
         return $notice;
     }
 
+    /**
+     * Make an URI for a status.
+     *
+     * @param object $status status object
+     *
+     * @return string URI
+     */
+
+    function makeStatusURI($username, $id)
+    {
+        return 'http://twitter.com/'
+          . $username
+          . '/status/'
+          . $id;
+    }
+
     /**
      * Look up a Profile by profileurl field.  Profile::staticGet() was
      * not working consistently.