♻️ Refactored activities

This commit is contained in:
2025-06-08 23:52:02 +08:00
parent 39533cced3
commit b8341734df
11 changed files with 3512 additions and 292 deletions

View File

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using DysonNetwork.Sphere.Activity;
using DysonNetwork.Sphere.Storage;
using NodaTime;
using NpgsqlTypes;
@ -22,7 +23,7 @@ public enum PostVisibility
Private
}
public class Post : ModelBase, IIdentifiedResource
public class Post : ModelBase, IIdentifiedResource, IActivity
{
public Guid Id { get; set; }
[MaxLength(1024)] public string? Title { get; set; }
@ -48,7 +49,7 @@ public class Post : ModelBase, IIdentifiedResource
public Post? RepliedPost { get; set; }
public Guid? ForwardedPostId { get; set; }
public Post? ForwardedPost { get; set; }
// Outdated fields, keep for backward compability
public ICollection<CloudFile> OutdatedAttachments { get; set; } = new List<CloudFile>();
[Column(TypeName = "jsonb")] public List<CloudFileReferenceObject> Attachments { get; set; } = [];
@ -67,6 +68,20 @@ public class Post : ModelBase, IIdentifiedResource
[NotMapped] public bool IsTruncated = false;
public string ResourceIdentifier => $"post/{Id}";
public Activity.Activity ToActivity()
{
return new Activity.Activity()
{
CreatedAt = CreatedAt,
UpdatedAt = UpdatedAt,
DeletedAt = DeletedAt,
Id = Id,
Type = RepliedPostId is null ? "posts.new" : "posts.new.replies",
ResourceIdentifier = ResourceIdentifier,
Data = null
};
}
}
public class PostTag : ModelBase

View File

@ -13,7 +13,6 @@ public class PostService(
AppDatabase db,
FileService fs,
FileReferenceService fileRefService,
ActivityService act,
IStringLocalizer<NotificationResource> localizer,
NotificationService nty,
IServiceScopeFactory factory
@ -107,8 +106,6 @@ public class PostService(
}
}
await act.CreateNewPostActivity(user, post);
if (post.PublishedAt is not null && post.PublishedAt.Value.ToDateTimeUtc() <= DateTime.UtcNow)
_ = Task.Run(async () =>
{
@ -341,8 +338,12 @@ public class PostService(
public static class PostQueryExtensions
{
public static IQueryable<Post> FilterWithVisibility(this IQueryable<Post> source, Account.Account? currentUser,
List<Guid> userFriends, bool isListing = false)
public static IQueryable<Post> FilterWithVisibility(
this IQueryable<Post> source,
Account.Account? currentUser,
List<Guid> userFriends,
bool isListing = false
)
{
var now = Instant.FromDateTimeUtc(DateTime.UtcNow);