Skip to content

Commit

Permalink
Automatically detect dismissible site-wide drops campaigns (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda authored Oct 25, 2024
1 parent 0f12970 commit aa94f79
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
public class DropCampaignSummary extends GQLType{
@JsonProperty("includesSubRequirement")
private boolean includesSubRequirement;
@JsonProperty("isPermanentlyDismissible")
private boolean permanentlyDismissible;
@JsonProperty("isSitewide")
private boolean sitewide;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.setdropscommunityhighlighttohidden.SetDropsCommunityHighlightToHiddenData;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.Channel;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.DropCampaign;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.DropCampaignSummary;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.SetDropsCommunityHighlightToHiddenPayload;
import fr.rakambda.channelpointsminer.miner.factory.TimeFactory;
import fr.rakambda.channelpointsminer.miner.log.LogContext;
Expand All @@ -23,11 +24,6 @@
@Log4j2
@RequiredArgsConstructor
public class UpdateStreamInfo implements Runnable{
private static final Collection<String> DISMISSIBLE_CAMPAIGNS = Set.of(
"dc4ff0b4-4de0-11ef-9ec3-621fb0811846",
"cbc3c726-8c0a-11ef-9b38-1ede7ff66562"
);

@NotNull
private final IMiner miner;

Expand Down Expand Up @@ -154,7 +150,7 @@ private void updateCampaigns(@NotNull Streamer streamer){
.map(DropsHighlightServiceAvailableDropsData::getChannel)
.map(Channel::getViewerDropCampaigns)
.flatMap(Collection::stream)
.filter(dropCampaign -> DISMISSIBLE_CAMPAIGNS.contains(dropCampaign.getId()))
.filter(dropCampaign -> isDismissibleGlobalCompaign(dropCampaign))
.forEach(dropCampaign -> dismissCampaign(miner, streamer, dropCampaign));
}
}
Expand All @@ -163,6 +159,12 @@ private void updateCampaigns(@NotNull Streamer streamer){
}
}

private boolean isDismissibleGlobalCompaign(@NotNull DropCampaign dropCampaign){
return Optional.ofNullable(dropCampaign.getSummary())
.map(summary -> summary.isSitewide() && summary.isPermanentlyDismissible())
.orElse(false);
}

private void dismissCampaign(@NotNull IMiner miner, @NotNull Streamer streamer, @NotNull DropCampaign dropCampaign){
var result = miner.getGqlApi().setDropsCommunityHighlightToHidden(streamer.getId(), dropCampaign.getId());
var isHidden = result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void nominalWithDrops(UnirestMock unirest){
.build()))
.build()))
.summary(DropCampaignSummary.builder()
.sitewide(true)
.permanentlyDismissible(true)
.includesSubRequirement(true)
.build())
.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.Channel;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.ChatRoomBanStatus;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.DropCampaign;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.DropCampaignSummary;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.StreamPlaybackAccessToken;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.types.User;
import fr.rakambda.channelpointsminer.miner.api.gql.gql.data.videoplayerstreaminfooverlaychannel.VideoPlayerStreamInfoOverlayChannelData;
Expand Down Expand Up @@ -91,6 +92,8 @@ class UpdateStreamInfoTest{
private Channel channel;
@Mock
private DropCampaign dropCampaign;
@Mock
private DropCampaignSummary dropCampaignSummary;

private URL spadeUrl;
private URL m3u8Url;
Expand Down Expand Up @@ -444,6 +447,10 @@ void updateWithDataStreamingUpdateCampaignDismissibleAndSettingActivated(){
when(gqlApi.dropsHighlightServiceAvailableDrops(STREAMER_ID)).thenReturn(Optional.of(dropsHighlightServiceAvailableDrops));
when(gqlApi.chatRoomBanStatus(STREAMER_ID, ACCOUNT_ID)).thenReturn(Optional.of(gqlResponseChatRoomBanStatus));

when(dropCampaign.getSummary()).thenReturn(dropCampaignSummary);
when(dropCampaignSummary.isSitewide()).thenReturn(true);
when(dropCampaignSummary.isPermanentlyDismissible()).thenReturn(true);

assertDoesNotThrow(() -> tested.run());

verify(gqlApi).videoPlayerStreamInfoOverlayChannel(STREAMER_USERNAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
}
],
"summary": {
"isPermanentlyDismissible": true,
"isSitewide": true,
"includesSubRequirement": true,
"__typename": "DropCampaignSummary"
},
Expand Down

0 comments on commit aa94f79

Please sign in to comment.