aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/CommandsManager.java2
-rw-r--r--src/main/java/com/juick/XMPPManager.java2
-rw-r--r--src/main/java/com/juick/config/AppConfig.java3
-rw-r--r--src/main/java/com/juick/model/Message.java3
-rw-r--r--src/main/java/com/juick/service/ChatServiceImpl.java1
-rw-r--r--src/main/java/com/juick/service/FileSystemStorageService.java7
-rw-r--r--src/main/java/com/juick/service/InfoService.java4
-rw-r--r--src/main/java/com/juick/service/StorageService.java4
-rw-r--r--src/main/java/com/juick/service/TelegramServiceImpl.java3
-rw-r--r--src/main/java/com/juick/util/HttpUtils.java4
-rw-r--r--src/main/java/com/juick/util/formatters/PlainTextFormatter.java2
-rw-r--r--src/main/java/com/juick/www/api/Mastodon.java2
-rw-r--r--src/main/java/com/juick/www/api/SystemActivity.java2
-rw-r--r--src/main/java/com/juick/www/api/activity/Profile.java15
-rw-r--r--src/main/java/com/juick/www/api/activity/model/Activity.java2
-rw-r--r--src/main/java/com/juick/www/filters/AnythingFilter.java1
-rw-r--r--src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java3
17 files changed, 24 insertions, 36 deletions
diff --git a/src/main/java/com/juick/CommandsManager.java b/src/main/java/com/juick/CommandsManager.java
index 588d0073..7488e331 100644
--- a/src/main/java/com/juick/CommandsManager.java
+++ b/src/main/java/com/juick/CommandsManager.java
@@ -417,7 +417,7 @@ public class CommandsManager {
public CommandResult commandOnOff(User user, URI attachment, String[] input) {
UserService.ActiveStatus newStatus;
String retValUpdated;
- if (input[0].toLowerCase().equals("on")) {
+ if (input[0].equalsIgnoreCase("on")) {
newStatus = UserService.ActiveStatus.Active;
retValUpdated = "XMPP notifications are activated";
} else {
diff --git a/src/main/java/com/juick/XMPPManager.java b/src/main/java/com/juick/XMPPManager.java
index 0c5cb2f4..9e24c347 100644
--- a/src/main/java/com/juick/XMPPManager.java
+++ b/src/main/java/com/juick/XMPPManager.java
@@ -239,7 +239,7 @@ public class XMPPManager implements NotificationListener {
return isBotJid || isDomainJid;
}
return isBotJid;
- };
+ }
private void sendJuickMessage(com.juick.model.Message jmsg, List<User> users) {
List<String> jids = new ArrayList<>();
diff --git a/src/main/java/com/juick/config/AppConfig.java b/src/main/java/com/juick/config/AppConfig.java
index 77229d1b..27622195 100644
--- a/src/main/java/com/juick/config/AppConfig.java
+++ b/src/main/java/com/juick/config/AppConfig.java
@@ -85,8 +85,7 @@ public class AppConfig {
HtmlRenderer helpRenderer() {
return HtmlRenderer.builder()
.attributeProviderFactory(context -> (node, tagName, attributes) -> {
- if (node instanceof Link) {
- Link link = (Link) node;
+ if (node instanceof Link link) {
if (link.getDestination().startsWith("/")) {
String destination = "/" + helpService().getHelpPath() + link.getDestination();
link.setDestination(destination);
diff --git a/src/main/java/com/juick/model/Message.java b/src/main/java/com/juick/model/Message.java
index 32d888a7..915d5f21 100644
--- a/src/main/java/com/juick/model/Message.java
+++ b/src/main/java/com/juick/model/Message.java
@@ -118,10 +118,9 @@ public class Message implements Comparable<Message>, Serializable {
if (obj == this)
return true;
- if (!(obj instanceof Message))
+ if (!(obj instanceof Message jmsg))
return false;
- Message jmsg = (Message) obj;
return (this.getMid() == jmsg.getMid() && this.getRid() == jmsg.getRid());
}
diff --git a/src/main/java/com/juick/service/ChatServiceImpl.java b/src/main/java/com/juick/service/ChatServiceImpl.java
index c0d2f17b..4247e49a 100644
--- a/src/main/java/com/juick/service/ChatServiceImpl.java
+++ b/src/main/java/com/juick/service/ChatServiceImpl.java
@@ -47,7 +47,6 @@ public class ChatServiceImpl extends BaseJdbcService implements ChatService {
return getJdbcTemplate().query(
"SELECT l.user_id, users.nick, l.last, pm.txt FROM pm "
+ "INNER JOIN users ON users.id = pm.user_id "
- + ""
+ "INNER JOIN (SELECT user_id, MAX(ts) AS last FROM pm "
+ "WHERE user_id_to=? GROUP BY user_id) l ON l.last = pm.ts "
+ "WHERE pm.user_id_to=? "
diff --git a/src/main/java/com/juick/service/FileSystemStorageService.java b/src/main/java/com/juick/service/FileSystemStorageService.java
index 89669283..c3ec9333 100644
--- a/src/main/java/com/juick/service/FileSystemStorageService.java
+++ b/src/main/java/com/juick/service/FileSystemStorageService.java
@@ -145,8 +145,7 @@ public class FileSystemStorageService implements StorageService {
try {
ImageMetadata metadata = Imaging.getMetadata(imageFile);
- if (metadata instanceof JpegImageMetadata) {
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ if (metadata instanceof JpegImageMetadata jpegMetadata) {
TiffField orientationField = jpegMetadata.findEXIFValue(TiffTagConstants.TIFF_TAG_ORIENTATION);
if (orientationField != null) {
@@ -228,10 +227,10 @@ public class FileSystemStorageService implements StorageService {
String targetExt = "png";
if (ImageIO.write(Scalr.resize(originalImage, 96), targetExt, tmpPath.toFile())) {
Files.move(tmpPath, getAvatarPath(user), copyOptions);
- };
+ }
if (ImageIO.write(Scalr.resize(originalImage, 32), targetExt, tmpPath.toFile())) {
Files.move(tmpPath, Paths.get(avatarSmallDir, getAvatarFileName(user, targetExt)), copyOptions);
- };
+ }
}
public Attachment getAttachment(File imgFile) throws IOException {
diff --git a/src/main/java/com/juick/service/InfoService.java b/src/main/java/com/juick/service/InfoService.java
index b10e325e..9540243e 100644
--- a/src/main/java/com/juick/service/InfoService.java
+++ b/src/main/java/com/juick/service/InfoService.java
@@ -58,9 +58,9 @@ public class InfoService {
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).toLocalDateTime()));
+ Integer.class, ZonedDateTime.now().minusMonths(1).toLocalDateTime()));
userStats.setActiveHalfyear(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM users WHERE banned=0 AND last_seen > ?",
- Integer.class, ZonedDateTime.now().minus(6, ChronoUnit.MONTHS).toLocalDateTime()));
+ Integer.class, ZonedDateTime.now().minusMonths(6).toLocalDateTime()));
Usage usage = new Usage();
usage.setUsers(userStats);
usage.setLocalPosts(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM messages WHERE privacy=1",
diff --git a/src/main/java/com/juick/service/StorageService.java b/src/main/java/com/juick/service/StorageService.java
index f1f72a60..1574c809 100644
--- a/src/main/java/com/juick/service/StorageService.java
+++ b/src/main/java/com/juick/service/StorageService.java
@@ -43,9 +43,9 @@ public interface StorageService {
*/
void saveAvatar(String tempFilename, User user) throws IOException;
- public Attachment getAttachment(File imgFile) throws IOException;
+ Attachment getAttachment(File imgFile) throws IOException;
- public Attachment getAvatarMetadata(User user) throws IOException;
+ Attachment getAvatarMetadata(User user) throws IOException;
String getBaseDirectory();
diff --git a/src/main/java/com/juick/service/TelegramServiceImpl.java b/src/main/java/com/juick/service/TelegramServiceImpl.java
index 3cd6c27d..3f11a47a 100644
--- a/src/main/java/com/juick/service/TelegramServiceImpl.java
+++ b/src/main/java/com/juick/service/TelegramServiceImpl.java
@@ -65,8 +65,7 @@ public class TelegramServiceImpl extends BaseJdbcService implements TelegramServ
if (uids.isEmpty()) {
return Collections.emptyList();
}
- return getNamedParameterJdbcTemplate().queryForList("" +
- "SELECT tg_id FROM telegram WHERE user_id IN(:uids)", new MapSqlParameterSource()
+ return getNamedParameterJdbcTemplate().queryForList("SELECT tg_id FROM telegram WHERE user_id IN(:uids)", new MapSqlParameterSource()
.addValue("uids", uids), Long.class);
}
}
diff --git a/src/main/java/com/juick/util/HttpUtils.java b/src/main/java/com/juick/util/HttpUtils.java
index 46bb3e2d..22598977 100644
--- a/src/main/java/com/juick/util/HttpUtils.java
+++ b/src/main/java/com/juick/util/HttpUtils.java
@@ -97,7 +97,7 @@ public class HttpUtils {
try {
urlConn = url.openConnection();
} catch (IOException e) {
- logger.error(String.format("Failed open url: %s", url.toString()));
+ logger.error(String.format("Failed open url: %s", url));
throw e;
}
@@ -108,7 +108,7 @@ public class HttpUtils {
Files.copy(is, Paths.get(tmpDir, attachmentFName));
return URI.create(String.format("juick://%s", attachmentFName));
} catch (IOException e) {
- logger.error(String.format("Failed download image by url: %s", url.toString()), e);
+ logger.error(String.format("Failed download image by url: %s", url), e);
throw e;
}
}
diff --git a/src/main/java/com/juick/util/formatters/PlainTextFormatter.java b/src/main/java/com/juick/util/formatters/PlainTextFormatter.java
index b1b1a44a..9a885bca 100644
--- a/src/main/java/com/juick/util/formatters/PlainTextFormatter.java
+++ b/src/main/java/com/juick/util/formatters/PlainTextFormatter.java
@@ -67,7 +67,7 @@ public class PlainTextFormatter {
sb.append(txt);
}
return String.format("@%s:%s\n%s\n#%s (%s%s) %s",
- m.getUser().getName(), MessageUtils.getTagsString(m), sb.toString(), formatPostNumber(m), timeAgo, repliesCount, formatUrl(m));
+ m.getUser().getName(), MessageUtils.getTagsString(m), sb, formatPostNumber(m), timeAgo, repliesCount, formatUrl(m));
}
public static String formatUrl(Message jmsg) {
diff --git a/src/main/java/com/juick/www/api/Mastodon.java b/src/main/java/com/juick/www/api/Mastodon.java
index eeca1fda..190ee5ef 100644
--- a/src/main/java/com/juick/www/api/Mastodon.java
+++ b/src/main/java/com/juick/www/api/Mastodon.java
@@ -182,8 +182,6 @@ public class Mastodon {
public record Preferences() {
}
- ;
-
@GetMapping("/api/v1/preferences")
public Preferences preferences() {
return new Preferences();
diff --git a/src/main/java/com/juick/www/api/SystemActivity.java b/src/main/java/com/juick/www/api/SystemActivity.java
index 59d5cc73..a75ef3b6 100644
--- a/src/main/java/com/juick/www/api/SystemActivity.java
+++ b/src/main/java/com/juick/www/api/SystemActivity.java
@@ -72,7 +72,7 @@ public class SystemActivity {
follow
}
- private ActivityType type;
+ private final ActivityType type;
private User from;
private List<User> to;
private Message message;
diff --git a/src/main/java/com/juick/www/api/activity/Profile.java b/src/main/java/com/juick/www/api/activity/Profile.java
index aa8f0394..d815c9d6 100644
--- a/src/main/java/com/juick/www/api/activity/Profile.java
+++ b/src/main/java/com/juick/www/api/activity/Profile.java
@@ -190,7 +190,7 @@ public class Profile {
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);
+ Stream<User> followersPage = followers.stream().skip(20L * page).limit(20);
OrderedCollectionPage result = new OrderedCollectionPage();
result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
@@ -234,7 +234,7 @@ public class Profile {
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);
+ Stream<User> followingPage = following.stream().skip(20L * page).limit(20);
OrderedCollectionPage result = new OrderedCollectionPage();
result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
@@ -268,7 +268,7 @@ public class Profile {
}
private String formatNote(Note note) {
- String markdown = remarkConverter.convertFragment((String) note.getContent());
+ String markdown = remarkConverter.convertFragment(note.getContent());
// combine note text with attachment urls
return note.getAttachment() == null ? markdown
: note.getAttachment().stream().map(attachment -> {
@@ -289,8 +289,7 @@ public class Profile {
if (context instanceof Activity activity) {
if ((StringUtils.isNotEmpty(visitor.getUri().toString())
&& visitor.getUri().equals(URI.create(activity.getActor()))) || !visitor.isAnonymous()) {
- if (activity instanceof Follow) {
- Follow followRequest = (Follow) activity;
+ if (activity instanceof Follow followRequest) {
applicationEventPublisher.publishEvent(new FollowEvent(this, followRequest));
return new ResponseEntity<>(CommandResult.fromString("Follow request accepted"), HttpStatus.ACCEPTED);
}
@@ -309,8 +308,7 @@ public class Profile {
}
}
if (activity instanceof Create) {
- if (activity.getObject() instanceof Note) {
- Note note = (Note) activity.getObject();
+ if (activity.getObject() instanceof Note note) {
URI noteId = URI.create(note.getId());
if (messagesService.replyExists(noteId)) {
return new ResponseEntity<>(CommandResult.fromString("Reply already exists"), HttpStatus.OK);
@@ -386,8 +384,7 @@ public class Profile {
logger.info("{} update their profile", activity.getActor());
return new ResponseEntity<>(CommandResult.fromString("Update accepted"), HttpStatus.ACCEPTED);
}
- if (activity.getObject() instanceof Note) {
- Note note = (Note) activity.getObject();
+ if (activity.getObject() instanceof Note note) {
logger.info("Got update to {}", note.getId());
if (activity.getActor().equals(note.getAttributedTo())) {
Message reply = messagesService.getReplyByUri(note.getId());
diff --git a/src/main/java/com/juick/www/api/activity/model/Activity.java b/src/main/java/com/juick/www/api/activity/model/Activity.java
index 7cc0b13f..427990c6 100644
--- a/src/main/java/com/juick/www/api/activity/model/Activity.java
+++ b/src/main/java/com/juick/www/api/activity/model/Activity.java
@@ -38,7 +38,7 @@ public abstract class Activity extends Context {
public void setActor(String actor) {
this.actor = actor;
if (StringUtils.isEmpty(getId())) {
- setId(String.format("%s#%s", this.actor, UUID.randomUUID().toString()));
+ setId(String.format("%s#%s", this.actor, UUID.randomUUID()));
}
}
diff --git a/src/main/java/com/juick/www/filters/AnythingFilter.java b/src/main/java/com/juick/www/filters/AnythingFilter.java
index ffd11b29..91422807 100644
--- a/src/main/java/com/juick/www/filters/AnythingFilter.java
+++ b/src/main/java/com/juick/www/filters/AnythingFilter.java
@@ -73,7 +73,6 @@ public class AnythingFilter extends OncePerRequestFilter {
}
}
}
- ;
if (userService.getUsernames().stream().anyMatch(name -> name.equals(anything))) {
servletResponse.sendRedirect("/" + anything + "/");
} else {
diff --git a/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java b/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
index 009cc83a..1ecfd40d 100644
--- a/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
+++ b/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
@@ -34,8 +34,7 @@ import java.util.Map;
public class FormatMessageFilter implements Filter {
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
- if (input instanceof Message) {
- Message msg = (Message) input;
+ if (input instanceof Message msg) {
if (msg.isHtml()) {
return new SafeString(msg.getText());
}