/// <summary> /// Asynchronously enumerates the topics in this board. /// </summary> /// <param name="options">Enumeration options.</param> /// <param name="pageSize"> /// How many topics should be fetched in batch per MediaWiki API request. /// No more than 100 (100 for bots) is allowed. /// </param> public async IAsyncEnumerable <Topic> EnumTopicsAsync(TopicListingOptions options, int pageSize, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (pageSize <= 0) { throw new ArgumentOutOfRangeException(nameof(pageSize)); } var sortParam = "user"; if ((options & TopicListingOptions.OrderByPosted) == TopicListingOptions.OrderByPosted) { sortParam = "newest"; } if ((options & TopicListingOptions.OrderByUpdated) == TopicListingOptions.OrderByUpdated) { sortParam = "updated"; } var queryParams = new Dictionary <string, object> { { "action", "flow" }, { "submodule", "view-topiclist" }, { "page", Title }, { "vtlsortby", sortParam }, { "vtlsavesortby", (options & TopicListingOptions.SaveSortingPreference) == TopicListingOptions.SaveSortingPreference }, { "vtllimit", pageSize }, { "vtlformat", "wikitext" }, }; NEXT_PAGE: var jresult = await Site.InvokeMediaWikiApiAsync(new MediaWikiFormRequestMessage(queryParams), cancellationToken); var jtopiclist = (JObject)jresult["flow"]["view-topiclist"]["result"]["topiclist"]; using (ExecutionContextStash.Capture()) foreach (var t in Topic.FromJsonTopicList(Site, jtopiclist)) { yield return(t); } // 2018-07-30 flow.view-topiclist.result.topiclist.links.pagination is [] instead of null for boards without pagination. var jpagination = jtopiclist["links"]?["pagination"]; var nextPageUrl = jpagination == null || jpagination is JArray ? null : (string)jpagination["fwd"]?["url"]; if (nextPageUrl != null) { var urlParams = FlowUtility.ParseUrlQueryParametrs(nextPageUrl); foreach (var pa in urlParams) { if (pa.Key.StartsWith("topiclist_")) { queryParams["vtl" + pa.Key[10..]] = pa.Value;
/// <inheritdoc cref="EnumTopicsAsync(TopicListingOptions, int, CancellationToken)"/> public IAsyncEnumerable <Topic> EnumTopicsAsync(TopicListingOptions options) { return(EnumTopicsAsync(options, 20)); }