-
-
Notifications
You must be signed in to change notification settings - Fork 16
[Flow] Getting started
Chen edited this page Nov 19, 2017
·
2 revisions
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.
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);
}
}
}
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);
}
}
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();
}