diff --git a/src/BirdsiteLive/Controllers/UsersController.cs b/src/BirdsiteLive/Controllers/UsersController.cs index 395bc17..8b7930b 100644 --- a/src/BirdsiteLive/Controllers/UsersController.cs +++ b/src/BirdsiteLive/Controllers/UsersController.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Text.Json; using System.Net.Mime; using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; using BirdsiteLive.ActivityPub; using BirdsiteLive.ActivityPub.Models; @@ -185,6 +184,44 @@ namespace BirdsiteLive.Controllers return View(displayTweet); } + // Mastodon API for QT in some apps + [Route("/api/v1/statuses/{statusId}")] + public async Task mastoApi(string id, string statusId) + { + if (!long.TryParse(statusId, out var parsedStatusId)) + return NotFound(); + + var tweet = await _twitterTweetService.GetTweetAsync(parsedStatusId); + if (tweet == null) + return NotFound(); + + var user = await _twitterUserService.GetUserAsync(tweet.Author.Acct); + var status = _statusService.GetActivity(tweet.Author.Acct, tweet); + var res = new MastodonPostApi() + { + id = parsedStatusId, + content = status.apObject.content, + created_at = status.published, + uri = $"https://{_instanceSettings.Domain}/users/{tweet.Author.Acct}/statuses/{tweet.Id}", + url = $"https://{_instanceSettings.Domain}/@{tweet.Author.Acct}/{tweet.Id}", + account = new MastodonUserApi() + { + Id = user.Id, + username = user.Acct, + acct = user.Acct, + display_name = user.Name, + Note = user.Description, + avatar = user.ProfileImageUrl, + avatar_static = user.ProfileImageUrl, + header = user.ProfileBannerURL, + header_static = user.ProfileBannerURL, + } + }; + + + var jsonApUser = JsonSerializer.Serialize(res); + return Content(jsonApUser, "application/activity+json; charset=utf-8"); + } [Route("/users/{id}/statuses/{statusId}/activity")] public async Task Activity(string id, string statusId) { diff --git a/src/BirdsiteLive/Models/MastodonPostApi.cs b/src/BirdsiteLive/Models/MastodonPostApi.cs new file mode 100644 index 0000000..b10e31f --- /dev/null +++ b/src/BirdsiteLive/Models/MastodonPostApi.cs @@ -0,0 +1,48 @@ +using System; + +namespace BirdsiteLive.Models; + +public class MastodonPostApi +{ + public long id { get; set; } + public string created_at { get; set; } + public long? in_reply_to_id { get; set; } = null; + public long? in_reply_to_account_id { get; set; } = null; + public bool sensitive { get; set; } = false; + public string spoiler_text { get; set; } = ""; + public string visibility { get; set; } = "public"; + public string language { get; set; } = "en"; + public string uri { get; set; } + public string url { get; set; } + public int replies_count { get; set; } = 0; + public int reblogs_count { get; set; } = 0; + public int favorite_count { get; set; } = 0; + public string content { get; set; } + public MastodonUserApi account { get; set; } + public MastodonAppApi application { get; } = new MastodonAppApi(); +} +public class MastodonUserApi +{ + public long Id { get; set; } + public string username { get; set; } + public string acct { get; set; } + public string display_name { get; set; } + public bool locked { get; set; } = false; + public bool bot { get; set; } = true; + public bool group { get; set; } = false; + public string Note { get; set; } + public string Url { get; set; } + public string avatar { get; set; } + public string avatar_static { get; set; } + public string header { get; set; } + public string header_static { get; set; } + public int followers_count { get; set; } = 0; + public int following_count { get; set; } = 0; + public int statuses_count { get; set; } = 0; +} + +public class MastodonAppApi +{ + public string name { get; set; } = "bird.makeup"; + public string url { get; set; } = "https://bird.makeup/"; +} diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs index b7e4106..489b775 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs @@ -90,7 +90,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers using (var dbConnection = Connection) { - var result = (await dbConnection.QueryAsync(query)).FirstOrDefault(); + var result = (await dbConnection.QueryAsync(query)).FirstOrDefault() ?? TimeSpan.Zero; return result; } }