Skip to content

Commit

Permalink
Add Reply to CreatePostAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Feb 24, 2024
1 parent d74b49b commit 04df284
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/FishyFlip.Tests/AuthorizedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public AuthorizedTests()
{
string handle = Environment.GetEnvironmentVariable("BLUESKY_TEST_HANDLE") ?? throw new ArgumentNullException();
string password = Environment.GetEnvironmentVariable("BLUESKY_TEST_PASSWORD") ?? throw new ArgumentNullException();
string instance = Environment.GetEnvironmentVariable("BLUESKY_INSTANCE_URL") ?? throw new ArgumentNullException();
var debugLog = new DebugLoggerProvider();
var atProtocolBuilder = new ATProtocolBuilder()
.EnableAutoRenewSession(false)
.WithInstanceUrl(new Uri("https://drasticactions.ninja"))
.WithInstanceUrl(new Uri(instance))
.WithLogger(debugLog.CreateLogger("FishyFlipTests"));
this.proto = atProtocolBuilder.Build();
this.proto.Server.CreateSessionAsync(handle, password).Wait();
Expand Down Expand Up @@ -261,6 +262,15 @@ public async Task CreatePostAsyncTest()
});
}

[Fact]
public async Task CreatePostWithReplyAsyncTest()
{
var test = (await this.proto.Repo.CreatePostAsync("CreatePostAsyncTest", null, null, null, new[] { "en" })).HandleResult();
Assert.True(test!.Cid is not null);
var reply = (await this.proto.Repo.CreatePostAsync("CreatePostAsyncTestReply", new Reply(new ReplyRef(test!.Cid, test.Uri!), new ReplyRef(test!.Cid, test.Uri!)), null, null, new[] { "en" })).HandleResult();
Assert.True(reply!.Cid is not null);
}

[Fact]
public async Task CreatePostWithImageAsyncTest()
{
Expand Down
27 changes: 26 additions & 1 deletion src/FishyFlip/ATProtoRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,36 @@ public Task<Result<CreatePostResponse>> CreatePostAsync(
string? rkey = null,
string? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.CreatePostAsync(text, null, facets, embed, langs, createdAt, rkey, swapCommit, cancellationToken);

/// <summary>
/// Creates a post asynchronously.
/// </summary>
/// <param name="text">The text of the post.</param>
/// <param name="reply">The post to reply to.</param>
/// <param name="facets">The facets associated with the post.</param>
/// <param name="embed">The embed associated with the post.</param>
/// <param name="langs">The languages associated with the post.</param>
/// <param name="createdAt">The creation date of the post.</param>
/// <param name="rkey">The rkey associated with the post.</param>
/// <param name="swapCommit">The swap commit associated with the post.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the result of creating the post.</returns>
public Task<Result<CreatePostResponse>> CreatePostAsync(
string text,
Reply? reply,
Facet[]? facets = null,
Embed? embed = default,
string[]? langs = null,
DateTime? createdAt = null,
string? rkey = null,
string? swapCommit = null,
CancellationToken cancellationToken = default)
{
CreatePostRecord record = new(
Constants.FeedType.Post,
this.proto.SessionManager!.Session!.Did.ToString()!,
new Post(embed, facets, createdAt ?? DateTime.UtcNow, null, text, langs, Constants.FeedType.Post),
new Post(embed, facets, createdAt ?? DateTime.UtcNow, reply, text, langs, Constants.FeedType.Post),
rkey,
swapCommit);
return this.CreateRecord<CreatePostRecord, CreatePostResponse>(record, this.Options.SourceGenerationContext.CreatePostRecord, this.Options.SourceGenerationContext.CreatePostResponse, cancellationToken);
Expand Down

0 comments on commit 04df284

Please sign in to comment.