Skip to content

Commit

Permalink
Add GetActorLikes
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jan 16, 2024
1 parent 958d937 commit 4a2a1f8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ As a general rule of thumb, `com.atproto` endpoints (such as `com.atproto.sync`)
| [app.bsky.feed.getAuthorFeed](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getAuthorFeed.json) ||
| [app.bsky.feed.getLikes](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getLikes.json) ||
| [app.bsky.feed.getPostThread](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getPostThread.json) ||
| [app.bsky.feed.getActorLikes](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getActorLikes.json) | |
| [app.bsky.feed.getActorLikes](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getActorLikes.json) | |
| [app.bsky.feed.getRepostedBy](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getRepostedBy.json) ||
| [app.bsky.feed.describeFeedGenerator](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/describeFeedGenerator.json) ||
| [app.bsky.feed.searchPosts](https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/searchPosts.json) ||
Expand Down
27 changes: 26 additions & 1 deletion samples/FishyFlipSamplesApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

string[] authMenuChoices =
[
"Exit", "Get List Blocks for Actor", "Get List Mutes for Actor", "Get Suggestion Follows",
"Exit", "Get Actor Likes", "Get List Blocks for Actor", "Get List Mutes for Actor", "Get Suggestion Follows",
"Get Lists Via ATIdentifier", "Get List Via ATUri"
];

Expand All @@ -64,6 +64,9 @@
var menuChoice = Prompt.Select("Menu", authMenuChoices);
switch (menuChoice)
{
case "Get Actor Likes":
await GetActorLikes(atProtocol);
break;
case "Get List Blocks for Actor":
await GetListBlocksForActor(atProtocol);
break;
Expand Down Expand Up @@ -111,6 +114,28 @@
}
}

async Task GetActorLikes(ATProtocol protocol)
{
var handle = Prompt.Input<string>("Handle", defaultValue: "drasticactions.dev",
validators: new[] { Validators.Required() });
var profile = (await protocol.Identity.ResolveHandleAsync(ATHandle.Create(handle)!)).HandleResult();
var likes = (await protocol.Feed.GetActorLikesAsync(profile.Did)).HandleResult();
if (likes is null)
{
Console.WriteLine("No likes found.");
return;
}

foreach (var item in likes.Feed)
{
Console.WriteLine(item.Post.Author);
Console.WriteLine(item.Post.IndexedAt);
Console.WriteLine(item.Post.Record?.Text);
Console.WriteLine("-----");

}
}

async Task GetListBlocksForActor(ATProtocol protocol)
{
var blocks = (await protocol.Graph.GetListBlocksAsync()).HandleResult();
Expand Down
15 changes: 15 additions & 0 deletions src/FishyFlip/BlueskyFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ public async Task<Result<Timeline>> GetAuthorFeedAsync(ATIdentifier handle, int
error => error!);
}

public async Task<Result<Timeline>> GetActorLikesAsync(ATIdentifier handle, int limit = 50, string? cursor = default, CancellationToken cancellationToken = default)
{
string url = $"{Constants.Urls.Bluesky.Feed.GetActorLikes}?actor={handle.ToString()}&limit={limit}";
if (cursor is not null)
{
url += $"&cursor={cursor}";
}

Multiple<Timeline?, Error> result = await this.Client.Get<Timeline>(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger);
return result
.Match<Result<Timeline>>(
authorFeed => (authorFeed ?? new Timeline(Array.Empty<FeedViewPost>(), null))!,
error => error!);
}

public async Task<Result<PostCollection>> GetPostsAsync(IEnumerable<ATUri> query, CancellationToken cancellationToken = default)
{
var answer = string.Join("&", query.Select(n => $"uris={n}"));
Expand Down
1 change: 1 addition & 0 deletions src/FishyFlip/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static class Bluesky
public static class Feed
{
public const string GetAuthorFeed = "/xrpc/app.bsky.feed.getAuthorFeed";
public const string GetActorLikes = "/xrpc/app.bsky.feed.getActorLikes";
public const string GetTimeline = "/xrpc/app.bsky.feed.getTimeline";
public const string GetFeedSkeleton = "/xrpc/app.bsky.feed.getFeedSkeleton";
public const string GetPostThread = "/xrpc/app.bsky.feed.getPostThread";
Expand Down

0 comments on commit 4a2a1f8

Please sign in to comment.