2019-07-17 12:05:44 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-07-17 12:05:44 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-07-17 12:05:44 +00:00
|
|
|
using Newtonsoft.Json;
|
2019-12-28 14:52:59 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2019-07-17 12:05:44 +00:00
|
|
|
using NodaTime;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
namespace PluralKit.API
|
2019-07-17 12:05:44 +00:00
|
|
|
{
|
|
|
|
public struct MessageReturn
|
|
|
|
{
|
|
|
|
[JsonProperty("timestamp")] public Instant Timestamp;
|
|
|
|
[JsonProperty("id")] public string Id;
|
2019-12-22 11:54:01 +00:00
|
|
|
[JsonProperty("original")] public string Original;
|
2019-07-17 12:05:44 +00:00
|
|
|
[JsonProperty("sender")] public string Sender;
|
|
|
|
[JsonProperty("channel")] public string Channel;
|
|
|
|
|
2019-12-28 14:52:59 +00:00
|
|
|
[JsonProperty("system")] public JObject System;
|
|
|
|
[JsonProperty("member")] public JObject Member;
|
2019-07-17 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[ApiController]
|
2020-05-07 02:39:49 +00:00
|
|
|
[ApiVersion("1.0")]
|
2019-07-17 12:05:44 +00:00
|
|
|
[Route("msg")]
|
2020-05-07 02:39:49 +00:00
|
|
|
[Route( "v{version:apiVersion}/msg" )]
|
2019-07-17 12:05:44 +00:00
|
|
|
public class MessageController: ControllerBase
|
|
|
|
{
|
2019-10-26 17:45:30 +00:00
|
|
|
private IDataStore _data;
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2020-06-15 23:15:59 +00:00
|
|
|
public MessageController(IDataStore _data)
|
2019-07-17 12:05:44 +00:00
|
|
|
{
|
2019-10-26 17:45:30 +00:00
|
|
|
this._data = _data;
|
2019-07-17 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("{mid}")]
|
|
|
|
public async Task<ActionResult<MessageReturn>> GetMessage(ulong mid)
|
|
|
|
{
|
2019-10-26 17:45:30 +00:00
|
|
|
var msg = await _data.GetMessage(mid);
|
2019-07-17 12:05:44 +00:00
|
|
|
if (msg == null) return NotFound("Message not found.");
|
|
|
|
|
|
|
|
return new MessageReturn
|
|
|
|
{
|
|
|
|
Timestamp = Instant.FromUnixTimeMilliseconds((long) (msg.Message.Mid >> 22) + 1420070400000),
|
|
|
|
Id = msg.Message.Mid.ToString(),
|
|
|
|
Channel = msg.Message.Channel.ToString(),
|
|
|
|
Sender = msg.Message.Sender.ToString(),
|
2020-06-15 23:15:59 +00:00
|
|
|
Member = msg.Member.ToJson(User.ContextFor(msg.System)),
|
|
|
|
System = msg.System.ToJson(User.ContextFor(msg.System)),
|
2019-12-22 11:54:01 +00:00
|
|
|
Original = msg.Message.OriginalMid?.ToString()
|
2019-07-17 12:05:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|