From: Brion Vibber Date: Tue, 5 Oct 2010 19:42:55 +0000 (-0700) Subject: Clean up event handling a bit X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=76353ede54edd8e99ddb9c209ff408486282c0c5;p=quix0rs-gnu-social.git Clean up event handling a bit --- diff --git a/plugins/TwitterBridge/scripts/streamtest.php b/plugins/TwitterBridge/scripts/streamtest.php index 04d91ef439..96ff33fa52 100644 --- a/plugins/TwitterBridge/scripts/streamtest.php +++ b/plugins/TwitterBridge/scripts/streamtest.php @@ -81,7 +81,41 @@ function homeStreamForUser(User $user) $user = User::staticGet('nickname', $nickname); $stream = homeStreamForUser($user); $stream->hookEvent('raw', function($data) { - var_dump($data); + common_log(LOG_INFO, json_encode($data)); +}); +$stream->hookEvent('friends', function($data) { + printf("Friend list: %s\n", implode(', ', $data)); +}); +$stream->hookEvent('favorite', function($data) { + printf("%s favorited %s's notice: %s\n", + $data['source']['screen_name'], + $data['target']['screen_name'], + $data['target_object']['text']); +}); +$stream->hookEvent('follow', function($data) { + printf("%s friended %s\n", + $data['source']['screen_name'], + $data['target']['screen_name']); +}); +$stream->hookEvent('delete', function($data) { + printf("Deleted status notification: %s\n", + $data['status']['id']); +}); +$stream->hookEvent('scrub_geo', function($data) { + 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) { + printf("Received status update from %s: %s\n", + $data['user']['screen_name'], + $data['text']); +}); +$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 diff --git a/plugins/TwitterBridge/twitterstreamreader.php b/plugins/TwitterBridge/twitterstreamreader.php index d440bdd4ef..3d6700d70e 100644 --- a/plugins/TwitterBridge/twitterstreamreader.php +++ b/plugins/TwitterBridge/twitterstreamreader.php @@ -104,14 +104,20 @@ abstract class TwitterStreamReader extends JsonStreamReader { $this->fireEvent('raw', $data, $forUserId); - if (isset($data['id']) && isset($data['text']) && isset($data['user'])) { + if (isset($data['text'])) { $this->fireEvent('status', $data); + return; + } + if (isset($data['event'])) { + $this->fireEvent($data['event'], $data); + return; } - $knownMeta = array('friends', 'delete', 'scrubgeo', 'limit', 'event', 'direct_message'); + $knownMeta = array('friends', 'delete', 'scrubgeo', 'limit', 'direct_message'); foreach ($knownMeta as $key) { if (isset($data[$key])) { $this->fireEvent($key, $data[$key], $forUserId); + return; } } }