X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FTwitterBridge%2Fdaemons%2Ftwitterstatusfetcher.php;h=dfd2d274c58ff240d13c865ba24123560244965a;hb=1f020125bf979271ff2682e1b1c95f2916e7a1ae;hp=7c624fdb3bacc605f823f847611fc943dff32b96;hpb=873b8328272ae9cb189477fd10e75b16d5ce050e;p=quix0rs-gnu-social.git diff --git a/plugins/TwitterBridge/daemons/twitterstatusfetcher.php b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php index 7c624fdb3b..dfd2d274c5 100755 --- a/plugins/TwitterBridge/daemons/twitterstatusfetcher.php +++ b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php @@ -179,14 +179,13 @@ class TwitterStatusFetcher extends ParallelizingDaemon $client = new TwitterOAuthClient($token->key, $token->secret); common_debug($this->name() . ' - Grabbing friends timeline with OAuth.'); } else { - $client = new TwitterBasicAuthClient($flink); - common_debug($this->name() . ' - Grabbing friends timeline with basic auth.'); + common_debug("Skipping friends timeline for $flink->foreign_id since not OAuth."); } $timeline = null; try { - $timeline = $client->statusesFriendsTimeline(); + $timeline = $client->statusesHomeTimeline(); } catch (Exception $e) { common_log(LOG_WARNING, $this->name() . ' - Twitter client unable to get friends timeline for user ' . @@ -215,7 +214,18 @@ class TwitterStatusFetcher extends ParallelizingDaemon continue; } - $this->saveStatus($status, $flink); + // Don't save it if the user is protected + // FIXME: save it but treat it as private + + if ($status->user->protected) { + continue; + } + + $notice = $this->saveStatus($status); + + if (!empty($notice)) { + Inbox::insertNotice($flink->user_id, $notice->id); + } } // Okay, record the time we synced with Twitter for posterity @@ -224,20 +234,17 @@ class TwitterStatusFetcher extends ParallelizingDaemon $flink->update(); } - function saveStatus($status, $flink) + function saveStatus($status) { $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 +256,19 @@ class TwitterStatusFetcher extends ParallelizingDaemon $this->name() . " - Ignoring duplicate import: $statusUri" ); - return; + return $dupe; + } + + common_debug("Saving status {$status->id} with data " . print_r($status, true)); + + // If it's a retweet, save it as a repeat! + + if (!empty($status->retweeted_status)) { + common_log(LOG_INFO, "Status {$status->id} is a retweet of {$status->retweeted_status->id}."); + $original = $this->saveStatus($status->retweeted_status); + $repeat = $original->repeat($profile->id, 'twitter'); + common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}"); + return $repeat; } $notice = new Notice(); @@ -263,7 +282,28 @@ class TwitterStatusFetcher extends ParallelizingDaemon ); $notice->source = 'twitter'; + $notice->reply_to = null; + + if (!empty($status->in_reply_to_status_id)) { + common_log(LOG_INFO, "Status {$status->id} is a reply to status {$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)) { + common_log(LOG_INFO, "Couldn't find local notice for status {$status->in_reply_to_status_id}"); + } else { + common_log(LOG_INFO, "Found local notice {$reply->id} for status {$status->in_reply_to_status_id}"); + $notice->reply_to = $reply->id; + $notice->conversation = $reply->conversation; + } + } + + if (empty($notice->conversation)) { + $conv = Conversation::create(); + $notice->conversation = $conv->id; + common_log(LOG_INFO, "No known conversation for status {$status->id} so making a new one {$conv->id}."); + } + $notice->is_local = Notice::GATEWAY; $notice->content = common_shorten_links($status->text); @@ -285,23 +325,27 @@ 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.'); - } - - 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.