public async Task <OperationResult <VoidResponse> > CreateComment(CreateCommentModel model, CancellationToken ct) { var results = Validate(model); if (results.Any()) { return(new OperationResult <VoidResponse>(new ValidationError(string.Join(Environment.NewLine, results.Select(i => i.ErrorMessage))))); } if (!UrlHelper.TryCastUrlToAuthorAndPermlink(model.ParentUrl, out var parentAuthor, out var parentPermlink)) { return(new OperationResult <VoidResponse>(new ApplicationError(Localization.Errors.IncorrectIdentifier))); } var permlink = OperationHelper.CreateReplyPermlink(model.Login, parentAuthor, parentPermlink); var commentModel = new CommentModel(model.Login, model.PostingKey, parentAuthor, parentPermlink, model.Login, permlink, string.Empty, model.Body, model.JsonMetadata); var bKey = $"{_ditchClient.GetType()}{model.IsNeedRewards}"; if (_beneficiariesCash.ContainsKey(bKey)) { commentModel.Beneficiaries = _beneficiariesCash[bKey]; } else { var beneficiaries = await GetBeneficiaries(model.IsNeedRewards, ct); if (beneficiaries.IsSuccess) { _beneficiariesCash[bKey] = commentModel.Beneficiaries = beneficiaries.Result.Beneficiaries; } } var result = await _ditchClient.Create(commentModel, ct); Trace($"post/{permlink}/comment", model.Login, result.Error, permlink, ct);//.Wait(5000); return(result); }
public async Task CreateCommentTest(KnownChains apiName) { var user = Users[apiName]; // Load last created post var userPostsRequest = new UserPostsModel(user.Login); userPostsRequest.ShowNsfw = true; userPostsRequest.ShowLowRated = true; var userPostsResponse = await Api[apiName].GetUserPosts(userPostsRequest, CancellationToken.None); AssertResult(userPostsResponse); var lastPost = userPostsResponse.Result.Results.First(); // 2) Create new comment // Wait for 20 seconds before commenting Thread.Sleep(TimeSpan.FromSeconds(20)); var createCommentModel = new CreateCommentModel(user, lastPost.Url, $"Test comment {DateTime.Now:G}", AppSettings.AppInfo); var createCommentResponse = await Api[apiName].CreateComment(createCommentModel, CancellationToken.None); AssertResult(createCommentResponse); Assert.That(createCommentResponse.Result.IsSuccess, Is.True); // Wait for data to be writed into blockchain Thread.Sleep(TimeSpan.FromSeconds(15)); // Load comments for this post and check them var getCommentsRequest = new NamedInfoModel(lastPost.Url); var commentsResponse = await Api[apiName].GetComments(getCommentsRequest, CancellationToken.None); AssertResult(commentsResponse); UrlHelper.TryCastUrlToAuthorAndPermlink(createCommentModel.ParentUrl, out var parentAuthor, out var parentPermlink); var permlink = OperationHelper.CreateReplyPermlink(user.Login, parentAuthor, parentPermlink); Assert.IsNotNull(commentsResponse.Result.Results.FirstOrDefault(i => i.Url.EndsWith(permlink))); }
public ReplyOperation(string parentAuthor, string parentPermlink, string author, string body, string jsonMetadata) : base(parentAuthor, parentPermlink, author, OperationHelper.CreateReplyPermlink(author, parentAuthor, parentPermlink), string.Empty, body, jsonMetadata) { }
private void CreateCommentTest(StringBuilder sb, int num) { sb.Append($"{num}) CreateCommentTest : "); StepFinished?.Invoke(sb.ToString()); // Load last created post var getPosts = new PostsModel(PostType.New) { Login = _user.Login }; var postsResp = _api.GetPosts(getPosts, CancellationToken.None) .Result; if (!postsResp.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {postsResp.Error.Message}"); return; } if (postsResp.Result.Results.Count == 0) { sb.AppendLine("fail. Reason:{Environment.NewLine} There are no Posts!"); return; } var testPost = postsResp.Result.Results.First(); var req = new CreateOrEditCommentModel(_user, testPost, "Hi, I am a bot for testing Ditch api, please ignore this comment.", _appInfo); var rez = _api.CreateOrEditComment(req, CancellationToken.None) .Result; if (!UrlHelper.TryCastUrlToAuthorAndPermlink(testPost.Url, out var parentAuthor, out var parentPermlink)) { sb.AppendLine($"fail. Reason:{Environment.NewLine} url to permlink cast."); return; } var permlink = OperationHelper.CreateReplyPermlink(_user.Login, parentAuthor, parentPermlink); if (!rez.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {rez.Error.Message}"); return; } Task.Delay(10000); var getComm = new NamedInfoModel(testPost.Url) { Offset = permlink, Limit = 1 }; var verifyPostresp = _api.GetComments(getComm, CancellationToken.None) .Result; if (!verifyPostresp.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {verifyPostresp.Error.Message}"); return; } if (verifyPostresp.Result.Results.Count != 1) { sb.AppendLine($"fail. Reason:{Environment.NewLine} Comment ({permlink}) not found!"); return; } sb.AppendLine("pass."); }
public CreateOrEditCommentModel(UserInfo user, Post parentPost, string body, IAppInfo appInfo) : base(user, parentPost, OperationHelper.CreateReplyPermlink(user.Login, parentPost.Author, parentPost.Permlink), string.Empty, body, $"{{\"app\": \"steepshot/v{appInfo.GetAppVersion()} b{appInfo.GetBuildVersion()} t\", \"device\":\"{appInfo.GetModel()}\"}}") { IsEditMode = false; }