pleroma: add Status.VisibleTo

This commit is contained in:
uwaa 2024-12-30 01:15:58 +00:00
parent 2b294f7137
commit 468af1877b

View file

@ -154,6 +154,35 @@ public class Status : ASObject
return ReplyToAccount == user.ID || Mentions.Any(m => m.ID == user.ID);
}
/// <summary>
/// Returns true if the status is visible to a particular account.
/// </summary>
public bool VisibleTo(Account account)
{
if (Author.ID == account.ID)
return true;
switch (Visibility)
{
case StatusVisibility.Public:
case StatusVisibility.Unlisted:
return true;
case StatusVisibility.Local:
return Author.Instance == account.Instance;
case StatusVisibility.Private: //TODO: Not correctly implemented, but finding the correct answer would require fetching the relationship
case StatusVisibility.Direct:
return Mentions.Any(mention => mention.ID == account.ID);
case StatusVisibility.List:
return false;
default:
return false;
}
}
public override string ToString() => $"{Author?.Username ?? "unknown"}: \"{Content}\"";
}