фиксы ахелпа
This commit is contained in:
parent
08ecd0f570
commit
62eabda73c
10 changed files with 77 additions and 20 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="True">
|
||||
<OutputPanel Name="TextOutput" VerticalExpand="true" />
|
||||
<OutputPanel Name="TextOutput" VerticalExpand="true" Access="Public" /> <!-- Sunrise-Edit -->
|
||||
<RichTextLabel Name="TypingIndicator" Access="Public" />
|
||||
<HistoryLineEdit Name="SenderLineEdit" />
|
||||
<RichTextLabel Name="RelayedToDiscordLabel" Access="Public" Visible="False" />
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (message.PlaySound && localPlayer.UserId != message.TrueSender && !message.DbLoad)
|
||||
if (message.PlaySound && localPlayer.UserId != message.TrueSender && !message.DbLoad) // Sunrise-Edit
|
||||
{
|
||||
if (_aHelpSound != null && (_bwoinkSoundEnabled || !_adminManager.IsActive()))
|
||||
_audio.PlayGlobal(_aHelpSound, Filter.Local(), false);
|
||||
|
|
@ -179,7 +179,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
|
|||
UIHelper?.Dispose();
|
||||
var ownerUserId = _playerManager.LocalUser!.Value;
|
||||
|
||||
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId, _bwoinkSystem) : new UserAHelpUIHandler(ownerUserId, _bwoinkSystem);
|
||||
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId, _bwoinkSystem) : new UserAHelpUIHandler(ownerUserId, _bwoinkSystem); // Sunrise-Edit
|
||||
UIHelper.DiscordRelayChanged(_discordRelayActive);
|
||||
|
||||
UIHelper.SendMessageAction = (userId, textMessage, playSound, adminOnly) => _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<NetUserId, BwoinkPanel> _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()
|
||||
|
|
|
|||
|
|
@ -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<string> 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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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<List<AHelpMessage>> GetAHelpMessagesByReceiverAsync(Guid receiverUserId);
|
||||
|
||||
#endregion
|
||||
// Sunrise-End
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue