Add missing properties to UserCreate
This commit is contained in:
parent
0fd0125700
commit
4632db029a
2 changed files with 46 additions and 17 deletions
|
@ -79,10 +79,34 @@ public class ASActor : ASObject {
|
|||
[JC(typeof(ASLinkConverter))]
|
||||
public ASLink? Url { get; set; }
|
||||
|
||||
public bool? IsBot => Type?.Any(p => p == "https://www.w3.org/ns/activitystreams#Service");
|
||||
[J("https://www.w3.org/ns/activitystreams#movedTo")]
|
||||
[JC(typeof(ASLinkConverter))]
|
||||
public ASLink? MovedTo { get; set; }
|
||||
|
||||
private const int NameLength = 128;
|
||||
private const int SummaryLength = 2048;
|
||||
// This is necessary because some AP implementations don't add this to the context, resulting in the expand operation failing to deserialize it
|
||||
[J("_:movedTo")]
|
||||
[JC(typeof(ASLinkConverter))]
|
||||
private ASLink? MovedToFallback {
|
||||
set => MovedTo = value;
|
||||
}
|
||||
|
||||
[J("https://www.w3.org/ns/activitystreams#alsoKnownAs")]
|
||||
[JC(typeof(ASLinkConverter))]
|
||||
public ASLink? AlsoKnownAs { get; set; }
|
||||
|
||||
[J("http://joinmastodon.org/ns#featured")]
|
||||
[JC(typeof(ASLinkConverter))]
|
||||
public ASLink? Featured { get; set; }
|
||||
|
||||
[J("http://joinmastodon.org/ns#featuredTags")]
|
||||
[JC(typeof(ASLinkConverter))]
|
||||
public ASLink? FeaturedTags { get; set; }
|
||||
|
||||
public bool IsBot => Type?.Any(p => p == "https://www.w3.org/ns/activitystreams#Service") ?? false;
|
||||
|
||||
private const int DisplayNameLength = 128;
|
||||
private const int UsernameLength = 128;
|
||||
private const int SummaryLength = 2048;
|
||||
|
||||
private static readonly List<string> ActorTypes = [
|
||||
"https://www.w3.org/ns/activitystreams#Person",
|
||||
|
@ -99,14 +123,14 @@ public class ASActor : ASObject {
|
|||
if (Id != uri) throw new Exception("Actor URI mismatch");
|
||||
|
||||
if (Inbox?.Link == null) throw new Exception("Actor inbox is invalid");
|
||||
if (Username == null || Username.Length > NameLength ||
|
||||
Regex.IsMatch(Username, @"^\w([\w-.]*\w)?$"))
|
||||
if (Username == null || Username.Length > UsernameLength ||
|
||||
!Regex.IsMatch(Username, @"^\w([\w-.]*\w)?$"))
|
||||
throw new Exception("Actor username is invalid");
|
||||
|
||||
//TODO: validate publicKey id host
|
||||
|
||||
DisplayName = DisplayName switch {
|
||||
{ Length: > 0 } => DisplayName.Truncate(NameLength),
|
||||
{ Length: > 0 } => DisplayName.Truncate(DisplayNameLength),
|
||||
_ => null
|
||||
};
|
||||
|
||||
|
|
|
@ -39,22 +39,27 @@ public class UserService(ILogger<UserService> logger, DatabaseContext db, HttpCl
|
|||
LastFetchedAt = DateTime.UtcNow,
|
||||
Name = actor.DisplayName,
|
||||
IsLocked = actor.IsLocked ?? false,
|
||||
IsBot = actor.IsBot ?? false,
|
||||
IsBot = actor.IsBot,
|
||||
Username = actor.Username!,
|
||||
UsernameLower = actor.Username!.ToLowerInvariant(),
|
||||
Host = AcctToTuple(acct).Host,
|
||||
//MovedToUri = actor.MovedTo
|
||||
//AlsoKnownAs
|
||||
IsExplorable = actor.IsDiscoverable ?? false,
|
||||
Inbox = actor.Inbox?.Link,
|
||||
SharedInbox = actor.SharedInbox?.Link,
|
||||
FollowersUri = actor.Followers?.Id,
|
||||
Uri = actor.Id,
|
||||
IsCat = actor.IsCat ?? false,
|
||||
Emojis = [],
|
||||
Tags = [],
|
||||
MovedToUri = actor.MovedTo?.Link,
|
||||
AlsoKnownAs = actor.AlsoKnownAs?.Link,
|
||||
IsExplorable = actor.IsDiscoverable ?? false,
|
||||
Inbox = actor.Inbox?.Link,
|
||||
SharedInbox = actor.SharedInbox?.Link,
|
||||
FollowersUri = actor.Followers?.Id,
|
||||
Uri = actor.Id,
|
||||
IsCat = actor.IsCat ?? false,
|
||||
Featured = actor.Featured?.Link,
|
||||
//FollowersCount
|
||||
//FollowingCount
|
||||
Emojis = [], //FIXME
|
||||
Tags = [], //FIXME
|
||||
};
|
||||
|
||||
//TODO: add UserProfile as well
|
||||
|
||||
await db.Users.AddAsync(user);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue