/// <summary> /// Returns a collector for the given type. If the collector doesn't exist one will be created. /// </summary> /// <param name="user"></param> /// <param name="baconMan"></param> /// <param name="sort"></param> /// <param name="sortTime"></param> /// <returns></returns> public static PostCollector GetCollector(User user, BaconManager baconMan, SortTypes sort = SortTypes.Hot, SortTimeTypes sortTime = SortTimeTypes.Week) { var container = new PostCollectorContext { User = user, SortType = sort, SortTimeType = sortTime }; container.UniqueId = "t2_" + user.Id + sort + sortTime; return((PostCollector)GetCollector(typeof(PostCollector), container.UniqueId, container, baconMan)); }
/// <summary> /// Returns a collector for the given type. If the collector doesn't exist one will be created. /// </summary> /// <param name="subreddit"></param> /// <returns></returns> public static PostCollector GetCollector(Subreddit subreddit, BaconManager baconMan, SortTypes sort = SortTypes.Hot, SortTimeTypes sortTime = SortTimeTypes.Week, string forcePostId = null) { PostCollectorContext container = new PostCollectorContext() { subreddit = subreddit, sortType = sort, forcePostId = forcePostId, sortTimeType = sortTime }; // Make the uniqueId. If we have a force post add that also so we don't get an existing collector with the real subreddit. container.UniqueId = subreddit.Id + sort + sortTime + (String.IsNullOrWhiteSpace(forcePostId) ? String.Empty : forcePostId); return((PostCollector)Collector <Post> .GetCollector(typeof(PostCollector), container.UniqueId, container, baconMan)); }
public PostCollector(PostCollectorContext collectorContext, BaconManager baconMan) : base(baconMan, collectorContext.UniqueId) { // Set the vars m_user = collectorContext.User; m_subreddit = collectorContext.subreddit; m_sortType = collectorContext.sortType; m_sortTimeType = collectorContext.sortTimeType; m_baconMan = baconMan; // If we are doing a top sort setup the sort time string optionalArgs = String.Empty; if (m_sortType == SortTypes.Top) { switch (m_sortTimeType) { case SortTimeTypes.AllTime: optionalArgs = "sort=top&t=all"; break; case SortTimeTypes.Day: optionalArgs = "sort=top&t=day"; break; case SortTimeTypes.Hour: optionalArgs = "sort=top&t=hour"; break; case SortTimeTypes.Month: optionalArgs = "sort=top&t=month"; break; case SortTimeTypes.Week: optionalArgs = "sort=top&t=week"; break; case SortTimeTypes.Year: optionalArgs = "sort=top&t=year"; break; } } string postCollectionUrl = ""; bool hasEmptyRoot = false; if (m_subreddit != null) { if (m_subreddit.DisplayName.ToLower() == "frontpage") { // Special case for the front page postCollectionUrl = $"/{SortTypeToString(m_sortType)}/.json"; } else if (m_subreddit.DisplayName.ToLower() == "saved") { // Special case for the saved posts postCollectionUrl = $"/user/{m_baconMan.UserMan.CurrentUser.Name}/saved/.json"; } else if (!String.IsNullOrWhiteSpace(collectorContext.forcePostId)) { // We are only going to try to grab one specific post. This is used by search and inbox to // link to a post. Since we are doing so, we need to make the unique id something unique for this post so we don't get // a cache. This should match the unique id we use to look up the subreddit above. SetUniqueId(m_subreddit.Id + m_sortType + collectorContext.forcePostId); postCollectionUrl = $"/r/{m_subreddit.DisplayName}/comments/{collectorContext.forcePostId}/.json"; hasEmptyRoot = true; } else { postCollectionUrl = $"/r/{m_subreddit.DisplayName}/{SortTypeToString(m_sortType)}/.json"; } } else { // Get posts for a user postCollectionUrl = $"user/{m_user.Name}/submitted/.json"; switch (m_sortType) { case SortTypes.Controversial: optionalArgs = "sort=controversial"; break; case SortTypes.Hot: optionalArgs = "sort=hot"; break; case SortTypes.New: optionalArgs = "sort=new"; break; case SortTypes.Top: optionalArgs = "sort=top"; break; } } InitListHelper(postCollectionUrl, hasEmptyRoot, true, optionalArgs); }