/// <summary> /// Provides a timeline view model populated by using the configuration for the given timeline. /// </summary> public TimelineViewModel PrepareTimelineViewModel(string TimelineNameOrId, bool isId = false) { var config = SocialAllianceConfig.Read(); var timelineConfig = config.ReadTimeline(TimelineNameOrId, isId); if (timelineConfig == null) { ErrorText = "There is no timeline configured with this name or Id: " + TimelineNameOrId; return null; } var timeline = new TimelineViewModel(timelineConfig); // TODO: Get YouTube timelines from config. List<YouTubeProvider> youTubeProviders = GetYouTubeProvidersFromConfig(timelineConfig.YouTubeProviders); List<TwitterProvider> twitterProviders = GetTwitterProvidersFromConfig(timelineConfig.TwitterProviders); // If providerConfig configured for any social account, fetch data. if (youTubeProviders.Any() || twitterProviders.Any()) { if (youTubeProviders.Count > 1 && timeline.SingleUser == true) { ErrorText = "The timeline was specified to be for only one user, but more than one YouTube feed was requested."; timeline.SingleUser = false; } if (twitterProviders.Count > 1 && timeline.SingleUser == true) { ErrorText = "The timeline was specified to be for only one user, but more than one Twitter timeline feed was requested."; timeline.SingleUser = false; } if (!timeline.SingleUser) { // Update the setting for user details in tweets for both Twitter request calls and display settings. UserDetailsInTweet = CorrectIncludeUserDetailsInTweet(twitterProviders); } // TODO: Optional? Modify to show publish time in tweets only? var providers = new List<ISocialProvider>(youTubeProviders).Concat(twitterProviders).ToList(); HowLongSincePublished = HowLongSincePublishedConsistency(providers); if (timeline.SingleUser) { timeline = SingleUserTimelineViewModel(timeline, youTubeProviders.ElementAt(0), twitterProviders.ElementAt(0)); } else { timeline = MultipleUsersTimelineViewModel(timeline, youTubeProviders, twitterProviders); } } return timeline; }
/// <summary> /// Prepares a merged or unmerged timeline including user information. /// </summary> private TimelineViewModel SingleUserTimelineViewModel(TimelineViewModel timeline, YouTubeProvider youTube, TwitterProvider twitter) { if (youTube != null) { var youTubeErrorText = ""; timeline.YouTubeAccount = youTube.GetYouTubeUserData(out youTubeErrorText); ErrorText += youTubeErrorText; } if (twitter != null) { var twitterErrorText = ""; timeline.TwitterAccount = twitter.GetTwitterUserData(out twitterErrorText); ErrorText += twitterErrorText; } // If user-related request errors exist, return without attempting to load the timeline data. if (ErrorText != "") { return null; } else { ErrorText = null; } if (timeline.Merged) { var mergedTimeline = new List<ISocialEntry>(timeline.TwitterAccount.Tweets); mergedTimeline = mergedTimeline.Concat(timeline.YouTubeAccount.Playlists.ElementAt(0).Entries).ToList(); mergedTimeline.Sort(new SocialEntriesRecentDateFirstComparer()); timeline.RecentActivity = mergedTimeline; } else { timeline.TwitterAccount.Tweets.ToList().Sort(new SocialEntriesRecentDateFirstComparer()); timeline.YouTubeAccount.Playlists.ElementAt(0).Entries.ToList().Sort(new SocialEntriesRecentDateFirstComparer()); } return timeline; }
/// <summary> /// Prepares a merged or unmerged timeline for multiple users. /// </summary> private TimelineViewModel MultipleUsersTimelineViewModel(TimelineViewModel timeline, IList<YouTubeProvider> youTubeProviders, IList<TwitterProvider> twitterProviders) { var youTubeTimeline = new List<Video>(); var twitterTimeline = new List<Tweet>(); foreach (var entry in youTubeProviders) { youTubeTimeline = youTubeTimeline.Concat(entry.GetChannelVideos()).ToList(); } foreach (var entry in twitterProviders) { twitterTimeline = twitterTimeline.Concat(entry.GetTwitterUserTimeline()).ToList(); } if (timeline.Merged) { var mergedTimeline = new List<ISocialEntry>(twitterTimeline).Concat(youTubeTimeline).ToList(); mergedTimeline.Sort(new SocialEntriesRecentDateFirstComparer()); timeline.RecentActivity = mergedTimeline; } else { twitterTimeline.Sort(new SocialEntriesRecentDateFirstComparer()); youTubeTimeline.Sort(new SocialEntriesRecentDateFirstComparer()); timeline.TwitterAccount = new TwitterTimelineViewModel(twitterTimeline); var playlist = new List<Playlist>(); playlist.Add(new Playlist(youTubeTimeline)); timeline.YouTubeAccount = new YouTubeVideoChannelViewModel(playlist); } return timeline; }