This commit is contained in:
2026-10-28 14:24:41 +02:00
parent bd22fa86b7
commit 2bc968a92c
5 changed files with 50 additions and 4 deletions
+8 -2
View File
@@ -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";