Skip to content

Commit

Permalink
Render continuing anonymous gift subs correctly (#1206)
Browse files Browse the repository at this point in the history
* Recognize continuing anonymous gifts separately from continuing regular gifts

* Update tests

* Render continuing anonymous gift subs correctly

* Fix comment
  • Loading branch information
ScrubN authored Sep 3, 2024
1 parent 7b0dd50 commit cd60424
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion TwitchDownloaderCore.Tests/ToolTests/HighlightIconsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ private static Comment CreateCommentWithMessage(string viewerDisplayName, string
// Special case, in separate method.
// ContinuingGift
[InlineData(
"{\"body\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"}],\"user_color\":\"#8A2BE2\",\"emoticons\":[]}",
"{\"body\":\"viewer8 is continuing the Gift Sub they got from viewer9! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is continuing the Gift Sub they got from viewer9! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"}],\"user_color\":\"#8A2BE2\",\"emoticons\":[]}",
HighlightType.ContinuingGift)]
// ContinuingAnonymousGift
[InlineData(
"{\"body\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"}],\"user_color\":\"#8A2BE2\",\"emoticons\":[]}",
HighlightType.ContinuingAnonymousGift)]
// PayingForward
[InlineData(
"{\"body\":\"viewer8 is paying forward the Gift they got from an anonymous gifter to the community! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is paying forward the Gift they got from an anonymous gifter to the community! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"},{\"_id\":\"bits\",\"version\":\"100\"}],\"user_color\":null,\"emoticons\":[]}",
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ private void DrawAccentedMessage(Comment comment, List<(SKImageInfo info, SKBitm
case HighlightType.GiftedMany:
case HighlightType.GiftedSingle:
case HighlightType.GiftedAnonymous:
case HighlightType.ContinuingAnonymousGift:
DrawGiftMessage(comment, sectionImages, emotePositionList, ref drawPos, defaultPos, highlightIcon, iconPoint);
break;
case HighlightType.ChannelPointHighlight:
Expand Down
10 changes: 8 additions & 2 deletions TwitchDownloaderCore/Tools/HighlightIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum HighlightType
GiftedMany,
GiftedSingle,
ContinuingGift,
ContinuingAnonymousGift,
GiftedAnonymous,
PayingForward,
ChannelPointHighlight,
Expand Down Expand Up @@ -104,8 +105,13 @@ public static HighlightType GetHighlightType(Comment comment)
if (bodyWithoutName.StartsWith(" gifted a Tier"))
return HighlightType.GiftedSingle;

if (bodyWithoutName.StartsWith(" is continuing the Gift Sub"))
if (bodyWithoutName.StartsWith(" is continuing the Gift Sub they got from"))
{
if (bodyWithoutName.EndsWith("from an anonymous user! "))
return HighlightType.ContinuingAnonymousGift;

return HighlightType.ContinuingGift;
}

if (bodyWithoutName.StartsWith(" is paying forward the Gift they got from"))
return HighlightType.PayingForward;
Expand Down Expand Up @@ -162,7 +168,7 @@ public SKImage GetHighlightIcon(HighlightType highlightType, SKColor textColor)
HighlightType.SubscribedPrime => _subscribedPrimeIcon ??= GenerateSvgIcon(SUBSCRIBED_PRIME_ICON_SVG, _purple),
HighlightType.GiftedSingle => _giftSingleIcon ??= GenerateSvgIcon(GIFTED_SINGLE_ICON_SVG, textColor),
HighlightType.GiftedMany => _giftManyIcon ??= GenerateGiftedManyIcon(),
HighlightType.GiftedAnonymous => _giftAnonymousIcon ??= GenerateSvgIcon(GIFTED_ANONYMOUS_ICON_SVG, textColor),
HighlightType.GiftedAnonymous or HighlightType.ContinuingAnonymousGift => _giftAnonymousIcon ??= GenerateSvgIcon(GIFTED_ANONYMOUS_ICON_SVG, textColor),
HighlightType.BitBadgeTierNotification => _bitBadgeTierNotificationIcon ??= GenerateSvgIcon(BIT_BADGE_TIER_NOTIFICATION_ICON_SVG, textColor),
HighlightType.WatchStreak => _watchStreakIcon ??= GenerateSvgIcon(WATCH_STREAK_ICON_SVG, textColor),
HighlightType.CharityDonation => _charityDonationIcon ??= GenerateSvgIcon(CHARITY_DONATION_ICON_SVG, textColor),
Expand Down

0 comments on commit cd60424

Please sign in to comment.