[backend/masto-client] Add status source endpoint (ISH-98)

This commit is contained in:
Laura Hausmann 2024-02-27 04:02:15 +01:00
parent 0c70a23770
commit edfa2e9c9a
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 26 additions and 6 deletions

View file

@ -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<string>? LikedNotes;
public List<string>? Renotes;
public List<EmojiEntity>? Emoji;
public bool Source;
}
}

View file

@ -86,3 +86,10 @@ public class StatusContext
[J("ancestors")] public required List<StatusEntity> Ancestors { get; set; }
[J("descendants")] public required List<StatusEntity> 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; }
}

View file

@ -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<IActionResult> 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<IActionResult> 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);
}
}