Skip to content

Commit

Permalink
Update firehose sample
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jan 3, 2024
1 parent fa602e1 commit 266dff9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions samples/FishyFlip.Firehose/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@
var debugLog = new DebugLoggerProvider();

// You can set a custom url with WithInstanceUrl
var atProtocolBuilder = new ATWebSocketProtocolBuilder()
var atWebProtocolBuilder = new ATWebSocketProtocolBuilder()
.WithLogger(debugLog.CreateLogger("FishyFlipDebug"));
var atWebProtocol = atWebProtocolBuilder.Build();

var atProtocolBuilder = new ATProtocolBuilder()
.WithLogger(debugLog.CreateLogger("FishyFlipDebug"));
var atProtocol = atProtocolBuilder.Build();

atProtocol.OnSubscribedRepoMessage += (sender, args) =>
atWebProtocol.OnSubscribedRepoMessage += (sender, args) =>
{
Task.Run(() => HandleMessageAsync(args.Message)).FireAndForgetSafeAsync();
};

await atProtocol.StartSubscribeReposAsync();
await atWebProtocol.StartSubscribeReposAsync();

var key = Console.ReadKey();

await atProtocol.StopSubscriptionAsync();
await atWebProtocol.StopSubscriptionAsync();

async Task HandleMessageAsync(SubscribeRepoMessage message)
{
Expand All @@ -50,11 +54,14 @@ async Task HandleMessageAsync(SubscribeRepoMessage message)
{
// The Actor Did.
var did = message.Commit.Repo;

var repo = (await atProtocol.Repo.DescribeRepoAsync(did)).HandleResult();

// Commit.Ops are the actions used when creating the message.
// In this case, it's a create record for the post.
// The path contains the post action and path, we need the path, so we split to get it.
var url = $"https://bsky.app/profile/{did}/post/{message.Commit.Ops![0]!.Path!.Split("/").Last()}";
Console.WriteLine($"Post URL: {url}");
Console.WriteLine($"Post URL: {url}, from {repo.Handle}");
}
}
}

0 comments on commit 266dff9

Please sign in to comment.