/// <summary> /// Add a new reply to the post. /// </summary> /// <param name="content">The content in reply.</param> /// <param name="options">The options for creating the reply.</param> /// <param name="cancellationToken">A token used to cancel the operation.</param> /// <returns>A new post containing the workflow ID of the new post.</returns> /// <remarks>For now Wikia only supports 2-level posts. /// If you attempt to reply to the level-2 post, /// the comment will be placed as level-2 (top-level) post.</remarks> public async Task <Post> ReplyAsync(string content, PostCreationOptions options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var method = GetPostCreationMethod(OwnerPage, options); if (method == METHOD_UNKNOWN) { await RefreshAsync(PostQueryOptions.None, cancellationToken); method = GetPostCreationMethod(OwnerPage, options); Debug.Assert(method != METHOD_UNKNOWN); } switch (method) { case METHOD_ARTICLE_COMMENT: if (!OwnerPage.HasId) { await RefreshAsync(PostQueryOptions.None, cancellationToken); Debug.Assert(OwnerPage.IsMissing || OwnerPage.HasId); } return(await RequestHelper.PostCommentAsync(Site, this, OwnerPage, Id, content, cancellationToken)); case METHOD_WALL_MESSAGE: if (!OwnerPage.HasTitle) { await RefreshAsync(PostQueryOptions.None, cancellationToken); Debug.Assert(OwnerPage.IsMissing || OwnerPage.HasTitle); } return(await RequestHelper.ReplyWallMessageAsync(Site, this, OwnerPage, Id, content, cancellationToken)); } return(null); }
internal static int GetPostCreationMethod(WikiPageStub owner, PostCreationOptions options) { if ((options & PostCreationOptions.AsArticleComment) == PostCreationOptions.AsArticleComment && (options & PostCreationOptions.AsWallMessage) == PostCreationOptions.AsWallMessage) { throw new ArgumentException("AsArticleComment and AsWallMessage are mutually exclusive.", nameof(options)); } if ((options & PostCreationOptions.AsArticleComment) == PostCreationOptions.AsArticleComment) { return(METHOD_ARTICLE_COMMENT); } if ((options & PostCreationOptions.AsWallMessage) == PostCreationOptions.AsWallMessage) { return(METHOD_WALL_MESSAGE); } if (!owner.HasNamespaceId) { return(METHOD_UNKNOWN); } var ns = owner.NamespaceId; return((ns == WikiaNamespaces.MessageWall || ns == WikiaNamespaces.Board) ? METHOD_WALL_MESSAGE : METHOD_ARTICLE_COMMENT); }
/// <summary> /// Asynchronously adds a new reply to the post. /// </summary> /// <param name="postTitle">Title of the new post, in wikitext format.</param> /// <param name="postContent">The content in reply.</param> /// <param name="relatedPages">When posting in the Forum, specifies titles of related pages (aka. topics). Can be <c>null</c>.</param> /// <param name="options">The options for creating the post.</param> /// <param name="cancellationToken">A token used to cancel the operation.</param> /// <returns>A new post containing the ID of the new post.</returns> /// <remarks> /// <para>Wikia natively supports post title on Message Walls and Forum Boards. /// For the unification of method signature, you can set <paramref name="postTitle"/> when posting /// article comment, but the content will be simply surrounded with <c><h2></c> HTML markup.</para> /// <para>If you leave <paramref name="postTitle"/> <c>null</c> or empty when posting on Message Walls, /// a default title (e.g. Message from [UserName]) will be used by Wikia.</para> /// </remarks> public async Task <Post> NewPostAsync(string postTitle, string postContent, IEnumerable <string> relatedPages, PostCreationOptions options, CancellationToken cancellationToken) { // Refresh to get the page id. var method = Post.GetPostCreationMethod(Page, options); if (method == Post.METHOD_UNKNOWN) { await RefreshAsync(cancellationToken); method = Post.GetPostCreationMethod(Page, options); Debug.Assert(method != Post.METHOD_UNKNOWN); } switch (method) { case Post.METHOD_ARTICLE_COMMENT: if (!Page.HasId) { await RefreshAsync(cancellationToken); Debug.Assert(Page.IsMissing || Page.HasId); } if (!string.IsNullOrEmpty(postTitle)) { postContent = "<h2>" + postTitle + "</h2>\n\n" + postContent; } return(await RequestHelper.PostCommentAsync(Site, this, Page, null, postContent, cancellationToken)); case Post.METHOD_WALL_MESSAGE: if (!Page.HasTitle) { await RefreshAsync(cancellationToken); Debug.Assert(Page.IsMissing || Page.HasTitle); } return(await RequestHelper.PostWallMessageAsync(Site, this, Page, postTitle, postContent, relatedPages, cancellationToken)); } return(null); }
/// <inheritdoc cref="NewPostAsync(string,string,IEnumerable{string},PostCreationOptions,CancellationToken)"/> public Task <Post> NewPostAsync(string postTitle, string postContent, IEnumerable <string> relatedPages, PostCreationOptions options) { return(NewPostAsync(postTitle, postContent, relatedPages, options, CancellationToken.None)); }
/// <inheritdoc cref="NewPostAsync(string,string,IEnumerable{string},PostCreationOptions,CancellationToken)"/> public Task <Post> NewPostAsync(string postTitle, string postContent, PostCreationOptions options) { return(NewPostAsync(postTitle, postContent, null, options, CancellationToken.None)); }
/// <inheritdoc cref="ReplyAsync(string,PostCreationOptions,CancellationToken)"/> public Task <Post> ReplyAsync(string content, PostCreationOptions options) { return(ReplyAsync(content, options, CancellationToken.None)); }