Clean up event handling a bit
This commit is contained in:
parent
5058e8fd14
commit
76353ede54
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user