Files
Govor/Govor.API/Controllers/MessageLookupController.cs
T
Artemy 632ac04b56 Add forwarding, friend controls, and benefits
Add message forwarding and reply lookup, friend removal and blocking endpoints, and database-backed Govor+ privileges with customizable profile tags. Include migrations, integration tests, and updated API and operations documentation.
2026-10-31 18:29:40 +07:00

29 lines
1.2 KiB
C#

using AutoMapper;
using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Messages;
using Govor.Contracts.Responses;
using Govor.Domain;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace Govor.API.Controllers;
/// <summary>Loads a reply target outside the current history page without exposing another conversation.</summary>
[ApiController]
[Authorize]
[Route("api/messages")]
public sealed class MessageLookupController(GovorDbContext db, ICurrentUserService currentUser, IMapper mapper) : ControllerBase
{
[HttpGet("{messageId:guid}")]
public async Task<IActionResult> Get(Guid messageId)
{
var message = await db.Messages.AsNoTracking().Include(m => m.MediaAttachments).ThenInclude(m => m.MediaFile)
.Include(m => m.Reactions).Include(m => m.MessageViews).AsSplitQuery()
.SingleOrDefaultAsync(m => m.Id == messageId);
if (message is null || !await db.HasChatAccessAsync(currentUser.GetCurrentUserId(), message.RecipientId, message.RecipientType))
return NotFound();
return Ok(mapper.Map<MessageResponse>(message));
}
}