[backend/federation] Attempt to make id optional for some object types

This commit is contained in:
Kopper 2024-09-13 15:24:26 +03:00 committed by Laura Hausmann
parent 481bd423b3
commit ade4481ae9
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
7 changed files with 48 additions and 11 deletions

View file

@ -56,7 +56,7 @@ public class ActivityFetcherService(
{ {
logger.LogDebug("Fetching activity {url} as user {id}", url, actor.Id); logger.LogDebug("Fetching activity {url} as user {id}", url, actor.Id);
var (activity, finalUri) = await FetchActivityInternalWrapper(url, actor, keypair); var (activity, finalUri) = await FetchActivityInternalWrapper(url, actor, keypair);
if (activity == null) return []; if (activity?.Id == null) return [];
var activityUri = new Uri(activity.Id); var activityUri = new Uri(activity.Id);
@ -70,7 +70,7 @@ public class ActivityFetcherService(
logger.LogDebug("Fetching activity {url} as user {id} (attempt 2)", activityIdUri.AbsoluteUri, actor.Id); logger.LogDebug("Fetching activity {url} as user {id} (attempt 2)", activityIdUri.AbsoluteUri, actor.Id);
(activity, finalUri) = await FetchActivityInternalWrapper(activityIdUri.AbsoluteUri, actor, keypair); (activity, finalUri) = await FetchActivityInternalWrapper(activityIdUri.AbsoluteUri, actor, keypair);
if (activity == null) return []; if (activity?.Id == null) return [];
activityUri = new Uri(activity.Id); activityUri = new Uri(activity.Id);

View file

@ -10,6 +10,14 @@ namespace Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
public class ASActivity : ASObject public class ASActivity : ASObject
{ {
[J("@id")]
[JR]
public new required string Id
{
get => base.Id ?? throw new NullReferenceException("base.Id should never be null on a required property");
set => base.Id = value;
}
[J($"{Constants.ActivityStreamsNs}#actor")] [J($"{Constants.ActivityStreamsNs}#actor")]
[JC(typeof(ASActorConverter))] [JC(typeof(ASActorConverter))]
public ASActor? Actor { get; set; } public ASActor? Actor { get; set; }

View file

@ -4,6 +4,7 @@ using Iceshrimp.Backend.Core.Extensions;
using J = Newtonsoft.Json.JsonPropertyAttribute; using J = Newtonsoft.Json.JsonPropertyAttribute;
using JC = Newtonsoft.Json.JsonConverterAttribute; using JC = Newtonsoft.Json.JsonConverterAttribute;
using JI = Newtonsoft.Json.JsonIgnoreAttribute; using JI = Newtonsoft.Json.JsonIgnoreAttribute;
using JR = Newtonsoft.Json.JsonRequiredAttribute;
using VC = Iceshrimp.Backend.Core.Federation.ActivityStreams.Types.ValueObjectConverter; using VC = Iceshrimp.Backend.Core.Federation.ActivityStreams.Types.ValueObjectConverter;
namespace Iceshrimp.Backend.Core.Federation.ActivityStreams.Types; namespace Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
@ -19,6 +20,14 @@ public class ASActor : ASObject
Types.Person, Types.Service, Types.Group, Types.Organization, Types.Application Types.Person, Types.Service, Types.Group, Types.Organization, Types.Application
]; ];
[J("@id")]
[JR]
public new required string Id
{
get => base.Id ?? throw new NullReferenceException("base.Id should never be null on a required property");
set => base.Id = value;
}
[J("https://misskey-hub.net/ns#_misskey_summary")] [J("https://misskey-hub.net/ns#_misskey_summary")]
[JC(typeof(VC))] [JC(typeof(VC))]
public string? MkSummary { get; set; } public string? MkSummary { get; set; }
@ -173,6 +182,7 @@ public class ASActor : ASObject
public static ASActor FromObject(ASObject obj) public static ASActor FromObject(ASObject obj)
{ {
if (obj.Id == null) throw new Exception("Unable to convert Object to Actor: Missing or invalid id");
return new ASActor { Id = obj.Id }; return new ASActor { Id = obj.Id };
} }

View file

@ -2,6 +2,7 @@ using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Database.Tables; using Iceshrimp.Backend.Core.Database.Tables;
using J = Newtonsoft.Json.JsonPropertyAttribute; using J = Newtonsoft.Json.JsonPropertyAttribute;
using JC = Newtonsoft.Json.JsonConverterAttribute; using JC = Newtonsoft.Json.JsonConverterAttribute;
using JR = Newtonsoft.Json.JsonRequiredAttribute;
using JI = Newtonsoft.Json.JsonIgnoreAttribute; using JI = Newtonsoft.Json.JsonIgnoreAttribute;
using VC = Iceshrimp.Backend.Core.Federation.ActivityStreams.Types.ValueObjectConverter; using VC = Iceshrimp.Backend.Core.Federation.ActivityStreams.Types.ValueObjectConverter;
@ -14,6 +15,14 @@ public class ASNote : ASObject
[JI] public bool VerifiedFetch = false; [JI] public bool VerifiedFetch = false;
public ASNote(bool withType = true) => Type = withType ? Types.Note : null; public ASNote(bool withType = true) => Type = withType ? Types.Note : null;
[J("@id")]
[JR]
public new required string Id
{
get => base.Id ?? throw new NullReferenceException("base.Id should never be null on a required property");
set => base.Id = value;
}
[J("https://misskey-hub.net/ns#_misskey_content")] [J("https://misskey-hub.net/ns#_misskey_content")]
[JC(typeof(VC))] [JC(typeof(VC))]
public string? MkContent public string? MkContent

View file

@ -10,14 +10,6 @@ namespace Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
public class ASObject : ASObjectBase public class ASObject : ASObjectBase
{ {
[J("@id")]
[JR]
public new required string Id
{
get => base.Id ?? throw new NullReferenceException("base.Id should never be null on a required property");
set => base.Id = value;
}
[J("@type")] [J("@type")]
[JC(typeof(StringListSingleConverter))] [JC(typeof(StringListSingleConverter))]
public string? Type { get; set; } public string? Type { get; set; }
@ -88,6 +80,14 @@ public class ASObject : ASObjectBase
public class ASTombstone : ASObject public class ASTombstone : ASObject
{ {
[J("@id")]
[JR]
public new required string Id
{
get => base.Id ?? throw new NullReferenceException("base.Id should never be null on a required property");
set => base.Id = value;
}
public ASTombstone() => Type = Types.Tombstone; public ASTombstone() => Type = Types.Tombstone;
} }

View file

@ -1,5 +1,6 @@
using Iceshrimp.Backend.Core.Configuration; using Iceshrimp.Backend.Core.Configuration;
using J = Newtonsoft.Json.JsonPropertyAttribute; using J = Newtonsoft.Json.JsonPropertyAttribute;
using JR = Newtonsoft.Json.JsonRequiredAttribute;
using JC = Newtonsoft.Json.JsonConverterAttribute; using JC = Newtonsoft.Json.JsonConverterAttribute;
using VC = Iceshrimp.Backend.Core.Federation.ActivityStreams.Types.ValueObjectConverter; using VC = Iceshrimp.Backend.Core.Federation.ActivityStreams.Types.ValueObjectConverter;
@ -7,6 +8,14 @@ namespace Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
public class ASPublicKey : ASObject public class ASPublicKey : ASObject
{ {
[J("@id")]
[JR]
public new required string Id
{
get => base.Id ?? throw new NullReferenceException("base.Id should never be null on a required property");
set => base.Id = value;
}
[J($"{Constants.W3IdSecurityNs}#owner")] [J($"{Constants.W3IdSecurityNs}#owner")]
[JC(typeof(ASObjectBaseConverter))] [JC(typeof(ASObjectBaseConverter))]
public ASObjectBase? Owner { get; set; } public ASObjectBase? Owner { get; set; }

View file

@ -1316,7 +1316,8 @@ public class NoteService(
// ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall // ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall
var followingUser = await db.Users.FirstOrDefaultAsync(p => p.IsFollowing(user)); var followingUser = await db.Users.FirstOrDefaultAsync(p => p.IsFollowing(user));
var notes = await objectResolver.IterateCollection(collection).Take(10) var notes = await objectResolver.IterateCollection(collection).Take(10)
.Select(p => ResolveNoteAsync(p.Id, null, followingUser, true)) .Where(p => p.Id != null)
.Select(p => ResolveNoteAsync(p.Id!, null, followingUser, true))
.AwaitAllNoConcurrencyAsync(); .AwaitAllNoConcurrencyAsync();
var previousPins = await db.Users.Where(p => p.Id == user.Id) var previousPins = await db.Users.Where(p => p.Id == user.Id)