Accept tags to patch event

This commit is contained in:
2023-07-05 23:34:44 +01:00
parent 135583cf4d
commit 87b3e3b271
3 changed files with 8 additions and 3 deletions

View File

@ -12,4 +12,7 @@ public class PatchEvent
[JsonProperty("image")]
public string Image { get; init; } = null!;
[JsonProperty("tags")]
public string[] Tags { get; init; } = Array.Empty<string>();
}

View File

@ -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();
}

View File

@ -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<string>());
var existingEvent = user.Event != default ? JsonConvert.DeserializeObject<NostrEvent>(user.Event, NostrSerializer.Settings) : null;
var ev = CreateStreamEvent(user, existingEvent?.Tags?.FindFirstTagValue("status") ?? "ended");