This commit is contained in:
@@ -8,6 +8,9 @@ using AyaNova.Api.ControllerHelpers;
|
|||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
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; }
|
||||||
|
}
|
||||||
//------------
|
//------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// One of "OpsOnly" or "Open"
|
/// One of "OpsOnly" or "Open"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="state">{"serverState":"Open"}</param>
|
/// <param name="state">{"serverState":"Open"}</param>
|
||||||
/// <returns>NoContent 204</returns>
|
/// <returns>New server state</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> PostServerState([FromBody] ServerStateModel state)
|
public async Task<IActionResult> PostServerState([FromBody] ServerStateModel state)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -79,7 +79,16 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
var UserName = await ct.User.Where(z => z.Id == userId).Select(z => z.Name).FirstOrDefaultAsync();
|
var UserName = await ct.User.Where(z => z.Id == userId).Select(z => z.Name).FirstOrDefaultAsync();
|
||||||
|
|
||||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = 0, Name = UserName };
|
//if they don't have a regular inapp subscription create one now
|
||||||
|
var defaultsub = await ct.NotifySubscription.FirstOrDefaultAsync(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == userId && z.DeliveryMethod == NotifyDeliveryMethod.App);
|
||||||
|
if (defaultsub == null)
|
||||||
|
{
|
||||||
|
defaultsub = new NotifySubscription() { UserId = userId, EventType = NotifyEventType.GeneralNotification, DeliveryMethod = NotifyDeliveryMethod.App };
|
||||||
|
await ct.NotifySubscription.AddAsync(defaultsub);
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = defaultsub.Id, Name = UserName };
|
||||||
await ct.NotifyEvent.AddAsync(n);
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user