diff --git a/Libraries/Core/Helpers/NotificationSendHelper.cs b/Libraries/Core/Helpers/NotificationSendHelper.cs index b31b4fdb..4c676eb6 100644 --- a/Libraries/Core/Helpers/NotificationSendHelper.cs +++ b/Libraries/Core/Helpers/NotificationSendHelper.cs @@ -14,7 +14,8 @@ public class NotificationSendHelper( IWebSocketConnectionHandler _sptWebSocketConnectionHandler, HashUtil _hashUtil, SaveServer _saveServer, - NotificationService _notificationService + NotificationService _notificationService, + TimeUtil _timeUtil ) { /// @@ -47,7 +48,28 @@ public class NotificationSendHelper( string messageText, MessageType messageType) { - throw new NotImplementedException(); + var dialog = GetDialog(sessionId, messageType, senderDetails); + + dialog.New += 1; + Message message = new Message { + Id = _hashUtil.Generate(), + UserId = dialog.Id, + MessageType = messageType, + DateTime = _timeUtil.GetTimeStamp(), + Text = messageText, + HasRewards = null, + RewardCollected = null, + Items = null, + }; + dialog.Messages.Add(message); + + WsChatMessageReceived notification = new WsChatMessageReceived { + EventType = NotificationEventType.new_message, + EventIdentifier = message.Id, + DialogId = message.UserId, + Message = message, + }; + SendMessage(sessionId, notification); } /// @@ -59,6 +81,26 @@ public class NotificationSendHelper( /// Dialogue protected Models.Eft.Profile.Dialogue GetDialog(string sessionId, MessageType messageType, UserDialogInfo senderDetails) { - throw new NotImplementedException(); + // Use trader id if sender is trader, otherwise use nickname + var key = senderDetails.Id; + var dialogueData = _saveServer.GetProfile(sessionId).DialogueRecords; + var isNewDialogue = dialogueData.ContainsKey(key); + var dialogue = dialogueData[key]; + + // Existing dialog not found, make new one + if (isNewDialogue) { + dialogue = new Models.Eft.Profile.Dialogue { + Id = key, + Type = messageType, + Messages = [], + Pinned = false, + New = 0, + AttachmentsNew = 0, + Users = senderDetails.Info.MemberCategory == MemberCategory.Trader ? null : [senderDetails], + }; + + dialogueData[key] = dialogue; + } + return dialogue; } } diff --git a/Libraries/Core/Utils/CompareUtil.cs b/Libraries/Core/Utils/CompareUtil.cs index 6c3cd5ad..4d3892b0 100644 --- a/Libraries/Core/Utils/CompareUtil.cs +++ b/Libraries/Core/Utils/CompareUtil.cs @@ -5,8 +5,55 @@ namespace Core.Utils; [Injectable] public class CompareUtil { + private readonly HashSet typesToCheckAgainst = [ + "string", + "number", + "boolean", + "bigint", + "symbol", + "undefined", + "null", + ]; + + /** + * This function does an object comparison, equivalent to applying reflections + * and scanning for all possible properties including arrays. + * @param v1 value 1 to compare + * @param v2 value 2 to compare + * @returns true if equal, false if not + */ public bool RecursiveCompare(object v1, object v2) { + // const typeOfv1 = typeof v1; + // const typeOfv2 = typeof v2; + // if (CompareUtil.typesToCheckAgainst.has(typeOfv1)) { + // return v1 === v2; + // } + // if (typeOfv1 === "object" && typeOfv2 === "object") { + // if (Array.isArray(v1)) { + // if (!Array.isArray(v2)) { + // return false; + // } + // const arr1 = v1 as Array; + // const arr2 = v2 as Array; + // if (arr1.length !== arr2.length) { + // return false; + // } + // return arr1.every((vOf1) => arr2.find((vOf2) => this.recursiveCompare(vOf1, vOf2))); + // } + // for (const propOf1 in v1) { + // if (v2[propOf1] === undefined) { + // return false; + // } + // return this.recursiveCompare(v1[propOf1], v2[propOf1]); + // } + // } + // if (typeOfv1 === typeOfv2) { + // return v1 === v2; + // } + // + // return false; + throw new NotImplementedException(); } } diff --git a/Server/Properties/launchSettings.json b/Server/Properties/launchSettings.json index 541f3861..88fa70a7 100644 --- a/Server/Properties/launchSettings.json +++ b/Server/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Spt Server Debug": { "commandName": "Project", - "hotReloadEnabled": true, + "hotReloadEnabled": false, "workingDirectory": "$(OutputPath)" } }