From 79cc9e325200aace3f3be40e608bcba0dad775be Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 8 Jul 2025 15:49:05 +0100 Subject: [PATCH] Fixed boxing issues and cleand up MailSendService --- .../Models/Eft/Profile/SptProfile.cs | 4 +-- .../Services/MailSendService.cs | 31 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/Profile/SptProfile.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/Profile/SptProfile.cs index 46bf7fe4..e72ecc28 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/Profile/SptProfile.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/Profile/SptProfile.cs @@ -269,10 +269,10 @@ public record Message public Dictionary? ExtensionData { get; set; } [JsonPropertyName("_id")] - public string? Id { get; set; } + public MongoId Id { get; set; } [JsonPropertyName("uid")] - public string? UserId { get; set; } + public MongoId UserId { get; set; } [JsonPropertyName("type")] public MessageType? MessageType { get; set; } diff --git a/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs b/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs index bbc38de8..ecac8aea 100644 --- a/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs @@ -187,7 +187,7 @@ public class MailSendService( RecipientId = sessionId, Sender = MessageType.SystemMessage, MessageText = message, - Items = new List(), + Items = [], }; // add items to message @@ -228,7 +228,7 @@ public class MailSendService( RecipientId = sessionId, Sender = MessageType.SystemMessage, TemplateId = messageLocaleId, - Items = new List(), + Items = [], }; // add items to message @@ -268,7 +268,7 @@ public class MailSendService( Sender = MessageType.UserMessage, SenderDetails = senderDetails, MessageText = message, - Items = new List(), + Items = [], }; // add items to message @@ -337,7 +337,7 @@ public class MailSendService( message.MessageType = MessageType.MessageWithItems; // Should prevent getting the same notification popup twice } - // Send message off to player so they get it in client + // Send notification to player informing them of mail delivery var notificationMessage = notifierHelper.CreateNewMessageNotification(message); notificationSendHelper.SendMessage(messageDetails.RecipientId, notificationMessage); } @@ -368,7 +368,7 @@ public class MailSendService( Id = new MongoId(), DateTime = timeUtil.GetTimeStamp(), HasRewards = false, - UserId = playerProfile.CharacterData.PmcData.Id, + UserId = playerProfile.CharacterData.PmcData.Id.Value, MessageType = MessageType.UserMessage, RewardCollected = false, Text = message, @@ -382,7 +382,7 @@ public class MailSendService( /// ID of dialog that will hold the message /// Various details on what the message must contain/do /// Message - private Message CreateDialogMessage(string dialogId, SendMessageDetails messageDetails) + private Message CreateDialogMessage(MongoId dialogId, SendMessageDetails messageDetails) { Message message = new() { @@ -394,7 +394,7 @@ public class MailSendService( TemplateId = messageDetails.TemplateId, HasRewards = false, RewardCollected = false, - SystemData = messageDetails.SystemData is not null ? messageDetails.SystemData : null, + SystemData = messageDetails.SystemData, ProfileChangeEvents = messageDetails.ProfileChangeEvents?.Count == 0 ? messageDetails.ProfileChangeEvents @@ -425,7 +425,7 @@ public class MailSendService( /// The ID of the message to reply to /// The ID of the dialogue (traderId or profileId) /// A new instance with data from the found message, otherwise undefined - protected ReplyTo? GetMessageToReplyTo(string recipientId, string replyToId, string dialogueId) + protected ReplyTo? GetMessageToReplyTo(MongoId recipientId, string replyToId, string dialogueId) { var currentDialogue = dialogueHelper.GetDialogueFromProfile(recipientId, dialogueId); @@ -511,8 +511,8 @@ public class MailSendService( // Prep return object itemsToSendToPlayer = new MessageItems { - Stash = parentItem.ParentId, - Data = new List(), + Stash = new MongoId(parentItem.ParentId), + Data = [], }; // Ensure Ids are unique and cont collide with items in player inventory later @@ -521,8 +521,7 @@ public class MailSendService( // Ensure item exits in items db foreach (var reward in messageDetails.Items) { - var itemTemplate = items[reward.Template]; - if (itemTemplate is null) + if (!items.TryGetValue(reward.Template, out var itemTemplate)) { logger.Error( serverLocalisationService.GetText( @@ -596,7 +595,7 @@ public class MailSendService( /// /// Possible items to choose from /// Chosen 'primary' item - private Item GetBaseItemFromRewards(List? items) + protected Item? GetBaseItemFromRewards(List items) { // Only one item in reward, return it if (items?.Count == 1) @@ -604,14 +603,14 @@ public class MailSendService( return items[0]; } - // Find first item with slotId that indicates its a 'base' item + // Find first item with slotId that indicates it's a 'base' item var item = items.FirstOrDefault(x => _slotNames.Contains(x.SlotId ?? "")); if (item is not null) { return item; } - // Not a singlular item + no items have a hideout/main slotid + // Not a singular item + no items have a hideout/main slotId // Look for first item without parent id item = items.FirstOrDefault(x => x.ParentId is null); if (item is not null) @@ -620,7 +619,7 @@ public class MailSendService( } // Just return first item in array - return items[0]; + return items.FirstOrDefault(); } ///