forked from SoDOff-Project/sodoff
75 lines
3.1 KiB
C#
75 lines
3.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using sodoff.Attributes;
|
|
using sodoff.Model;
|
|
using sodoff.Schema;
|
|
using sodoff.Services;
|
|
using sodoff.Util;
|
|
|
|
namespace sodoff.Controllers.Common;
|
|
public class MessagingController : Controller {
|
|
|
|
private readonly MessagingService messagingService;
|
|
private readonly DBContext ctx;
|
|
public MessagingController(MessagingService messagingService, DBContext ctx)
|
|
{
|
|
this.messagingService = messagingService;
|
|
this.ctx = ctx;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Produces("application/xml")]
|
|
[Route("MessagingWebService.asmx/GetUserMessageQueue")]
|
|
[VikingSession]
|
|
public ArrayOfMessageInfo? GetUserMessageQueue(Viking viking, [FromForm] bool showOldMessages, [FromForm] bool showDeletedMessages) {
|
|
return messagingService.ConstructUserMessageInfoArray(viking, showOldMessages, showDeletedMessages);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Produces("application/xml")]
|
|
[Route("MessagingWebService.asmx/SendMessage")]
|
|
[VikingSession]
|
|
public IActionResult SendMessage(Viking viking, [FromForm] Guid toUser, [FromForm] int messageID, [FromForm] string data) {
|
|
// find viking to send to
|
|
Viking? toViking = ctx.Vikings.FirstOrDefault(e => e.Uid == toUser);
|
|
if (toViking == null) return Ok(false);
|
|
|
|
// clients (at least older ones) don't send what typeID the message is, its encoded in data
|
|
ArrayOfKeyValuePairOfStringString arrayOfKeyValuePairOfStringString = XmlUtil.DeserializeXml<ArrayOfKeyValuePairOfStringString>(data);
|
|
MessageTypeID typeID = (MessageTypeID)int.Parse(arrayOfKeyValuePairOfStringString.KeyValuePairOfStringString![0].Value ?? "0");
|
|
|
|
var msg = messagingService.AddMessageToViking(viking, toViking, MessageType.Data, typeID, MessageLevel.WhiteList, data, "[[Line1]]=[[{{BuddyUserName}}]] has sent you a {{MessageType}}!", "[[Line1]]=[[{{BuddyUserName}}]] has sent you a {{MessageType}}!");
|
|
if (msg != null) return Ok(true);
|
|
else return Ok(false);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Produces("application/xml")]
|
|
[Route("MessagingWebService.asmx/SaveMessage")]
|
|
public IActionResult SaveMessage([FromForm] int userMessageQueueId, [FromForm] bool isNew, [FromForm] bool IsDeleted) {
|
|
var updatedMessage = messagingService.UpdateMessageByQueueID(userMessageQueueId, isNew, IsDeleted);
|
|
if (updatedMessage != null) return Ok(true);
|
|
else return Ok(false);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Produces("application/xml")]
|
|
[Route("MessageWebService.asmx/GetCombinedListMessage")]
|
|
public ArrayOfCombinedListMessage? GetCombinedListMessage([FromForm] Guid userId)
|
|
{
|
|
// find viking
|
|
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
|
|
|
if (viking != null) return messagingService.ConstructCombinedMessageArray(viking);
|
|
else return new ArrayOfCombinedListMessage();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Produces("application/xml")]
|
|
[Route("MessageWebService.asmx/RemoveMessageFromBoard")]
|
|
public IActionResult RemoveMessageFromBoard([FromForm] int messageID)
|
|
{
|
|
messagingService.RemoveMessage(messageID);
|
|
return Ok(true);
|
|
}
|
|
}
|