2019-07-17 12:05:44 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-12-28 14:52:59 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.API;
|
|
|
|
|
|
|
|
[ApiController]
|
2022-01-20 00:25:04 +00:00
|
|
|
[Route("v1")]
|
2021-11-27 02:10:56 +00:00
|
|
|
public class MessageController: ControllerBase
|
2019-07-17 12:05:44 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly IDatabase _db;
|
|
|
|
private readonly ModelRepository _repo;
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public MessageController(ModelRepository repo, IDatabase db)
|
|
|
|
{
|
|
|
|
_repo = repo;
|
|
|
|
_db = db;
|
|
|
|
}
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2022-01-20 00:25:04 +00:00
|
|
|
[HttpGet("msg/{mid}")]
|
2021-11-27 02:10:56 +00:00
|
|
|
public async Task<ActionResult<JObject>> GetMessage(ulong mid)
|
|
|
|
{
|
|
|
|
var msg = await _db.Execute(c => _repo.GetMessage(c, mid));
|
|
|
|
if (msg == null) return NotFound("Message not found.");
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2022-01-15 00:47:12 +00:00
|
|
|
var ctx = msg.System == null ? LookupContext.ByNonOwner : User.ContextFor(msg.System);
|
|
|
|
return msg.ToJson(ctx, APIVersion.V1);
|
2019-07-17 12:05:44 +00:00
|
|
|
}
|
|
|
|
}
|