Skip to content

Commit

Permalink
Add Feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Aug 1, 2023
1 parent 07cf799 commit 1fa2df0
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FishyFlip/ATProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public ATProtocol(ATProtocolOptions options)
/// </summary>
public ATProtoDebug Debug => new(this);

/// <summary>
/// Gets the ATProto Unspecced Protocol.
/// </summary>
public BlueskyUnspecced Unspecced => new(this);

/// <summary>
/// Gets the ATProto Feed Protocol.
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions src/FishyFlip/BlueskyFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,30 @@ public async Task<Result<Timeline>> GetTimelineAsync(int limit = 50, string? cur
timeline => (timeline ?? new Timeline(Array.Empty<FeedViewPost>(), null))!,
error => error!);
}

public async Task<Result<FeedPostList>> GetFeedAsync(ATUri uri, int limit = 30, string? cursor = default, CancellationToken cancellationToken = default)
{
string url = $"{Constants.Urls.Bluesky.Feed.GetFeed}?feed={uri}&limit={limit}";
if (cursor is not null)
{
url += $"&cursor={cursor}";
}

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

public async Task<Result<FeedGeneratorRecord>> GetFeedGeneratorAsync(ATUri uri, CancellationToken cancellationToken = default)
{
string url = $"{Constants.Urls.Bluesky.Feed.GetFeedGenerator}?feed={uri}";

Multiple<FeedGeneratorRecord?, Error> result = await this.Client.Get<FeedGeneratorRecord>(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger);
return result
.Match<Result<FeedGeneratorRecord>>(
timeline => timeline!,
error => error!);
}
}
41 changes: 41 additions & 0 deletions src/FishyFlip/BlueskyUnspecced.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// <copyright file="BlueskyUnspecced.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

namespace FishyFlip;

/// <summary>
/// Bluesky Unspecced.
/// </summary>
public sealed class BlueskyUnspecced
{
private ATProtocol proto;

/// <summary>
/// Initializes a new instance of the <see cref="BlueskyUnspecced"/> class.
/// </summary>
/// <param name="proto"><see cref="ATProtocol"/>.</param>
internal BlueskyUnspecced(ATProtocol proto)
{
this.proto = proto;
}

private ATProtocolOptions Options => this.proto.Options;

private HttpClient Client => this.proto.Client;

public async Task<Result<FeedResultList>> GetPopularFeedGeneratorsAsync(int limit = 50, string? cursor = default, CancellationToken cancellationToken = default)
{
string url = $"{Constants.Urls.Bluesky.Unspecced.GetPopularFeedGenerators}?limit={limit}";
if (cursor is not null)
{
url += $"&cursor={cursor}";
}

Multiple<FeedResultList?, Error> result = await this.Client.Get<FeedResultList>(url, this.Options.JsonSerializerOptions, cancellationToken, this.Options.Logger);
return result
.Match<Result<FeedResultList>>(
timeline => (timeline ?? new FeedResultList(Array.Empty<FeedRecord>(), null))!,
error => error!);
}
}
7 changes: 7 additions & 0 deletions src/FishyFlip/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public static class Feed
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";
public const string GetFeedGenerator = "/xrpc/app.bsky.feed.getFeedGenerator";
public const string GetFeed = "/xrpc/app.bsky.feed.getFeed";
public const string GetPosts = "/xrpc/app.bsky.feed.getPosts";
public const string GetLikes = "/xrpc/app.bsky.feed.getLikes";
public const string GetRepostedBy = "/xrpc/app.bsky.feed.getRepostedBy";
Expand Down Expand Up @@ -134,6 +136,11 @@ public static class Notification
public const string NotificationListNotifications = "/xrpc/app.bsky.notification.listNotifications";
public const string NotificationGetUnreadCount = "/xrpc/app.bsky.notification.getUnreadCount";
}

public static class Unspecced
{
public const string GetPopularFeedGenerators = "/xrpc/app.bsky.unspecced.getPopularFeedGenerators";
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/FishyFlip/Models/FeedRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <copyright file="FeedRecord.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

namespace FishyFlip.Models;

public record FeedRecord(ATUri Uri, ATDid Did, string Avatar, FeedCreator Creator, Cid Cid, string DisplayName, Viewer Viewer, int LikeCount, DateTime IndexedAt, string Description)
{
}

public record FeedGeneratorRecord(bool IsOnline, bool IsValid, FeedRecord View);

public record FeedPostList(FeedPost[] Feed, string? Cursor);

public record FeedPost(PostView Post);

public record FeedResultList(FeedRecord[] Feeds, string? Cursor);

public record FeedCreator(string Did,
string Handle,
string DisplayName,
string Avatar,
Viewer Viewer,
IReadOnlyList<Label> Labels);

0 comments on commit 1fa2df0

Please sign in to comment.