Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Notify favorite
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 20, 2016
1 parent 3e91598 commit 94191cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
22 changes: 20 additions & 2 deletions src/containers/timeline-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,26 @@ const mapDispatchToProps = (dispatch, props) => {
},
startStreaming: () => {
const proxy = new TimelineProxy(addTweet, props.account, true);
client.userStream((tweet) => {
proxy.addTweet(tweet);
client.userStream((stream) => {
stream.on('data', function(data) {
if (data['friends']) {
// noop
} else if (data['event']) {
// noop
} else if (data['delete']) {
// noop
} else if (data['created_at']) {
// This is a normal tweet
proxy.addTweet(data);
}
});

stream.on('favorite', (event) => {
new Notification(
`${event.source.screen_name} favorited:`,
{ body: `${event.target.screen_name} "${event.target_object.text}"` },
);
});
});
},
};
Expand Down
13 changes: 1 addition & 12 deletions src/utils/twitter-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,7 @@ export default class TwitterClient {

userStream(callback) {
this.client.stream('user', {}, (stream) => {
stream.on('data', function(data) {
if (data['friends']) {
// noop
} else if (data['event']) {
// noop
} else if (data['delete']) {
// noop
} else if (data['created_at']) {
// This is a normal tweet
callback(data);
}
});
callback(stream);

stream.on('error', (error) => {
// ignoring because of too many errors
Expand Down

0 comments on commit 94191cd

Please sign in to comment.