diff --git a/src/BirdsiteLive.ActivityPub/Models/Actor.cs b/src/BirdsiteLive.ActivityPub/Models/Actor.cs index d517dc8..0552f25 100644 --- a/src/BirdsiteLive.ActivityPub/Models/Actor.cs +++ b/src/BirdsiteLive.ActivityPub/Models/Actor.cs @@ -12,11 +12,13 @@ namespace BirdsiteLive.ActivityPub public string[] context { get; set; } = new[] { "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1" }; public string id { get; set; } public string type { get; set; } + public string followers { get; set; } public string preferredUsername { get; set; } public string name { get; set; } public string summary { get; set; } public string url { get; set; } public string inbox { get; set; } + public bool? discoverable { get; set; } = true; public PublicKey publicKey { get; set; } public Image icon { get; set; } public Image image { get; set; } diff --git a/src/BirdsiteLive.ActivityPub/Models/Followers.cs b/src/BirdsiteLive.ActivityPub/Models/Followers.cs new file mode 100644 index 0000000..85c44d2 --- /dev/null +++ b/src/BirdsiteLive.ActivityPub/Models/Followers.cs @@ -0,0 +1,15 @@ +using BirdsiteLive.ActivityPub.Converters; +using Newtonsoft.Json; + +namespace BirdsiteLive.ActivityPub.Models +{ + public class Followers + { + [JsonProperty("@context")] + [JsonConverter(typeof(ContextArrayConverter))] + public string context { get; set; } = "https://www.w3.org/ns/activitystreams"; + + public string id { get; set; } + public string type { get; set; } = "OrderedCollection"; + } +} \ No newline at end of file diff --git a/src/BirdsiteLive.Domain/UserService.cs b/src/BirdsiteLive.Domain/UserService.cs index f2482d1..1e6e8dc 100644 --- a/src/BirdsiteLive.Domain/UserService.cs +++ b/src/BirdsiteLive.Domain/UserService.cs @@ -48,7 +48,8 @@ namespace BirdsiteLive.Domain var user = new Actor { id = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}", - type = "Person", + type = "Service", //Person Service + followers = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}/followers", preferredUsername = twitterUser.Acct, name = twitterUser.Name, inbox = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}/inbox", diff --git a/src/BirdsiteLive/Controllers/UsersController.cs b/src/BirdsiteLive/Controllers/UsersController.cs index 3f2d701..0f6d7e3 100644 --- a/src/BirdsiteLive/Controllers/UsersController.cs +++ b/src/BirdsiteLive/Controllers/UsersController.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Mime; +using System.Runtime.InteropServices.WindowsRuntime; using System.Threading; using System.Threading.Tasks; using BirdsiteLive.ActivityPub; +using BirdsiteLive.ActivityPub.Models; using BirdsiteLive.Common.Settings; using BirdsiteLive.Domain; using BirdsiteLive.Models; @@ -56,7 +58,7 @@ namespace BirdsiteLive.Controllers Acct = user.Acct, Url = user.Url, ProfileImageUrl = user.ProfileImageUrl, - + InstanceHandle = $"@{user.Acct}@{_instanceSettings.Domain}" }; return View(displayableUser); @@ -95,7 +97,7 @@ namespace BirdsiteLive.Controllers using (var reader = new StreamReader(Request.Body)) { var body = await reader.ReadToEndAsync(); - System.IO.File.WriteAllText($@"C:\apdebug\{Guid.NewGuid()}.json", body); + //System.IO.File.WriteAllText($@"C:\apdebug\{Guid.NewGuid()}.json", body); var activity = ApDeserializer.ProcessActivity(body); // Do something @@ -130,6 +132,21 @@ namespace BirdsiteLive.Controllers return Accepted(); } + [Route("/users/{id}/followers")] + [HttpGet] + public async Task Followers(string id) + { + var r = Request.Headers["Accept"].First(); + if (!r.Contains("application/activity+json")) return NotFound(); + + var followers = new Followers + { + id = $"https://{_instanceSettings.Domain}/users/{id}/followers" + }; + var jsonApUser = JsonConvert.SerializeObject(followers); + return Content(jsonApUser, "application/activity+json; charset=utf-8"); + } + private Dictionary RequestHeaders(IHeaderDictionary header) { return header.ToDictionary, string, string>(h => h.Key.ToLowerInvariant(), h => h.Value);