🐛 Trying to fix bugs...

This commit is contained in:
LittleSheep 2025-05-31 13:18:17 +08:00
parent b8c15bde1a
commit 6965744d5a
5 changed files with 39 additions and 29 deletions

View File

@ -84,6 +84,7 @@ public class AccountContact : ModelBase
public Instant? VerifiedAt { get; set; }
[MaxLength(1024)] public string Content { get; set; } = string.Empty;
public Guid AccountId { get; set; }
[JsonIgnore] public Account Account { get; set; } = null!;
}
@ -100,6 +101,7 @@ public class AccountAuthFactor : ModelBase
public AccountAuthFactorType Type { get; set; }
[MaxLength(8196)] public string? Secret { get; set; } = null;
public Guid AccountId { get; set; }
[JsonIgnore] public Account Account { get; set; } = null!;
public AccountAuthFactor HashSecret(int cost = 12)

View File

@ -264,22 +264,29 @@ public class NotificationService
if (_apns == null)
throw new InvalidOperationException("The apple notification push service is not initialized.");
await _apns.SendAsync(new Dictionary<string, object>
var alertDict = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(notification.Title))
alertDict["title"] = notification.Title;
if (!string.IsNullOrEmpty(notification.Subtitle))
alertDict["subtitle"] = notification.Subtitle;
if (!string.IsNullOrEmpty(notification.Content))
alertDict["body"] = notification.Content;
var payload = new Dictionary<string, object>
{
["topic"] = notification.Topic,
["aps"] = new Dictionary<string, object>
{
["topic"] = notification.Topic,
["aps"] = new Dictionary<string, object>
{
["alert"] = new Dictionary<string, object>
{
["title"] = notification.Title ?? string.Empty,
["subtitle"] = notification.Subtitle ?? string.Empty,
["body"] = notification.Content ?? string.Empty
}
},
["sound"] = (notification.Priority > 0 ? "default" : null) ?? string.Empty,
["mutable-content"] = 1,
["meta"] = notification.Meta ?? new Dictionary<string, object>()
["alert"] = alertDict
},
["sound"] = (notification.Priority > 0 ? "default" : null) ?? string.Empty,
["mutable-content"] = 1,
["meta"] = notification.Meta ?? new Dictionary<string, object>()
};
await _apns.SendAsync(
payload,
deviceToken: subscription.DeviceToken,
apnsId: notification.Id.ToString(),
apnsPriority: notification.Priority,

View File

@ -18,7 +18,6 @@ public class ActivityReaderService(AppDatabase db, PostService ps)
if (postsId.Count > 0)
{
var posts = await db.Posts.Where(e => postsId.Contains(e.Id))
.Include(e => e.Publisher)
.Include(e => e.ThreadedPost)
.Include(e => e.ForwardedPost)
.Include(e => e.Attachments)
@ -27,6 +26,7 @@ public class ActivityReaderService(AppDatabase db, PostService ps)
.FilterWithVisibility(currentUser, userFriends)
.ToListAsync();
posts = PostService.TruncatePostContent(posts);
posts = await ps.LoadPublishers(posts);
var reactionMaps = await ps.GetPostReactionMapBatch(postsId);
foreach (var post in posts)

View File

@ -54,7 +54,9 @@ public class Post : ModelBase
[JsonIgnore] public NpgsqlTsVector SearchVector { get; set; } = null!;
public Guid PublisherId { get; set; }
public Publisher.Publisher Publisher { get; set; } = null!;
public ICollection<PostReaction> Reactions { get; set; } = new List<PostReaction>();
public ICollection<PostTag> Tags { get; set; } = new List<PostTag>();
public ICollection<PostCategory> Categories { get; set; } = new List<PostCategory>();

View File

@ -275,13 +275,12 @@ public class PostService(
public async Task<List<Post>> LoadPublishers(List<Post> posts)
{
var publisherIds = posts
.Where(e => e.Publisher.AccountId != null)
.SelectMany<Post, Guid?>(e =>
[
e.Publisher.Id,
e.RepliedPost?.Publisher.Id,
e.ForwardedPost?.Publisher.Id,
e.ThreadedPost?.Publisher.Id
e.PublisherId,
e.RepliedPost?.PublisherId,
e.ForwardedPost?.PublisherId,
e.ThreadedPost?.PublisherId
])
.Where(e => e != null)
.Distinct()
@ -289,24 +288,24 @@ public class PostService(
if (publisherIds.Count == 0) return posts;
var publishers = await db.Publishers
.Where(e => e.AccountId != null && publisherIds.Contains(e.AccountId.Value))
.ToDictionaryAsync(e => e.AccountId!.Value);
.Where(e => publisherIds.Contains(e.Id))
.ToDictionaryAsync(e => e.Id);
foreach (var post in posts)
{
if (publishers.TryGetValue(post.Publisher.Id, out var publisher))
if (publishers.TryGetValue(post.PublisherId, out var publisher))
post.Publisher = publisher;
if (post.RepliedPost?.Publisher.Id != null &&
publishers.TryGetValue(post.RepliedPost.Publisher.Id, out var repliedPublisher))
if (post.RepliedPost?.PublisherId != null &&
publishers.TryGetValue(post.RepliedPost.PublisherId, out var repliedPublisher))
post.RepliedPost.Publisher = repliedPublisher;
if (post.ForwardedPost?.Publisher.Id != null &&
publishers.TryGetValue(post.ForwardedPost.Publisher.Id, out var forwardedPublisher))
if (post.ForwardedPost?.PublisherId != null &&
publishers.TryGetValue(post.ForwardedPost.PublisherId, out var forwardedPublisher))
post.ForwardedPost.Publisher = forwardedPublisher;
if (post.ThreadedPost?.Publisher.Id != null &&
publishers.TryGetValue(post.ThreadedPost.Publisher.Id, out var threadedPublisher))
if (post.ThreadedPost?.PublisherId != null &&
publishers.TryGetValue(post.ThreadedPost.PublisherId, out var threadedPublisher))
post.ThreadedPost.Publisher = threadedPublisher;
}