🐛 Fix loading poll
This commit is contained in:
@@ -341,7 +341,7 @@ public class PostController(
|
|||||||
post.ForwardedPostId = forwardedPost.Id;
|
post.ForwardedPostId = forwardedPost.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.PollId is not null)
|
if (request.PollId.HasValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -493,7 +493,7 @@ public class PostController(
|
|||||||
if (request.Type is not null) post.Type = request.Type.Value;
|
if (request.Type is not null) post.Type = request.Type.Value;
|
||||||
if (request.Meta is not null) post.Meta = request.Meta;
|
if (request.Meta is not null) post.Meta = request.Meta;
|
||||||
|
|
||||||
if (request.PollId is not null)
|
if (request.PollId.HasValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -661,24 +661,20 @@ public partial class PostService(
|
|||||||
g => g.Count()
|
g => g.Count()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadPollEmbed(Post post, Account? currentUser)
|
private async Task LoadPollEmbed(Post post, Account? currentUser)
|
||||||
{
|
{
|
||||||
if (!post.Meta!.TryGetValue("embeds", out var existingEmbeds) ||
|
if (!post.Meta!.TryGetValue("embeds", out var value))
|
||||||
existingEmbeds is not List<EmbeddableBase>)
|
|
||||||
{
|
|
||||||
post.Meta["embeds"] = new List<Dictionary<string, object>>();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
var embeds = (List<Dictionary<string, object>>)post.Meta["embeds"];
|
var embeds = (List<Dictionary<string, object>>)value;
|
||||||
|
|
||||||
// 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") && (string)e["type"] == "poll");
|
||||||
|
|
||||||
if (pollIndex < 0) return;
|
if (pollIndex < 0) return;
|
||||||
|
|
||||||
var pollEmbed = embeds[pollIndex];
|
var pollEmbed = embeds[pollIndex];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -698,7 +694,7 @@ public partial class PostService(
|
|||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,11 +709,10 @@ public partial class PostService(
|
|||||||
posts = await LoadPublishers(posts);
|
posts = await LoadPublishers(posts);
|
||||||
posts = await LoadInteractive(posts, currentUser);
|
posts = await LoadInteractive(posts, currentUser);
|
||||||
|
|
||||||
var postsWithEmbed = posts
|
foreach (
|
||||||
.Where(e => e.Meta is not null && e.Meta.ContainsKey("embeds"))
|
var post in posts
|
||||||
.ToList();
|
.Where(e => e.Meta is not null && e.Meta.ContainsKey("embeds"))
|
||||||
|
)
|
||||||
foreach (var post in postsWithEmbed)
|
|
||||||
await LoadPollEmbed(post, currentUser);
|
await LoadPollEmbed(post, currentUser);
|
||||||
|
|
||||||
if (truncate)
|
if (truncate)
|
||||||
|
Reference in New Issue
Block a user