ntfy
This commit is contained in:
@@ -14,6 +14,7 @@ namespace StatiKosev.Controllers;
|
||||
[Route("messages")]
|
||||
public class PrivateMessageController(
|
||||
MessageService messagesService,
|
||||
NtfyNotifier ntfy,
|
||||
IStringLocalizer<StringValues> strings,
|
||||
IConfiguration config,
|
||||
ILogger<PrivateMessageController> logger) : Controller
|
||||
@@ -39,10 +40,15 @@ public class PrivateMessageController(
|
||||
|
||||
logger.LogInformation("Received private message from {UserId}", userId ?? "anonymous");
|
||||
|
||||
if (userId is null || senderUsername is null || req.Anonymous)
|
||||
var anonymous = userId is null || senderUsername is null || req.Anonymous;
|
||||
if (anonymous)
|
||||
await messagesService.SendAnonymousAsync(req.Body, userAgent);
|
||||
else
|
||||
await messagesService.SendAsUserAsync(req.Body, userId, senderUsername, userAgent);
|
||||
await messagesService.SendAsUserAsync(req.Body, userId!, senderUsername!, userAgent);
|
||||
|
||||
ntfy.Notify("New message",
|
||||
$"{(anonymous ? "Anonymous" : senderUsername)}: {req.Body[..Math.Min(req.Body.Length, 200)]}",
|
||||
"envelope");
|
||||
|
||||
TempData["Status"] = strings["MessageSent"].Value;
|
||||
TempData["StatusType"] = "success";
|
||||
|
||||
Reference in New Issue
Block a user