From: lzk <124214523+lzk228@users.noreply.github.com>
Date: Sat, 21 Jun 2025 09:19:27 +0000 (+0200)
Subject: allow to publish news without ui (#35262)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=3b6f4c5b3ea3cb0d5338a437a90242a9836682ee;p=space-station-14.git
allow to publish news without ui (#35262)
* 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>
---
diff --git a/Content.Server/MassMedia/Systems/NewsSystem.cs b/Content.Server/MassMedia/Systems/NewsSystem.cs
index d3cd94f656..0abaa7fb16 100644
--- a/Content.Server/MassMedia/Systems/NewsSystem.cs
+++ b/Content.Server/MassMedia/Systems/NewsSystem.cs
@@ -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"))
+ ));
+ }
+ }
+
+ ///
+ /// Set the alert level based on the station's entity ID.
+ ///
+ /// Entity on the station to which news will be added.
+ /// Title of the news article.
+ /// Content of the news article.
+ /// Author of the news article.
+ /// Entity which caused the news article to publish. Used for admin logs.
+ 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();
+
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