[backend/masto-client] Support renote visibility parameter

This commit is contained in:
Laura Hausmann 2024-02-22 17:59:10 +01:00
parent 3671dfd2b5
commit f45d4978cc
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -126,7 +126,7 @@ public class StatusController(
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))] [ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))] [ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))] [ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> Renote(string id) public async Task<IActionResult> Renote(string id, [FromHybrid] string? visibility)
{ {
var user = HttpContext.GetUserOrFail(); var user = HttpContext.GetUserOrFail();
if (!await db.Notes.AnyAsync(p => p.RenoteId == id && p.User == user && p.IsPureRenote)) if (!await db.Notes.AnyAsync(p => p.RenoteId == id && p.User == user && p.IsPureRenote))
@ -137,7 +137,14 @@ public class StatusController(
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync() ??
throw GracefulException.RecordNotFound(); throw GracefulException.RecordNotFound();
await noteSvc.CreateNoteAsync(user, Note.NoteVisibility.Followers, renote: note); var renoteVisibility = visibility != null
? StatusEntity.DecodeVisibility(visibility)
: Note.NoteVisibility.Followers;
if (renoteVisibility == Note.NoteVisibility.Specified)
throw GracefulException.BadRequest("Renote visibility must be one of: public, unlisted, private");
await noteSvc.CreateNoteAsync(user, renoteVisibility, renote: note);
} }
return await GetNote(id); return await GetNote(id);