using MongoDB.Entities; using PrivaPub.Federation.Objects; using PrivaPub.Models.Social; using PrivaPub.Tests.Support.Host; using System.Globalization; using System.Net; using System.Numerics; using System.Text.Json.Nodes; namespace PrivaPub.Tests.Support { public static class FederatedSeeds { public static string Origin(RemoteActor actor) => new Uri(actor.Id).GetLeftPart(UriPartial.Authority); public static string NewId(RemoteActor actor, string kind) => $"{Origin(actor)}/{kind}/{Guid.NewGuid():N}"; public static JsonObject PublicNote(RemoteActor author, string content = "
hello
", params string[] cc) => new() { ["id"] = NewId(author, "notes"), ["type"] = "Note", ["attributedTo"] = author.Id, ["content"] = content, ["published"] = DateTime.UtcNow.ToString("O"), ["to"] = new JsonArray(Addressing.Public), ["cc"] = new JsonArray(cc.Prepend(author.Id + "/followers").Select(c => (JsonNode)c).ToArray()) }; public static JsonObject Create(RemoteActor author, JsonObject note) => new() { ["id"] = NewId(author, "activities"), ["type"] = "Create", ["actor"] = author.Id, ["object"] = note.DeepClone() }; public static JsonObject Activity(RemoteActor actor, string type, JsonNode inner) => new() { ["id"] = NewId(actor, "activities"), ["type"] = type, ["actor"] = actor.Id, ["object"] = inner.DeepClone() }; public static string IdOf(JsonNode node) => node["id"]!.GetValue