🐛 Fix realm lost info when transfering between services

This commit is contained in:
2025-11-02 01:52:42 +08:00
parent 8f5f1efa24
commit 70fdc247e7
2 changed files with 22 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ public class SnRealm : ModelBase, IIdentifiedResource
[Column(TypeName = "jsonb")] public SnCloudFileReferenceObject? Picture { get; set; }
[Column(TypeName = "jsonb")] public SnCloudFileReferenceObject? Background { get; set; }
[Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; }
[JsonIgnore] public ICollection<SnRealmMember> Members { get; set; } = new List<SnRealmMember>();
@@ -36,7 +36,12 @@ public class SnRealm : ModelBase, IIdentifiedResource
Id = Id.ToString(),
Name = Name,
Slug = Slug,
Description = Description,
Picture = Picture?.ToProtoValue(),
Background = Background?.ToProtoValue(),
Verification = Verification?.ToProtoValue(),
IsCommunity = IsCommunity,
AccountId = AccountId.ToString(),
IsPublic = IsPublic
};
}
@@ -48,9 +53,16 @@ public class SnRealm : ModelBase, IIdentifiedResource
Id = Guid.Parse(proto.Id),
Name = proto.Name,
Slug = proto.Slug,
Description = "",
Description = proto.Description,
Picture = proto.Picture is not null ? SnCloudFileReferenceObject.FromProtoValue(proto.Picture) : null,
Background = proto.Background is not null
? SnCloudFileReferenceObject.FromProtoValue(proto.Background)
: null,
Verification =
proto.Verification is not null ? SnVerificationMark.FromProtoValue(proto.Verification) : null,
IsCommunity = proto.IsCommunity,
IsPublic = proto.IsPublic
IsPublic = proto.IsPublic,
AccountId = Guid.Parse(proto.AccountId),
};
}
}
@@ -89,6 +101,7 @@ public class SnRealmMember : ModelBase
{
proto.Account = Account.ToProtoValue();
}
return proto;
}
@@ -101,12 +114,15 @@ public class SnRealmMember : ModelBase
Role = proto.Role,
JoinedAt = proto.JoinedAt?.ToInstant(),
LeaveAt = proto.LeaveAt?.ToInstant(),
Realm = proto.Realm != null ? SnRealm.FromProtoValue(proto.Realm) : new SnRealm() // Provide default or handle null
Realm = proto.Realm != null
? SnRealm.FromProtoValue(proto.Realm)
: new SnRealm() // Provide default or handle null
};
if (proto.Account != null)
{
member.Account = SnAccount.FromProtoValue(proto.Account);
}
return member;
}
}
}

View File

@@ -367,7 +367,7 @@ public class TimelineService(
.Select(p => p.RealmId!.Value)
.Distinct()
.ToList();
if (!postRealmIds.Any())
if (postRealmIds.Count == 0)
return;
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
@@ -376,9 +376,7 @@ public class TimelineService(
foreach (var post in posts.Where(p => p.RealmId != null))
{
if (realmDict.TryGetValue(post.RealmId!.Value, out var realm))
{
post.Realm = realm;
}
}
}