aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api/webhooks
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www/api/webhooks')
-rw-r--r--src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java26
-rw-r--r--src/main/java/com/juick/www/api/webhooks/TelegramWebhook.java2
-rw-r--r--src/main/java/com/juick/www/api/webhooks/VkWebhook.java8
3 files changed, 7 insertions, 29 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 99999838..c05585ac 100644
--- a/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java
+++ b/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java
@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -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);
}
}
diff --git a/src/main/java/com/juick/www/api/webhooks/TelegramWebhook.java b/src/main/java/com/juick/www/api/webhooks/TelegramWebhook.java
index 76b38168..4636e9f6 100644
--- a/src/main/java/com/juick/www/api/webhooks/TelegramWebhook.java
+++ b/src/main/java/com/juick/www/api/webhooks/TelegramWebhook.java
@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
diff --git a/src/main/java/com/juick/www/api/webhooks/VkWebhook.java b/src/main/java/com/juick/www/api/webhooks/VkWebhook.java
index 9e4477b1..d69d00be 100644
--- a/src/main/java/com/juick/www/api/webhooks/VkWebhook.java
+++ b/src/main/java/com/juick/www/api/webhooks/VkWebhook.java
@@ -29,7 +29,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@@ -62,9 +62,9 @@ public class VkWebhook {
if (secretKey.equals(secret)) {
if (type.startsWith("donut_")) {
var vkId = json.get("object").get("user_id").asLong(0);
- var userId = userService.getUIDbyVKID(vkId);
- if (userId > 0) {
- vkService.updatePremiumStatus(userId);
+ var user = userService.getUserByVKID(vkId);
+ if (user.isPresent()) {
+ vkService.updatePremiumStatus(user.get().getUid());
}
}
return "ok";