aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api/webhooks
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-07-19 13:25:06 +0300
committerGravatar Vitaly Takmazov2024-07-20 22:58:16 +0300
commite14d4612d313b7424b2163ba247843655c4dfca1 (patch)
treee9cf4ce93be54f77fe500019325e3d3463bab2f6 /src/main/java/com/juick/www/api/webhooks
parent5c71aa619e5e64babaf52aec7c01204ed02ffe69 (diff)
Update premium status on login
Diffstat (limited to 'src/main/java/com/juick/www/api/webhooks')
-rw-r--r--src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java24
1 files changed, 1 insertions, 23 deletions
diff --git a/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java b/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java
index d8467ff0..c05585ac 100644
--- a/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java
+++ b/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java
@@ -67,28 +67,6 @@ public class PatreonWebhook {
var updatedEmails = StreamSupport.stream(json.get("included").spliterator(), false)
.filter(node -> node.get("type").textValue().equals("user"))
.map(node -> node.get("attributes").get("email").textValue()).toList();
- var campainsResponse = patreonService.fetchCampaigns();
- List<String> activeEmails = new ArrayList<>();
- campainsResponse.forEach(campaign -> {
- var pledgesResponse = patreonService.fetchPledges(campaign);
- pledgesResponse.forEach(pledge -> {
- logger.info("Pledge email: {}", pledge);
- activeEmails.add(pledge);
- });
- });
- activeEmails.forEach(email -> {
- var user = userService.getUserByEmail(email);
- if (!user.isAnonymous()) {
- userService.setPremium(user.getUid(), true);
- }
- });
- updatedEmails.stream().filter(email -> !activeEmails.contains(email))
- .forEach(deleted -> {
- var user = userService.getUserByEmail(deleted);
- if (!user.isAnonymous()) {
- logger.info("User is not a patron anymore: {}", deleted);
- userService.setPremium(user.getUid(), false);
- }
- });
+ patreonService.updateStatus(updatedEmails);
}
}