]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Clean up event handling a bit
authorBrion Vibber <brion@pobox.com>
Tue, 5 Oct 2010 19:42:55 +0000 (12:42 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 5 Oct 2010 19:42:55 +0000 (12:42 -0700)
plugins/TwitterBridge/scripts/streamtest.php
plugins/TwitterBridge/twitterstreamreader.php

index 04d91ef4399318147ef657b7b86d3b88c69ef1f2..96ff33fa528ad9a4b94aa1d66248f010be770e20 100644 (file)
@@ -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
index d440bdd4efed3062d71f90fcd1ec1dd8d1b7180e..3d6700d70efaed5a02d622c8ec48848beaaae3d6 100644 (file)
@@ -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;
             }
         }
     }