🐛 Fix post load poll, again...

This commit is contained in:
2025-08-05 22:18:58 +08:00
parent 822a339532
commit 7367f372c0

View File

@@ -678,27 +678,19 @@ public partial class PostService(
// Find the index of the poll embed first // Find the index of the poll embed first
var pollIndex = embeds.FindIndex(e => var pollIndex = embeds.FindIndex(e =>
e.ContainsKey("Type") && (string)e["Type"] == "poll"); e.ContainsKey("Type") && ((JsonElement)e["Type"]).ToString() == "poll");
if (pollIndex < 0) return; if (pollIndex < 0) return;
var pollEmbed = embeds[pollIndex]; var pollEmbed = embeds[pollIndex];
try try
{ {
var pollId = pollEmbed["Id"] switch var pollId = Guid.Parse(((JsonElement)pollEmbed["Id"]).ToString());
{
Guid g => g,
string s when !string.IsNullOrEmpty(s) => Guid.Parse(s),
_ => default(Guid?)
};
if (pollId.HasValue)
{
var currentUserId = currentUser is not null ? Guid.Parse(currentUser.Id) : (Guid?)null; var currentUserId = currentUser is not null ? Guid.Parse(currentUser.Id) : (Guid?)null;
var updatedPoll = await polls.LoadPollEmbed(pollId.Value, currentUserId); var updatedPoll = await polls.LoadPollEmbed(pollId, currentUserId);
embeds[pollIndex] = updatedPoll.ToDictionary(); embeds[pollIndex] = updatedPoll.ToDictionary();
} }
}
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "Failed to load poll embed for post {PostId}", post.Id); logger.LogError(ex, "Failed to load poll embed for post {PostId}", post.Id);