This commit is contained in:
@@ -8,6 +8,9 @@ using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -164,6 +167,42 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send direct message notification to selected users
|
||||
/// </summary>
|
||||
/// <returns>NoContent on success or error</returns>
|
||||
[HttpPost("direct-message")]
|
||||
public async Task<IActionResult> SendNotifyDirectMessage([FromBody] NotifyDirectMessage notifyDirectMessage)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var message = $"{UserNameFromContext.Name(HttpContext.Items)}: \"{notifyDirectMessage.Message}\"";
|
||||
foreach (long l in notifyDirectMessage.Users)
|
||||
{
|
||||
if (l != 0)
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, message, null, l);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
public class NotifyDirectMessage
|
||||
{
|
||||
public NotifyDirectMessage()
|
||||
{
|
||||
Users = new List<long>();
|
||||
}
|
||||
[Required]
|
||||
public string Message { get; set; }
|
||||
|
||||
[Required]
|
||||
public List<long> Users { get; set; }
|
||||
}
|
||||
//------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user