OutboxPublisher works out who a post goes to, Mastodon's way: followers'
shared inboxes for public, unlisted and followers-only; every mentioned
remote account's own inbox; the recipients only for direct; the parent's
author for a reply; a community's followers for a post in it; nobody for
a circle. Creates, updates and deletes all use it.
- Local posts take a visibility (public, unlisted, followers-only) and a
spoiler text next to the content-warning flag.
- /clientapi/post/update keeps the previous version as a revision,
re-renders, and sends Update{Note} with `updated` to the same to/cc.
- Deleting is now soft: the content, title, spoiler, media and revisions
are cleared, timeline entries removed, the parent's reply count goes
down, Delete goes to the stored audience, and the object answers 410
with a Tombstone instead of 404.
- Editing a persona's profile sends Update{Person} to its followers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
using PrivaPub.ClientModels;
|
|
using PrivaPub.ClientModels.Post;
|
|
using PrivaPub.Extensions;
|
|
using PrivaPub.Resources;
|
|
using PrivaPub.Services;
|
|
|
|
namespace PrivaPub.Controllers.ClientToServer
|
|
{
|
|
[ApiController,
|
|
Route("clientapi/post"),
|
|
Authorize(Policy = Policies.IsUser)]
|
|
public class PostController : ControllerBase
|
|
{
|
|
readonly IPostsService _postsService;
|
|
readonly IStringLocalizer _localizer;
|
|
|
|
public PostController(IPostsService postsService, IStringLocalizer<GenericRes> localizer)
|
|
{
|
|
_postsService = postsService;
|
|
_localizer = localizer;
|
|
}
|
|
|
|
[HttpGet, Route("/clientapi/post/list")]
|
|
public async Task<IActionResult> List([FromQuery] string avatarId, [FromQuery] string groupId, CancellationToken token) =>
|
|
Answer(await _postsService.GetPosts(User.GetUserId(), avatarId, groupId, token));
|
|
|
|
[HttpPost, Route("/clientapi/post/insert")]
|
|
public async Task<IActionResult> Insert(InsertPostForm form, CancellationToken token) =>
|
|
!ModelState.IsValid ? Invalid() : Answer(await _postsService.InsertPost(User.GetUserId(), form, token));
|
|
|
|
[HttpPost, Route("/clientapi/post/update")]
|
|
public async Task<IActionResult> Update(UpdatePostForm form, CancellationToken token) =>
|
|
!ModelState.IsValid ? Invalid() : Answer(await _postsService.UpdatePost(User.GetUserId(), form, token));
|
|
|
|
[HttpPost, Route("/clientapi/post/delete")]
|
|
public async Task<IActionResult> Delete(DeletePostForm form, CancellationToken token) =>
|
|
!ModelState.IsValid ? Invalid() : Answer(await _postsService.DeletePost(User.GetUserId(), form, token));
|
|
|
|
[HttpGet, Route("/clientapi/dm/list")]
|
|
public async Task<IActionResult> Dms([FromQuery] string avatarId, [FromQuery] string dmGroupId, CancellationToken token) =>
|
|
Answer(await _postsService.GetDms(User.GetUserId(), avatarId, dmGroupId, token));
|
|
|
|
[HttpPost, Route("/clientapi/dm/insert")]
|
|
public async Task<IActionResult> InsertDm(InsertDmForm form, CancellationToken token) =>
|
|
!ModelState.IsValid ? Invalid() : Answer(await _postsService.InsertDm(User.GetUserId(), form, token));
|
|
|
|
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(_localizer["Invalid model."]));
|
|
|
|
IActionResult Answer(WebResult result) => result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
|
|
}
|
|
}
|