diff options
Diffstat (limited to 'src/main/java/com')
4 files changed, 22 insertions, 8 deletions
diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java index fad4e0da..295909cc 100644 --- a/src/main/java/com/juick/SignatureManager.java +++ b/src/main/java/com/juick/SignatureManager.java @@ -177,9 +177,8 @@ public class SignatureManager { public Optional<Context> discoverPerson(String acct) { Jid acctId = Jid.of(acct); URI resourceUri = UriComponentsBuilder.fromPath("/.well-known/webfinger").host(acctId.getDomain()) - .scheme("https").queryParam("resource", String.format("%s", acctId.toEscapedString())).build().toUri(); + .scheme("https").queryParam("resource", "acct:" + acct).build().toUri(); HttpHeaders headers = new HttpHeaders(); - headers.add("Accept", "application/jrd+json"); HttpEntity<Void> webfingerRequest = new HttpEntity<>(headers); try { ResponseEntity<Account> response = apClient.exchange(resourceUri, HttpMethod.GET, webfingerRequest, diff --git a/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java b/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java index 8b578aa0..79beaa09 100644 --- a/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java +++ b/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2021, Juick + * Copyright (C) 2008-2022, 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 @@ -17,6 +17,7 @@ package com.juick.util; +import org.jetbrains.annotations.NotNull; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; @@ -30,8 +31,8 @@ import com.juick.www.api.activity.model.Activity; public class ActivityPubRequestInterceptor implements ClientHttpRequestInterceptor { @Override - public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { - request.getHeaders().set(HttpHeaders.ACCEPT, Activity.ACTIVITY_MEDIA_TYPE); + public @NotNull ClientHttpResponse intercept(HttpRequest request, byte @NotNull [] body, + ClientHttpRequestExecution execution) throws IOException { request.getHeaders().set(HttpHeaders.USER_AGENT, "Juick/2.x"); return execution.execute(request, body); } diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 7a95acb5..0ece7249 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -192,9 +192,9 @@ public class MessageUtils { // <a href="#12">/12</a> msg = msg.replaceAll(replyNumberRegex, "$1<a href=\"#$2\">/$2</a>$3"); - // @username@jabber.org - // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a> - msg = msg.replaceAll(jidRegex, "$1<span class=\"h-card\"><a class=\"u-url\" href=\"https://juick.com/$2/\">@$2</a></span>$3"); + // @username@mastodon.social + // <a href="http://juick.com/mention?username=username@mastodon.social/">@username@mastodon.social</a> + msg = msg.replaceAll(jidRegex, "$1<span class=\"h-card\"><a class=\"u-url\" href=\"http://juick.com/mention?username=$2\">@$2</a></span>$3"); // @username // <a href="http://juick.com/username/">@username</a> diff --git a/src/main/java/com/juick/www/controllers/Compat.java b/src/main/java/com/juick/www/controllers/Compat.java index ebf584dc..936a8e5c 100644 --- a/src/main/java/com/juick/www/controllers/Compat.java +++ b/src/main/java/com/juick/www/controllers/Compat.java @@ -17,17 +17,31 @@ package com.juick.www.controllers; +import com.juick.SignatureManager; +import com.juick.util.HttpNotFoundException; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; +import javax.inject.Inject; + @Controller public class Compat { + @Inject + private SignatureManager signatureManager; @GetMapping("/share") public RedirectView share(@RequestParam String text, RedirectAttributes attributes) { attributes.addAttribute("body", text); return new RedirectView("/post"); } + @GetMapping("/mention") + public RedirectView mention(@RequestParam String username) { + var profile = signatureManager.discoverPerson(username); + if (profile.isPresent()) { + return new RedirectView(profile.get().getUrl()); + } + throw new HttpNotFoundException(); + } } |