From 87b3e3b2711d9167bce8c4a5642d774ec9beb555 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 5 Jul 2023 23:34:44 +0100 Subject: [PATCH] Accept tags to patch event --- NostrStreamer/ApiModel/PatchEvent.cs | 3 +++ NostrStreamer/Controllers/NostrController.cs | 2 +- NostrStreamer/Services/StreamManager.cs | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/NostrStreamer/ApiModel/PatchEvent.cs b/NostrStreamer/ApiModel/PatchEvent.cs index 1bb7831..5556c5b 100644 --- a/NostrStreamer/ApiModel/PatchEvent.cs +++ b/NostrStreamer/ApiModel/PatchEvent.cs @@ -12,4 +12,7 @@ public class PatchEvent [JsonProperty("image")] public string Image { get; init; } = null!; + + [JsonProperty("tags")] + public string[] Tags { get; init; } = Array.Empty(); } diff --git a/NostrStreamer/Controllers/NostrController.cs b/NostrStreamer/Controllers/NostrController.cs index ce105fe..d78b77d 100644 --- a/NostrStreamer/Controllers/NostrController.cs +++ b/NostrStreamer/Controllers/NostrController.cs @@ -71,7 +71,7 @@ public class NostrController : Controller var pubkey = GetPubKey(); if (string.IsNullOrEmpty(pubkey)) return Unauthorized(); - await _streamManager.PatchEvent(pubkey, req.Title, req.Summary, req.Image); + await _streamManager.PatchEvent(pubkey, req.Title, req.Summary, req.Image, req.Tags); return Accepted(); } diff --git a/NostrStreamer/Services/StreamManager.cs b/NostrStreamer/Services/StreamManager.cs index 2687e54..5348029 100644 --- a/NostrStreamer/Services/StreamManager.cs +++ b/NostrStreamer/Services/StreamManager.cs @@ -71,7 +71,8 @@ public class StreamManager _logger.LogInformation("Stream consumed {n} seconds for {pubkey} costing {cost} sats", duration, user.PubKey, cost); if (user.Balance >= balanceAlertThreshold && user.Balance - cost < balanceAlertThreshold) { - _nostr.Send(new NostrEventRequest(CreateStreamChat(user, $"Your balance is below {balanceAlertThreshold} sats, please topup"))); + _nostr.Send(new NostrEventRequest(CreateStreamChat(user, + $"Your balance is below {balanceAlertThreshold} sats, please topup"))); } if (user.Balance <= 0) @@ -81,7 +82,7 @@ public class StreamManager } } - public async Task PatchEvent(string pubkey, string? title, string? summary, string? image) + public async Task PatchEvent(string pubkey, string? title, string? summary, string? image, string[]? tags) { var user = await _db.Users.SingleOrDefaultAsync(a => a.PubKey == pubkey); if (user == default) throw new Exception("User not found"); @@ -89,6 +90,7 @@ public class StreamManager user.Title = title; user.Summary = summary; user.Image = image; + user.Tags = string.Join(",", tags ?? Array.Empty()); var existingEvent = user.Event != default ? JsonConvert.DeserializeObject(user.Event, NostrSerializer.Settings) : null; var ev = CreateStreamEvent(user, existingEvent?.Tags?.FindFirstTagValue("status") ?? "ended");