diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs b/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs index f8d42bbd..5dbb81c1 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs @@ -75,7 +75,7 @@ public class NoteRenderer( }) .ToList(); - var content = text != null + var content = text != null && data?.Source != true ? await mfmConverter.ToHtmlAsync(text, mentionedUsers, note.UserHost) : null; @@ -106,7 +106,7 @@ public class NoteRenderer( ContentWarning = note.Cw ?? "", Visibility = StatusEntity.EncodeVisibility(note.Visibility), Content = content, - Text = text, + Text = data?.Source == true ? text : null, Mentions = mentions, IsPinned = false, Attachments = attachments, @@ -226,5 +226,6 @@ public class NoteRenderer( public List? LikedNotes; public List? Renotes; public List? Emoji; + public bool Source; } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Schemas/Entities/StatusEntity.cs b/Iceshrimp.Backend/Controllers/Mastodon/Schemas/Entities/StatusEntity.cs index 6f72df44..bf6010d5 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Schemas/Entities/StatusEntity.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Schemas/Entities/StatusEntity.cs @@ -85,4 +85,11 @@ public class StatusContext { [J("ancestors")] public required List Ancestors { get; set; } [J("descendants")] public required List Descendants { get; set; } +} + +public class StatusSource +{ + [J("id")] public required string Id { get; set; } + [J("text")] public required string Text { get; set; } + [J("spoiler_text")] public required string ContentWarning { get; set; } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs b/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs index fc7628e6..b9f29239 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs @@ -276,19 +276,31 @@ public class StatusController( [HttpDelete("{id}")] [Authorize("write:statuses")] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))] - [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))] [ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))] public async Task DeleteNote(string id) { var user = HttpContext.GetUserOrFail(); var note = await db.Notes.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id && p.User == user) ?? throw GracefulException.RecordNotFound(); - if (user.Id != note.UserId) - throw GracefulException.RecordNotFound(); - var res = await noteRenderer.RenderAsync(note, user); + var res = await noteRenderer.RenderAsync(note, user, new NoteRenderer.NoteRendererDto { Source = true }); await noteSvc.DeleteNoteAsync(note); return Ok(res); } + + [HttpGet("{id}/source")] + [Authorize("read:statuses")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusSource))] + [ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))] + public async Task GetNoteSource(string id) + { + var user = HttpContext.GetUserOrFail(); + var res = await db.Notes.Where(p => p.Id == id && p.User == user) + .Select(p => new StatusSource { Id = p.Id, ContentWarning = p.Cw ?? "", Text = p.Text ?? "" }) + .FirstOrDefaultAsync() ?? + throw GracefulException.RecordNotFound(); + + return Ok(res); + } } \ No newline at end of file