]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
save Twitter mentions as StatusNet replies
authorEvan Prodromou <evan@status.net>
Mon, 6 Sep 2010 12:54:04 +0000 (08:54 -0400)
committerEvan Prodromou <evan@status.net>
Mon, 6 Sep 2010 12:54:04 +0000 (08:54 -0400)
plugins/TwitterBridge/daemons/twitterstatusfetcher.php

index b310b8f36adecc5b87fba1a8110e4794f1a3f07c..e092cd1dd7edbbe5f8ab12bbd156c7cc49ca2c15 100755 (executable)
@@ -348,6 +348,9 @@ class TwitterStatusFetcher extends ParallelizingDaemon
         }
 
         Notice_to_status::saveNew($notice->id, $status->id);
+
+        $this->saveStatusMentions($notice, $status);
+
         $notice->blowOnInsert();
 
         return $notice;
@@ -776,6 +779,29 @@ class TwitterStatusFetcher extends ParallelizingDaemon
     {
         return "@<a href='http://twitter.com/{$object->screen_name}' title='{$object->name}'>{$object->screen_name}</a>";
     }
+
+    function saveStatusMentions($notice, $status)
+    {
+        $mentions = array();
+
+        if (empty($status->entities) || empty($status->entities->user_mentions)) {
+            return;
+        }
+
+        foreach ($status->entities->user_mentions as $mention) {
+            $flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE);
+            if (!empty($flink)) {
+                $user = User::staticGet('id', $flink->user_id);
+                if (!empty($user)) {
+                    $reply = new Reply();
+                    $reply->notice_id  = $notice->id;
+                    $reply->profile_id = $user->id;
+                    common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}");
+                    $id = $reply->insert();
+                }
+            }
+        }
+    }
 }
 
 $id    = null;