diff --git a/Content.Client/Administration/Systems/BwoinkSystem.cs b/Content.Client/Administration/Systems/BwoinkSystem.cs index 0b21928f28..72c87b6ba6 100644 --- a/Content.Client/Administration/Systems/BwoinkSystem.cs +++ b/Content.Client/Administration/Systems/BwoinkSystem.cs @@ -39,9 +39,11 @@ namespace Content.Client.Administration.Systems RaiseNetworkEvent(new BwoinkClientTypingUpdated(channel, typing)); } + // Sunrise-Start public void LoadDbMessages(NetUserId userId) { RaiseNetworkEvent(new BwoinkRequestDbMessages(userId)); } + // Sunrise-End } } diff --git a/Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs b/Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs index af8ec50eb6..b13bbc0381 100644 --- a/Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs +++ b/Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs @@ -303,8 +303,17 @@ namespace Content.Client.Administration.UI.Bwoink { var panel = AHelpHelper.EnsurePanel(ch.Value); panel.Visible = true; + // Sunrise-Start if (!panel.LoadDb) + { + /* + * SUNRISE-TODO: Если открыть ахелп в котором уже есть сообщения то при загрузке с бд они продублируются. + * Ничего лучше чем очищать все сообщения перед загрузкой истории я не придумал. + */ + panel.TextOutput.Clear(); AHelpHelper.LoadDbMessages(ch.Value); + } + // Sunrise-End } } diff --git a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml index 9213768ddc..31f46c5500 100644 --- a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml +++ b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Orientation="Vertical" HorizontalExpand="True"> - + diff --git a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs index 47dcf1faca..92821d75f4 100644 --- a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs +++ b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs @@ -56,11 +56,11 @@ namespace Content.Client.Administration.UI.Bwoink public void ReceiveLine(SharedBwoinkSystem.BwoinkTextMessage message) { - if (!Visible && !message.DbLoad) + if (!Visible && !message.DbLoad) // Sunrise-Edit Unread++; var formatted = new FormattedMessage(1); - var formattedDate = $"[bold]{message.SentAt:dd.MM HH:mm}[/bold]"; + var formattedDate = $"[bold]{message.SentAt:dd.MM HH:mm}[/bold]"; // Sunrise-Edit formatted.AddMarkupOrThrow($"{formattedDate} {message.Text}"); TextOutput.AddMessage(formatted); LastMessage = message.SentAt; diff --git a/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs b/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs index 2f3b594536..15418f3f4f 100644 --- a/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs +++ b/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs @@ -136,7 +136,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged _bwoinkSystem?.Send(userId, textMessage, playSound, adminOnly); @@ -338,10 +338,10 @@ public interface IAHelpUIHandler : IDisposable public sealed class AdminAHelpUIHandler : IAHelpUIHandler { private readonly NetUserId _ownerId; - private BwoinkSystem? _bwoinkSystem; - public AdminAHelpUIHandler(NetUserId owner, BwoinkSystem? bwoinkSystem) + private BwoinkSystem? _bwoinkSystem; // Sunrise-Edit + public AdminAHelpUIHandler(NetUserId owner, BwoinkSystem? bwoinkSystem) // Sunrise-Edit { - _bwoinkSystem = bwoinkSystem; + _bwoinkSystem = bwoinkSystem; // Sunrise-Edit _ownerId = owner; } private readonly Dictionary _activePanelMap = new(); @@ -416,6 +416,7 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler panel.UpdatePlayerTyping(args.PlayerName, args.Typing); } + // Sunrise-Start public void SetLoadDb(NetUserId userId) { if (_activePanelMap.TryGetValue(userId, out var panel)) @@ -428,6 +429,7 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler { _bwoinkSystem?.LoadDbMessages(userId); } + // Sunrise-End public event Action? OnClose; public event Action? OnOpen; @@ -514,11 +516,11 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler public sealed class UserAHelpUIHandler : IAHelpUIHandler { private readonly NetUserId _ownerId; - private BwoinkSystem? _bwoinkSystem; - public UserAHelpUIHandler(NetUserId owner, BwoinkSystem? bwoinkSystem) + private BwoinkSystem? _bwoinkSystem; // Sunrise-Edit + public UserAHelpUIHandler(NetUserId owner, BwoinkSystem? bwoinkSystem) // Sunrise-Edit { _ownerId = owner; - _bwoinkSystem = bwoinkSystem; + _bwoinkSystem = bwoinkSystem; // Sunrise-Edit } public bool IsAdmin => false; public bool IsOpen => _window is { Disposed: false, IsOpen: true }; @@ -535,6 +537,7 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler _window!.OpenCentered(); } + // Sunrise-Start public void SetLoadDb(NetUserId userId) { LoadDb = true; @@ -544,6 +547,7 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler { return LoadDb; } + // Sunrise-End public void Close() { @@ -552,8 +556,6 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler public void ToggleWindow() { - if (!IsLoadDb(_ownerId)) - _bwoinkSystem?.LoadDbMessages(_ownerId); EnsureInit(_discordRelayActive); if (_window!.IsOpen) { @@ -613,9 +615,21 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler _window.OnOpen += () => { OnOpen?.Invoke(); }; _window.Contents.AddChild(_chatPanel); - var introText = Loc.GetString("bwoink-system-introductory-message"); - var introMessage = new SharedBwoinkSystem.BwoinkTextMessage( _ownerId, SharedBwoinkSystem.SystemUserId, introText); - Receive(introMessage); + // Sunrise-Start + if (!IsLoadDb(_ownerId)) + { + /* + * SUNRISE-TODO: Если открыть ахелп в котором уже есть сообщения то при загрузке с бд они продублируются. + * Ничего лучше чем очищать все сообщения перед загрузкой истории я не придумал. + */ + _chatPanel.TextOutput.Clear(); + _bwoinkSystem?.LoadDbMessages(_ownerId); + } + + //var introText = Loc.GetString("bwoink-system-introductory-message"); + //var introMessage = new SharedBwoinkSystem.BwoinkTextMessage( _ownerId, SharedBwoinkSystem.SystemUserId, introText); + //Receive(introMessage); + // Sunrise-End } public void Dispose() diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 2878eb9f12..c14fe2cb76 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -347,12 +347,17 @@ namespace Content.Server.Administration.Systems } } + // Sunrise-Start private async void OnRequestDbMessages(BwoinkRequestDbMessages msg, EntitySessionEventArgs args) { var isAdmin = _adminManager.IsAdmin(args.SenderSession); var messages = await _dbManager.GetAHelpMessagesByReceiverAsync(msg.UserId); + /* + * SUNRISE-TODO: Мы отправляем всю историю по одному сообщению используя ванильный класс. + * Вероятно более разумно было бы отправлять все сообщения одним эвентом... Возможно. + */ foreach (var aHelpMessage in messages) { var formatMessage = await FormatDbAhelpMessage( @@ -368,7 +373,7 @@ namespace Content.Server.Administration.Systems (NetUserId) aHelpMessage.ReceiverUserId, (NetUserId) aHelpMessage.SenderUserId, formatMessage, - aHelpMessage.SentAt.DateTime, + aHelpMessage.SentAt.DateTime.ToLocalTime(), playSound: aHelpMessage.PlaySound, adminOnly: aHelpMessage.AdminOnly, dbLoad: true); @@ -383,6 +388,10 @@ namespace Content.Server.Administration.Systems private async Task FormatDbAhelpMessage(string message, NetUserId senderUserId, bool playSound = true, bool adminOnly = false) { + /* + * SUNRISE-TODO: Ахуенная идея, обращаться к БД при каждом форматировании сообщения. + * Очевидно нужно использовать кеширование, но мне впадлу. + */ var senderAdmin = await _adminManager.LoadAdminData(senderUserId); var senderData = await _dbManager.GetPlayerRecordByUserId(senderUserId); var username = ""; @@ -392,7 +401,7 @@ namespace Content.Server.Administration.Systems } string bwoinkText; - string adminPrefix = ""; + var adminPrefix = ""; if (_config.GetCVar(CCVars.AhelpAdminPrefix) && senderAdmin is not null && senderAdmin.Value.dat.Title is not null) { @@ -432,6 +441,7 @@ namespace Content.Server.Administration.Systems return $"{(adminOnly ? Loc.GetString("bwoink-message-admin-only") : !playSound ? Loc.GetString("bwoink-message-silent") : "")} {bwoinkText}: {escapedText}"; } + // Sunrise-End private void OnServerNameChanged(string obj) { @@ -816,8 +826,10 @@ namespace Content.Server.Administration.Systems LogBwoink(msg); - var sentAt = DateTimeOffset.UtcNow; + // Sunrise-Start + var sentAt = DateTimeOffset.Now; _dbManager.AddAHelpMessage(senderSession.UserId, message.UserId, message.Text, sentAt, message.PlaySound, message.AdminOnly); + // Sunrise-End var admins = GetTargetAdmins(); diff --git a/Content.Server/Database/ServerDbBase.cs b/Content.Server/Database/ServerDbBase.cs index 6507ef0a88..5097333825 100644 --- a/Content.Server/Database/ServerDbBase.cs +++ b/Content.Server/Database/ServerDbBase.cs @@ -1746,7 +1746,7 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id} #endregion - + // Sunrise-Start # region Ahelp public async Task AddAHelpMessage(Guid senderUserId, Guid receiverUserId, string message, DateTimeOffset sentAt, bool playSound, bool adminOnly) @@ -1777,6 +1777,7 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id} } # endregion + // Sunrise-End # region IPIntel diff --git a/Content.Server/Database/ServerDbManager.cs b/Content.Server/Database/ServerDbManager.cs index ee577fbd6b..46f6244eb5 100644 --- a/Content.Server/Database/ServerDbManager.cs +++ b/Content.Server/Database/ServerDbManager.cs @@ -362,6 +362,7 @@ namespace Content.Server.Database #endregion + // Sunrise-Start #region Ahelp Task AddAHelpMessage(Guid senderSessionUserId, Guid messageUserId, string message, DateTimeOffset sentAt, bool playSound, bool adminOnly); @@ -369,6 +370,7 @@ namespace Content.Server.Database public Task> GetAHelpMessagesByReceiverAsync(Guid receiverUserId); #endregion + // Sunrise-End } /// diff --git a/Content.Shared/Administration/SharedBwoinkSystem.cs b/Content.Shared/Administration/SharedBwoinkSystem.cs index 83a08f2b4a..fd116464b7 100644 --- a/Content.Shared/Administration/SharedBwoinkSystem.cs +++ b/Content.Shared/Administration/SharedBwoinkSystem.cs @@ -25,6 +25,7 @@ namespace Content.Shared.Administration { } + // Sunrise-Start [Serializable, NetSerializable] public sealed class BwoinkRequestDbMessages : EntityEventArgs { @@ -46,6 +47,7 @@ namespace Content.Shared.Administration UserId = userId; } } + // Sunrise-End [Serializable, NetSerializable] public sealed class BwoinkTextMessage : EntityEventArgs diff --git a/Resources/Changelog/ChangelogSunrise.yml b/Resources/Changelog/ChangelogSunrise.yml index 7cf0bf655a..0718182795 100644 --- a/Resources/Changelog/ChangelogSunrise.yml +++ b/Resources/Changelog/ChangelogSunrise.yml @@ -14584,3 +14584,18 @@ type: Tweak id: 995 time: '2025-04-11T19:00:55.402486+00:00' +- author: VigersRay + changes: + - message: "\u0418\u0441\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u043E \u0434\u0443\ + \u0431\u043B\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0430\u0445\u0435\ + \u043B\u043F\u0430 \u043F\u043E\u0441\u043B\u0435 \u0437\u0430\u0433\u0440\u0443\ + \u0437\u043A\u0438 \u0438\u0441\u0442\u043E\u0440\u0438\u0438." + type: Fix + - message: "\u0418\u0441\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0430 \u043F\u0440\ + \u0438\u0432\u044F\u0437\u043A\u0430 \u0432\u0440\u0435\u043C\u0435\u043D\u0438\ + \ \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0439 \u0430\u0445\u0435\u043B\ + \u043F\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u044B\u0445 \u0441\ + \ \u0431\u0434 \u043A UTC+0." + type: Fix + id: 996 + time: '2025-04-11T21:52:05.290887+00:00'