⚗️ Activity pub

This commit is contained in:
2025-12-28 18:08:35 +08:00
parent f06d93a348
commit 2471fa2e75
27 changed files with 6506 additions and 9 deletions

View File

@@ -0,0 +1,78 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Shared.Models;
public class SnFediverseActivity : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
[MaxLength(2048)]
public string Uri { get; set; } = null!;
public FediverseActivityType Type { get; set; }
[MaxLength(2048)]
public string? ObjectUri { get; set; }
[MaxLength(2048)]
public string? TargetUri { get; set; }
public Instant? PublishedAt { get; set; }
public bool IsLocal { get; set; }
[Column(TypeName = "jsonb")]
public Dictionary<string, object>? RawData { get; set; }
public Guid ActorId { get; set; }
[JsonIgnore]
public SnFediverseActor Actor { get; set; } = null!;
public Guid? ContentId { get; set; }
[JsonIgnore]
public SnFediverseContent? Content { get; set; }
public Guid? TargetActorId { get; set; }
[JsonIgnore]
public SnFediverseActor? TargetActor { get; set; }
public Guid? LocalPostId { get; set; }
public Guid? LocalAccountId { get; set; }
public ActivityStatus Status { get; set; } = ActivityStatus.Pending;
[MaxLength(4096)]
public string? ErrorMessage { get; set; }
}
public enum FediverseActivityType
{
Create,
Update,
Delete,
Follow,
Unfollow,
Like,
Announce,
Undo,
Accept,
Reject,
Add,
Remove,
Block,
Unblock,
Flag,
Move
}
public enum ActivityStatus
{
Pending,
Processing,
Completed,
Failed
}

View File

@@ -0,0 +1,78 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Shared.Models;
[Index(nameof(Uri), IsUnique = true)]
public class SnFediverseActor : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
[MaxLength(2048)]
public string Uri { get; set; } = null!;
[MaxLength(256)]
public string Username { get; set; } = null!;
[MaxLength(2048)]
public string? DisplayName { get; set; }
[MaxLength(4096)]
public string? Bio { get; set; }
[MaxLength(2048)]
public string? InboxUri { get; set; }
[MaxLength(2048)]
public string? OutboxUri { get; set; }
[MaxLength(2048)]
public string? FollowersUri { get; set; }
[MaxLength(2048)]
public string? FollowingUri { get; set; }
[MaxLength(2048)]
public string? FeaturedUri { get; set; }
[MaxLength(2048)]
public string? PublicKeyId { get; set; }
[MaxLength(8192)]
public string? PublicKey { get; set; }
[Column(TypeName = "jsonb")]
public Dictionary<string, object>? Metadata { get; set; }
[MaxLength(2048)]
public string? AvatarUrl { get; set; }
[MaxLength(2048)]
public string? HeaderUrl { get; set; }
public bool IsBot { get; set; } = false;
public bool IsLocked { get; set; } = false;
public bool IsDiscoverable { get; set; } = true;
public Guid InstanceId { get; set; }
[JsonIgnore]
public SnFediverseInstance Instance { get; set; } = null!;
[JsonIgnore]
public ICollection<SnFediverseContent> Contents { get; set; } = [];
[JsonIgnore]
public ICollection<SnFediverseActivity> Activities { get; set; } = [];
[JsonIgnore]
public ICollection<SnFediverseRelationship> FollowingRelationships { get; set; } = [];
[JsonIgnore]
public ICollection<SnFediverseRelationship> FollowerRelationships { get; set; } = [];
public Instant? LastFetchedAt { get; set; }
public Instant? LastActivityAt { get; set; }
}

View File

@@ -0,0 +1,143 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Shared.Models;
[Index(nameof(Uri), IsUnique = true)]
public class SnFediverseContent : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
[MaxLength(2048)]
public string Uri { get; set; } = null!;
public FediverseContentType Type { get; set; }
[MaxLength(1024)]
public string? Title { get; set; }
[MaxLength(4096)]
public string? Summary { get; set; }
public string? Content { get; set; }
public string? ContentHtml { get; set; }
[MaxLength(2048)]
public string? Language { get; set; }
[MaxLength(2048)]
public string? InReplyTo { get; set; }
[MaxLength(2048)]
public string? AnnouncedContentUri { get; set; }
public Instant? PublishedAt { get; set; }
public Instant? EditedAt { get; set; }
public bool IsSensitive { get; set; } = false;
[Column(TypeName = "jsonb")]
public List<ContentAttachment>? Attachments { get; set; }
[Column(TypeName = "jsonb")]
public List<ContentMention>? Mentions { get; set; }
[Column(TypeName = "jsonb")]
public List<ContentTag>? Tags { get; set; }
[Column(TypeName = "jsonb")]
public List<ContentEmoji>? Emojis { get; set; }
[Column(TypeName = "jsonb")]
public Dictionary<string, object>? Metadata { get; set; }
public Guid ActorId { get; set; }
[JsonIgnore]
public SnFediverseActor Actor { get; set; } = null!;
public Guid InstanceId { get; set; }
[JsonIgnore]
public SnFediverseInstance Instance { get; set; } = null!;
[JsonIgnore]
public ICollection<SnFediverseActivity> Activities { get; set; } = [];
[JsonIgnore]
public ICollection<SnFediverseReaction> Reactions { get; set; } = [];
public int ReplyCount { get; set; }
public int BoostCount { get; set; }
public int LikeCount { get; set; }
public Guid? LocalPostId { get; set; }
[NotMapped]
public SnPost? LocalPost { get; set; }
}
public enum FediverseContentType
{
Note,
Article,
Image,
Video,
Audio,
Page,
Question,
Event,
Document
}
public class ContentAttachment
{
[MaxLength(2048)]
public string? Url { get; set; }
[MaxLength(2048)]
public string? MediaType { get; set; }
[MaxLength(1024)]
public string? Name { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
[MaxLength(64)]
public string? Blurhash { get; set; }
}
public class ContentMention
{
[MaxLength(256)]
public string? Username { get; set; }
[MaxLength(2048)]
public string? Url { get; set; }
[MaxLength(2048)]
public string? ActorUri { get; set; }
}
public class ContentTag
{
[MaxLength(256)]
public string? Name { get; set; }
[MaxLength(2048)]
public string? Url { get; set; }
}
public class ContentEmoji
{
[MaxLength(64)]
public string? Shortcode { get; set; }
[MaxLength(2048)]
public string? StaticUrl { get; set; }
[MaxLength(2048)]
public string? Url { get; set; }
}

View File

@@ -0,0 +1,46 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Shared.Models;
[Index(nameof(Domain), IsUnique = true)]
public class SnFediverseInstance : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
[MaxLength(256)]
public string Domain { get; set; } = null!;
[MaxLength(512)]
public string? Name { get; set; }
[MaxLength(4096)]
public string? Description { get; set; }
[MaxLength(2048)]
public string? Software { get; set; }
[MaxLength(2048)]
public string? Version { get; set; }
[Column(TypeName = "jsonb")]
public Dictionary<string, object>? Metadata { get; set; }
public bool IsBlocked { get; set; } = false;
public bool IsSilenced { get; set; } = false;
[MaxLength(2048)]
public string? BlockReason { get; set; }
[JsonIgnore]
public ICollection<SnFediverseActor> Actors { get; set; } = [];
[JsonIgnore]
public ICollection<SnFediverseContent> Contents { get; set; } = [];
public Instant? LastFetchedAt { get; set; }
public Instant? LastActivityAt { get; set; }
}

View File

@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Shared.Models;
public class SnFediverseReaction : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
[MaxLength(2048)]
public string Uri { get; set; } = null!;
public FediverseReactionType Type { get; set; }
[MaxLength(64)]
public string? Emoji { get; set; }
public bool IsLocal { get; set; }
public Guid ContentId { get; set; }
[JsonIgnore]
public SnFediverseContent Content { get; set; } = null!;
public Guid ActorId { get; set; }
[JsonIgnore]
public SnFediverseActor Actor { get; set; } = null!;
public Guid? LocalAccountId { get; set; }
public Guid? LocalReactionId { get; set; }
}
public enum FediverseReactionType
{
Like,
Emoji,
Dislike
}

View File

@@ -0,0 +1,46 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Shared.Models;
public class SnFediverseRelationship : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid ActorId { get; set; }
[JsonIgnore]
public SnFediverseActor Actor { get; set; } = null!;
public Guid TargetActorId { get; set; }
[JsonIgnore]
public SnFediverseActor TargetActor { get; set; } = null!;
public RelationshipState State { get; set; } = RelationshipState.Pending;
public bool IsFollowing { get; set; } = false;
public bool IsFollowedBy { get; set; } = false;
public bool IsMuting { get; set; } = false;
public bool IsBlocking { get; set; } = false;
public Instant? FollowedAt { get; set; }
public Instant? FollowedBackAt { get; set; }
[MaxLength(4096)]
public string? RejectReason { get; set; }
public bool IsLocalActor { get; set; }
public Guid? LocalAccountId { get; set; }
public Guid? LocalPublisherId { get; set; }
}
public enum RelationshipState
{
Pending,
Accepted,
Rejected
}

View File

@@ -30,6 +30,7 @@ public class SnPublisher : ModelBase, IIdentifiedResource
[Column(TypeName = "jsonb")] public SnCloudFileReferenceObject? Background { get; set; }
[Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; }
[Column(TypeName = "jsonb")] public Dictionary<string, object>? Meta { get; set; }
[IgnoreMember] [JsonIgnore] public ICollection<SnPost> Posts { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnPoll> Polls { get; set; } = [];