public void OnNext(StreamingMessage streamingMessage) { if (!(streamingMessage is StatusMessage message)) { return; } var text = message.Status.FullText ?? message.Status.Text; var urlPattern = new Regex(@"http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?"); while (true) { var match = urlPattern.Match(text); if (!match.Success) { break; } text = text.Replace(match.Groups[0].Value, ""); } var mediaUrl = message.Status.Entities.Media?[0].MediaUrlHttps; var tweet = new TwitterMessage { Id = message.Status.Id, Text = text, Time = message.Status.CreatedAt.DateTime, UserName = message.Status.User.Name, UserHandle = (message.Status.User.ScreenName != message.Status.User.Name) ? "@" + message.Status.User.ScreenName : "", UserImage = message.Status.User.ProfileImageUrlHttps, TextColor = "black", BackgroundColor = GetBackgroundColor(message.Status.User.Name), MediaUrl = mediaUrl }; NewTweet?.Invoke(tweet); }
private void OnNewTweetReceived(TwitterMessage tweet) { Tweets.Insert(0, tweet); Tweets = Tweets.Take(_settings.MaxTweets).ToList(); NewTweet?.Invoke(tweet); }