Skip to content

Commit

Permalink
Refactor Cid to ATCid
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Feb 15, 2024
1 parent 64a016a commit f2da3b0
Show file tree
Hide file tree
Showing 63 changed files with 208 additions and 208 deletions.
2 changes: 1 addition & 1 deletion src/FishyFlip/ATProtoModeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal ATProtoModeration(ATProtocol proto)
/// <param name="reason">The reason for the moderation report. This is optional.</param>
/// <param name="cancellationToken">A token that may be used to cancel the operation. This is optional.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a <see cref="Result{ModerationRecord}"/> that represents the moderation record.</returns>
public Task<Result<ModerationRecord?>> CreateModerationReportPostAsync(ModerationReasonType reasonType, ATUri uri, Cid cid, string? reason = default, CancellationToken cancellationToken = default)
public Task<Result<ModerationRecord?>> CreateModerationReportPostAsync(ModerationReasonType reasonType, ATUri uri, ATCid cid, string? reason = default, CancellationToken cancellationToken = default)
{
return this.Client.Post<CreateModerationReportPost, ModerationRecord?>(
Constants.Urls.ATProtoModeration.CreateReport,
Expand Down
40 changes: 20 additions & 20 deletions src/FishyFlip/ATProtoRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal ATProtoRepo(ATProtocol proto)
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the reference to the created like record.</returns>
public Task<Result<RecordRef>> CreateLikeAsync(
Cid cid,
ATCid cid,
ATUri uri,
DateTime? createdAt = null,
CancellationToken cancellationToken = default)
Expand All @@ -59,7 +59,7 @@ public Task<Result<RecordRef>> CreateLikeAsync(
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the reference to the created repost.</returns>
public Task<Result<RecordRef>> CreateRepostAsync(
Cid cid,
ATCid cid,
ATUri uri,
DateTime? createdAt = null,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -215,7 +215,7 @@ public Task<Result<RecordRef>> CreateCurateListAsync(
/// <param name="cid">The CID (Content Identifier) of the post.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the retrieved post record, or null if not found.</returns>
public async Task<Result<PostRecord?>> GetPostAsync(ATIdentifier repo, string rkey, Cid? cid = null, CancellationToken cancellationToken = default)
public async Task<Result<PostRecord?>> GetPostAsync(ATIdentifier repo, string rkey, ATCid? cid = null, CancellationToken cancellationToken = default)
=> await this.GetRecordAsync<PostRecord>(Constants.FeedType.Post, this.Options.SourceGenerationContext.PostRecord, repo, rkey, cid, cancellationToken);

/// <summary>
Expand All @@ -225,7 +225,7 @@ public Task<Result<RecordRef>> CreateCurateListAsync(
/// <param name="cid">The CID of the actor record. If null, the latest record will be retrieved.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the actor record, or null if not found.</returns>
public async Task<Result<ActorRecord?>> GetActorAsync(ATIdentifier repo, Cid? cid = null, CancellationToken cancellationToken = default)
public async Task<Result<ActorRecord?>> GetActorAsync(ATIdentifier repo, ATCid? cid = null, CancellationToken cancellationToken = default)
=> await this.GetRecordAsync<ActorRecord>(Constants.ActorTypes.Profile, this.Options.SourceGenerationContext.ActorRecord, repo, "self", cid, cancellationToken);

/// <summary>
Expand Down Expand Up @@ -256,7 +256,7 @@ public Task<Result<UploadBlobResponse>> UploadBlobAsync(StreamContent content, C
/// <param name="cid">Optional. The CID (Content Identifier) of the record. If specified, the method retrieves the record with this CID.</param>
/// <param name="cancellationToken">Optional. A CancellationToken that can be used to cancel the operation.</param>
/// <returns>A Task that represents the asynchronous operation. The task result contains a Result object with the retrieved record of type T, or null if the record was not found.</returns>
public async Task<Result<T?>> GetRecordAsync<T>(string collection, JsonTypeInfo<T> type, ATIdentifier repo, string rkey, Cid? cid = null, CancellationToken cancellationToken = default)
public async Task<Result<T?>> GetRecordAsync<T>(string collection, JsonTypeInfo<T> type, ATIdentifier repo, string rkey, ATCid? cid = null, CancellationToken cancellationToken = default)
where T : ATFeedTypeAPI
{
string url = $"{Constants.Urls.ATProtoRepo.GetRecord}?collection={collection}&repo={repo}&rkey={rkey}";
Expand Down Expand Up @@ -290,8 +290,8 @@ public Task<Result<UploadBlobResponse>> UploadBlobAsync(StreamContent content, C
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeleteFollowAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.GraphTypes.Follow, rkey, swapRecord, swapCommit, cancellationToken);

Expand All @@ -305,8 +305,8 @@ public Task<Result<Success>> DeleteFollowAsync(
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeleteBlockAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.GraphTypes.Block, rkey, swapRecord, swapCommit, cancellationToken);

Expand All @@ -320,8 +320,8 @@ public Task<Result<Success>> DeleteBlockAsync(
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeleteLikeAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.FeedType.Like, rkey, swapRecord, swapCommit, cancellationToken);

Expand All @@ -335,8 +335,8 @@ public Task<Result<Success>> DeleteLikeAsync(
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeletePostAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.FeedType.Post, rkey, swapRecord, swapCommit, cancellationToken);

Expand All @@ -350,8 +350,8 @@ public Task<Result<Success>> DeletePostAsync(
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeleteRepostAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.FeedType.Repost, rkey, swapRecord, swapCommit, cancellationToken);

Expand All @@ -365,8 +365,8 @@ public Task<Result<Success>> DeleteRepostAsync(
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeleteListAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.GraphTypes.List, rkey, swapRecord, swapCommit, cancellationToken);

Expand All @@ -380,8 +380,8 @@ public Task<Result<Success>> DeleteListAsync(
/// <returns>A Task that represents the asynchronous operation. The task result contains a Success object indicating whether the operation was successful.</returns>
public Task<Result<Success>> DeleteListItemAsync(
string rkey,
Cid? swapRecord = null,
Cid? swapCommit = null,
ATCid? swapRecord = null,
ATCid? swapCommit = null,
CancellationToken cancellationToken = default)
=> this.DeleteRecordAsync(Constants.GraphTypes.ListItem, rkey, swapRecord, swapCommit, cancellationToken);

Expand Down Expand Up @@ -539,7 +539,7 @@ private Task<Result<T2>> CreateRecord<T, T2>(T record, JsonTypeInfo<T> c1, JsonT
this.Options.Logger);
}

private async Task<Result<Success>> DeleteRecordAsync(string collection, string rkey, Cid? swapRecord = null, Cid? swapCommit = null, CancellationToken cancellationToken = default)
private async Task<Result<Success>> DeleteRecordAsync(string collection, string rkey, ATCid? swapRecord = null, ATCid? swapCommit = null, CancellationToken cancellationToken = default)
{
DeleteRecord record = new(
collection,
Expand Down
30 changes: 15 additions & 15 deletions src/FishyFlip/ATProtoSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ internal ATProtoSync(ATProtocol proto)
/// Get a Blob.
/// </summary>
/// <param name="did"><see cref="ATDid"/>.</param>
/// <param name="cid"><see cref="Cid"/>.</param>
/// <param name="cid"><see cref="ATCid"/>.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>Result of Blob.</returns>
public async Task<Result<Blob?>> GetBlobAsync(ATDid did, Cid cid, CancellationToken cancellationToken = default)
public async Task<Result<Blob?>> GetBlobAsync(ATDid did, ATCid cid, CancellationToken cancellationToken = default)
{
string url = $"{Constants.Urls.ATProtoSync.GetBlob}?did={did}&cid={cid}";
return await this.Client.GetBlob(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger);
Expand Down Expand Up @@ -130,12 +130,12 @@ internal ATProtoSync(ATProtocol proto)
/// Get Commit Path.
/// </summary>
/// <param name="did">Actor ATDid.</param>
/// <param name="latest">Latest Cid Commit.</param>
/// <param name="earliest">Earliest Cid Commit.</param>
/// <param name="latest">Latest ATCid Commit.</param>
/// <param name="earliest">Earliest ATCid Commit.</param>
/// <param name="cancellationToken">Optional Cancellation Token.</param>
/// <returns>result of CommitPath.</returns>
[Obsolete("Deprecated in Repo V3. This should no longer work.")]
public async Task<Result<CommitPath?>> GetCommitPathAsync(ATDid did, Cid? latest = default, Cid? earliest = default, CancellationToken cancellationToken = default)
public async Task<Result<CommitPath?>> GetCommitPathAsync(ATDid did, ATCid? latest = default, ATCid? earliest = default, CancellationToken cancellationToken = default)
{
var url = $"{Constants.Urls.ATProtoSync.GetCommitPath}&did={did}";
if (latest is not null)
Expand All @@ -155,11 +155,11 @@ internal ATProtoSync(ATProtocol proto)
/// Get Blocks.
/// </summary>
/// <param name="did">Actor ATDid.</param>
/// <param name="commits">Array of Cid Commits.</param>
/// <param name="commits">Array of ATCid Commits.</param>
/// <param name="onDecoded">OnCarDecoded callback.</param>
/// <param name="cancellationToken">Optional Cancellation Token.</param>
/// <returns>Blocks.</returns>
public Task<Result<Success?>> GetBlocksAsync(ATDid did, Cid[] commits, OnCarDecoded onDecoded, CancellationToken cancellationToken = default)
public Task<Result<Success?>> GetBlocksAsync(ATDid did, ATCid[] commits, OnCarDecoded onDecoded, CancellationToken cancellationToken = default)
{
var commitList = string.Join("&", commits.Select(n => $"cids={n}"));
var url = $"{Constants.Urls.ATProtoSync.GetBlocks}?did={did}&{commitList}";
Expand All @@ -176,12 +176,12 @@ internal ATProtoSync(ATProtocol proto)
/// Download Blocks as CAR file.
/// </summary>
/// <param name="did">Actor ATDid.</param>
/// <param name="commits">Array of Cid Commits.</param>
/// <param name="commits">Array of ATCid Commits.</param>
/// <param name="path">Path to file.</param>
/// <param name="filename">Filename.</param>
/// <param name="cancellationToken">Optional Cancellation Token.</param>
/// <returns>Blocks.</returns>
public Task<Result<Success?>> DownloadBlocksAsync(ATDid did, Cid[] commits, string? path = default, string? filename = default, CancellationToken cancellationToken = default)
public Task<Result<Success?>> DownloadBlocksAsync(ATDid did, ATCid[] commits, string? path = default, string? filename = default, CancellationToken cancellationToken = default)
{
var commitList = string.Join("&", commits.Select(n => $"cids={n}"));
var url = $"{Constants.Urls.ATProtoSync.GetBlocks}?did={did}&{commitList}";
Expand All @@ -201,11 +201,11 @@ internal ATProtoSync(ATProtocol proto)
/// </summary>
/// <param name="did">Actor ATDid.</param>
/// <param name="onDecoded">OnCarDecoded callback.</param>
/// <param name="commit">Cid Commit.</param>
/// <param name="commit">ATCid Commit.</param>
/// <param name="cancellationToken">Optional Cancellation token.</param>
/// <returns>Result of success.</returns>
[Obsolete("Deprecated in favor of GetRepo")]
public Task<Result<Success?>> GetCheckoutAsync(ATDid did, OnCarDecoded onDecoded, Cid? commit = default, CancellationToken cancellationToken = default)
public Task<Result<Success?>> GetCheckoutAsync(ATDid did, OnCarDecoded onDecoded, ATCid? commit = default, CancellationToken cancellationToken = default)
{
var url = $"{Constants.Urls.ATProtoSync.GetCheckout}?did={did}";
if (commit is not null)
Expand All @@ -230,7 +230,7 @@ internal ATProtoSync(ATProtocol proto)
/// <param name="filename">Filename.</param>
/// <param name="cancellationToken">Optional Cancellation Token.</param>
/// <returns>Result of success.</returns>
public Task<Result<Success?>> DownloadCheckoutAsync(ATDid did, Cid? commit = default, string? path = default, string? filename = default, CancellationToken cancellationToken = default)
public Task<Result<Success?>> DownloadCheckoutAsync(ATDid did, ATCid? commit = default, string? path = default, string? filename = default, CancellationToken cancellationToken = default)
{
var url = $"{Constants.Urls.ATProtoSync.GetCheckout}?did={did}";
if (commit is not null)
Expand All @@ -254,7 +254,7 @@ internal ATProtoSync(ATProtocol proto)
/// <param name="commit">Commit.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>Result of success.</returns>
public Task<Result<Success?>> GetRecordAsync(string collection, ATDid repo, string rkey, OnCarDecoded onDecoded, Cid? commit = default, CancellationToken cancellationToken = default)
public Task<Result<Success?>> GetRecordAsync(string collection, ATDid repo, string rkey, OnCarDecoded onDecoded, ATCid? commit = default, CancellationToken cancellationToken = default)
{
var url = $"{Constants.Urls.ATProtoSync.GetRecord}?collection={collection}&did={repo}&rkey={rkey}";
if (commit is not null)
Expand Down Expand Up @@ -285,7 +285,7 @@ internal ATProtoSync(ATProtocol proto)
string collection,
ATDid repo,
string rkey,
Cid? commit = default,
ATCid? commit = default,
string? path = default,
string? filename = default,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -337,7 +337,7 @@ internal ATProtoSync(ATProtocol proto)
/// <param name="since">Optional revision of the repo to list blobs since.</param>
/// <param name="cursor">Optional Cursor. Used to continue response.</param>
/// <param name="cancellationToken">Optional Cancellation Token.</param>
/// <returns>Result of Cids.</returns>
/// <returns>Result of ATCids.</returns>
public async Task<Result<ListBlobs?>> ListBlobsAsync(ATDid repo, int limit = 500, string? since = default, string? cursor = default, CancellationToken cancellationToken = default)
{
var url = Constants.Urls.ATProtoSync.ListBlobs + $"?did={repo}&limit={limit}";
Expand Down
4 changes: 2 additions & 2 deletions src/FishyFlip/ATProtocolOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ATProtocolOptions
/// </summary>
public ATProtocolOptions()
{
// HACK: Decodes a message to load the default Cid protocols.
// HACK: Decodes a message to load the default ATCid protocols.
Cid.Decode("bafyreiezjt5bqt2xpcdfvisud7jrd4zuxygz4ssnuge3ddjcoptanvcnsa");
this.HttpClient = new HttpClient(new HttpClientHandler { MaxRequestContentBufferSize = int.MaxValue });
this.Url = new Uri("https://bsky.social");
Expand All @@ -30,7 +30,7 @@ public ATProtocolOptions()
new AtDidJsonConverter(),
new EmbedConverter(),
new ATRecordJsonConverter(),
new CidConverter(),
new ATCidConverter(),
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/FishyFlip/ATWebSocketProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void HandleProgressStatus(CarProgressStatusEvent e)
case FrameHeaderOperation.Error:
var frameError = new FrameError(objects[1]);
message.Error = frameError;
this.logger?.LogError($"WSS: Error: {frameError.Message}");
this.logger?.LogError($"WSS: ATError: {frameError.Message}");
this.CloseAsync(WebSocketCloseStatus.InternalServerError, frameError.Message ?? string.Empty).FireAndForgetSafeAsync(this.logger);
break;
default:
Expand Down Expand Up @@ -288,7 +288,7 @@ private async Task ReceiveMessages(ClientWebSocket webSocket, CancellationToken
}
catch (Exception e)
{
this.logger?.LogError(e, "WSS: Error receiving message.");
this.logger?.LogError(e, "WSS: ATError receiving message.");
}
}
}
Expand Down
Loading

0 comments on commit f2da3b0

Please sign in to comment.