aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api/Notifications.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-04 03:38:19 +0300
committerGravatar Vitaly Takmazov2023-01-04 05:46:16 +0300
commitc471503ede9aad91193ff6f93966196e6aff15d6 (patch)
tree8c70c8f58b140465be651cd019f26eadd476711f /src/main/java/com/juick/www/api/Notifications.java
parent086d9a7625bfc5a386f5b1028d364fb546c2fa9d (diff)
OAuth authentication for Mastodon and ActivityPub C2S
Diffstat (limited to 'src/main/java/com/juick/www/api/Notifications.java')
-rw-r--r--src/main/java/com/juick/www/api/Notifications.java88
1 files changed, 25 insertions, 63 deletions
diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java
index 09dad9e2..32ba3dc1 100644
--- a/src/main/java/com/juick/www/api/Notifications.java
+++ b/src/main/java/com/juick/www/api/Notifications.java
@@ -17,36 +17,19 @@
package com.juick.www.api;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import javax.inject.Inject;
-
-import com.juick.model.AnonymousUser;
-import com.juick.model.ExternalToken;
-import com.juick.model.Message;
-import com.juick.model.Status;
-import com.juick.model.User;
-import com.juick.service.MessagesService;
-import com.juick.service.PushQueriesService;
-import com.juick.service.SubscriptionService;
-import com.juick.service.TelegramService;
-import com.juick.service.UserService;
-import com.juick.service.security.annotation.Visitor;
+import com.juick.model.*;
+import com.juick.service.*;
import com.juick.util.HttpBadRequestException;
import com.juick.util.HttpForbiddenException;
-
+import io.swagger.v3.oas.annotations.Hidden;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
-import io.swagger.v3.oas.annotations.Hidden;
+import javax.inject.Inject;
+import java.util.Collections;
+import java.util.List;
/**
* Created by vitalyster on 24.10.2016.
@@ -88,7 +71,7 @@ public class Notifications {
@Hidden
@RequestMapping(value = "/api/notifications", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<User> doGet(
- @Visitor User visitor,
+ @ModelAttribute(binding = false) User visitor,
@RequestParam(required = false, defaultValue = "0") int uid,
@RequestParam(required = false, defaultValue = "0") int mid,
@RequestParam(required = false, defaultValue = "0") int rid) {
@@ -127,24 +110,17 @@ public class Notifications {
@Hidden
@RequestMapping(value = "/api/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doDelete(
- @Visitor User visitor,
+ @ModelAttribute User visitor,
@RequestBody List<ExternalToken> list) {
if (!visitor.equals(serviceUser)) {
throw new HttpForbiddenException();
}
list.forEach(t -> {
switch (t.type()) {
- case "gcm":
- pushQueriesService.deleteGCMToken(t.token());
- break;
- case "apns":
- pushQueriesService.deleteAPNSToken(t.token());
- break;
- case "mpns":
- pushQueriesService.deleteMPNSToken(t.token());
- break;
- default:
- throw new HttpBadRequestException();
+ case "gcm" -> pushQueriesService.deleteGCMToken(t.token());
+ case "apns" -> pushQueriesService.deleteAPNSToken(t.token());
+ case "mpns" -> pushQueriesService.deleteMPNSToken(t.token());
+ default -> throw new HttpBadRequestException();
}
});
@@ -153,24 +129,17 @@ public class Notifications {
@Hidden
@RequestMapping(value = "/api/notifications/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doDeleteTokens(
- @Visitor User visitor,
+ @ModelAttribute User visitor,
@RequestBody List<ExternalToken> list) {
if (!visitor.equals(serviceUser)) {
throw new HttpForbiddenException();
}
list.forEach(t -> {
switch (t.type()) {
- case "gcm":
- pushQueriesService.deleteGCMToken(t.token());
- break;
- case "apns":
- pushQueriesService.deleteAPNSToken(t.token());
- break;
- case "mpns":
- pushQueriesService.deleteMPNSToken(t.token());
- break;
- default:
- throw new HttpBadRequestException();
+ case "gcm" -> pushQueriesService.deleteGCMToken(t.token());
+ case "apns" -> pushQueriesService.deleteAPNSToken(t.token());
+ case "mpns" -> pushQueriesService.deleteMPNSToken(t.token());
+ default -> throw new HttpBadRequestException();
}
});
@@ -180,21 +149,14 @@ public class Notifications {
@Hidden
@RequestMapping(value = "/api/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doPut(
- @Visitor User visitor,
+ @ModelAttribute User visitor,
@RequestBody List<ExternalToken> list) {
list.forEach(t -> {
switch (t.type()) {
- case "gcm":
- pushQueriesService.addGCMToken(visitor.getUid(), t.token());
- break;
- case "apns":
- pushQueriesService.addAPNSToken(visitor.getUid(), t.token());
- break;
- case "mpns":
- pushQueriesService.addMPNSToken(visitor.getUid(), t.token());
- break;
- default:
- throw new HttpBadRequestException();
+ case "gcm" -> pushQueriesService.addGCMToken(visitor.getUid(), t.token());
+ case "apns" -> pushQueriesService.addAPNSToken(visitor.getUid(), t.token());
+ case "mpns" -> pushQueriesService.addMPNSToken(visitor.getUid(), t.token());
+ default -> throw new HttpBadRequestException();
}
});
return Status.OK;
@@ -203,7 +165,7 @@ public class Notifications {
@Deprecated
@RequestMapping(value = "/api/android/register", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doAndroidRegister(
- @Visitor User visitor,
+ @ModelAttribute User visitor,
@RequestParam(name = "regid") String regId) {
pushQueriesService.addGCMToken(visitor.getUid(), regId);
return Status.OK;
@@ -212,7 +174,7 @@ public class Notifications {
@Deprecated
@RequestMapping(value = "/api/winphone/register", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doWinphoneRegister(
- @Visitor User visitor,
+ @ModelAttribute User visitor,
@RequestParam(name = "url") String regId) {
pushQueriesService.addMPNSToken(visitor.getUid(), regId);
return Status.OK;