From b4682bfa8a912651f831bf934d8735c7f92af3a6 Mon Sep 17 00:00:00 2001 From: Angelo Fallaria Date: Mon, 6 Jan 2025 19:40:37 +0800 Subject: [PATCH 01/14] NanoChat Notification Fix --- .../Cartridges/NanoChatCartridgeSystem.cs | 75 +++++++------------ .../DeltaV/NanoChat/NanoChatSystem.cs | 24 ++++++ .../DeltaV/NanoChat/NanoChatCardComponent.cs | 6 ++ 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/Content.Server/DeltaV/CartridgeLoader/Cartridges/NanoChatCartridgeSystem.cs b/Content.Server/DeltaV/CartridgeLoader/Cartridges/NanoChatCartridgeSystem.cs index e9e01041f15..a784e0c6410 100644 --- a/Content.Server/DeltaV/CartridgeLoader/Cartridges/NanoChatCartridgeSystem.cs +++ b/Content.Server/DeltaV/CartridgeLoader/Cartridges/NanoChatCartridgeSystem.cs @@ -38,25 +38,6 @@ public override void Initialize() SubscribeLocalEvent(OnUiReady); SubscribeLocalEvent(OnMessage); - - Subs.BuiEvents(PdaUiKey.Key, subs => - { - subs.Event(OnPdaClosed); - }); - } - - // Reset current chat when PDA closes. - private void OnPdaClosed(EntityUid uid, PdaComponent component, BoundUIClosedEvent args) - { - var exists = GetCardEntity(uid, out var cardEntity); - - if (!exists) - return; - - _nanoChat.SetCurrentChat( - (cardEntity.Owner, (NanoChatCardComponent?) cardEntity.Comp), - null - ); } public override void Update(float frameTime) @@ -401,7 +382,7 @@ private void DeliverMessageToRecipient(Entity sender, return; _nanoChat.AddMessage((recipient, recipient.Comp), senderNumber.Value, message with { DeliveryFailed = false }); - HandleUnreadNotification(recipient, message); + HandleUnreadNotification(recipient, message, (uint) senderNumber); var msgEv = new NanoChatMessageReceivedEvent(recipient); RaiseLocalEvent(ref msgEv); @@ -411,42 +392,36 @@ private void DeliverMessageToRecipient(Entity sender, /// /// Handles unread message notifications and updates unread status. /// - private void HandleUnreadNotification(Entity recipient, NanoChatMessage message) + private void HandleUnreadNotification(Entity recipient, + NanoChatMessage message, + uint senderNumber) { // Get sender name from contacts or fall back to number var recipients = _nanoChat.GetRecipients((recipient, recipient.Comp)); - var senderName = recipients.TryGetValue(message.SenderId, out var existingRecipient) - ? existingRecipient.Name + var senderName = recipients.TryGetValue(message.SenderId, out var senderRecipient) + ? senderRecipient.Name : $"#{message.SenderId:D4}"; - - var shouldUnread = true; - - if (!recipient.Comp.Recipients[message.SenderId].HasUnread && !recipient.Comp.NotificationsMuted) - { - var pdaQuery = EntityQueryEnumerator(); - while (pdaQuery.MoveNext(out var pdaUid, out var pdaComp)) - { - if (pdaComp.ContainedId != recipient) - continue; - - if (_ui.IsUiOpen((pdaUid, null), PdaUiKey.Key) && recipient.Comp.CurrentChat == message.SenderId) - { - shouldUnread = false; - break; - } - - _cartridge.SendNotification(pdaUid, - Loc.GetString("nano-chat-new-message-title", ("sender", senderName)), - Loc.GetString("nano-chat-new-message-body", ("message", TruncateMessage(message.Content)))); - break; - } - } + var hasSelectedCurrentChat = _nanoChat.GetCurrentChat((recipient, recipient.Comp)) == senderNumber; // Update unread status - _nanoChat.SetRecipient( - (recipient, recipient.Comp), - message.SenderId, - existingRecipient with { HasUnread = shouldUnread }); + if (!hasSelectedCurrentChat) + _nanoChat.SetRecipient((recipient, recipient.Comp), + message.SenderId, + senderRecipient with { HasUnread = true }); + + if (recipient.Comp.NotificationsMuted || + recipient.Comp.PdaUid is not {} pdaUid || + !TryComp(pdaUid, out var loader) || + // Don't notify if the recipient has the NanoChat program open with this chat selected. + (hasSelectedCurrentChat && + _ui.IsUiOpen(pdaUid, PdaUiKey.Key) && + HasComp(loader.ActiveProgram))) + return; + + _cartridge.SendNotification(pdaUid, + Loc.GetString("nano-chat-new-message-title", ("sender", senderName)), + Loc.GetString("nano-chat-new-message-body", ("message", TruncateMessage(message.Content))), + loader); } /// diff --git a/Content.Server/DeltaV/NanoChat/NanoChatSystem.cs b/Content.Server/DeltaV/NanoChat/NanoChatSystem.cs index fb0ca32aa66..87a174a4fce 100644 --- a/Content.Server/DeltaV/NanoChat/NanoChatSystem.cs +++ b/Content.Server/DeltaV/NanoChat/NanoChatSystem.cs @@ -7,6 +7,8 @@ using Content.Shared.DeltaV.CartridgeLoader.Cartridges; using Content.Shared.DeltaV.NanoChat; using Content.Shared.NameIdentifier; +using Content.Shared.PDA; +using Robust.Shared.Containers; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -26,10 +28,32 @@ public sealed class NanoChatSystem : SharedNanoChatSystem public override void Initialize() { base.Initialize(); + + SubscribeLocalEvent(OnInserted); + SubscribeLocalEvent(OnRemoved); + SubscribeLocalEvent(OnCardInit); SubscribeLocalEvent(OnMicrowaved, after: [typeof(IdCardSystem)]); } + private void OnInserted(Entity ent, ref EntGotInsertedIntoContainerMessage args) + { + if (args.Container.ID != PdaComponent.PdaIdSlotId) + return; + + ent.Comp.PdaUid = args.Container.Owner; + Dirty(ent); + } + + private void OnRemoved(Entity ent, ref EntGotRemovedFromContainerMessage args) + { + if (args.Container.ID != PdaComponent.PdaIdSlotId) + return; + + ent.Comp.PdaUid = null; + Dirty(ent); + } + private void OnMicrowaved(Entity ent, ref BeingMicrowavedEvent args) { // Skip if the entity was deleted (e.g., by ID card system burning it) diff --git a/Content.Shared/DeltaV/NanoChat/NanoChatCardComponent.cs b/Content.Shared/DeltaV/NanoChat/NanoChatCardComponent.cs index 7e40be79832..03caf4a618c 100644 --- a/Content.Shared/DeltaV/NanoChat/NanoChatCardComponent.cs +++ b/Content.Shared/DeltaV/NanoChat/NanoChatCardComponent.cs @@ -49,4 +49,10 @@ public sealed partial class NanoChatCardComponent : Component /// [DataField] public bool NotificationsMuted; + + /// + /// The PDA that this card is currently inserted to. + /// + [DataField] + public EntityUid? PdaUid = null; } From 96bf27a99d11bd2eb07353268a8dcf82e582566f Mon Sep 17 00:00:00 2001 From: Angelo Fallaria Date: Mon, 6 Jan 2025 19:44:11 +0800 Subject: [PATCH 02/14] Use correct title for editing a contact --- .../DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml b/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml index 76a8513796b..11c6ed4787d 100644 --- a/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml +++ b/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml @@ -1,5 +1,5 @@ From 7755048ed60d9b2e3557ab1853a2c5feae409709 Mon Sep 17 00:00:00 2001 From: Angelo Fallaria Date: Tue, 7 Jan 2025 01:56:22 +0800 Subject: [PATCH 03/14] rename Edit Chat 'Create' button to 'Confirm' --- .../DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml | 4 ++-- .../DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml.cs | 4 ++-- .../Locale/en-US/deltav/cartridge-loader/cartridges.ftl | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml b/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml index 11c6ed4787d..3b229e824a8 100644 --- a/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml +++ b/Content.Client/DeltaV/CartridgeLoader/Cartridges/EditChatPopup.xaml @@ -42,8 +42,8 @@ Text="{Loc nano-chat-cancel}" StyleClasses="OpenRight" MinSize="80 0" /> -