From 730c1170a063cee41313866f1b2e82f778f5b535 Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 17 Jan 2025 11:14:22 +0000 Subject: [PATCH] Updated `CreateDialogMessage` implementation --- Core/Models/Spt/Dialog/SendMessageDetails.cs | 6 ++- Core/Services/MailSendService.cs | 47 ++++++++++++++++---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Core/Models/Spt/Dialog/SendMessageDetails.cs b/Core/Models/Spt/Dialog/SendMessageDetails.cs index c09793dc..0f9d0d4a 100644 --- a/Core/Models/Spt/Dialog/SendMessageDetails.cs +++ b/Core/Models/Spt/Dialog/SendMessageDetails.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Core.Models.Eft.Common.Tables; using Core.Models.Eft.Profile; using Core.Models.Enums; @@ -78,6 +78,10 @@ public class SendMessageDetails /// [JsonPropertyName("profileChangeEvents")] public List? ProfileChangeEvents { get; set; } + + /** Optional - the MongoID of the dialogue message to reply to */ + [JsonPropertyName("replyTo")] + public string? ReplyTo { get; set; } } public class ProfileChangeEvent diff --git a/Core/Services/MailSendService.cs b/Core/Services/MailSendService.cs index c501d205..3ee5033d 100644 --- a/Core/Services/MailSendService.cs +++ b/Core/Services/MailSendService.cs @@ -366,18 +366,49 @@ public class MailSendService ProfileChangeEvents = (messageDetails.ProfileChangeEvents?.Count == 0) ? messageDetails.ProfileChangeEvents : null }; - // Clean up empty system data - // if (message.SystemData is null) { - // delete message.SystemData; - // } - - // Clean up empty template id - // if (message.TemplateId is null) - // delete message.templateId; + // handle replyTo + if (messageDetails.ReplyTo is not null) + { + var replyMessage = GetMessageToReplyTo(messageDetails.RecipientId, messageDetails.ReplyTo, dialogId); + if (replyMessage is not null) + { + message.ReplyTo = replyMessage; + } + } return message; } + /** + * @param recipientId The id of the recipient + * @param replyToId The id of the message to reply to + * @param dialogueId The id of the dialogue (traderId or profileId) + * @returns A new instance with data from the found message, otherwise undefined + */ + protected ReplyTo? GetMessageToReplyTo(string recipientId, string replyToId, string dialogueId) { + var currentDialogue = _dialogueHelper.GetDialogueFromProfile(recipientId, dialogueId); + + if (currentDialogue is null) { + _logger.Warning($"Unable to find dialogue: {dialogueId} from sender"); + return null; + } + + var messageToReplyTo = currentDialogue.Messages?.FirstOrDefault(message => message.Id == replyToId); + if (messageToReplyTo is null) + { + return null; + } + + return new ReplyTo + { + Id = messageToReplyTo.Id, + DateTime = messageToReplyTo.DateTime, + MessageType = messageToReplyTo.MessageType, + UserId = messageToReplyTo.UserId, + Text = messageToReplyTo.Text + }; + } + /** * Add items to message and adjust various properties to reflect the items being added * @param message Message to add items to