From 94191cd629d440beb967c5fcfaf80858e90817d6 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 20 Mar 2016 16:55:56 +0900 Subject: [PATCH] Notify favorite --- src/containers/timeline-container.js | 22 ++++++++++++++++++++-- src/utils/twitter-client.js | 13 +------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/containers/timeline-container.js b/src/containers/timeline-container.js index f339b71..b42ad62 100644 --- a/src/containers/timeline-container.js +++ b/src/containers/timeline-container.js @@ -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}"` }, + ); + }); }); }, }; diff --git a/src/utils/twitter-client.js b/src/utils/twitter-client.js index abf2b60..4f111a8 100644 --- a/src/utils/twitter-client.js +++ b/src/utils/twitter-client.js @@ -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