diff options
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Service.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Service.java b/juick-server/src/main/java/com/juick/server/api/Service.java index 41f05f97..2351c076 100644 --- a/juick-server/src/main/java/com/juick/server/api/Service.java +++ b/juick-server/src/main/java/com/juick/server/api/Service.java @@ -3,6 +3,7 @@ package com.juick.server.api; import com.juick.User; import com.juick.server.CommandsManager; import com.juick.server.EmailManager; +import com.juick.server.ServerManager; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.UserUtils; import com.juick.service.EmailService; @@ -17,8 +18,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; import springfox.documentation.annotations.ApiIgnore; import javax.inject.Inject; @@ -50,6 +53,8 @@ public class Service { private String tmpDir; @Value("${banned_emails:}") private String[] ignoredEmails; + @Inject + private ServerManager serverManager; Session session = Session.getDefaultInstance(new Properties()); @@ -131,4 +136,15 @@ public class Service { throw new HttpForbiddenException(); } } + @GetMapping("/api/events") + public SseEmitter handle() { + logger.info("{} connected", UserUtils.getCurrentUser().getName()); + SseEmitter emitter = new SseEmitter(86400000L); + serverManager.getSessions().add(new ServerManager.EventSession(UserUtils.getCurrentUser(), emitter)); + + emitter.onCompletion(() -> serverManager.getSessions().remove(emitter)); + emitter.onTimeout(() -> serverManager.getSessions().remove(emitter)); + + return emitter; + } } |