Skip to content

Commit

Permalink
SteamWishlistDiscountNotifier: Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
darklinkpower committed Dec 3, 2024
1 parent 83dc13f commit a6373e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public List<CWishlistGetWishlistSortedFilteredResponseWishlistItem> GetWishlist(
var allWishlistItems = new List<CWishlistGetWishlistSortedFilteredResponseWishlistItem>();
var startIndex = 0;
const int pageSize = 2000;

while (true)
{
var requestData = new CWishlistGetWishlistSortedFilteredRequest
Expand Down Expand Up @@ -81,8 +80,14 @@ public List<CWishlistGetWishlistSortedFilteredResponseWishlistItem> GetWishlist(
}

var response = ProtobufUtilities.DeserializeResponse<CWishlistGetWishlistSortedFilteredResponse>(requestResult.Content);
allWishlistItems.AddRange(response.Items);
if (response.Items.Count < pageSize)

// Steam returns the full wishlist list, but the StoreId of items will be null if they fall outside the requested index range.
// In this method, we ensure that only the items within the current range (defined by startIndex and pageSize) are added to the result list.
// We continue to request additional pages until all items in the wishlist are fetched.
var itemsToAdd = response.Items.Skip(startIndex).Take(pageSize).ToList();
allWishlistItems.AddRange(itemsToAdd);
var totalRequestedRange = startIndex + pageSize;
if (itemsToAdd.Count < pageSize || totalRequestedRange >= response.Items.Count)
{
break;
}
Expand All @@ -94,5 +99,6 @@ public List<CWishlistGetWishlistSortedFilteredResponseWishlistItem> GetWishlist(
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,30 @@ private void UpdateTracketServiceConfig(SteamWishlistDiscountNotifierSettings se

private void WishlistTrackerService_WishlistTrackedItemAdded(object sender, WishlistTrackedItemAddedEventArgs e)
{
var newWishlistItem = e.Item;
if (newWishlistItem.DiscountPct == 0 || !GetShouldDisplayNotification(newWishlistItem))
var addedItem = e.Item;
if (!addedItem.DiscountPct.HasValue ||
addedItem.DiscountPct == 0 ||
_settings.Settings.NotificationMinDiscount > addedItem.DiscountPct ||
!GetShouldDisplayNotification(addedItem))
{
return;
}

var notificationLines = new List<string>
{
string.Format(ResourceProvider.GetString("LOCSteam_Wishlist_Notif_GameOnSaleLabel"), newWishlistItem.Name) + "\n",
string.Format(ResourceProvider.GetString("LOCSteam_Wishlist_Notif_DiscountPercent"), newWishlistItem.DiscountPct ?? 0),
string.Format(ResourceProvider.GetString("LOCSteam_Wishlist_Notif_GameOnSaleLabel"), addedItem.Name) + "\n",
string.Format(ResourceProvider.GetString("LOCSteam_Wishlist_Notif_DiscountPercent"), addedItem.DiscountPct ?? 0),
string.Format("{0} -> {1}",
newWishlistItem.FormattedOriginalPrice ?? "?",
newWishlistItem.FormattedFinalPrice ?? "?")
addedItem.FormattedOriginalPrice ?? "?",
addedItem.FormattedFinalPrice ?? "?")
};

var finalNotificationMessageText = string.Join("\n", notificationLines);
var notificationMessage = new NotificationMessage(
e.Id.ToString(),
finalNotificationMessageText,
NotificationType.Info,
() => OpenDiscountedItemUrl(newWishlistItem.AppId)
() => OpenDiscountedItemUrl(addedItem.AppId)
);

PlayniteApi.Notifications.Add(notificationMessage);
Expand Down Expand Up @@ -179,11 +182,16 @@ private void WishlistTrackerService_WishlistTrackedItemChanged(object sender, Wi
else if (newItem.DiscountPct.HasValue && newItem.DiscountPct > 0)
{
// Item now on discount
if (_settings.Settings.NotificationMinDiscount > newItem.DiscountPct)
{
return;
}

var notificationLines = new List<string>
{
string.Format(ResourceProvider.GetString("LOCSteam_Wishlist_Notif_GameOnSaleLabel"), newItem.Name) + "\n",
string.Format(ResourceProvider.GetString("LOCSteam_Wishlist_Notif_DiscountPercent"), newItem.DiscountPct),
string.Format("{0} -> {1}", oldItem.FormattedFinalPrice, newItem.FormattedFinalPrice)
string.Format("{0} -> {1}", newItem.FormattedFinalPrice, newItem.FormattedFinalPrice)
};

PlayniteApi.Notifications.Add(new NotificationMessage(
Expand Down

0 comments on commit a6373e0

Please sign in to comment.