function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice instanceof Notice) { try { $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE); common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to attentions for user " . $flink->user_id); try { Attention::saveNew($notice, $flink->getProfile()); } catch (Exception $e) { // Log the exception, but make sure we don't bail out, we // still have a queue item to remove here-after. common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " . $e->getMessage()); } } catch (NoResultException $e) { common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver); } } return true; }
function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice) { $flink = Foreign_link::getByForeignID(TWITTER_SERVICE, $receiver); if ($flink) { // @fixme this should go through more regular channels? Inbox::insertNotice($flink->user_id, $notice->id); } } return true; }
function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice) { $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE); if ($flink) { common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to inbox " . $flink->user_id); // @fixme this should go through more regular channels? Inbox::insertNotice($flink->user_id, $notice->id); } else { common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver); } } return true; }
$stream->hookEvent('follow', function ($data, $context) { printf("%s friended %s\n", $data->source->screen_name, $data->target->screen_name); }); $stream->hookEvent('unfollow', function ($data, $context) { printf("%s unfriended %s\n", $data->source->screen_name, $data->target->screen_name); }); $stream->hookEvent('delete', function ($data, $context) { printf("Deleted status notification: %s\n", $data->status->id); }); $stream->hookEvent('scrub_geo', function ($data, $context) { printf("Req to scrub geo data for user id %s up to status ID %s\n", $data->user_id, $data->up_to_status_id); }); $stream->hookEvent('status', function ($data, $context) { printf("Received status update from %s: %s\n", $data->user->screen_name, $data->text); if (have_option('import')) { $importer = new TwitterImport(); printf("\timporting..."); $notice = $importer->importStatus($data); if (!$notice instanceof Notice) { printf(" FAIL\n"); } } }); $stream->hookEvent('direct_message', function ($data) { printf("Direct message from %s to %s: %s\n", $data->sender->screen_name, $data->recipient->screen_name, $data->text); }); class TwitterManager extends IoManager { function __construct(TwitterStreamReader $stream) { $this->stream = $stream;