Beispiel #1
0
        private async Task InitTweetinvi()
        {
            MarkConnected(false);
            twitterConfig = Helpers.GetConfig <Twitter, TwitterConfig>();
            if (!twitterConfig.IsPopulated())
            {
                Log("Twitter configuration missing!");
                return;
            }

            var twitterClient = new TwitterClient(twitterConfig.ConsumerKey, twitterConfig.ConsumerSecret, twitterConfig.UserAccessToken, twitterConfig.UserAccessSecret);

            twitterClient.Config.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;

            var stream = twitterClient.Streams.CreateFilteredStream();
            var user   = await twitterClient.Users.GetAuthenticatedUserAsync();

            var friends = user.GetFriendIds();

            while (!friends.Completed)
            {
                var page = await friends.NextPageAsync();

                page.ForEach(id => stream.AddFollow(id));
            }
            stream.MatchOn = MatchOn.Follower;
            stream.MatchingTweetReceived += (s, e) =>
            {
                if (e.MatchOn == MatchOn.Follower && !e.Tweet.Text.StartsWith("@"))
                {
                    PushTileData(e.Tweet);
                }
            };
            stream.StreamStarted += (s, e) =>
            {
                Log("Stream started!");
                MarkConnected();
            };
            stream.StreamStopped += (s, e) =>
            {
                Log("Stream stopped: " + string.Join(" - ", e.Exception.Message, e.DisconnectMessage));
                MarkConnected(false);
                Thread.Sleep(1000);
                stream.StartMatchingAllConditionsAsync().Wait();
            };

            var currentTimeline = await user.GetHomeTimelineAsync();

            foreach (var t in currentTimeline.OrderByDescending(c => c.CreatedAt.LocalDateTime)
                     .Take(20)
                     .OrderBy(c => c.CreatedAt.LocalDateTime))
            {
                PushTileData(t);
            }

            await stream.StartMatchingAllConditionsAsync();
        }
Beispiel #2
0
 public TwitterConfigViewModel(TwitterConfig twitterConfig, LogViewer logViewer)
 {
     TwitterConfig = twitterConfig;
     LogViewer     = logViewer;
     SaveItems     = ReactiveCommand.Create(async() =>
     {
         await Helpers.SaveConfigFile <Twitter>(TwitterConfig);
         CloseWindow.OnNext(true);
     });
 }