diff --git a/Directory.Packages.props b/Directory.Packages.props index 04e561b..979bc9c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,10 +6,10 @@ - + - + diff --git a/src/FishyFlip.Tests/AnonymousTests.cs b/src/FishyFlip.Tests/AnonymousTests.cs index 26848b6..b752c0e 100644 --- a/src/FishyFlip.Tests/AnonymousTests.cs +++ b/src/FishyFlip.Tests/AnonymousTests.cs @@ -29,8 +29,7 @@ public async Task GetBlocksAsyncTest() var postCid1 = Cid.Decode("bafyreibby2anauk6ef2ntmeyebeb3yosncathvohhjrb7jmxfpyljyeq2e"); var postCid2 = Cid.Decode("bafyreiausj2iabpfs2mbmp2qtaszd2jokmsogto7z6zrz3pkncx3emyx4m"); - var oncardecoded = new OnCarDecoded((e) => { - + var oncardecoded = new OnCarDecoded((e) => { }); var result = await this.proto.Sync.GetBlocksAsync(atDid, new[] { postCid1, postCid2 }, oncardecoded); diff --git a/src/FishyFlip/ATProtoRepo.cs b/src/FishyFlip/ATProtoRepo.cs index 45e8b42..aa6515b 100644 --- a/src/FishyFlip/ATProtoRepo.cs +++ b/src/FishyFlip/ATProtoRepo.cs @@ -97,13 +97,16 @@ public Task> CreateBlockAsync( return this.Client .Post( - Constants.Urls.ATProtoRepo.CreateRecord, this.Options.JsonSerializerOptions, record, - cancellationToken, this.Options.Logger); + Constants.Urls.ATProtoRepo.CreateRecord, + this.Options.JsonSerializerOptions, + record, + cancellationToken, + this.Options.Logger); } public async Task> GetPostAsync(ATIdentifier repo, string rkey, Cid? cid = null, CancellationToken cancellationToken = default) => await this.GetRecordAsync(Constants.FeedType.Post, repo, rkey, cid, cancellationToken); - + public async Task> GetActorAsync(ATIdentifier repo, Cid? cid = null, CancellationToken cancellationToken = default) => await this.GetRecordAsync(Constants.ActorTypes.Profile, repo, "self", cid, cancellationToken); @@ -112,8 +115,11 @@ public Task> UploadBlobAsync(StreamContent content, C return this.Client .Post( - Constants.Urls.ATProtoRepo.UploadBlob, this.Options.JsonSerializerOptions, content, - cancellationToken, this.Options.Logger); + Constants.Urls.ATProtoRepo.UploadBlob, + this.Options.JsonSerializerOptions, + content, + cancellationToken, + this.Options.Logger); } public async Task> GetRecordAsync(string collection, ATIdentifier repo, string rkey, Cid? cid = null, CancellationToken cancellationToken = default) @@ -128,44 +134,42 @@ public Task> UploadBlobAsync(StreamContent content, C return await this.Client.Get(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger); } - public async Task> DescribeRepoAsync(ATIdentifier identifier, CancellationToken cancellationToken = default) + public async Task> DescribeRepoAsync(ATIdentifier identifier, CancellationToken cancellationToken = default) { string url = $"{Constants.Urls.ATProtoRepo.DescribeRepo}?repo={identifier}"; return await this.Client.Get(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger); } - private Task> CreateRecord(X record, CancellationToken cancellationToken = default) - { - return - this.Client - .Post( - Constants.Urls.ATProtoRepo.CreateRecord, this.Options.JsonSerializerOptions, record, - cancellationToken, this.Options.Logger); - } - - private Task> PutRecord(X record, CancellationToken cancellationToken = default) - { - return - this.Client - .Post( - Constants.Urls.ATProtoRepo.PutRecord, this.Options.JsonSerializerOptions, record, - cancellationToken, this.Options.Logger); - } - - public Task> DeleteFollowAsync(ATIdentifier repo, string rkey, - Cid? swapRecord = null, Cid? swapCommit = null, CancellationToken cancellationToken = default) + public Task> DeleteFollowAsync( + ATIdentifier repo, + string rkey, + Cid? swapRecord = null, + Cid? swapCommit = null, + CancellationToken cancellationToken = default) => this.DeleteRecordAsync(Constants.GraphTypes.Follow, repo, rkey, swapRecord, swapCommit, cancellationToken); - public Task> DeleteBlockAsync(ATIdentifier repo, string rkey, - Cid? swapRecord = null, Cid? swapCommit = null, CancellationToken cancellationToken = default) + public Task> DeleteBlockAsync( + ATIdentifier repo, + string rkey, + Cid? swapRecord = null, + Cid? swapCommit = null, + CancellationToken cancellationToken = default) => this.DeleteRecordAsync(Constants.GraphTypes.Block, repo, rkey, swapRecord, swapCommit, cancellationToken); - public Task> DeleteLikeAsync(ATIdentifier repo, string rkey, - Cid? swapRecord = null, Cid? swapCommit = null, CancellationToken cancellationToken = default) + public Task> DeleteLikeAsync( + ATIdentifier repo, + string rkey, + Cid? swapRecord = null, + Cid? swapCommit = null, + CancellationToken cancellationToken = default) => this.DeleteRecordAsync(Constants.FeedType.Like, repo, rkey, swapRecord, swapCommit, cancellationToken); - public Task> DeletePostAsync(ATIdentifier repo, string rkey, - Cid? swapRecord = null, Cid? swapCommit = null, CancellationToken cancellationToken = default) + public Task> DeletePostAsync( + ATIdentifier repo, + string rkey, + Cid? swapRecord = null, + Cid? swapCommit = null, + CancellationToken cancellationToken = default) => this.DeleteRecordAsync(Constants.FeedType.Post, repo, rkey, swapRecord, swapCommit, cancellationToken); public async Task> DeleteRecordAsync(string collection, ATIdentifier repo, string rkey, Cid? swapRecord = null, Cid? swapCommit = null, CancellationToken cancellationToken = default) @@ -222,4 +226,28 @@ public async Task> DeleteRecordAsync(string collection, ATIdenti return await this.Client.Get(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger); } + + private Task> PutRecord(T record, CancellationToken cancellationToken = default) + { + return + this.Client + .Post( + Constants.Urls.ATProtoRepo.PutRecord, + this.Options.JsonSerializerOptions, + record, + cancellationToken, + this.Options.Logger); + } + + private Task> CreateRecord(T record, CancellationToken cancellationToken = default) + { + return + this.Client + .Post( + Constants.Urls.ATProtoRepo.CreateRecord, + this.Options.JsonSerializerOptions, + record, + cancellationToken, + this.Options.Logger); + } } diff --git a/src/FishyFlip/ATWebSocketProtocol.cs b/src/FishyFlip/ATWebSocketProtocol.cs index a22c80c..8e1f31d 100644 --- a/src/FishyFlip/ATWebSocketProtocol.cs +++ b/src/FishyFlip/ATWebSocketProtocol.cs @@ -11,7 +11,6 @@ public sealed class ATWebSocketProtocol : IDisposable { private const int ReceiveBufferSize = 32768; private ClientWebSocket client; - private CancellationToken? token; private bool disposedValue; private ILogger? logger; private Uri instanceUri; @@ -20,7 +19,7 @@ public sealed class ATWebSocketProtocol : IDisposable /// /// Initializes a new instance of the class. /// - /// . + /// . internal ATWebSocketProtocol(ATProtocol protocol) { this.protocol = protocol; diff --git a/src/FishyFlip/Models/AtDid.cs b/src/FishyFlip/Models/AtDid.cs index d225521..f67c412 100644 --- a/src/FishyFlip/Models/AtDid.cs +++ b/src/FishyFlip/Models/AtDid.cs @@ -4,17 +4,33 @@ namespace FishyFlip.Models; +/// +/// ATDid. +/// public class ATDid : ATIdentifier { + /// + /// Initializes a new instance of the class. + /// + /// Actor Handler. [JsonConstructor] - protected ATDid(string Handler) + protected ATDid(string handler) { - this.Handler = Handler; + this.Handler = handler; } + /// + /// Gets the Actor Handler. + /// public string Handler { get; } - public static ATDid? Create(string uri) + /// + /// Create a new ATDid. + /// + /// Uri. + /// ATDid. + /// Thrown if URI is null or empty. + public static new ATDid? Create(string uri) { if (string.IsNullOrEmpty(uri)) { @@ -30,6 +46,12 @@ protected ATDid(string Handler) return new ATDid(uri); } + /// + /// Validate if a given string is a valid ATDid. + /// + /// Uri. + /// Bool. + /// Thrown if uri is null or empty. public static bool IsValid(string uri) { if (string.IsNullOrEmpty(uri)) @@ -40,11 +62,18 @@ public static bool IsValid(string uri) return DIDValidator.EnsureValidDid(uri); } + /// public override string ToString() { return this.Handler.ToString(); } + /// + /// Create a new ATDid. + /// + /// ATUri. + /// ATDid. + /// Thrown if uri is null or empty. internal static ATDid? Create(ATUri uri) { if (uri == null)