]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
allow to publish news without ui (#35262)
authorlzk <124214523+lzk228@users.noreply.github.com>
Sat, 21 Jun 2025 09:19:27 +0000 (11:19 +0200)
committerGitHub <noreply@github.com>
Sat, 21 Jun 2025 09:19:27 +0000 (11:19 +0200)
* allow to publish news without ui

* the hell was that

* apply

* apply review

* sure

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
* okay

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Server/MassMedia/Systems/NewsSystem.cs

index d3cd94f6566a86cb5cca5f9a5c60da4c253c88ed..0abaa7fb16b0f0894575cdd5e5b941c220d950d8 100644 (file)
@@ -133,7 +133,7 @@ public sealed class NewsSystem : SharedNewsSystem
             _adminLogger.Add(
                 LogType.Chat, LogImpact.Medium,
                 $"{ToPrettyString(msg.Actor):actor} deleted news article {article.Title} by {article.Author}: {article.Content}"
-                );
+            );
 
             articles.RemoveAt(msg.ArticleNum);
             _audio.PlayPvs(ent.Comp.ConfirmSound, ent);
@@ -164,9 +164,6 @@ public sealed class NewsSystem : SharedNewsSystem
         if (!ent.Comp.PublishEnabled)
             return;
 
-        if (!TryGetArticles(ent, out var articles))
-            return;
-
         if (!CanUse(msg.Actor, ent.Owner))
             return;
 
@@ -180,32 +177,62 @@ public sealed class NewsSystem : SharedNewsSystem
         var title = msg.Title.Trim();
         var content = msg.Content.Trim();
 
-        var article = new NewsArticle
+        if (TryAddNews(ent, title, content, out var article, authorName, msg.Actor))
+        {
+            _audio.PlayPvs(ent.Comp.ConfirmSound, ent);
+
+            _chatManager.SendAdminAnnouncement(Loc.GetString("news-publish-admin-announcement",
+                                                             ("actor", msg.Actor),
+                                                             ("title", article.Value.Title),
+                                                             ("author", article.Value.Author ?? Loc.GetString("news-read-ui-no-author"))
+            ));
+        }
+    }
+
+    /// <summary>
+    /// Set the alert level based on the station's entity ID.
+    /// </summary>
+    /// <param name="uid">Entity on the station to which news will be added.</param>
+    /// <param name="title">Title of the news article.</param>
+    /// <param name="content">Content of the news article.</param>
+    /// <param name="author">Author of the news article.</param>
+    /// <param name="actor">Entity which caused the news article to publish. Used for admin logs.</param>
+    public bool TryAddNews(EntityUid uid, string title, string content, [NotNullWhen(true)] out NewsArticle? article, string? author = null, EntityUid? actor = null)
+    {
+        if (!TryGetArticles(uid, out var articles))
+        {
+            article = null;
+            return false;
+        }
+
+        article = new NewsArticle
         {
             Title = title.Length <= MaxTitleLength ? title : $"{title[..MaxTitleLength]}...",
             Content = content.Length <= MaxContentLength ? content : $"{content[..MaxContentLength]}...",
-            Author = authorName,
+            Author = author,
             ShareTime = _ticker.RoundDuration()
         };
 
-        _audio.PlayPvs(ent.Comp.ConfirmSound, ent);
-
-        _adminLogger.Add(
-            LogType.Chat,
-            LogImpact.Medium,
-            $"{ToPrettyString(msg.Actor):actor} created news article {article.Title} by {article.Author}: {article.Content}"
-            );
-
-        _chatManager.SendAdminAnnouncement(Loc.GetString("news-publish-admin-announcement",
-            ("actor", msg.Actor),
-            ("title", article.Title),
-            ("author", article.Author ?? Loc.GetString("news-read-ui-no-author"))
-            ));
+        articles.Add(article.Value);
 
-        articles.Add(article);
+        if (actor != null)
+        {
+            _adminLogger.Add(
+                LogType.Chat,
+                LogImpact.Medium,
+                $"{ToPrettyString(actor):actor} created news article {article.Value.Title} by {article.Value.Author}: {article.Value.Content}");
+        }
+        else
+        {
+            _adminLogger.Add(
+                LogType.Chat,
+                LogImpact.Medium,
+                $"Created news article {article.Value.Title} by {article.Value.Author}: {article.Value.Content}");
+        }
 
-        var args = new NewsArticlePublishedEvent(article);
+        var args = new NewsArticlePublishedEvent(article.Value);
         var query = EntityQueryEnumerator<NewsReaderCartridgeComponent>();
+
         while (query.MoveNext(out var readerUid, out _))
         {
             RaiseLocalEvent(readerUid, ref args);
@@ -215,6 +242,8 @@ public sealed class NewsSystem : SharedNewsSystem
             Task.Run(async () => await SendArticleToDiscordWebhook(article));
 
         UpdateWriterDevices();
+
+        return true;
     }
     #endregion