Skip to content

Commit 9cbee9e

Browse files
Erik Bylundkirre-bylund
authored andcommitted
fix: Change notification lookup table to store verifying info
1 parent 51eba76 commit 9cbee9e

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Runtime/Game/Requests/NotificationRequests.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ public class LootLockerListNotificationsResponse : LootLockerResponse
551551
/// Pagination data for this set of notifications
552552
/// </summary>
553553
public LootLockerExtendedPagination Pagination { get; set; }
554+
554555
/// <summary>
555556
/// Will mark all unread notifications in this response as read in LootLocker (though remember to check the response if it succeeded)
556557
/// </summary>
@@ -578,21 +579,25 @@ public void MarkUnreadNotificationsAsRead(Action<LootLockerReadNotificationsResp
578579
public bool TryGetNotificationsByIdentifyingValue(string identifyingValue, out LootLockerNotification[] notifications)
579580
{
580581
notifications = null;
581-
if (!NotificationLookupTable.TryGetValue(identifyingValue, out var indexes))
582+
if (!NotificationLookupTable.TryGetValue(identifyingValue, out var lookupEntries))
582583
{
583584
return false;
584585
}
585586

586587
var foundNotifications = new List<LootLockerNotification>();
587-
foreach (var index in indexes)
588+
foreach (var lookupEntry in lookupEntries)
588589
{
589-
if (index < 0 || index >= Notifications.Length)
590+
if (lookupEntry.NotificationIndex < 0 || lookupEntry.NotificationIndex >= Notifications.Length)
590591
{
591592
// The notifications array is not the same as when the lookup table was populated
592593
return false;
593594
}
594-
var notification = Notifications[index];
595-
if (!notification.Content.ContextAsDictionary.ContainsValue(identifyingValue))
595+
var notification = Notifications[lookupEntry.NotificationIndex];
596+
if (notification == null
597+
|| !notification.Id.Equals(lookupEntry.NotificationId, StringComparison.OrdinalIgnoreCase)
598+
|| !notification.Content.ContextAsDictionary.TryGetValue(lookupEntry.IdentifyingKey, out string actualContextValue)
599+
|| actualContextValue == null
600+
|| !actualContextValue.Equals(identifyingValue, StringComparison.OrdinalIgnoreCase))
596601
{
597602
// The notifications array is not the same as when the lookup table was populated
598603
return false;
@@ -647,21 +652,36 @@ public void PopulateConvenienceStructures()
647652

648653
if (identifyingKey != null && notification.Content.ContextAsDictionary.TryGetValue(identifyingKey, out var value) && value != null)
649654
{
655+
var lookupEntry = new LootLockerNotificationLookupTableEntry
656+
{
657+
IdentifyingKey = identifyingKey,
658+
NotificationId = notification.Id,
659+
NotificationIndex = i
660+
};
650661
if (NotificationLookupTable.TryGetValue(value, out var indexes))
651662
{
652-
indexes.Add(i);
663+
indexes.Add(lookupEntry);
653664
}
654665
else
655666
{
656-
NotificationLookupTable.Add(value, new List<int> { i });
667+
NotificationLookupTable.Add(value, new List<LootLockerNotificationLookupTableEntry> { lookupEntry });
657668
}
658669
}
659670
++i;
660671
}
661672
}
662673

663674
private readonly List<string> UnreadNotifications = new List<string>();
664-
private readonly Dictionary<string, List<int>> NotificationLookupTable = new Dictionary<string, List<int>>();
675+
676+
/// <summary>
677+
/// </summary>
678+
private struct LootLockerNotificationLookupTableEntry
679+
{
680+
public string IdentifyingKey { get; set; }
681+
public string NotificationId { get; set; }
682+
public int NotificationIndex { get; set; }
683+
};
684+
private readonly Dictionary<string, List<LootLockerNotificationLookupTableEntry>> NotificationLookupTable = new Dictionary<string, List<LootLockerNotificationLookupTableEntry>>();
665685
};
666686

667687
/// <summary>

0 commit comments

Comments
 (0)