♻️ Move the chat part of the Sphere service to the Messager service

This commit is contained in:
2026-01-01 22:09:08 +08:00
parent c503083df7
commit ab37bbc7b0
50 changed files with 3042 additions and 611 deletions

View File

@@ -24,16 +24,16 @@ public class SnAccount : ModelBase
public Guid? AutomatedId { get; set; }
public SnAccountProfile Profile { get; set; } = null!;
public ICollection<SnAccountContact> Contacts { get; set; } = [];
public ICollection<SnAccountBadge> Badges { get; set; } = [];
public List<SnAccountContact> Contacts { get; set; } = [];
public List<SnAccountBadge> Badges { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnAccountAuthFactor> AuthFactors { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnAccountConnection> Connections { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnAuthSession> Sessions { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnAuthChallenge> Challenges { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnAccountAuthFactor> AuthFactors { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnAccountConnection> Connections { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnAuthSession> Sessions { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnAuthChallenge> Challenges { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnAccountRelationship> OutgoingRelationships { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnAccountRelationship> IncomingRelationships { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnAccountRelationship> OutgoingRelationships { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnAccountRelationship> IncomingRelationships { get; set; } = [];
[NotMapped] public SnSubscriptionReferenceObject? PerkSubscription { get; set; }

View File

@@ -113,7 +113,7 @@ public class SnCheckInResult : ModelBase
public int? RewardExperience { get; set; }
[Column(TypeName = "jsonb")]
public ICollection<CheckInFortuneTip> Tips { get; set; } = new List<CheckInFortuneTip>();
public List<CheckInFortuneTip> Tips { get; set; } = new List<CheckInFortuneTip>();
public Guid AccountId { get; set; }
public SnAccount Account { get; set; } = null!;
@@ -135,7 +135,7 @@ public class DailyEventResponse
{
public Instant Date { get; set; }
public SnCheckInResult? CheckInResult { get; set; }
public ICollection<SnAccountStatus> Statuses { get; set; } = new List<SnAccountStatus>();
public List<SnAccountStatus> Statuses { get; set; } = new List<SnAccountStatus>();
}
public enum PresenceType

View File

@@ -17,7 +17,7 @@ public class SnChatMessage : ModelBase, IIdentifiedResource
[Column(TypeName = "jsonb")] public List<SnCloudFileReferenceObject> Attachments { get; set; } = [];
public ICollection<SnChatMessageReaction> Reactions { get; set; } = new List<SnChatMessageReaction>();
public List<SnChatReaction> Reactions { get; set; } = new();
public Guid? RepliedMessageId { get; set; }
public SnChatMessage? RepliedMessage { get; set; }
@@ -66,7 +66,7 @@ public enum MessageReactionAttitude
Negative,
}
public class SnChatMessageReaction : ModelBase
public class SnChatReaction : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid MessageId { get; set; }

View File

@@ -33,7 +33,7 @@ public class SnChatRoom : ModelBase, IIdentifiedResource
[IgnoreMember]
[JsonIgnore]
public ICollection<SnChatMember> Members { get; set; } = new List<SnChatMember>();
public List<SnChatMember> Members { get; set; } = new List<SnChatMember>();
public Guid? AccountId { get; set; }
@@ -46,7 +46,7 @@ public class SnChatRoom : ModelBase, IIdentifiedResource
[NotMapped]
[JsonPropertyName("members")]
public ICollection<ChatMemberTransmissionObject> DirectMembers { get; set; } =
public List<ChatMemberTransmissionObject> DirectMembers { get; set; } =
new List<ChatMemberTransmissionObject>();
public string ResourceIdentifier => $"chatroom:{Id}";
@@ -81,30 +81,22 @@ public class SnChatMember : ModelBase
public SnChatRoom ChatRoom { get; set; } = null!;
public Guid AccountId { get; set; }
[NotMapped]
public SnAccount? Account { get; set; }
[NotMapped] public SnAccount? Account { get; set; }
[NotMapped] public SnAccountStatus? Status { get; set; }
[NotMapped]
public SnAccountStatus? Status { get; set; }
[MaxLength(1024)]
public string? Nick { get; set; }
[MaxLength(1024)] public string? Nick { get; set; }
public ChatMemberNotify Notify { get; set; } = ChatMemberNotify.All;
public Instant? LastReadAt { get; set; }
public Instant? JoinedAt { get; set; }
public Instant? LeaveAt { get; set; }
[JsonIgnore] public List<SnChatMessage> Messages { get; set; } = [];
[JsonIgnore] public List<SnChatReaction> Reactions { get; set; } = [];
public Guid? InvitedById { get; set; }
public SnChatMember? InvitedBy { get; set; }
// Backwards support field
[NotMapped]
public int Role { get; } = 0;
[NotMapped]
public bool IsBot { get; } = false;
/// <summary>
/// The break time is the user doesn't receive any message from this member for a while.
/// Expect mentioned him or her.
@@ -147,13 +139,6 @@ public class ChatMemberTransmissionObject : ModelBase
public Instant? TimeoutUntil { get; set; }
public ChatTimeoutCause? TimeoutCause { get; set; }
// Backwards support field
[NotMapped]
public int Role { get; } = 0;
[NotMapped]
public bool IsBot { get; } = false;
public static ChatMemberTransmissionObject FromEntity(SnChatMember member)
{
return new ChatMemberTransmissionObject

View File

@@ -57,7 +57,7 @@ public class SnCloudFile : ModelBase, ICloudFile, IIdentifiedResource
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? FastUploadLink { get; set; }
public ICollection<SnCloudFileReference> References { get; set; } = new List<SnCloudFileReference>();
public List<SnCloudFileReference> References { get; set; } = new List<SnCloudFileReference>();
public Guid AccountId { get; set; }

View File

@@ -30,7 +30,7 @@ public class SnCustomApp : ModelBase, IIdentifiedResource
[Column(TypeName = "jsonb")] public SnCustomAppOauthConfig? OauthConfig { get; set; }
[Column(TypeName = "jsonb")] public SnCustomAppLinks? Links { get; set; }
[JsonIgnore] public ICollection<SnCustomAppSecret> Secrets { get; set; } = new List<SnCustomAppSecret>();
[JsonIgnore] public List<SnCustomAppSecret> Secrets { get; set; } = new List<SnCustomAppSecret>();
public Guid ProjectId { get; set; }
public SnDevProject Project { get; set; } = null!;

View File

@@ -34,8 +34,8 @@ public class SnFediverseActor : ModelBase
public Guid InstanceId { get; set; }
public SnFediverseInstance Instance { get; set; } = null!;
[JsonIgnore] public ICollection<SnFediverseRelationship> FollowingRelationships { get; set; } = [];
[JsonIgnore] public ICollection<SnFediverseRelationship> FollowerRelationships { get; set; } = [];
[JsonIgnore] public List<SnFediverseRelationship> FollowingRelationships { get; set; } = [];
[JsonIgnore] public List<SnFediverseRelationship> FollowerRelationships { get; set; } = [];
public Instant? LastFetchedAt { get; set; }
public Instant? LastActivityAt { get; set; }

View File

@@ -27,7 +27,7 @@ public class SnFediverseInstance : ModelBase
public bool IsSilenced { get; set; } = false;
[MaxLength(2048)] public string? BlockReason { get; set; }
[JsonIgnore] public ICollection<SnFediverseActor> Actors { get; set; } = [];
[JsonIgnore] public List<SnFediverseActor> Actors { get; set; } = [];
public Instant? LastFetchedAt { get; set; }
public Instant? LastActivityAt { get; set; }

View File

@@ -81,8 +81,8 @@ public class SnPermissionGroup : ModelBase
public Guid Id { get; set; } = Guid.NewGuid();
[MaxLength(1024)] public string Key { get; set; } = null!;
public ICollection<SnPermissionNode> Nodes { get; set; } = [];
[JsonIgnore] public ICollection<SnPermissionGroupMember> Members { get; set; } = [];
public List<SnPermissionNode> Nodes { get; set; } = [];
[JsonIgnore] public List<SnPermissionGroupMember> Members { get; set; } = [];
}
public class SnPermissionGroupMember : ModelBase

View File

@@ -2,6 +2,8 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using System.Text.Json.Serialization;
using DysonNetwork.Shared.Proto;
using Google.Protobuf.WellKnownTypes;
using NodaTime;
namespace DysonNetwork.Shared.Models;
@@ -19,6 +21,60 @@ public class SnPoll : ModelBase
public Guid PublisherId { get; set; }
[JsonIgnore] public SnPublisher? Publisher { get; set; }
public Poll ToProtoValue()
{
var proto = new Poll
{
Id = Id.ToString(),
IsAnonymous = IsAnonymous,
PublisherId = PublisherId.ToString(),
Publisher = Publisher?.ToProtoValue(),
CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()),
UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset()),
};
if (Title != null)
proto.Title = Title;
if (Description != null)
proto.Description = Description;
if (EndedAt.HasValue)
proto.EndedAt = Timestamp.FromDateTimeOffset(EndedAt.Value.ToDateTimeOffset());
proto.Questions.AddRange(Questions.Select(q => q.ToProtoValue()));
if (DeletedAt.HasValue)
proto.DeletedAt = Timestamp.FromDateTimeOffset(DeletedAt.Value.ToDateTimeOffset());
return proto;
}
public static SnPoll FromProtoValue(Poll proto)
{
var poll = new SnPoll
{
Id = Guid.Parse(proto.Id),
Title = proto.Title != null ? proto.Title : null,
Description = proto.Description != null ? proto.Description : null,
IsAnonymous = proto.IsAnonymous,
PublisherId = Guid.Parse(proto.PublisherId),
Publisher = proto.Publisher != null ? SnPublisher.FromProtoValue(proto.Publisher) : null,
CreatedAt = Instant.FromDateTimeOffset(proto.CreatedAt.ToDateTimeOffset()),
UpdatedAt = Instant.FromDateTimeOffset(proto.UpdatedAt.ToDateTimeOffset()),
};
if (proto.EndedAt != null)
poll.EndedAt = Instant.FromDateTimeOffset(proto.EndedAt.ToDateTimeOffset());
poll.Questions.AddRange(proto.Questions.Select(SnPollQuestion.FromProtoValue));
if (proto.DeletedAt != null)
poll.DeletedAt = Instant.FromDateTimeOffset(proto.DeletedAt.ToDateTimeOffset());
return poll;
}
}
public enum PollQuestionType
@@ -44,6 +100,46 @@ public class SnPollQuestion : ModelBase
public Guid PollId { get; set; }
[JsonIgnore] public SnPoll Poll { get; set; } = null!;
public PollQuestion ToProtoValue()
{
var proto = new PollQuestion
{
Id = Id.ToString(),
Type = (Proto.PollQuestionType)((int)Type + 1),
Title = Title,
Order = Order,
IsRequired = IsRequired,
};
if (Description != null)
proto.Description = Description;
if (Options != null)
proto.Options.AddRange(Options.Select(o => o.ToProtoValue()));
return proto;
}
public static SnPollQuestion FromProtoValue(PollQuestion proto)
{
var question = new SnPollQuestion
{
Id = Guid.Parse(proto.Id),
Type = (PollQuestionType)((int)proto.Type - 1),
Title = proto.Title,
Order = proto.Order,
IsRequired = proto.IsRequired,
};
if (proto.Description != null)
question.Description = proto.Description;
if (proto.Options.Count > 0)
question.Options = proto.Options.Select(SnPollOption.FromProtoValue).ToList();
return question;
}
}
public class SnPollOption
@@ -52,6 +148,32 @@ public class SnPollOption
[Required][MaxLength(1024)] public string Label { get; set; } = null!;
[MaxLength(4096)] public string? Description { get; set; }
public int Order { get; set; } = 0;
public PollOption ToProtoValue()
{
var proto = new PollOption
{
Id = Id.ToString(),
Label = Label,
Order = Order,
};
if (Description != null)
proto.Description = Description;
return proto;
}
public static SnPollOption FromProtoValue(PollOption proto)
{
return new SnPollOption
{
Id = Guid.Parse(proto.Id),
Label = proto.Label,
Description = proto.Description != null ? proto.Description : null,
Order = proto.Order,
};
}
}
public class SnPollAnswer : ModelBase
@@ -63,4 +185,40 @@ public class SnPollAnswer : ModelBase
public Guid PollId { get; set; }
[JsonIgnore] public SnPoll? Poll { get; set; }
[NotMapped] public SnAccount? Account { get; set; }
public PollAnswer ToProtoValue()
{
var proto = new PollAnswer
{
Id = Id.ToString(),
Answer = GrpcTypeHelper.ConvertObjectToByteString(Answer),
AccountId = AccountId.ToString(),
PollId = PollId.ToString(),
CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()),
UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset()),
};
if (DeletedAt.HasValue)
proto.DeletedAt = Timestamp.FromDateTimeOffset(DeletedAt.Value.ToDateTimeOffset());
return proto;
}
public static SnPollAnswer FromProtoValue(PollAnswer proto)
{
var answer = new SnPollAnswer
{
Id = Guid.Parse(proto.Id),
Answer = GrpcTypeHelper.ConvertByteStringToObject<Dictionary<string, JsonElement>>(proto.Answer),
AccountId = Guid.Parse(proto.AccountId),
PollId = Guid.Parse(proto.PollId),
CreatedAt = Instant.FromDateTimeOffset(proto.CreatedAt.ToDateTimeOffset()),
UpdatedAt = Instant.FromDateTimeOffset(proto.UpdatedAt.ToDateTimeOffset()),
};
if (proto.DeletedAt != null)
answer.DeletedAt = Instant.FromDateTimeOffset(proto.DeletedAt.ToDateTimeOffset());
return answer;
}
}

View File

@@ -35,14 +35,14 @@ public class SnPublisher : ModelBase, IIdentifiedResource
[MaxLength(8192)] [JsonIgnore] public string? PrivateKeyPem { get; set; }
[MaxLength(8192)] public string? PublicKeyPem { get; set; }
[IgnoreMember] [JsonIgnore] public ICollection<SnPost> Posts { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnPoll> Polls { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnPostCollection> Collections { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnPublisherMember> Members { get; set; } = [];
[IgnoreMember] [JsonIgnore] public ICollection<SnPublisherFeature> Features { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnPost> Posts { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnPoll> Polls { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnPostCollection> Collections { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnPublisherMember> Members { get; set; } = [];
[IgnoreMember] [JsonIgnore] public List<SnPublisherFeature> Features { get; set; } = [];
[JsonIgnore]
public ICollection<SnPublisherSubscription> Subscriptions { get; set; } = [];
public List<SnPublisherSubscription> Subscriptions { get; set; } = [];
public Guid? AccountId { get; set; }
public Guid? RealmId { get; set; }

View File

@@ -24,7 +24,7 @@ public class SnRealm : ModelBase, IIdentifiedResource
[Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; }
[IgnoreMember] [JsonIgnore] public ICollection<SnRealmMember> Members { get; set; } = new List<SnRealmMember>();
[IgnoreMember] [JsonIgnore] public List<SnRealmMember> Members { get; set; } = new List<SnRealmMember>();
public Guid AccountId { get; set; }

View File

@@ -11,7 +11,7 @@ public class SnWallet : ModelBase
{
public Guid Id { get; set; } = Guid.NewGuid();
public ICollection<SnWalletPocket> Pockets { get; set; } = new List<SnWalletPocket>();
public List<SnWalletPocket> Pockets { get; set; } = new List<SnWalletPocket>();
public Guid AccountId { get; set; }
public SnAccount Account { get; set; } = null!;
@@ -98,7 +98,7 @@ public class SnWalletFund : ModelBase
public SnAccount CreatorAccount { get; set; } = null!;
// Recipients
public ICollection<SnWalletFundRecipient> Recipients { get; set; } = new List<SnWalletFundRecipient>();
public List<SnWalletFundRecipient> Recipients { get; set; } = new List<SnWalletFundRecipient>();
// Expiration
public Instant ExpiredAt { get; set; }