Skip to content

[Flow] Getting started

Chen edited this page Mar 21, 2021 · 2 revisions

This library will not receive feature updates in the near future since v0.7.5 as the development of StructuredDiscussion is stalled:

The StructuredDiscussions extension was developed by the Collaboration team at the Wikimedia Foundation. It is still being maintained to fix bugs, but no substantial development on the extension has been done since 2015, other than a rename to "StructuredDiscussions" in September 2017. Development may possibly start again in the future.

StructuredDiscussions (previously known as "Flow") is an extension for discussions on MediaWiki site.

WCL provides access to most of the functionalities in Flow. See library reference for more actions supported.

For how to work with IAsyncEnumerable<T>, see Generators#How to work with IAsyncEnumerable.

Library references

Enumerate topics and their replies from a Board

static async Task ListTopicsAsync()
{
    var board = new Board(myWikiSite, "Project Talk:Flow");
    // Fetch top 20 topics from the board.
    var topics = await board.EnumTopicsAsync().Take(20).ToList();
    foreach (var t in topics)
    {
        Console.WriteLine(t.TopicTitle);
        Console.WriteLine("  Author: {0}", t.TopicTitleRevision.Author);
        // OP's post content is t.Posts[0]
        foreach (var p in t.Posts)
        {
            Console.WriteLine("  {0} {1} {2}", p.LastRevision.Author, p.LastRevision.TimeStamp,
                p.Content.Substring(0, 10));
            if (p.Replies.Count > 0)
                Console.WriteLine("    {0} replies.", p.Replies.Count);
        }
    }
}

Fetch posts under a given topic

static async Task ListPostsAsync()
{
    var topic = new Topic(myWikiSite, "Topic:U1cdhclin7ux7mrz");
    // Fetch topic information, as well as all the posts and replies under this topic
    await topic.RefreshAsync();
    Console.WriteLine(topic.TopicTitle);
    Console.WriteLine("  Author: {0}", topic.TopicTitleRevision.Author);
    // OP's post content is t.Posts[0]
    foreach (var p in topic.Posts)
    {
        Console.WriteLine("  {0} {1} {2}", p.LastRevision.Author, p.LastRevision.TimeStamp,
            p.Content.Substring(0, 10));
        if (p.Replies.Count > 0)
            Console.WriteLine("    {0} replies.", p.Replies.Count);
    }
}

Reply and lock/close a topic

static async Task CommentAndCloseTopicAsync()
{
    var topic = new Topic(myWikiSite, "Topic:U1cdhclin7ux7mrz");
    // If we are not interested in the topic's information, we can skip the RefreshAsync invocation.
    await topic.ReplyAsync("I will close this topic now.");
    // Mark the topic as locked/closed/resolved
    await topic.LockAsync(LockAction.Lock, "Case closed.");
    // Edit topic summary that will be shown on the closed topic.
    topic.Summary = "The topic has been automatically closed by WCL.";
    await topic.UpdateSummaryAsync();
}