From 468af1877bf11c2155d1f0762f992aa736997939 Mon Sep 17 00:00:00 2001 From: uwaa Date: Mon, 30 Dec 2024 01:15:58 +0000 Subject: [PATCH] pleroma: add Status.VisibleTo --- Pleroma/Models/Status.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Pleroma/Models/Status.cs b/Pleroma/Models/Status.cs index cca9cb1..90f9883 100644 --- a/Pleroma/Models/Status.cs +++ b/Pleroma/Models/Status.cs @@ -154,6 +154,35 @@ public class Status : ASObject return ReplyToAccount == user.ID || Mentions.Any(m => m.ID == user.ID); } + /// + /// Returns true if the status is visible to a particular account. + /// + 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}\""; }