summaryrefslogtreecommitdiff
path: root/plugins/TwitterBridge
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-10-05 12:42:55 -0700
committerBrion Vibber <brion@pobox.com>2010-10-05 12:42:55 -0700
commit76353ede54edd8e99ddb9c209ff408486282c0c5 (patch)
treef7f901ca281b186517750e63f2aad418e222a449 /plugins/TwitterBridge
parent5058e8fd14340fc846b224ccff4e3a27dafc3134 (diff)
Clean up event handling a bit
Diffstat (limited to 'plugins/TwitterBridge')
-rw-r--r--plugins/TwitterBridge/scripts/streamtest.php36
-rw-r--r--plugins/TwitterBridge/twitterstreamreader.php10
2 files changed, 43 insertions, 3 deletions
diff --git a/plugins/TwitterBridge/scripts/streamtest.php b/plugins/TwitterBridge/scripts/streamtest.php
index 04d91ef43..96ff33fa5 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 d440bdd4e..3d6700d70 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;
}
}
}