diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index d255a0227..f0d028155 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -252,7 +252,7 @@ namespace ArchiSteamFarm { } internal sealed class NotificationsCallback : CallbackMsg { - internal readonly HashSet Notifications; + internal readonly Dictionary Notifications; internal NotificationsCallback(JobID jobID, CMsgClientUserNotifications msg) { if ((jobID == null) || (msg == null)) { @@ -262,24 +262,22 @@ namespace ArchiSteamFarm { JobID = jobID; // We might get null body here, and that means there are no notifications related to trading - Dictionary notificationsMap = new Dictionary(1) { - { ENotification.Trading, 0 } - }; + Notifications = new Dictionary(1) { { ENotification.Trading, 0 } }; - if (msg.notifications != null) { - foreach (CMsgClientUserNotifications.Notification notification in msg.notifications) { - ENotification type = (ENotification) notification.user_notification_type; - - if (type == ENotification.Unknown) { - ASF.ArchiLogger.LogNullError(nameof(notification.user_notification_type)); - continue; - } - - notificationsMap[type] = notification.count; - } + if (msg.notifications == null) { + return; } - Notifications = new HashSet(notificationsMap.Select(kv => new Notification(kv.Key, kv.Value))); + foreach (CMsgClientUserNotifications.Notification notification in msg.notifications) { + ENotification type = (ENotification) notification.user_notification_type; + + if (type == ENotification.Unknown) { + ASF.ArchiLogger.LogNullError(nameof(notification.user_notification_type)); + continue; + } + + Notifications[type] = notification.count; + } } internal NotificationsCallback(JobID jobID, CMsgClientItemAnnouncements msg) { @@ -288,21 +286,7 @@ namespace ArchiSteamFarm { } JobID = jobID; - Notifications = new HashSet { new Notification(ENotification.Items, msg.count_new_items) }; - } - - internal sealed class Notification { - internal readonly uint Count; - internal readonly ENotification Type; - - internal Notification(ENotification type, uint count = 0) { - if (type == ENotification.Unknown) { - throw new ArgumentNullException(nameof(type)); - } - - Type = type; - Count = count; - } + Notifications = new Dictionary(1) { { ENotification.Items, msg.count_new_items } }; } internal enum ENotification : byte { diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 22c0e046f..64508f55e 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -2035,11 +2035,11 @@ namespace ArchiSteamFarm { return; } - foreach (ArchiHandler.NotificationsCallback.Notification notification in callback.Notifications) { - switch (notification.Type) { + foreach (KeyValuePair notification in callback.Notifications) { + switch (notification.Key) { case ArchiHandler.NotificationsCallback.ENotification.Items: - bool newItems = notification.Count > ItemsCount; - ItemsCount = notification.Count; + bool newItems = notification.Value > ItemsCount; + ItemsCount = notification.Value; if (newItems) { CardsFarmer.OnNewItemsNotification().Forget(); @@ -2051,8 +2051,8 @@ namespace ArchiSteamFarm { break; case ArchiHandler.NotificationsCallback.ENotification.Trading: - bool newTrades = notification.Count > TradesCount; - TradesCount = notification.Count; + bool newTrades = notification.Value > TradesCount; + TradesCount = notification.Value; if (newTrades) { Trading.OnNewTrade().Forget(); @@ -2060,7 +2060,7 @@ namespace ArchiSteamFarm { break; default: - ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(notification.Type), notification.Type)); + ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(notification.Key), notification.Key)); break; } }