Handle note visibility
This commit is contained in:
parent
431bbaccb2
commit
5f3696fa74
2 changed files with 15 additions and 5 deletions
|
@ -31,13 +31,22 @@ public class ASNote : ASObject {
|
|||
public ASNoteSource? Source { get; set; }
|
||||
|
||||
[J("https://www.w3.org/ns/activitystreams#to")]
|
||||
public List<LDIdObject>? To { get; set; } = [];
|
||||
public List<LDIdObject> To { get; set; } = [];
|
||||
|
||||
[J("https://www.w3.org/ns/activitystreams#cc")]
|
||||
public List<LDIdObject>? Cc { get; set; } = [];
|
||||
public List<LDIdObject> Cc { get; set; } = [];
|
||||
|
||||
[J("https://www.w3.org/ns/activitystreams#attributedTo")]
|
||||
public List<LDIdObject>? AttributedTo { get; set; } = [];
|
||||
public List<LDIdObject> AttributedTo { get; set; } = [];
|
||||
|
||||
public Note.NoteVisibility? Visibility => Note.NoteVisibility.Public;
|
||||
public Note.NoteVisibility GetVisibility(ASActor actor) {
|
||||
if (To.Any(p => p.Id == "https://www.w3.org/ns/activitystreams#Public"))
|
||||
return Note.NoteVisibility.Public;
|
||||
if (Cc.Any(p => p.Id == "https://www.w3.org/ns/activitystreams#Public"))
|
||||
return Note.NoteVisibility.Home;
|
||||
if (To.Any(p => p.Id is not null && p.Id == (actor.Followers?.Id ?? actor.Id + "/followers")))
|
||||
return Note.NoteVisibility.Followers;
|
||||
|
||||
return Note.NoteVisibility.Specified;
|
||||
}
|
||||
}
|
|
@ -49,7 +49,8 @@ public class NoteService(ILogger<NoteService> logger, DatabaseContext db, UserRe
|
|||
CreatedAt = note.PublishedAt?.ToUniversalTime() ??
|
||||
throw GracefulException.UnprocessableEntity("Missing or invalid PublishedAt field"),
|
||||
UserHost = user.Host,
|
||||
Visibility = Note.NoteVisibility.Public //TODO: parse to & cc fields
|
||||
Visibility = note.GetVisibility(actor)
|
||||
//TODO: parse to fields for specified visibility & mentions
|
||||
};
|
||||
|
||||
await db.Notes.AddAsync(dbNote);
|
||||
|
|
Loading…
Add table
Reference in a new issue