aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-08 21:38:27 +0300
committerGravatar Vitaly Takmazov2018-11-08 21:38:27 +0300
commit7aaa3f9a29c280f01c677c918932620be45cdbd7 (patch)
tree39947b2c889afd08f9c73ba54fab91159d2af258 /juick-server/src/main/java/com/juick/server/api
parent3ea9770d0d43fbe45449ac4531ec4b0a374d98ea (diff)
Merge everything into single Spring Boot application
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/ApiSocialLogin.java302
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Index.java54
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java201
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Notifications.java221
-rw-r--r--juick-server/src/main/java/com/juick/server/api/PM.java116
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java245
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Service.java166
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Tags.java54
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Users.java179
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java379
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Activity.java23
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Context.java123
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Accept.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Announce.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Block.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Create.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Delete.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Follow.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Like.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/activities/Undo.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Hashtag.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Image.java15
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Key.java24
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Link.java15
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java12
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java64
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollection.java25
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollectionPage.java58
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Person.java87
-rw-r--r--juick-server/src/main/java/com/juick/server/api/apple/AppSiteAssociation.java49
-rw-r--r--juick-server/src/main/java/com/juick/server/api/hostmeta/HostMeta.java25
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/Feeds.java75
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java153
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java111
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModule.java33
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleGenerator.java70
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleImpl.java54
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleParser.java42
-rw-r--r--juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java51
-rw-r--r--juick-server/src/main/java/com/juick/server/api/webfinger/model/Account.java24
-rw-r--r--juick-server/src/main/java/com/juick/server/api/webfinger/model/Link.java31
-rw-r--r--juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java57
-rw-r--r--juick-server/src/main/java/com/juick/server/api/xnodeinfo2/Info.java51
-rw-r--r--juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/NodeInfo.java54
-rw-r--r--juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Server.java40
-rw-r--r--juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/ServiceInfo.java24
-rw-r--r--juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Usage.java31
-rw-r--r--juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/UserStats.java31
48 files changed, 0 insertions, 3423 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/ApiSocialLogin.java b/juick-server/src/main/java/com/juick/server/api/ApiSocialLogin.java
deleted file mode 100644
index 8d9f9402..00000000
--- a/juick-server/src/main/java/com/juick/server/api/ApiSocialLogin.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package com.juick.server.api;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.scribejava.apis.FacebookApi;
-import com.github.scribejava.apis.VkontakteApi;
-import com.github.scribejava.core.builder.ServiceBuilder;
-import com.github.scribejava.core.model.OAuth2AccessToken;
-import com.github.scribejava.core.model.OAuthRequest;
-import com.github.scribejava.core.model.Verb;
-import com.github.scribejava.core.oauth.OAuth20Service;
-import com.juick.model.facebook.User;
-import com.juick.server.util.HttpBadRequestException;
-import com.juick.service.CrosspostService;
-import com.juick.service.EmailService;
-import com.juick.service.TelegramService;
-import com.juick.service.UserService;
-import com.juick.model.vk.UsersResponse;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
-
-/**
- *
- * @author Ugnich Anton
- */
-@Controller
-public class ApiSocialLogin {
-
- private static final Logger logger = LoggerFactory.getLogger(ApiSocialLogin.class);
-
- @Value("${facebook_appid:appid}")
- private String FACEBOOK_APPID;
- @Value("${facebook_secret:secret}")
- private String FACEBOOK_SECRET;
- private static final String FACEBOOK_REDIRECT = "https://api.juick.com/_fblogin";
- private static final String VK_REDIRECT = "https://api.juick.com/_vklogin";
- private static final String TWITTER_VERIFY_URL = "https://api.twitter.com/1.1/account/verify_credentials.json";
- @Inject
- private ObjectMapper jsonMapper;
- private ServiceBuilder facebookBuilder, twitterBuilder, vkBuilder;
-
- @Value("${twitter_consumer_key:appid}")
- private String twitterConsumerKey;
- @Value("${twitter_consumer_secret:secret}")
- private String twitterConsumerSecret;
- @Value("${vk_appid:appid}")
- private String VK_APPID;
- @Value("${vk_secret:secret}")
- private String VK_SECRET;
- @Value("${telegram_token:secret}")
- private String telegramToken;
-
- @Inject
- private CrosspostService crosspostService;
- @Inject
- private UserService userService;
- @Inject
- private EmailService emailService;
- @Inject
- private TelegramService telegramService;
-
- @PostConstruct
- public void init() {
- facebookBuilder = new ServiceBuilder(FACEBOOK_APPID);
- twitterBuilder = new ServiceBuilder(twitterConsumerKey);
- vkBuilder = new ServiceBuilder(VK_APPID);
- }
-
- @GetMapping("/api/_fblogin")
- protected String doFacebookLogin(@RequestParam(required = false) String code,
- @RequestParam(required = false) String state) throws IOException, ExecutionException, InterruptedException {
- if (StringUtils.isBlank(code)) {
- String fbstate = UUID.randomUUID().toString();
- crosspostService.addFacebookState(fbstate, state);
- OAuth20Service facebookAuthService = facebookBuilder
- .apiSecret(FACEBOOK_SECRET)
- .callback(FACEBOOK_REDIRECT)
- .scope("email")
- .state(fbstate)
- .build(FacebookApi.instance());
- return "redirect:" + facebookAuthService.getAuthorizationUrl();
- }
-
- String redirectUrl = crosspostService.verifyFacebookState(state);
-
- if (StringUtils.isEmpty(redirectUrl)) {
- logger.error("state is missing");
- throw new HttpBadRequestException();
- }
- OAuth20Service facebookService = facebookBuilder
- .apiKey(FACEBOOK_APPID)
- .apiSecret(FACEBOOK_SECRET)
- .callback(FACEBOOK_REDIRECT)
- .scope("email")
- .state(state)
- .build(FacebookApi.instance());
- OAuth2AccessToken token = facebookService.getAccessToken(code);
- final OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v2.10/me?fields=id,name,link,verified,email");
- facebookService.signRequest(token, meRequest);
- String graph = facebookService.execute(meRequest).getBody();
- if (StringUtils.isBlank(graph)) {
- logger.error("FACEBOOK GRAPH ERROR");
- throw new HttpBadRequestException();
- }
- User fb = jsonMapper.readValue(graph, User.class);
- long fbID = NumberUtils.toLong(fb.getId(), 0);
- if (fbID == 0 || StringUtils.isBlank(fb.getName()) || StringUtils.isBlank(fb.getLink())) {
- logger.error("Missing required fields, id: {}, name: {}, link: {}", fbID, fb.getName(), fb.getLink());
- throw new HttpBadRequestException();
- }
-
- int uid = crosspostService.getUIDbyFBID(fbID);
- if (uid > 0) {
- if (!crosspostService.updateFacebookUser(fbID, token.getAccessToken(), fb.getName(), fb.getLink())) {
- logger.error("error updating facebook user, id: {}, token: {}", fbID, token.getAccessToken());
- throw new HttpBadRequestException();
- }
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(redirectUrl);
- uriComponentsBuilder.queryParam("hash", userService.getHashByUID(uid));
- return "redirect:" + uriComponentsBuilder.build().toUriString();
- } else if (fb.getVerified()) {
- if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName(), fb.getLink())) {
- if (StringUtils.isNotEmpty(fb.getEmail())) {
- logger.info("found {} for facebook user {}", fb.getEmail(), fb.getLink());
- Integer userId = crosspostService.getUIDbyFBID(fbID);
- if (!emailService.getEmails(userId, false).contains(fb.getEmail())) {
- emailService.addEmail(userId, fb.getEmail());
- }
- }
- logger.info("email not found for facebook user {}", fb.getLink());
- throw new HttpBadRequestException();
- }
- return "redirect:/signup?type=fb&hash=" + state;
- } else {
- logger.error("Facebook account is not verified, id: {}", fbID);
- throw new HttpBadRequestException();
- }
- }/*
- @GetMapping("/_twitter")
- protected void doTwitterLogin(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ExecutionException, InterruptedException {
- String hash = StringUtils.EMPTY, request_token = StringUtils.EMPTY, request_token_secret = StringUtils.EMPTY;
- String verifier = request.getParameter("oauth_verifier");
- Cookie[] cookies = request.getCookies();
- for (Cookie cookie : cookies) {
- if (cookie.getName().equals("hash")) {
- hash = cookie.getValue();
- }
- if (cookie.getName().equals("request_token")) {
- request_token = cookie.getValue();
- }
- if (cookie.getName().equals("request_token_secret")) {
- request_token_secret = cookie.getValue();
- }
- }
- com.juick.User user = UserUtils.getCurrentUser();
- OAuth10aService oAuthService = twitterBuilder
- .apiSecret(twitterConsumerSecret)
- .callback("http://juick.com/_twitter")
- .build(TwitterApi.instance());
-
- if (request_token.isEmpty() && request_token_secret.isEmpty()
- && (verifier == null || verifier.isEmpty())) {
- OAuth1RequestToken requestToken = oAuthService.getRequestToken();
- String authUrl = oAuthService.getAuthorizationUrl(requestToken);
- response.addCookie(new Cookie("request_token", requestToken.getToken()));
- response.addCookie(new Cookie("request_token_secret", requestToken.getTokenSecret()));
- response.setStatus(HttpServletResponse.SC_FOUND);
- response.setHeader("Location", authUrl);
- } else {
- if (verifier != null && verifier.length() > 0) {
- OAuth1RequestToken requestToken = new OAuth1RequestToken(request_token, request_token_secret);
- OAuth1AccessToken accessToken = oAuthService.getAccessToken(requestToken, verifier);
- OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, TWITTER_VERIFY_URL);
- oAuthService.signRequest(accessToken, oAuthRequest);
- com.juick.twitter.User twitterUser = jsonMapper.readValue(oAuthService.execute(oAuthRequest).getBody(),
- com.juick.twitter.User.class);
- if (userService.linkTwitterAccount(user, accessToken.getToken(), accessToken.getTokenSecret(),
- twitterUser.getScreenName())) {
- response.setStatus(HttpServletResponse.SC_FOUND);
- response.setHeader("Location", "http://juick.com/settings");
- } else {
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- }
- }
- }*/
- @GetMapping("/api/_vklogin")
- protected String doVKLogin(@RequestParam(required = false) String code,
- @RequestParam String state) throws IOException, ExecutionException, InterruptedException {
- if (StringUtils.isBlank(code)) {
- String vkstate = UUID.randomUUID().toString();
- crosspostService.addVKState(vkstate, state);
- OAuth20Service vkAuthService = vkBuilder
- .apiSecret(VK_SECRET)
- .scope("friends,wall,offline")
- .state(vkstate)
- .callback(VK_REDIRECT)
- .build(VkontakteApi.instance());
- return "redirect:" + vkAuthService.getAuthorizationUrl();
- }
-
- String redirectUrl = crosspostService.verifyVKState(state);
- if (StringUtils.isBlank(redirectUrl)) {
- logger.error("state is missing");
- throw new HttpBadRequestException();
- }
-
- OAuth20Service vkService = vkBuilder
- .apiKey(VK_APPID)
- .apiSecret(VK_SECRET)
- .build(VkontakteApi.instance());
- OAuth2AccessToken token = vkService.getAccessToken(code);
-
- OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://api.vk.com/method/users.get?fields=screen_name&v=5.73");
- vkService.signRequest(token, meRequest);
- String graph = vkService.execute(meRequest).getBody();
-
- com.juick.model.vk.User jsonUser = jsonMapper.readValue(graph, UsersResponse.class).getUsers().get(0);
- String vkName = jsonUser.getFirstName() + " " + jsonUser.getLastName();
- String vkLink = jsonUser.getScreenName();
-
- if (vkName.length() == 1 || StringUtils.isBlank(vkLink)) {
- logger.error("vk user error");
- throw new HttpBadRequestException();
- }
-
- Long vkID = NumberUtils.toLong(jsonUser.getId(), 0);
- int uid = crosspostService.getUIDbyVKID(vkID);
- if (uid > 0) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(redirectUrl);
- uriComponentsBuilder.queryParam("hash", userService.getHashByUID(uid));
- return "redirect:" + uriComponentsBuilder.build().toUriString();
- } else {
- String loginhash = UUID.randomUUID().toString();
- if (!crosspostService.createVKUser(vkID, loginhash, token.getAccessToken(), vkName, vkLink)) {
- logger.error("create vk user error");
- throw new HttpBadRequestException();
- }
- return "redirect:/signup?type=vk&hash=" + loginhash;
- }
- }
- /*
- @GetMapping("/_tglogin")
- public String doDurovLogin(HttpServletRequest request,
- @RequestParam Map<String, String> params,
- HttpServletResponse response) {
- String dataCheckString = params.entrySet().stream()
- .filter(p -> !p.getKey().equals("hash"))
- .sorted(Map.Entry.comparingByKey())
- .map(p -> p.getKey() + "=" + p.getValue())
- .collect(Collectors.joining("\n"));
- String hash = params.get("hash");
- byte[] secretKey = DigestUtils.sha256(telegramToken);
- String resultString = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secretKey).hmacHex(dataCheckString);
- if (hash.equals(resultString)) {
- Long tgUser = Long.valueOf(params.get("id"));
- int uid = telegramService.getUser(tgUser);
- if (uid > 0) {
- Cookie c = new Cookie("hash", userService.getHashByUID(uid));
- c.setMaxAge(50 * 24 * 60 * 60);
- response.addCookie(c);
- return Utils.getPreviousPageByRequest(request).orElse("redirect:/");
- } else {
- String username = StringUtils.defaultString(params.get("username"), params.get("first_name"));
- telegramService.createTelegramUser(tgUser, username);
- return "redirect:/signup?type=durov&hash=" + userService.getSignUpHashByTelegramID(tgUser, username);
- }
- } else {
- logger.warn("invalid tg hash {} for {}", resultString, hash);
- }
- throw new HttpBadRequestException();
- }*/
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/Index.java b/juick-server/src/main/java/com/juick/server/api/Index.java
deleted file mode 100644
index 56f01370..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Index.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.Status;
-import com.juick.server.WebsocketManager;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
-import springfox.documentation.annotations.ApiIgnore;
-
-import javax.inject.Inject;
-import java.net.URI;
-
-/**
- * Created by vitalyster on 25.07.2016.
- */
-@RestController
-public class Index {
- @Inject
- private WebsocketManager wsHandler;
-
- @ApiIgnore
- @RequestMapping(value = { "/api/", "/ws/" }, method = RequestMethod.GET, headers = "Connection!=Upgrade")
- public ResponseEntity<Void> description() {
- URI redirectUri = ServletUriComponentsBuilder.fromCurrentRequestUri().path("/swagger-ui.html").build().toUri();
- return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).location(redirectUri).build();
- }
- @ApiIgnore
- @RequestMapping(value = "/api/status", method = RequestMethod.GET,
- produces = MediaType.APPLICATION_JSON_UTF8_VALUE, headers = "Connection!=Upgrade")
- public Status status() {
- return Status.getStatus(String.valueOf(wsHandler.getClients().size()));
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
deleted file mode 100644
index 4f0009dd..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.Message;
-import com.juick.Tag;
-import com.juick.User;
-import com.juick.server.Utils;
-import com.juick.service.component.MessageReadEvent;
-import com.juick.model.CommandResult;
-import com.juick.server.util.HttpBadRequestException;
-import com.juick.server.util.HttpNotFoundException;
-import com.juick.server.util.UserUtils;
-import com.juick.service.MessagesService;
-import com.juick.service.TagService;
-import com.juick.service.UserService;
-import org.apache.commons.io.IOUtils;
-import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.*;
-
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * @author ugnich
- */
-@RestController
-@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
-public class Messages {
-
- private static final ResponseEntity<List<com.juick.Message>> NOT_FOUND = ResponseEntity
- .status(HttpStatus.NOT_FOUND)
- .body(Collections.emptyList());
-
- private static final ResponseEntity<List<com.juick.Message>> FORBIDDEN = ResponseEntity
- .status(HttpStatus.FORBIDDEN)
- .body(Collections.emptyList());
-
- @Inject
- private MessagesService messagesService;
- @Inject
- private UserService userService;
- @Inject
- private TagService tagService;
- @Inject
- private ApplicationEventPublisher applicationEventPublisher;
-
- // TODO: serialize image urls
-
- @GetMapping("/api/home")
- public ResponseEntity<List<com.juick.Message>> getHome(
- @RequestParam(defaultValue = "0") int before_mid) {
- User visitor = UserUtils.getCurrentUser();
- if (!visitor.isAnonymous()) {
- int vuid = visitor.getUid();
- List<Integer> mids = messagesService.getMyFeed(vuid, before_mid, true);
- return ResponseEntity.ok(messagesService.getMessages(visitor, mids));
- }
- return FORBIDDEN;
- }
-
- @GetMapping("/api/messages")
- public ResponseEntity<List<com.juick.Message>> getMessages(
- @RequestParam(required = false) String uname,
- @RequestParam(name = "before_mid", defaultValue = "0") Integer before,
- @RequestParam(required = false, defaultValue = "0") Integer daysback,
- @RequestParam(required = false) String withrecommended,
- @RequestParam(required = false) String popular,
- @RequestParam(required = false) String search,
- @RequestParam(required = false, defaultValue = "0") Integer page,
- @RequestParam(required = false) String media,
- @RequestParam(required = false) String tag) {
-
- User visitor = UserUtils.getCurrentUser();
-
- List<Integer> mids;
- if (!StringUtils.isEmpty(uname)) {
- User user = userService.getUserByName(uname);
- if (!user.isAnonymous()) {
- if (!StringUtils.isEmpty(media)) {
- mids = messagesService.getUserPhotos(user.getUid(), 0, before);
- } else if (!StringUtils.isEmpty(tag)) {
- Tag tagObject = tagService.getTag(tag, false);
- if (tagObject != null) {
- mids = messagesService.getUserTag(user.getUid(), tagObject.TID, 0, before);
- } else {
- return NOT_FOUND;
- }
- } else if (!StringUtils.isEmpty(withrecommended)) {
- mids = messagesService.getUserBlogWithRecommendations(user.getUid(), 0, before);
- } else if (daysback > 0) {
- mids = messagesService.getUserBlogAtDay(user.getUid(), 0, daysback);
- } else if (!StringUtils.isEmpty(search)) {
- mids = messagesService.getUserSearch(visitor, user.getUid(), Utils.encodeSphinx(search), 0, page);
- } else {
- mids = messagesService.getUserBlog(user.getUid(), 0, before);
- }
- } else {
- return NOT_FOUND;
- }
- } else {
- if (!StringUtils.isEmpty(popular)) {
- mids = messagesService.getPopular(visitor.getUid(), before);
- } else if (!StringUtils.isEmpty(media)) {
- mids = messagesService.getPhotos(visitor.getUid(), before);
- } else if (!StringUtils.isEmpty(tag)) {
- Tag tagObject = tagService.getTag(tag, false);
- if (tagObject != null) {
- mids = messagesService.getTag(tagObject.TID, visitor.getUid(), before, 20);
- } else {
- return NOT_FOUND;
- }
- } else if (!StringUtils.isEmpty(search)) {
- mids = messagesService.getSearch(visitor, Utils.encodeSphinx(search), page);
- } else {
- mids = messagesService.getAll(visitor.getUid(), before);
- }
- }
- return ResponseEntity.ok(messagesService.getMessages(visitor, mids));
- }
- @DeleteMapping("/api/messages")
- public CommandResult deleteMessage(@RequestParam int mid, @RequestParam(required = false, defaultValue = "0") int rid) {
- User visitor = UserUtils.getCurrentUser();
- if (rid > 0) {
- if (messagesService.deleteReply(visitor.getUid(), mid, rid)) {
- return CommandResult.fromString("Reply deleted");
- }
- }
- if (messagesService.deleteMessage(visitor.getUid(), mid)) {
- return CommandResult.fromString("Message deleted");
- }
- throw new HttpBadRequestException();
- }
- @GetMapping("/api/messages/discussions")
- public List<Message> getDiscussions(
- @RequestParam(required = false, defaultValue = "0") Long to) {
- return messagesService.getMessages(UserUtils.getCurrentUser(), messagesService.getDiscussions(UserUtils.getCurrentUser().getUid(), to));
- }
- @GetMapping("/api/thread")
- public ResponseEntity<List<com.juick.Message>> getThread(
- @RequestParam(defaultValue = "0") int mid) {
- User visitor = UserUtils.getCurrentUser();
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg != null) {
- if (!messagesService.canViewThread(mid, visitor.getUid())) {
- return FORBIDDEN;
- } else {
- if (userService.getUserByName(msg.getUser().getName()).isBanned()) {
- throw new HttpNotFoundException();
- }
- msg.setRecommendations(new HashSet<>(messagesService.getMessageRecommendations(msg.getMid())));
- List<com.juick.Message> replies = messagesService.getReplies(visitor, mid);
- if (!visitor.isAnonymous()) {
- userService.updateLastSeen(visitor);
- applicationEventPublisher.publishEvent(
- new MessageReadEvent(this, visitor, msg));
- }
- replies.add(0, msg);
- return ResponseEntity.ok(replies);
- }
- }
- return NOT_FOUND;
- }
- @GetMapping(value = "/api/thread/mark_read/{mid}-{rid}.gif", produces = MediaType.IMAGE_GIF_VALUE)
- public byte[] markThreadRead(@PathVariable int mid, @PathVariable int rid) throws IOException {
- User visitor = UserUtils.getCurrentUser();
- if (!visitor.isAnonymous()) {
- messagesService.setLastReadComment(visitor, mid, rid);
- Message msg = messagesService.getMessage(mid);
- userService.updateLastSeen(visitor);
- applicationEventPublisher.publishEvent(
- new MessageReadEvent(this, visitor, msg));
- return IOUtils.toByteArray(
- Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif")));
- }
- throw new HttpBadRequestException();
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/Notifications.java b/juick-server/src/main/java/com/juick/server/api/Notifications.java
deleted file mode 100644
index 62275f5a..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Notifications.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.Message;
-import com.juick.Status;
-import com.juick.ExternalToken;
-import com.juick.User;
-import com.juick.model.AnonymousUser;
-import com.juick.server.util.HttpBadRequestException;
-import com.juick.server.util.HttpForbiddenException;
-import com.juick.service.MessagesService;
-import com.juick.service.PushQueriesService;
-import com.juick.service.SubscriptionService;
-import com.juick.server.util.UserUtils;
-import com.juick.service.UserService;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
-import springfox.documentation.annotations.ApiIgnore;
-
-import javax.inject.Inject;
-import java.io.IOException;
-import java.security.Principal;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Created by vitalyster on 24.10.2016.
- */
-@RestController
-public class Notifications {
-
- @Inject
- private PushQueriesService pushQueriesService;
- @Inject
- private MessagesService messagesService;
- @Inject
- private SubscriptionService subscriptionService;
- @Inject
- private UserService userService;
-
-
- private User collectTokens(Integer uid) {
- User user = userService.getUserByUID(uid).orElse(AnonymousUser.INSTANCE);
- user.setUnreadCount(messagesService.getUnread(user).size());
- pushQueriesService.getGCMRegID(uid).forEach(t -> user.getTokens().add(new ExternalToken(null, "gcm", t, null)));
- pushQueriesService.getAPNSToken(uid).forEach(t -> user.getTokens().add(new ExternalToken(null, "apns", t, null)));
- pushQueriesService.getMPNSURL(uid).forEach(t -> user.getTokens().add(new ExternalToken(null, "mpns", t, null)));
- return user;
- }
-
- @ApiIgnore
- @RequestMapping(value = "/api/notifications", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public ResponseEntity<List<User>> doGet(
- @RequestParam(required = false, defaultValue = "0") int uid,
- @RequestParam(required = false, defaultValue = "0") int mid,
- @RequestParam(required = false, defaultValue = "0") int rid) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous() || !(visitor.getName().equals("juick"))) {
- throw new HttpForbiddenException();
- }
- if (uid > 0 && mid == 0) {
- // PM
- return ResponseEntity.ok(Collections.singletonList(collectTokens(uid)));
- } else {
- if (mid > 0) {
- // reply
- Message msg = messagesService.getMessage(mid);
- if (msg != null) {
- List<User> users;
- if (rid > 0) {
- Message op = messagesService.getMessage(mid);
- Message reply = messagesService.getReply(mid, rid);
- users = subscriptionService.getUsersSubscribedToComments(op, reply);
- } else {
- users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg);
- }
-
- return ResponseEntity.ok(users.stream().map(User::getUid)
- .map(this::collectTokens).collect(Collectors.toList()));
- }
- } else {
- // read
- return ResponseEntity.ok(Collections.singletonList(collectTokens(uid)));
- }
- }
- throw new HttpBadRequestException();
- }
-
- @ApiIgnore
- @RequestMapping(value = "/api/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doDelete(
- @RequestBody List<ExternalToken> list) {
- User visitor = UserUtils.getCurrentUser();
- if ((visitor.isAnonymous()) || !(visitor.getName().equals("juick"))) {
- throw new HttpForbiddenException();
- }
- list.forEach(t -> {
- switch (t.getType()) {
- case "gcm":
- pushQueriesService.deleteGCMToken(t.getToken());
- break;
- case "apns":
- pushQueriesService.deleteAPNSToken(t.getToken());
- break;
- case "mpns":
- pushQueriesService.deleteMPNSToken(t.getToken());
- break;
- default:
- throw new HttpBadRequestException();
- }
- });
-
- return Status.OK;
- }
- @ApiIgnore
- @RequestMapping(value = "/api/notifications/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doDeleteTokens(
- @RequestBody List<ExternalToken> list) {
- User visitor = UserUtils.getCurrentUser();
- if ((visitor.isAnonymous()) || !(visitor.getName().equals("juick"))) {
- throw new HttpForbiddenException();
- }
- list.forEach(t -> {
- switch (t.getType()) {
- case "gcm":
- pushQueriesService.deleteGCMToken(t.getToken());
- break;
- case "apns":
- pushQueriesService.deleteAPNSToken(t.getToken());
- break;
- case "mpns":
- pushQueriesService.deleteMPNSToken(t.getToken());
- break;
- default:
- throw new HttpBadRequestException();
- }
- });
-
- return Status.OK;
- }
-
- @ApiIgnore
- @RequestMapping(value = "/api/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doPut(
- @RequestBody List<ExternalToken> list) throws IOException {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- list.forEach(t -> {
- switch (t.getType()) {
- case "gcm":
- pushQueriesService.addGCMToken(visitor.getUid(), t.getToken());
- break;
- case "apns":
- pushQueriesService.addAPNSToken(visitor.getUid(), t.getToken());
- break;
- case "mpns":
- pushQueriesService.addMPNSToken(visitor.getUid(), t.getToken());
- break;
- default:
- throw new HttpBadRequestException();
- }
- });
- return Status.OK;
- }
-
- @Deprecated
- @RequestMapping(value = "/api/android/register", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doAndroidRegister(
- @RequestParam(name = "regid") String regId) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- pushQueriesService.addGCMToken(visitor.getUid(), regId);
- return Status.OK;
- }
-
- @Deprecated
- @RequestMapping(value = "/api/android/unregister", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doAndroidUnRegister(@RequestParam(name = "regid") String regId) {
- pushQueriesService.deleteGCMToken(regId);
- return Status.OK;
- }
-
- @Deprecated
- @RequestMapping(value = "/api/winphone/register", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doWinphoneRegister(
- Principal principal,
- @RequestParam(name = "url") String regId) {
- User visitor = UserUtils.getCurrentUser();
- pushQueriesService.addMPNSToken(visitor.getUid(), regId);
- return Status.OK;
- }
-
- @Deprecated
- @RequestMapping(value = "/api/winphone/unregister", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public Status doWinphoneUnRegister(@RequestParam(name = "url") String regId) {
- pushQueriesService.deleteMPNSToken(regId);
- return Status.OK;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/PM.java b/juick-server/src/main/java/com/juick/server/api/PM.java
deleted file mode 100644
index 0c36fe00..00000000
--- a/juick-server/src/main/java/com/juick/server/api/PM.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.Chat;
-import com.juick.User;
-import com.juick.service.component.MessageEvent;
-import com.juick.model.AnonymousUser;
-import com.juick.model.PrivateChats;
-import com.juick.server.util.*;
-import com.juick.service.PMQueriesService;
-import com.juick.service.UserService;
-import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.http.MediaType;
-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 javax.inject.Inject;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author ugnich
- */
-@RestController
-public class PM {
- @Inject
- private UserService userService;
- @Inject
- private PMQueriesService pmQueriesService;
- @Inject
- private ApplicationEventPublisher applicationEventPublisher;
-
- @RequestMapping(value = "/api/pm", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public List<com.juick.Message> doGetPM(
- @RequestParam(required = false) String uname) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- int uid = 0;
- if (uname != null && uname.matches("^[a-zA-Z0-9\\-]{2,16}$")) {
- uid = userService.getUIDbyName(uname);
- }
-
- if (uid == 0) {
- throw new HttpBadRequestException();
- }
-
- return pmQueriesService.getPMMessages(visitor.getUid(), uid);
- }
-
- @RequestMapping(value = "/api/pm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public com.juick.Message doPostPM(
- @RequestParam String uname,
- @RequestParam String body) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- User userTo = AnonymousUser.INSTANCE;
- if (WebUtils.isUserName(uname)) {
- userTo = userService.getUserByName(uname);
- }
-
- if (userTo.getUid() == 0 || body == null || body.length() < 1 || body.length() > 10240) {
- throw new HttpBadRequestException();
- }
-
- if (userService.isInBLAny(userTo.getUid(), visitor.getUid())) {
- throw new HttpForbiddenException();
- }
-
- if (pmQueriesService.createPM(visitor.getUid(), userTo.getUid(), body)) {
- com.juick.Message jmsg = new com.juick.Message();
- jmsg.setUser(visitor);
- jmsg.setText(body);
- jmsg.setTo(userTo);
- applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(jmsg.getTo())));
- return jmsg;
-
- }
- throw new HttpBadRequestException();
- }
- @RequestMapping(value = "/api/groups_pms", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public PrivateChats doGetGroupsPMs(
- @RequestParam(defaultValue = "5") int cnt) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- // TODO: ignore cnt param for now but make sure paging param will not be cnt
-
- List<Chat> lastconv = pmQueriesService.getLastChats(visitor);
- PrivateChats pms = new PrivateChats();
- pms.setUsers(lastconv);
- return pms;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java
deleted file mode 100644
index 303ff109..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Post.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.Message;
-import com.juick.Reaction;
-import com.juick.Status;
-import com.juick.User;
-import com.juick.server.CommandsManager;
-import com.juick.model.CommandResult;
-import com.juick.server.util.*;
-import com.juick.service.MessagesService;
-import com.juick.service.SubscriptionService;
-import com.juick.service.UserService;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.inject.Inject;
-import javax.validation.constraints.NotNull;
-import java.net.URI;
-import java.net.URL;
-import java.util.List;
-
-/**
- * Created by vt on 24/11/2016.
- */
-@RestController
-public class Post {
- private static Logger logger = LoggerFactory.getLogger(Post.class);
-
- @Inject
- private UserService userService;
- @Inject
- private MessagesService messagesService;
- @Inject
- private SubscriptionService subscriptionService;
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
- @Value("${img_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String imgDir;
- @Inject
- CommandsManager commandsManager;
-
- @RequestMapping(value = "/api/post", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- @ResponseStatus(value = HttpStatus.OK)
- public CommandResult doPostMessage(
- @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body,
- @RequestParam(required = false) String img,
- @RequestParam(required = false) MultipartFile attach) throws Exception {
- User visitor = UserUtils.getCurrentUser();
-
- if (visitor.isAnonymous())
- throw new HttpForbiddenException();
-
- if (body.length() > 4096) {
- throw new HttpBadRequestException();
- }
- body = body.replace("\r", StringUtils.EMPTY);
-
- URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
-
- if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
- URI juickUri = URI.create(img);
- if (juickUri.getScheme().equals("juick")) {
- attachmentFName = juickUri;
- } else {
- try {
- URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
- } catch (Exception e) {
- logger.error("DOWNLOAD ERROR", e);
- throw new HttpBadRequestException();
- }
- }
- }
- if (StringUtils.isBlank(body) && StringUtils.isBlank(attachmentFName.toString())) {
- // Should be there for compatibility
- throw new HttpBadRequestException();
- }
- return commandsManager.processCommand(visitor, body, attachmentFName);
- }
-
- @RequestMapping(value = "/api/comment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public CommandResult doPostComment(
- @RequestParam(defaultValue = "0") int mid,
- @RequestParam(defaultValue = "0") int rid,
- @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body,
- @RequestParam(required = false) String img,
- @RequestParam(required = false) MultipartFile attach)
- throws Exception {
- User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
- throw new HttpForbiddenException();
- }
- if (mid == 0) {
- throw new HttpBadRequestException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
-
- com.juick.Message reply = null;
- if (rid > 0) {
- reply = messagesService.getReply(mid, rid);
- if (reply == null) {
- throw new HttpNotFoundException();
- }
- }
-
- if (body.length() > 4096) {
- throw new HttpBadRequestException();
- }
- body = body.replace("\r", StringUtils.EMPTY);
-
- if ((msg.ReadOnly && msg.getUser().getUid() != vuid) || userService.isInBLAny(msg.getUser().getUid(), vuid)
- || (reply != null && userService.isInBLAny(reply.getUser().getUid(), vuid))) {
- throw new HttpForbiddenException();
- }
-
- URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
-
- if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
- try {
- attachmentFName = HttpUtils.downloadImage(new URL(img), tmpDir);
- } catch (Exception e) {
- logger.error("DOWNLOAD ERROR", e);
- throw new HttpBadRequestException();
- }
- }
- if (StringUtils.isBlank(body) && StringUtils.isBlank(attachmentFName.toString())) {
- // Should be there for compatibility
- throw new HttpBadRequestException();
- }
- return commandsManager.processCommand(visitor, String.format("#%d/%d %s", mid, rid, body),
- attachmentFName);
- }
-
- @PostMapping("/api/like")
- @ResponseStatus(value = HttpStatus.OK)
- public Status doPostRecomm(@RequestParam Integer mid) throws Exception {
- com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
- if (msg.getUser().getUid() == visitor.getUid()) {
- throw new HttpForbiddenException();
- }
- CommandResult status = commandsManager.processCommand(visitor, String.format("! #%d", mid),
- URI.create(StringUtils.EMPTY));
- return Status.getStatus(status.getText());
- }
-
- @PostMapping("/api/subscribe")
- @ResponseStatus(value = HttpStatus.OK)
- public Status doPostSubscribe(@RequestParam Integer mid) throws Exception {
- com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
- if (msg.getUser().getUid() == visitor.getUid()) {
- throw new HttpForbiddenException();
- }
- CommandResult status = commandsManager.processCommand(visitor, String.format("S #%d", mid),
- URI.create(StringUtils.EMPTY));
- return Status.getStatus(status.getText());
- }
-
- @GetMapping("/api/reactions")
- @ResponseStatus(value = HttpStatus.OK)
- public List<Reaction> reactionsList() {
- return messagesService.listReactions();
- }
-
- @PostMapping("/api/react")
- @ResponseStatus(value = HttpStatus.OK)
- public Status doPostReact(@RequestParam Integer mid,@RequestParam @NotNull int reactionId,
- @RequestParam (required = false, defaultValue = "1") int count) {
-
- logger.info("got reaction with type: {}", reactionId);
- com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
- if (msg.getUser().getUid() == visitor.getUid()) {
- throw new HttpForbiddenException();
- }
- MessagesService.RecommendStatus recommendStatus = MessagesService.RecommendStatus.Error;
- for (int i = 0; i < count; i++)
- recommendStatus = messagesService.likeMessage(mid, visitor.getUid(),
- reactionId);
-
- return recommendStatus == MessagesService.RecommendStatus.Error ? Status.ERROR :Status.OK;
- }
-
- @PostMapping("/api/update")
- public CommandResult updateMessage(@RequestParam Integer mid,
- @RequestParam(required = false, defaultValue = "0") Integer rid,
- @RequestParam String body) {
- User visitor = UserUtils.getCurrentUser();
- User author = rid == 0 ? messagesService.getMessageAuthor(mid) : messagesService.getReply(mid, rid).getUser();
- if (visitor.equals(author)) {
- if (messagesService.updateMessage(mid, rid, body)) {
- Message result = rid == 0 ? messagesService.getMessage(mid) : messagesService.getReply(mid, rid);
- return CommandResult.build(result, "Message updated", StringUtils.EMPTY);
- }
- throw new HttpBadRequestException();
- }
- throw new HttpForbiddenException();
- }
-}
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
deleted file mode 100644
index ed62886f..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Service.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package com.juick.server.api;
-
-import com.juick.Message;
-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;
-import com.juick.service.UserService;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.mail.util.MimeMessageParser;
-import org.slf4j.Logger;
-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.ExceptionHandler;
-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.context.request.async.AsyncRequestTimeoutException;
-import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
-import springfox.documentation.annotations.ApiIgnore;
-
-import javax.inject.Inject;
-import javax.mail.Session;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Paths;
-import java.util.*;
-
-@Controller
-public class Service {
- private static Logger logger = LoggerFactory.getLogger(Service.class);
- @Inject
- private UserService userService;
- @Inject
- private EmailService emailService;
- @Inject
- private CommandsManager commandsManager;
- @Inject
- private EmailManager emailManager;
- @Value("${api_user:juick}")
- private String serviceUser;
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
- @Value("${banned_emails:}")
- private String[] ignoredEmails;
- @Inject
- private ServerManager serverManager;
-
- private Session session = Session.getDefaultInstance(new Properties());
-
- @ApiIgnore
- @PostMapping("/api/mail")
- @ResponseStatus(value = HttpStatus.OK)
- public void processMail(InputStream data) throws Exception {
- if (UserUtils.getCurrentUser().getName().equals(serviceUser)) {
- MimeMessage msg = new MimeMessage(session, data);
- String[] returnPaths = msg.getHeader("Return-Path");
- if (returnPaths != null) {
- logger.info("got msg with return path {}", returnPaths[0]);
- if (returnPaths[0].equals("<>")) {
- return;
- }
- }
- String from = msg.getFrom() == null || msg.getFrom().length > 1 ? ((InternetAddress) msg.getSender()).getAddress()
- : ((InternetAddress) msg.getFrom()[0]).getAddress();
-
- User visitor = userService.getUserByEmail(from);
- if (!visitor.isAnonymous()) {
- MimeMessageParser parser = new MimeMessageParser(msg);
- parser.parse();
- final String[] body = {parser.getPlainContent()};
- if (body[0] == null) {
- parser.getAttachmentList().stream()
- .filter(a -> a.getContentType().equals("text/plain")).findFirst()
- .ifPresent(a -> {
- try {
- body[0] = IOUtils.toString(a.getInputStream(), StandardCharsets.UTF_8);
- logger.info("got text: {}", body[0]);
- } catch (IOException e) {
- logger.info("attachment error: {}", e);
- }
- });
- }
- final String[] attachmentFName = new String[1];
- parser.getAttachmentList().stream().filter(a ->
- a.getContentType().equals("image/jpeg") || a.getContentType().equals("image/png"))
- .findFirst().ifPresent(a -> {
- logger.info("got attachment: {}", a.getContentType());
- String attachmentType;
- if (a.getContentType().equals("image/jpeg")) {
- attachmentType = "jpg";
- } else {
- attachmentType = "png";
- }
- attachmentFName[0] = DigestUtils.md5Hex(UUID.randomUUID().toString()) + "." + attachmentType;
- try {
- logger.info("got inputstream: {}", a.getInputStream());
- FileOutputStream fos = new FileOutputStream(Paths.get(tmpDir, attachmentFName[0]).toString());
- IOUtils.copy(a.getInputStream(), fos);
- fos.close();
- } catch (IOException e) {
- logger.info("attachment error: {}", e);
- }
- });
- String[] inReplyToHeaders = msg.getHeader("In-Reply-To");
- if (inReplyToHeaders != null && inReplyToHeaders.length > 0) {
- Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim()).useDelimiter(EmailManager.MSGID_PATTERN);
- int mid = Integer.parseInt(inReplyToScanner.next());
- int rid = Integer.parseInt(inReplyToScanner.next());
- logger.info("Message is reply to #{}/{}", mid, rid);
- body[0] = rid > 0 ? String.format("#%d/%d %s", mid, rid, body[0])
- : String.format("#%d %s", mid, body[0]);
- }
- URI attachmentUri = StringUtils.isNotEmpty(attachmentFName[0]) ? URI.create(String.format("juick://%s", attachmentFName[0]))
- : URI.create(StringUtils.EMPTY);
- commandsManager.processCommand(visitor, body[0], attachmentUri);
- } else {
- if (!Arrays.asList(ignoredEmails).contains(from)) {
- String verificationCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
- emailService.addVerificationCode(null, from, verificationCode);
- String signupUrl = String.format("Follow this link to create Juick account: https://juick.com/signup?type=email&hash=%s", verificationCode);
- emailManager.sendEmail(from, "Juick registration", signupUrl, StringUtils.EMPTY, Collections.emptyMap());
- }
- }
- } else {
- throw new HttpForbiddenException();
- }
- }
- private void endSession(SseEmitter emitter) {
- serverManager.getSessions().stream()
- .filter(s -> s.getEmitter().equals(emitter))
- .forEach(session -> serverManager.getSessions().remove(session));
- }
- @GetMapping("/api/events")
- public SseEmitter handle() throws IOException {
- User visitor = UserUtils.getCurrentUser();
- logger.info("{} connected", visitor.getName());
- if (!visitor.isAnonymous()) {
- userService.updateLastSeen(visitor);
- }
- SseEmitter emitter = new SseEmitter(600000L);
- serverManager.getSessions().add(new ServerManager.EventSession(visitor, emitter));
-
- emitter.onCompletion(() -> endSession(emitter));
- emitter.onTimeout(() -> endSession(emitter));
-
- return emitter;
- }
- @ExceptionHandler(AsyncRequestTimeoutException.class)
- public void eventErrorHandler(Exception ex) {
- logger.debug("SSE timeout", ex);
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/Tags.java b/juick-server/src/main/java/com/juick/server/api/Tags.java
deleted file mode 100644
index 7a8e572a..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Tags.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.User;
-import com.juick.model.TagStats;
-import com.juick.server.util.UserUtils;
-import com.juick.service.TagService;
-import org.springframework.http.MediaType;
-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 javax.inject.Inject;
-import java.util.List;
-
-/**
- * Created by vitalyster on 29.11.2016.
- */
-@RestController
-public class Tags {
- @Inject
- private TagService tagService;
-
- @RequestMapping(value = "/api/tags", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public List<TagStats> tags(
- @RequestParam(required = false, defaultValue = "0") int user_id
- ) {
- User visitor = UserUtils.getCurrentUser();
- if (user_id == 0) {
- user_id = visitor.getUid();
- }
- if (user_id > 0) {
- return tagService.getUserTagStats(user_id);
- }
- return tagService.getTagStats();
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/Users.java b/juick-server/src/main/java/com/juick/server/api/Users.java
deleted file mode 100644
index 7686d722..00000000
--- a/juick-server/src/main/java/com/juick/server/api/Users.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api;
-
-import com.juick.User;
-import com.juick.model.ApplicationStatus;
-import com.juick.model.UserInfo;
-import com.juick.server.util.HttpForbiddenException;
-import com.juick.server.util.HttpNotFoundException;
-import com.juick.service.CrosspostService;
-import com.juick.service.EmailService;
-import com.juick.service.MessagesService;
-import com.juick.service.UserService;
-import com.juick.server.util.UserUtils;
-import com.juick.server.util.WebUtils;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
-
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author ugnich
- */
-@RestController
-public class Users {
- @Inject
- private UserService userService;
- @Inject
- private MessagesService messagesService;
- @Inject
- private CrosspostService crosspostService;
- @Inject
- private EmailService emailService;
-
- @RequestMapping(value = "/api/auth", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public String getAuthToken() {
- return userService.getHashByUID(UserUtils.getCurrentUser().getUid());
- }
-
- @RequestMapping(value = "/api/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public List<User> doGetUsers(
- @RequestParam(value = "uname", required = false) List<String> unames) {
- List<com.juick.User> users = new ArrayList<>();
-
- if (unames != null) {
- unames.removeIf(WebUtils::isNotUserName);
-
- if (!unames.isEmpty() && unames.size() < 20)
- users.addAll(userService.getUsersByName(unames));
- }
-
- if (!users.isEmpty())
- return users;
- if (!UserUtils.getCurrentUser().isAnonymous()) {
- return Collections.singletonList(UserUtils.getCurrentUser());
- }
-
- throw new HttpNotFoundException();
- }
-
- @GetMapping("/api/me")
- public SecureUser getMe() {
- User visitor = UserUtils.getCurrentUser();
- SecureUser me = new SecureUser();
- me.setUid(visitor.getUid());
- me.setName(visitor.getName());
- me.setAuthHash(getAuthToken());
- List<Integer> unread = messagesService.getUnread(visitor);
- me.setUnread(unread);
- me.setUnreadCount(unread.size());
- me.setRead(userService.getUserFriends(visitor.getUid()));
- me.setReaders(userService.getUserReaders(visitor.getUid()));
- return me;
- }
-
- @RequestMapping(value = "/api/users/read", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public List<User> doGetUserRead(
- @RequestParam String uname) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- int uid = 0;
- if (uname == null) {
- uid = visitor.getUid();
- } else {
- if (WebUtils.isUserName(uname)) {
- com.juick.User u = userService.getUserByName(uname);
- if (!u.isAnonymous()) {
- uid = u.getUid();
- }
- }
- }
-
- if (uid > 0) {
- return userService.getUserFriends(uid);
- }
- throw new HttpNotFoundException();
- }
-
- @RequestMapping(value = "/api/users/readers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public List<User> doGetUserReaders(
- @RequestParam String uname) {
- User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- int uid = 0;
- if (uname == null) {
- uid = visitor.getUid();
- } else {
- if (WebUtils.isUserName(uname)) {
- com.juick.User u = userService.getUserByName(uname);
- if (!u.isAnonymous()) {
- uid = u.getUid();
- }
- }
- }
-
- if (uid > 0) {
- return userService.getUserReaders(uid);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping("/api/info/{uname}")
- public UserInfo getUserInfo(@PathVariable String uname) {
- User user = userService.getUserByName(uname);
- if (!user.isBanned()) {
- return userService.getUserInfo(user);
- }
- throw new HttpNotFoundException();
- }
-
- class SecureUser extends User {
- public String getHash() {
- return getAuthHash();
- }
- public UserInfo getUserInfo() {
- return userService.getUserInfo(this);
- }
- public List<String> getJIDs() {
- return userService.getAllJIDs(this);
- }
- public List<String> getEmails() {
- return userService.getEmails(this);
- }
- public String getActiveEmail() {
- return emailService.getNotificationsEmail(this.getUid());
- }
- public String getTwitterName() {
- return crosspostService.getTwitterName(this.getUid());
- }
- public String getTelegramName() {
- return crosspostService.getTelegramName(this.getUid());
- }
- public ApplicationStatus getFacebookStatus() {
- return crosspostService.getFbCrossPostStatus(this.getUid());
- }
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
deleted file mode 100644
index 10390ea1..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ /dev/null
@@ -1,379 +0,0 @@
-package com.juick.server.api.activity;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.juick.Message;
-import com.juick.User;
-import com.juick.model.CommandResult;
-import com.juick.server.ActivityPubManager;
-import com.juick.server.CommandsManager;
-import com.juick.server.KeystoreManager;
-import com.juick.server.SignatureManager;
-import com.juick.server.api.activity.model.Activity;
-import com.juick.server.api.activity.model.Context;
-import com.juick.server.api.activity.model.activities.Announce;
-import com.juick.server.api.activity.model.activities.Create;
-import com.juick.server.api.activity.model.activities.Delete;
-import com.juick.server.api.activity.model.activities.Follow;
-import com.juick.server.api.activity.model.activities.Undo;
-import com.juick.server.api.activity.model.objects.Image;
-import com.juick.server.api.activity.model.objects.Key;
-import com.juick.server.api.activity.model.objects.Note;
-import com.juick.server.api.activity.model.objects.OrderedCollection;
-import com.juick.server.api.activity.model.objects.OrderedCollectionPage;
-import com.juick.server.api.activity.model.objects.Person;
-import com.juick.server.util.HttpBadRequestException;
-import com.juick.server.util.HttpNotFoundException;
-import com.juick.server.util.UserUtils;
-import com.juick.service.MessagesService;
-import com.juick.service.UserService;
-import com.juick.service.activities.DeleteUserEvent;
-import com.juick.service.activities.FollowEvent;
-import com.juick.service.activities.UndoFollowEvent;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
-import org.springframework.web.util.UriComponents;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import javax.inject.Inject;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-@RestController
-public class Profile {
- private static final Logger logger = LoggerFactory.getLogger(Profile.class);
- @Inject
- private UserService userService;
- @Inject
- private MessagesService messagesService;
- @Inject
- private KeystoreManager keystoreManager;
- @Inject
- private SignatureManager signatureManager;
- @Inject
- private ActivityPubManager activityPubManager;
- @Inject
- private ApplicationEventPublisher applicationEventPublisher;
- @Inject
- private CommandsManager commandsManager;
- @Value("${web_domain:localhost}")
- private String domain;
- @Value("${ap_base_uri:http://localhost:8080/}")
- private String baseUri;
- @Value("${img_url:http://localhost:8080/i/}")
- private String baseImagesUri;
- @Inject
- private ObjectMapper jsonMapper;
-
- @GetMapping(value = "/u/{userName}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public Person getUser(@PathVariable String userName) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- Person person = new Person();
- person.setId(activityPubManager.personUri(user));
- person.setUrl(activityPubManager.personWebUri(user));
- person.setName(userName);
- person.setPreferredUsername(userName);
- Key publicKey = new Key();
- publicKey.setId(person.getId() + "#main-key");
- publicKey.setOwner(person.getId());
- publicKey.setPublicKeyPem(keystoreManager.getPublicKeyPem());
- person.setPublicKey(publicKey);
- person.setInbox(activityPubManager.inboxUri());
- person.setOutbox(activityPubManager.outboxUri(user));
- person.setFollowers(activityPubManager.followersUri(user));
- person.setFollowing(activityPubManager.followingUri(user));
- UriComponentsBuilder image = UriComponentsBuilder.fromUriString(baseImagesUri);
- image.path(String.format("/a/%d.png", user.getUid()));
- Image avatar = new Image();
- avatar.setUrl(image.toUriString());
- avatar.setMediaType("image/png");
- person.setIcon(avatar);
- return (Person) Context.build(person);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/u/{userName}/blog/toc", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollection getOutbox(@PathVariable String userName) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri);
- OrderedCollection blog = new OrderedCollection();
- blog.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
- blog.setTotalItems(userService.getStatsMessages(user.getUid()));
- blog.setFirst(uriComponentsBuilder.path(String.format("/u/%s/blog", userName)).toUriString());
- return (OrderedCollection) Context.build(blog);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/u/{userName}/blog", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollectionPage getOutboxPage(@PathVariable String userName,
- @RequestParam(required = false, defaultValue = "0") int before) {
- User visitor = UserUtils.getCurrentUser();
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
- String personUri = uri.path(String.format("/u/%s", userName)).toUriString();
- List<Integer> mids = messagesService.getUserBlog(user.getUid(), 0, before);
- List<Note> notes = messagesService.getMessages(visitor, mids).stream().map(activityPubManager::makeNote).collect(Collectors.toList());
- OrderedCollectionPage page = new OrderedCollectionPage();
- page.setPartOf(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString());
- page.setFirst(uri.replacePath(String.format("/u/%s/blog", userName)).toUriString());
- page.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
- page.setOrderedItems(notes.stream().map(a -> {
- Create create = new Create();
- create.setId(a.getId() + "#Create");
- create.setTo(a.getTo());
- create.setActor(personUri);
- create.setObject(a);
- create.setPublished(a.getPublished());
- return create;
- }).collect(Collectors.toList()));
- int beforeNext = mids.stream().reduce((fst, second) -> second).orElse(0);
- if (beforeNext > 0) {
- page.setNext(uri.queryParam("before", beforeNext).toUriString());
- }
- page.setLast(uri.replaceQueryParam("before", "1").toUriString());
- return (OrderedCollectionPage) Context.build(page);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/u/{userName}/followers/toc", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollection getFollowers(@PathVariable String userName) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri);
- OrderedCollection followers = new OrderedCollection();
- followers.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
- followers.setTotalItems(userService.getStatsMyReaders(user.getUid()));
- followers.setFirst(uriComponentsBuilder.path(String.format("/u/%s/followers", userName)).toUriString());
- return (OrderedCollection) Context.build(followers);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/u/{userName}/followers", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollectionPage getFollowersPage(@PathVariable String userName,
- @RequestParam(required = false, defaultValue = "0") int page) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri);
- uriComponentsBuilder.path(String.format("/u/%s/followers", userName));
- List<User> followers = userService.getUserReaders(user.getUid());
- Stream<User> followersPage = followers.stream().skip(20 * page).limit(20);
-
- OrderedCollectionPage result = new OrderedCollectionPage();
- result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
- result.setOrderedItems(followersPage.map(a -> {
- Person follower = new Person();
- follower.setName(a.getName());
- follower.setPreferredUsername(a.getName());
- follower.setUrl(activityPubManager.personWebUri(a));
- return follower;
- }).collect(Collectors.toList()));
- boolean hasNext = followers.size() <= 20 * page;
- if (hasNext) {
- result.setNext(uriComponentsBuilder.queryParam("page", page + 1).toUriString());
- }
- return (OrderedCollectionPage) Context.build(result);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/u/{userName}/following/toc", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollection getFollowing(@PathVariable String userName) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri);
- OrderedCollection following = new OrderedCollection();
- following.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
- following.setTotalItems(userService.getUserFriends(user.getUid()).size());
- following.setFirst(uriComponentsBuilder.path(String.format("/u/%s/followers", userName)).toUriString());
- return (OrderedCollection) Context.build(following);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/u/{userName}/following", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollectionPage getFollowingPage(@PathVariable String userName,
- @RequestParam(required = false, defaultValue = "0") int page) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri);
- uriComponentsBuilder.path(String.format("/u/%s/following", userName));
- List<User> following = userService.getUserFriends(user.getUid());
- Stream<User> followingPage = following.stream().skip(20 * page).limit(20);
-
- OrderedCollectionPage result = new OrderedCollectionPage();
- result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
- result.setOrderedItems(followingPage.map(a -> {
- Person follower = new Person();
- follower.setName(a.getName());
- follower.setPreferredUsername(a.getName());
- follower.setUrl(activityPubManager.personWebUri(a));
- return follower;
- }).collect(Collectors.toList()));
- boolean hasNext = following.size() <= 20 * page;
- if (hasNext) {
- result.setNext(uriComponentsBuilder.queryParam("page", page + 1).toUriString());
- }
- return (OrderedCollectionPage) Context.build(result);
- }
- throw new HttpNotFoundException();
- }
-
- @GetMapping(value = "/n/{mid}-{rid}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public Context showNote(@PathVariable int mid, @PathVariable int rid) {
- if (rid > 0) {
- // reply
- return Context.build(activityPubManager.makeNote(
- messagesService.getReply(mid, rid)));
- }
- return Context.build(activityPubManager.makeNote(
- messagesService.getMessage(mid)));
- }
-
- @PostMapping(value = "/api/inbox", consumes = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public ResponseEntity<Void> processInbox(@RequestBody Activity activity,
- @RequestHeader(name = "Host") String host,
- @RequestHeader(name = "Date") String date,
- @RequestHeader(name = "Digest", required = false) String digest,
- @RequestHeader(name = "Content-Type") String contentType,
- @RequestHeader(name = "User-Agent", required = false) String userAgent,
- @RequestHeader(name = "Accept-Encoding", required = false) String acceptEncoding,
- @RequestHeader(name = "Signature", required = false) String signature) throws Exception {
- UriComponents componentsBuilder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
- Map<String, String> headers = new HashMap<>();
- headers.put("host", host.split(":", 2)[0]);
- headers.put("date", date);
- headers.put("digest", digest);
- headers.put("content-type", contentType);
- headers.put("user-agent", userAgent);
- headers.put("accept-encoding", acceptEncoding);
- boolean valid = signatureManager.verifySignature(signature, URI.create(activity.getActor()), "POST",
- componentsBuilder.getPath(), headers);
- if (valid) {
- if (activity instanceof Follow) {
- Follow followRequest = (Follow) activity;
- String actor = followRequest.getActor();
- Person follower = (Person) signatureManager.getContext(URI.create(actor)).orElseThrow(HttpBadRequestException::new);
- applicationEventPublisher.publishEvent(
- new FollowEvent(this, followRequest));
- return new ResponseEntity<>(HttpStatus.ACCEPTED);
-
- }
- if (activity instanceof Undo) {
- String follower = (String) ((Map) activity.getObject()).get("object");
- applicationEventPublisher.publishEvent(new UndoFollowEvent(this, activity.getActor(), follower));
- return new ResponseEntity<>(HttpStatus.OK);
- }
- if (activity instanceof Delete) {
- if (activity.getObject() instanceof String) {
- // Delete user
- applicationEventPublisher.publishEvent(new DeleteUserEvent(this, (String)activity.getObject()));
- return new ResponseEntity<>(HttpStatus.OK);
- }
- }
- if (activity instanceof Create) {
- if (activity.getObject() instanceof Map) {
- Map<String, Object> note = (Map<String, Object>) activity.getObject();
- if (note.get("type").equals("Note")) {
- URI noteId = URI.create((String) note.get("id"));
- if (messagesService.replyExists(noteId)) {
- return new ResponseEntity<>(HttpStatus.OK);
- } else {
- String inReplyTo = (String) note.get("inReplyTo");
- if (StringUtils.isNotBlank(inReplyTo)) {
- if (inReplyTo.startsWith(baseUri)) {
- UriComponents uri = UriComponentsBuilder.fromUriString(inReplyTo).build();
- String postId = uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1).replace("-", "/");
- User user = new User();
- user.setUri(URI.create(activity.getActor()));
- String attachment = StringUtils.EMPTY;
- if (note.get("attachment") != null && ((List) note.get("attachment")).size() > 0) {
- Map<String, Object> attachmentObj = (Map<String, Object>) ((List<Object>) note.get("attachment")).get(0);
- attachment = (String) attachmentObj.get("url");
- }
- CommandResult result = commandsManager.processCommand(user, String.format("#%s %s", postId, note.get("content")), URI.create(attachment));
- logger.info(jsonMapper.writeValueAsString(result));
- if (result.getNewMessage().isPresent()) {
- messagesService.updateReplyUri(result.getNewMessage().get(), noteId);
- return new ResponseEntity<>(HttpStatus.OK);
- } else {
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
- }
- } else {
- Message reply = messagesService.getReplyByUri(inReplyTo);
- if (reply != null) {
- User user = new User();
- user.setUri(URI.create(activity.getActor()));
- String attachment = StringUtils.EMPTY;
- if (note.get("attachment") != null && ((List) note.get("attachment")).size() > 0) {
- Map<String, Object> attachmentObj = (Map<String, Object>) ((List<Object>) note.get("attachment")).get(0);
- attachment = (String) attachmentObj.get("url");
- }
- CommandResult result = commandsManager.processCommand(user, String.format("#%d/%d %s", reply.getMid(), reply.getRid(), note.get("content")), URI.create(attachment));
- logger.info(jsonMapper.writeValueAsString(result));
- if (result.getNewMessage().isPresent()) {
- messagesService.updateReplyUri(result.getNewMessage().get(), noteId);
- return new ResponseEntity<>(HttpStatus.OK);
- } else {
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
- }
- }
- }
- }
- }
- }
- }
- }
- if (activity instanceof Delete) {
- Map<String, Object> tombstone = (Map<String, Object>) activity.getObject();
- if (tombstone.get("type").equals("Tombstone")) {
- URI actor = URI.create(activity.getActor());
- URI reply = URI.create((String)tombstone.get("id"));
- messagesService.deleteReply(actor, reply);
- return new ResponseEntity<>(HttpStatus.OK);
- }
- }
- if (activity instanceof Announce) {
- logger.info("Announce: {}", jsonMapper.writeValueAsString(activity));
- return new ResponseEntity<>(HttpStatus.OK);
- }
- logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
- }
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
- }
- @PostMapping(value = "/u/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public User fetchUser(@RequestParam URI uri) {
- Person person = (Person) signatureManager.getContext(uri).orElseThrow(HttpBadRequestException::new);
- User user = new User();
- user.setUri(URI.create(person.getUrl()));
- user.setName(person.getPreferredUsername());
- if (person.getIcon() != null) {
- user.setAvatar(person.getIcon().getUrl());
- }
- return user;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Activity.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Activity.java
deleted file mode 100644
index ec126b88..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/Activity.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.juick.server.api.activity.model;
-
-public abstract class Activity extends Context {
-
- private String actor;
- private Object object;
-
- public String getActor() {
- return actor;
- }
-
- public void setActor(String actor) {
- this.actor = actor;
- }
-
- public Object getObject() {
- return object;
- }
-
- public void setObject(Object object) {
- this.object = object;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java
deleted file mode 100644
index 0df8f8c7..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package com.juick.server.api.activity.model;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonSubTypes;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.juick.server.api.activity.model.activities.*;
-import com.juick.server.api.activity.model.objects.*;
-
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property="type")
-@JsonSubTypes({
- @JsonSubTypes.Type(value = Create.class, name = "Create"),
- @JsonSubTypes.Type(value = Delete.class, name = "Delete"),
- @JsonSubTypes.Type(value = Follow.class, name = "Follow"),
- @JsonSubTypes.Type(value = Accept.class, name = "Accept"),
- @JsonSubTypes.Type(value = Undo.class, name = "Undo"),
- @JsonSubTypes.Type(value = Like.class, name = "Like"),
- @JsonSubTypes.Type(value = Block.class, name = "Block"),
- @JsonSubTypes.Type(value = Announce.class, name = "Announce"),
- @JsonSubTypes.Type(value = Activity.class, name = "Activity"),
- @JsonSubTypes.Type(value = Image.class, name = "Image"),
- @JsonSubTypes.Type(value = Key.class, name = "Key"),
- @JsonSubTypes.Type(value = Link.class, name = "Link"),
- @JsonSubTypes.Type(value = Hashtag.class, name = "Hashtag"),
- @JsonSubTypes.Type(value = Mention.class, name = "Mention"),
- @JsonSubTypes.Type(value = Note.class, name = "Note"),
- @JsonSubTypes.Type(value = OrderedCollection.class, name = "OrderedCollection"),
- @JsonSubTypes.Type(value = OrderedCollectionPage.class, name = "OrderedCollectionPage"),
- @JsonSubTypes.Type(value = Person.class, name = "Person")
-})
-public abstract class Context {
-
- private List<Object> context;
-
- private String id;
-
- private String name;
-
- private Instant published;
-
- private String url;
-
- private List<String> to;
-
- private List<Context> tags;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getType() {
- return getClass().getSimpleName();
- }
-
- @JsonProperty("@context")
- public List<Object> getContext() {
- return context;
- }
-
- public final static String ACTIVITY_STREAMS_URI = "https://www.w3.org/ns/activitystreams";
- public final static String SECURITY_URI = "https://w3id.org/security/v1";
- public final static String LD_JSON_MEDIA_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
- public final static String ACTIVITY_MEDIA_TYPE = "application/activity+json";
- public final static String ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE = ACTIVITY_MEDIA_TYPE + "; profile=\"https://www.w3.org/ns/activitystreams\"";
-
- public Instant getPublished() {
- return published;
- }
-
- public void setPublished(Instant published) {
- this.published = published;
- }
-
- public List<String> getTo() {
- return to;
- }
-
- public void setTo(List<String> to) {
- this.to = to;
- }
-
- public static Context build(Context response) {
- response.context = new ArrayList(Arrays.asList(ACTIVITY_STREAMS_URI, SECURITY_URI));
- response.context.add(Collections.singletonMap("Hashtag", "as:Hashtag"));
- return response;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- @JsonProperty("tag")
- public List<Context> getTags() {
- return tags;
- }
-
- public void setTags(List<Context> tags) {
- this.tags = tags;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Accept.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Accept.java
deleted file mode 100644
index 1e0a9968..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Accept.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Accept extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Announce.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Announce.java
deleted file mode 100644
index f2859404..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Announce.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Announce extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Block.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Block.java
deleted file mode 100644
index 0e5a02d4..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Block.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Block extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Create.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Create.java
deleted file mode 100644
index 52507373..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Create.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Create extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Delete.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Delete.java
deleted file mode 100644
index f4392020..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Delete.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Delete extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Follow.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Follow.java
deleted file mode 100644
index 573ecc6e..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Follow.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Follow extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Like.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Like.java
deleted file mode 100644
index 3670293d..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Like.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Like extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Undo.java b/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Undo.java
deleted file mode 100644
index 4e87e9d0..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/activities/Undo.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.activities;
-
-import com.juick.server.api.activity.model.Activity;
-
-public class Undo extends Activity {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Hashtag.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Hashtag.java
deleted file mode 100644
index 34e73be6..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Hashtag.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.juick.server.api.activity.model.Context;
-
-public class Hashtag extends Context {
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Image.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Image.java
deleted file mode 100644
index e067f729..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Image.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.juick.server.api.activity.model.Context;
-
-public class Image extends Context {
- private String mediaType;
-
- public String getMediaType() {
- return mediaType;
- }
-
- public void setMediaType(String mediaType) {
- this.mediaType = mediaType;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Key.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Key.java
deleted file mode 100644
index 075c51dd..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Key.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.juick.server.api.activity.model.Context;
-
-public class Key extends Context {
- private String owner;
- private String publicKeyPem;
-
- public String getOwner() {
- return owner;
- }
-
- public void setOwner(String owner) {
- this.owner = owner;
- }
-
- public String getPublicKeyPem() {
- return publicKeyPem;
- }
-
- public void setPublicKeyPem(String publicKeyPem) {
- this.publicKeyPem = publicKeyPem;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Link.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Link.java
deleted file mode 100644
index 0c4f26dc..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Link.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.juick.server.api.activity.model.Context;
-
-public class Link extends Context {
- private String href;
-
- public String getHref() {
- return href;
- }
-
- public void setHref(String href) {
- this.href = href;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java
deleted file mode 100644
index bcb52d37..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class Mention extends Link {
- @JsonCreator
- public Mention(@JsonProperty("href") String href, @JsonProperty("name") String name) {
- this.setHref(href);
- this.setName(name);
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java
deleted file mode 100644
index baad2d3b..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.juick.server.api.activity.model.Context;
-
-import java.util.List;
-
-public class Note extends Context {
- private String content;
- private String attributedTo;
- private String inReplyTo;
- private List<Image> attachment;
- private List<String> to;
- private List<String> cc;
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public String getAttributedTo() {
- return attributedTo;
- }
-
- public void setAttributedTo(String attributedTo) {
- this.attributedTo = attributedTo;
- }
-
- @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
- public List<Image> getAttachment() {
- return attachment;
- }
-
- public void setAttachment(List<Image> attachment) {
- this.attachment = attachment;
- }
-
- public List<String> getTo() {
- return to;
- }
-
- public void setTo(List<String> to) {
- this.to = to;
- }
-
- public List<String> getCc() {
- return cc;
- }
-
- public void setCc(List<String> cc) {
- this.cc = cc;
- }
-
- public String getInReplyTo() {
- return inReplyTo;
- }
-
- public void setInReplyTo(String inReplyTo) {
- this.inReplyTo = inReplyTo;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollection.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollection.java
deleted file mode 100644
index 426cf331..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollection.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.juick.server.api.activity.model.Context;
-
-public class OrderedCollection extends Context {
-
- private int totalItems;
-
- public int getTotalItems() {
- return totalItems;
- }
-
- public void setTotalItems(int totalItems) {
- this.totalItems = totalItems;
- }
- private String first;
-
- public String getFirst() {
- return first;
- }
-
- public void setFirst(String first) {
- this.first = first;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollectionPage.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollectionPage.java
deleted file mode 100644
index 601919ba..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/OrderedCollectionPage.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.juick.server.api.activity.model.Context;
-
-import java.util.List;
-
-public class OrderedCollectionPage extends Context {
-
- private String partOf;
-
- private String first;
-
- private String next;
-
- private String last;
-
- private List<? extends Context> orderedItems;
-
- public String getNext() {
- return next;
- }
-
- public void setNext(String next) {
- this.next = next;
- }
-
- public List<? extends Context> getOrderedItems() {
- return orderedItems;
- }
-
- public void setOrderedItems(List<? extends Context> orderedItems) {
- this.orderedItems = orderedItems;
- }
-
- public String getPartOf() {
- return partOf;
- }
-
- public void setPartOf(String partOf) {
- this.partOf = partOf;
- }
-
- public String getFirst() {
- return first;
- }
-
- public void setFirst(String first) {
- this.first = first;
- }
-
- public String getLast() {
- return last;
- }
-
- public void setLast(String last) {
- this.last = last;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Person.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Person.java
deleted file mode 100644
index 2d3a45d7..00000000
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Person.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.juick.server.api.activity.model.objects;
-
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.juick.server.api.activity.model.Context;
-
-public class Person extends Context {
-
- private String name;
- private String preferredUsername;
- private Image icon;
- private String inbox;
- private String outbox;
- private String following;
- private String followers;
- private Key publicKey;
-
- @Override
- public String getType() {
- return "Person";
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
- public Image getIcon() {
- return icon;
- }
-
- public void setIcon(Image icon) {
- this.icon = icon;
- }
-
- public String getOutbox() {
- return outbox;
- }
-
- public void setOutbox(String outbox) {
- this.outbox = outbox;
- }
-
- public String getInbox() {
- return inbox;
- }
-
- public void setInbox(String inbox) {
- this.inbox = inbox;
- }
-
- public String getFollowing() {
- return following;
- }
-
- public void setFollowing(String following) {
- this.following = following;
- }
-
- public String getFollowers() {
- return followers;
- }
-
- public void setFollowers(String followers) {
- this.followers = followers;
- }
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
- public Key getPublicKey() {
- return publicKey;
- }
-
- public void setPublicKey(Key publicKey) {
- this.publicKey = publicKey;
- }
-
- public String getPreferredUsername() {
- return preferredUsername;
- }
-
- public void setPreferredUsername(String preferredUsername) {
- this.preferredUsername = preferredUsername;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/apple/AppSiteAssociation.java b/juick-server/src/main/java/com/juick/server/api/apple/AppSiteAssociation.java
deleted file mode 100644
index 81ab6960..00000000
--- a/juick-server/src/main/java/com/juick/server/api/apple/AppSiteAssociation.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.juick.server.api.apple;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.Collections;
-import java.util.List;
-
-@RestController
-public class AppSiteAssociation {
- @Value("${ios_app_id:}")
- private String appId;
-
- @GetMapping("/.well-known/apple-app-site-association")
- @ResponseBody
- public SiteAssociations appSiteAssociations() {
- WebCredentials webCredentials = new WebCredentials();
- webCredentials.setApps(Collections.singletonList(appId));
- SiteAssociations siteAssociations = new SiteAssociations();
- siteAssociations.setWebcredentials(webCredentials);
- return siteAssociations;
- }
-
- private class SiteAssociations {
- private WebCredentials webcredentials;
-
- public WebCredentials getWebcredentials() {
- return webcredentials;
- }
-
- public void setWebcredentials(WebCredentials webcredentials) {
- this.webcredentials = webcredentials;
- }
- }
-
- private class WebCredentials {
- private List<String> apps;
-
- public List<String> getApps() {
- return apps;
- }
-
- public void setApps(List<String> apps) {
- this.apps = apps;
- }
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/hostmeta/HostMeta.java b/juick-server/src/main/java/com/juick/server/api/hostmeta/HostMeta.java
deleted file mode 100644
index fa4d2a3f..00000000
--- a/juick-server/src/main/java/com/juick/server/api/hostmeta/HostMeta.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.juick.server.api.hostmeta;
-
-import com.cliqset.xrd.Link;
-import com.cliqset.xrd.XRD;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.Collections;
-
-import static com.cliqset.xrd.XRDConstants.XRD_MEDIA_TYPE;
-
-@RestController
-public class HostMeta {
- @Value("${ap_base_uri:http://localhost:8080/}")
- private String baseUri;
- @GetMapping(value = "/.well-known/host-meta", produces = XRD_MEDIA_TYPE)
- public XRD hostMetaResponse() {
- Link webfinger = new Link();
- webfinger.setTemplate(String.format("%swebfinger?resource={uri}", baseUri));
- XRD xrd = new XRD();
- xrd.setLinks(Collections.singletonList(webfinger));
- return xrd;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java b/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
deleted file mode 100644
index c72f3a5e..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss;
-
-import com.juick.User;
-import com.juick.server.util.HttpBadRequestException;
-import com.juick.server.util.UserUtils;
-import com.juick.service.MessagesService;
-import com.juick.service.UserService;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-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.servlet.ModelAndView;
-
-import javax.inject.Inject;
-import java.util.List;
-
-/**
- * Created by vitalyster on 13.12.2016.
- */
-@Controller
-public class Feeds {
-
- @Inject
- private MessagesService messagesService;
- @Inject
- private UserService userService;
-
- @RequestMapping(value = "/rss/{userName}/blog", method = RequestMethod.GET, produces = "text/xml; charset=utf-8")
- public ModelAndView getBlog(@PathVariable String userName) {
- User user = userService.getUserByName(userName);
- if (!user.isAnonymous()) {
- List<Integer> mids = messagesService.getUserBlog(user.getUid(), 0, 0);
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.setViewName("messagesView");
- modelAndView.addObject("user", user);
- modelAndView.addObject("messages", messagesService.getMessages(UserUtils.getCurrentUser(), mids));
- return modelAndView;
- }
- throw new HttpBadRequestException();
- }
-
- @RequestMapping(value = "/rss/", method = RequestMethod.GET, produces = "text/xml; charset=utf-8")
- public ModelAndView getLast(@RequestParam(value = "hours", required = false, defaultValue = "0") Integer hours) {
- List<Integer> mids = messagesService.getLastMessages(hours);
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.setViewName("messagesView");
- modelAndView.addObject("messages", messagesService.getMessages(UserUtils.getCurrentUser(),mids));
- return modelAndView;
- }
- @RequestMapping(value = "/rss/comments", method = RequestMethod.GET, produces = "text/xml; charset=utf-8")
- public ModelAndView getLastReplies(@RequestParam(value = "hours", required = false, defaultValue = "0") Integer hours) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.setViewName("repliesView");
- modelAndView.addObject("messages", messagesService.getLastReplies(hours));
- return modelAndView;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java b/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java
deleted file mode 100644
index c0ae4a97..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss;
-
-import com.juick.Message;
-import com.juick.User;
-import com.juick.server.api.rss.extension.JuickModule;
-import com.juick.server.api.rss.extension.JuickModuleImpl;
-import com.juick.util.MessageUtils;
-import com.rometools.modules.atom.modules.AtomLinkModule;
-import com.rometools.modules.atom.modules.AtomLinkModuleImpl;
-import com.rometools.modules.mediarss.MediaEntryModuleImpl;
-import com.rometools.modules.mediarss.MediaModule;
-import com.rometools.modules.mediarss.MediaModuleImpl;
-import com.rometools.modules.mediarss.types.MediaContent;
-import com.rometools.modules.mediarss.types.Metadata;
-import com.rometools.modules.mediarss.types.Thumbnail;
-import com.rometools.modules.mediarss.types.UrlReference;
-import com.rometools.rome.feed.atom.Link;
-import com.rometools.rome.feed.rss.*;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
-
-import javax.annotation.Nonnull;
-import javax.annotation.PostConstruct;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * Created by vitalyster on 13.12.2016.
- */
-public class MessagesView extends AbstractRssFeedView {
-
- private static final Logger logger = LoggerFactory.getLogger(MessagesView.class);
-
- @PostConstruct
- public void init() {
- setContentType("application/rss+xml;charset=UTF-8");
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected List<Item> buildFeedItems(@Nonnull Map<String, Object> model,
- @Nonnull HttpServletRequest request,
- @Nonnull HttpServletResponse response) {
- List<Message> msgs = (List<Message>)model.get("messages");
- return msgs.stream().map(this::createRssItem).collect(Collectors.toList());
- }
-
- @Override
- protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) {
- Object userObj = model.get("user");
- if (userObj != null) {
- User user = (User) userObj;
- feed.setDescription(String.format("The latest messages by @%s at Juick", user.getName()));
- String title = String.format("%s - Juick", user.getName());
- feed.setTitle(title);
- String link = String.format("http://juick.com/%s/", user.getName());
- feed.setLink(link);
- Image rssImage = new Image();
- rssImage.setUrl(String.format("http://juick.com/a/%d.png", user.getUid()));
- rssImage.setTitle(title);
- rssImage.setLink(link);
- feed.setImage(rssImage);
- String href = String.format("http://rss.juick.com/%s/blog", user.getName());
- AtomLinkModule atomLinkModule = new AtomLinkModuleImpl();
- Link atomLink = new Link();
- atomLink.setHref(href);
- atomLink.setType("application/rss+xml");
- atomLink.setRel("self");
- atomLinkModule.setLinks(Collections.singletonList(atomLink));
-
- feed.getModules().add(atomLinkModule);
- } else {
- feed.setDescription("The latest messages at Juick");
- feed.setLink("http://juick.com/");
- feed.setTitle("Juick");
- }
-
- MediaModule mediaModule = new MediaModuleImpl();
- feed.getModules().add(mediaModule);
-
-
- }
-
- private Item createRssItem(Message msg) {
- Item item = new Item();
- String messageUrl = String.format("http://juick.com/%s/%d", msg.getUser().getName(), msg.getMid());
- String messageTitle = String.format("@%s: %s", msg.getUser().getName(), MessageUtils.getTagsString(msg));
- boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code"));
- String messageDescription = isCode ? MessageUtils.formatMessageCode(StringUtils.defaultString(msg.getText()))
- : MessageUtils.formatMessage(StringUtils.defaultString(msg.getText()));
- item.setLink(messageUrl);
- //item.setGuid(messageUrl);
- item.setTitle(messageTitle);
- Description description = new Description();
- description.setType("text/html");
- description.setValue(messageDescription);
- item.setDescription(description);
- item.setPubDate(Date.from(msg.getTimestamp()));
- item.setComments(messageUrl);
- msg.getTags().stream().map(t -> {
- Category category = new Category();
- category.setValue(t.getName());
- return category;
- }).forEach(c -> item.getCategories().add(c));
- JuickModule juickModule = new JuickModuleImpl();
- juickModule.setUid(msg.getUser().getUid());
- item.getModules().add(juickModule);
- if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
- String type = msg.getAttachmentType().equals("jpg") ? "image/jpeg" : "image/png";
- MediaEntryModuleImpl module = new MediaEntryModuleImpl();
- try {
- UrlReference reference = new UrlReference(MessageUtils.attachmentUrl(msg));
- MediaContent mediaContent = new MediaContent(reference);
- mediaContent.setType(type);
- Metadata metadata = new Metadata();
- metadata.setThumbnail(new Thumbnail[]{new Thumbnail(new URI(msg.getPhoto().getThumbnail()))});
- module.setMetadata(metadata);
- module.setMediaContents(new MediaContent[]{mediaContent});
- item.getModules().add(module);
- } catch (URISyntaxException e) {
- logger.error("Invalid URI", e);
- }
-
- }
- return item;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java b/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
deleted file mode 100644
index a0ab801e..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss;
-
-import com.juick.model.ResponseReply;
-import com.juick.util.MessageUtils;
-import com.rometools.modules.mediarss.MediaEntryModuleImpl;
-import com.rometools.modules.mediarss.MediaModule;
-import com.rometools.modules.mediarss.MediaModuleImpl;
-import com.rometools.modules.mediarss.types.MediaContent;
-import com.rometools.modules.mediarss.types.Metadata;
-import com.rometools.modules.mediarss.types.Thumbnail;
-import com.rometools.modules.mediarss.types.UrlReference;
-import com.rometools.rome.feed.rss.Channel;
-import com.rometools.rome.feed.rss.Description;
-import com.rometools.rome.feed.rss.Item;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
-
-import javax.annotation.Nonnull;
-import javax.annotation.PostConstruct;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * Created by vitalyster on 13.12.2016.
- */
-public class RepliesView extends AbstractRssFeedView {
-
- private static final Logger logger = LoggerFactory.getLogger(RepliesView.class);
-
- @PostConstruct
- public void init() {
- setContentType("application/rss+xml;charset=UTF-8");
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected @Nonnull List<Item> buildFeedItems(@Nonnull Map<String, Object> model,
- @Nonnull HttpServletRequest request,
- @Nonnull HttpServletResponse response) {
- List<ResponseReply> msgs = (List<ResponseReply>)model.get("messages");
- return msgs.stream().map(this::createRssItem).collect(Collectors.toList());
- }
-
- @Override
- protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) {
- feed.setTitle("Juick");
- feed.setLink("http://juick.com/");
- feed.setDescription("The latest comments at Juick");
- MediaModule mediaModule = new MediaModuleImpl();
- feed.getModules().add(mediaModule);
- }
-
- private Item createRssItem(ResponseReply msg) {
- Item item = new Item();
- String messageUrl = String.format("http://juick.com/m/%d#%d", msg.getMid(), msg.getRid());
- String messageTitle = String.format("@%s:", msg.getUname());
- String messageDescription = msg.isHtml() ? msg.getDescription() : MessageUtils.formatMessage(msg.getDescription());
- item.setLink(messageUrl);
- //item.setGuid(messageUrl);
- item.setTitle(messageTitle);
- Description description = new Description();
- description.setType("text/html");
- description.setValue(messageDescription);
- item.setDescription(description);
- item.setPubDate(msg.getPubDate());
- if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
- String type = msg.getAttachmentType().equals("jpg") ? "image/jpeg" : "image/png";
- MediaEntryModuleImpl module = new MediaEntryModuleImpl();
- try {
- UrlReference reference = new UrlReference(
- String.format("http://i.juick.com/photos-1024/%d-%d.%s", msg.getMid(), msg.getRid(), type));
- MediaContent mediaContent = new MediaContent(reference);
- mediaContent.setType(type);
- Metadata metadata = new Metadata();
- metadata.setThumbnail(new Thumbnail[]{new Thumbnail(
- new URI(String.format("http://i.juick.com/ps/%d-%d.%s", msg.getMid(), msg.getRid(), type)))});
- module.setMetadata(metadata);
- module.setMediaContents(new MediaContent[]{mediaContent});
- item.getModules().add(module);
- } catch (URISyntaxException e) {
- logger.error("Invalid URI", e);
- }
-
- }
- return item;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModule.java b/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModule.java
deleted file mode 100644
index a4198518..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModule.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss.extension;
-
-import com.rometools.rome.feed.module.Module;
-
-/**
- * Created by vitalyster on 13.12.2016.
- */
-public interface JuickModule extends Module {
-
- String URI = "http://juick.com/";
-
- Integer getUid();
-
- void setUid(Integer uid);
-
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleGenerator.java b/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleGenerator.java
deleted file mode 100644
index 90dec35f..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleGenerator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss.extension;
-
-import com.rometools.rome.feed.module.Module;
-import com.rometools.rome.io.ModuleGenerator;
-import org.jdom2.Element;
-import org.jdom2.Namespace;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Created by vt on 13/12/2016.
- */
-public class JuickModuleGenerator implements ModuleGenerator {
-
- private static final Namespace JUICK_NS = Namespace.getNamespace("juick", JuickModule.URI);
-
- @Override
- public String getNamespaceUri() {
- return JuickModule.URI;
- }
-
- private static final Set<Namespace> NAMESPACES;
-
- static {
- Set<Namespace> nss = new HashSet<>();
- nss.add(JUICK_NS);
- NAMESPACES = Collections.unmodifiableSet(nss);
- }
-
- @Override
- public Set<Namespace> getNamespaces() {
- return NAMESPACES;
- }
-
- @Override
- public void generate(Module module, Element element) {
- // this is not necessary, it is done to avoid the namespace definition in every item.
- Element root = element;
- while (root.getParent()!=null && root.getParent() instanceof Element) {
- root = element.getParentElement();
- }
- root.addNamespaceDeclaration(JUICK_NS);
-
- JuickModule juickModule = (JuickModule) module;
- if (juickModule.getUid() > 0) {
- Element user = new Element("user", JUICK_NS);
- user.setAttribute("uid", String.valueOf(juickModule.getUid()), JUICK_NS);
- element.addContent(user);
- }
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleImpl.java b/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleImpl.java
deleted file mode 100644
index dbdd8c85..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleImpl.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss.extension;
-
-import com.rometools.rome.feed.CopyFrom;
-import com.rometools.rome.feed.module.ModuleImpl;
-
-/**
- * Created by vitalyster on 13.12.2016.
- */
-public class JuickModuleImpl extends ModuleImpl implements JuickModule {
-
- private Integer uid;
-
- public JuickModuleImpl() {
- super(JuickModule.class, JuickModule.URI);
- }
-
- @Override
- public Integer getUid() {
- return uid;
- }
-
- @Override
- public void setUid(Integer uid) {
- this.uid = uid;
- }
-
- @Override
- public Class<? extends CopyFrom> getInterface() {
- return JuickModule.class;
- }
-
- @Override
- public void copyFrom(CopyFrom obj) {
- JuickModule juickModule = (JuickModule) obj;
- setUid(juickModule.getUid());
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleParser.java b/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleParser.java
deleted file mode 100644
index a3d0e175..00000000
--- a/juick-server/src/main/java/com/juick/server/api/rss/extension/JuickModuleParser.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.rss.extension;
-
-import com.rometools.rome.feed.module.Module;
-import com.rometools.rome.io.ModuleParser;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.jdom2.Element;
-
-import java.util.Locale;
-
-/**
- * Created by vitalyster on 13.12.2016.
- */
-public class JuickModuleParser implements ModuleParser {
- @Override
- public String getNamespaceUri() {
- return JuickModule.URI;
- }
-
- @Override
- public Module parse(Element element, Locale locale) {
- JuickModuleImpl juickModule = new JuickModuleImpl();
- juickModule.setUid(NumberUtils.toInt(element.getAttributeValue("uid", JuickModule.URI), 0));
- return juickModule;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java b/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java
deleted file mode 100644
index 71a0ca31..00000000
--- a/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.juick.server.api.webfinger;
-
-import com.juick.User;
-import com.juick.server.api.webfinger.model.Account;
-import com.juick.server.api.webfinger.model.Link;
-import com.juick.server.util.HttpNotFoundException;
-import com.juick.service.UserService;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.util.UriComponentsBuilder;
-import rocks.xmpp.addr.Jid;
-
-import javax.inject.Inject;
-import java.util.Collections;
-
-import static com.juick.server.api.activity.model.Context.ACTIVITY_MEDIA_TYPE;
-
-@RestController
-public class Resource {
- @Inject
- private UserService userService;
- @Value("${web_domain:localhost}")
- private String domain;
- @Value("${ap_base_uri:http://localhost:8080/}")
- private String baseUri;
-
- @GetMapping("/.well-known/webfinger")
- public Account getWebResource(@RequestParam String resource) {
- if (resource.startsWith("acct:")) {
- Jid account = Jid.of(resource.substring(5));
- if (account.getDomain().equals(domain)) {
- User user = userService.getUserByName(account.getLocal());
- if (!user.isAnonymous()) {
- UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUri);
- builder.path(String.format("/u/%s", user.getName()));
- Link blog = new Link();
- blog.setRel("self");
- blog.setType(ACTIVITY_MEDIA_TYPE);
- blog.setHref(builder.toUriString());
- Account result = new Account();
- result.setSubject(resource);
- result.setLinks(Collections.singletonList(blog));
- return result;
- }
- }
- }
- throw new HttpNotFoundException();
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/webfinger/model/Account.java b/juick-server/src/main/java/com/juick/server/api/webfinger/model/Account.java
deleted file mode 100644
index 892fa303..00000000
--- a/juick-server/src/main/java/com/juick/server/api/webfinger/model/Account.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.juick.server.api.webfinger.model;
-
-import java.util.List;
-
-public class Account {
- private String subject;
- private List<Link> links;
-
- public String getSubject() {
- return subject;
- }
-
- public void setSubject(String subject) {
- this.subject = subject;
- }
-
- public List<Link> getLinks() {
- return links;
- }
-
- public void setLinks(List<Link> links) {
- this.links = links;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/webfinger/model/Link.java b/juick-server/src/main/java/com/juick/server/api/webfinger/model/Link.java
deleted file mode 100644
index 48e7ab67..00000000
--- a/juick-server/src/main/java/com/juick/server/api/webfinger/model/Link.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.juick.server.api.webfinger.model;
-
-public class Link {
- private String rel;
- private String type;
- private String href;
-
- public String getRel() {
- return rel;
- }
-
- public void setRel(String rel) {
- this.rel = rel;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getHref() {
- return href;
- }
-
- public void setHref(String href) {
- this.href = href;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java b/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java
deleted file mode 100644
index 7a5cebda..00000000
--- a/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.juick.server.api.webhooks;
-
-import com.juick.server.TelegramBotManager;
-import com.pengrad.telegrambot.BotUtils;
-import com.pengrad.telegrambot.model.Update;
-import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseStatus;
-import org.springframework.web.bind.annotation.RestController;
-import springfox.documentation.annotations.ApiIgnore;
-
-import javax.inject.Inject;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-
-/**
- * Created by vt on 24/11/2016.
- */
-@ApiIgnore
-@RestController
-@ConditionalOnProperty({"telegram_token"})
-public class TelegramWebhook {
- private static final Logger logger = LoggerFactory.getLogger(TelegramWebhook.class);
- @Inject
- private TelegramBotManager telegramBotManager;
-
- @RequestMapping(value = "/api/tlgmbtwbhk", method = RequestMethod.POST)
- @ResponseStatus(value = HttpStatus.OK)
- public void processUpdate(InputStream body) throws Exception {
- String data = IOUtils.toString(body, StandardCharsets.UTF_8);
- logger.info("Telegram update: {}", data);
- Update update = BotUtils.parseUpdate(data);
- telegramBotManager.processUpdate(update);
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/Info.java b/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/Info.java
deleted file mode 100644
index c12df55f..00000000
--- a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/Info.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.juick.server.api.xnodeinfo2;
-
-import com.juick.server.api.xnodeinfo2.model.*;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.inject.Inject;
-import java.time.Instant;
-import java.time.ZonedDateTime;
-import java.time.temporal.ChronoUnit;
-import java.util.Arrays;
-
-@RestController
-public class Info {
- @Value("${ap_base_uri:http://localhost:8080/}")
- private String baseUri;
- @Inject
- private JdbcTemplate jdbcTemplate;
-
- @GetMapping("/.well-known/x-nodeinfo2")
- public NodeInfo showNodeInfo() {
- NodeInfo nodeInfo = new NodeInfo();
- Server server = new Server();
- server.setBaseUrl(baseUri);
- server.setName("Juick");
- server.setSoftware("Juick");
- server.setVersion("2.x");
- nodeInfo.setServer(server);
- nodeInfo.setProtocols(Arrays.asList("xmpp", "activitypub", "smtp"));
- ServiceInfo serviceInfo = new ServiceInfo();
- serviceInfo.setInbound(Arrays.asList("jabber", "mastodon", "email", "telegram"));
- serviceInfo.setOutbound(Arrays.asList("jabber", "mastodon", "telegram", "twitter", "email", "rss"));
- nodeInfo.setServices(serviceInfo);
- UserStats userStats = new UserStats();
- userStats.setTotal(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM users WHERE banned=0", Integer.class));
- userStats.setActiveMonth(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM users WHERE banned=0 AND last_seen > ?",
- Integer.class, ZonedDateTime.now().minus(1, ChronoUnit.MONTHS).toInstant()));
- userStats.setActiveHalfyear(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM users WHERE banned=0 AND last_seen > ?",
- Integer.class, ZonedDateTime.now().minus(6, ChronoUnit.MONTHS).toInstant()));
- Usage usage = new Usage();
- usage.setUsers(userStats);
- usage.setLocalPosts(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM messages",
- Integer.class));
- usage.setLocalComments(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM replies",
- Integer.class));
- nodeInfo.setUsage(usage);
- return nodeInfo;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/NodeInfo.java b/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/NodeInfo.java
deleted file mode 100644
index 06fe354f..00000000
--- a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/NodeInfo.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.juick.server.api.xnodeinfo2.model;
-
-import java.util.List;
-
-public class NodeInfo {
-
- private Server server;
-
- private List<String> protocols;
-
- private ServiceInfo services;
-
- public String getVersion() {
- return "1.0";
- }
-
- public Server getServer() {
- return server;
- }
-
- public void setServer(Server server) {
- this.server = server;
- }
-
- public List<String> getProtocols() {
- return protocols;
- }
-
- public void setProtocols(List<String> protocols) {
- this.protocols = protocols;
- }
-
- public ServiceInfo getServices() {
- return services;
- }
-
- public void setServices(ServiceInfo services) {
- this.services = services;
- }
-
- public boolean getOpenRegistrations() {
- return true;
- }
-
- private Usage usage;
-
- public Usage getUsage() {
- return usage;
- }
-
- public void setUsage(Usage usage) {
- this.usage = usage;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Server.java b/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Server.java
deleted file mode 100644
index a772d268..00000000
--- a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Server.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.juick.server.api.xnodeinfo2.model;
-
-public class Server {
- private String baseUrl;
- private String name;
- private String software;
- private String version;
-
- public String getBaseUrl() {
- return baseUrl;
- }
-
- public void setBaseUrl(String baseUrl) {
- this.baseUrl = baseUrl;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getSoftware() {
- return software;
- }
-
- public void setSoftware(String software) {
- this.software = software;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/ServiceInfo.java b/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/ServiceInfo.java
deleted file mode 100644
index 5b6d2baa..00000000
--- a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/ServiceInfo.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.juick.server.api.xnodeinfo2.model;
-
-import java.util.List;
-
-public class ServiceInfo {
- private List<String> inbound;
- private List<String> outbound;
-
- public List<String> getInbound() {
- return inbound;
- }
-
- public void setInbound(List<String> inbound) {
- this.inbound = inbound;
- }
-
- public List<String> getOutbound() {
- return outbound;
- }
-
- public void setOutbound(List<String> outbound) {
- this.outbound = outbound;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Usage.java b/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Usage.java
deleted file mode 100644
index e04ea48b..00000000
--- a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/Usage.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.juick.server.api.xnodeinfo2.model;
-
-public class Usage {
- private UserStats users;
- private int localPosts;
- private int localComments;
-
- public UserStats getUsers() {
- return users;
- }
-
- public void setUsers(UserStats users) {
- this.users = users;
- }
-
- public int getLocalPosts() {
- return localPosts;
- }
-
- public void setLocalPosts(int localPosts) {
- this.localPosts = localPosts;
- }
-
- public int getLocalComments() {
- return localComments;
- }
-
- public void setLocalComments(int localComments) {
- this.localComments = localComments;
- }
-}
diff --git a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/UserStats.java b/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/UserStats.java
deleted file mode 100644
index 515661e3..00000000
--- a/juick-server/src/main/java/com/juick/server/api/xnodeinfo2/model/UserStats.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.juick.server.api.xnodeinfo2.model;
-
-public class UserStats {
- private int total;
- private int activeHalfyear;
- private int activeMonth;
-
- public int getTotal() {
- return total;
- }
-
- public void setTotal(int total) {
- this.total = total;
- }
-
- public int getActiveHalfyear() {
- return activeHalfyear;
- }
-
- public void setActiveHalfyear(int activeHalfyear) {
- this.activeHalfyear = activeHalfyear;
- }
-
- public int getActiveMonth() {
- return activeMonth;
- }
-
- public void setActiveMonth(int activeMonth) {
- this.activeMonth = activeMonth;
- }
-}