aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/CommandsManager.java6
-rw-r--r--src/main/java/com/juick/XMPPManager.java18
-rw-r--r--src/main/java/com/juick/config/XMPPConfig.java6
-rw-r--r--src/main/java/com/juick/service/ChatService.java (renamed from src/main/java/com/juick/service/PMQueriesService.java)12
-rw-r--r--src/main/java/com/juick/service/ChatServiceImpl.java (renamed from src/main/java/com/juick/service/PMQueriesServiceImpl.java)10
-rw-r--r--src/main/java/com/juick/www/api/PM.java10
-rw-r--r--src/main/java/com/juick/www/controllers/Site.java6
7 files changed, 32 insertions, 36 deletions
diff --git a/src/main/java/com/juick/CommandsManager.java b/src/main/java/com/juick/CommandsManager.java
index 0c16fbbd..6b33cf16 100644
--- a/src/main/java/com/juick/CommandsManager.java
+++ b/src/main/java/com/juick/CommandsManager.java
@@ -39,7 +39,7 @@ import com.juick.model.Tag;
import com.juick.model.TagStats;
import com.juick.model.User;
import com.juick.service.MessagesService;
-import com.juick.service.PMQueriesService;
+import com.juick.service.ChatService;
import com.juick.service.PrivacyQueriesService;
import com.juick.service.ShowQueriesService;
import com.juick.service.StorageService;
@@ -80,7 +80,7 @@ public class CommandsManager {
@Inject
private TagService tagService;
@Inject
- private PMQueriesService pmQueriesService;
+ private ChatService chatService;
@Inject
private ShowQueriesService showQueriesService;
@Inject
@@ -192,7 +192,7 @@ public class CommandsManager {
user_to.setAvatar(webApp.getAvatarUrl(user_to));
if (!user_to.isAnonymous()) {
if (!userService.isInBLAny(user_to.getUid(), user_from.getUid())) {
- if (pmQueriesService.createPM(user_from.getUid(), user_to.getUid(), body)) {
+ if (chatService.createMessage(user_from.getUid(), user_to.getUid(), body)) {
Message jmsg = new Message();
jmsg.setUser(user_from);
jmsg.setTo(user_to);
diff --git a/src/main/java/com/juick/XMPPManager.java b/src/main/java/com/juick/XMPPManager.java
index 1080b1b9..9bd3b7b5 100644
--- a/src/main/java/com/juick/XMPPManager.java
+++ b/src/main/java/com/juick/XMPPManager.java
@@ -20,7 +20,7 @@ package com.juick;
import com.juick.model.CommandResult;
import com.juick.model.User;
import com.juick.service.MessagesService;
-import com.juick.service.PMQueriesService;
+import com.juick.service.ChatService;
import com.juick.service.StorageService;
import com.juick.service.UserService;
import com.juick.service.component.NotificationListener;
@@ -31,16 +31,13 @@ import com.juick.util.formatters.PlainTextFormatter;
import com.juick.util.xmpp.iq.MessageQuery;
import com.juick.www.WebApp;
import com.juick.www.api.SystemActivity;
-import jakarta.annotation.PostConstruct;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
-import org.springframework.stereotype.Component;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.XmppException;
import rocks.xmpp.core.session.Extension;
@@ -70,7 +67,6 @@ import rocks.xmpp.extensions.version.SoftwareVersionManager;
import rocks.xmpp.extensions.version.model.SoftwareVersion;
import javax.annotation.Nonnull;
-import javax.inject.Inject;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
@@ -94,19 +90,19 @@ public class XMPPManager implements NotificationListener {
private final CommandsManager commandsManager;
private final MessagesService messagesService;
private final UserService userService;
- private final PMQueriesService pmQueriesService;
+ private final ChatService chatService;
private final Jid jid;
public XMPPManager(String botJid, String componentName, int componentPort, String componentHost,
String password, Resource vCardImage, CommandsManager commandsManager,
StorageService storageService, MessagesService messagesService, UserService userService,
- PMQueriesService pmQueriesService, Executor applicationTaskExecutor, WebApp webApp) {
+ ChatService chatService, Executor applicationTaskExecutor, WebApp webApp) {
jid = Jid.of(botJid);
this.commandsManager = commandsManager;
this.messagesService = messagesService;
this.userService = userService;
- this.pmQueriesService = pmQueriesService;
+ this.chatService = chatService;
logger.info("xmpp component start connecting to {}", componentPort);
XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
.extensions(Extension.of(com.juick.model.Message.class), Extension.of(MessageQuery.class))
@@ -346,7 +342,7 @@ public class XMPPManager implements NotificationListener {
Message mm = new Message();
mm.setTo(Jid.of(userJid));
mm.setType(Message.Type.CHAT);
- boolean inroster = pmQueriesService.havePMinRoster(msg.getUser().getUid(), userJid);
+ boolean inroster = chatService.havePMinRoster(msg.getUser().getUid(), userJid);
if (inroster) {
mm.setFrom(Jid.of(msg.getUser().getName(), "juick.com", "Juick"));
mm.setBody(msg.getText());
@@ -491,7 +487,7 @@ public class XMPPManager implements NotificationListener {
} else {
int uid_to = userService.getUIDbyName(username);
if (uid_to > 0) {
- pmQueriesService.addPMinRoster(uid_to, p.getFrom().asBareJid().toEscapedString());
+ chatService.addPMinRoster(uid_to, p.getFrom().asBareJid().toEscapedString());
canSubscribe = true;
}
}
@@ -519,7 +515,7 @@ public class XMPPManager implements NotificationListener {
if (!toJuick) {
int uid_to = userService.getUIDbyName(username);
if (uid_to > 0) {
- pmQueriesService.removePMinRoster(uid_to, p.getFrom().asBareJid().toEscapedString());
+ chatService.removePMinRoster(uid_to, p.getFrom().asBareJid().toEscapedString());
}
}
diff --git a/src/main/java/com/juick/config/XMPPConfig.java b/src/main/java/com/juick/config/XMPPConfig.java
index 73077760..5593b228 100644
--- a/src/main/java/com/juick/config/XMPPConfig.java
+++ b/src/main/java/com/juick/config/XMPPConfig.java
@@ -20,7 +20,7 @@ package com.juick.config;
import com.juick.CommandsManager;
import com.juick.XMPPManager;
import com.juick.service.MessagesService;
-import com.juick.service.PMQueriesService;
+import com.juick.service.ChatService;
import com.juick.service.StorageService;
import com.juick.service.UserService;
import com.juick.www.WebApp;
@@ -57,7 +57,7 @@ public class XMPPConfig {
@Inject
private UserService userService;
@Inject
- private PMQueriesService pmQueriesService;
+ private ChatService chatService;
@Inject
private Executor applicationTaskExecutor;
@Inject
@@ -66,7 +66,7 @@ public class XMPPConfig {
@Bean(destroyMethod = "close")
XMPPManager xmppConnection() {
return new XMPPManager(botJid, componentName, componentPort, componentHost, password, vCardImage,
- commandsManager, storageService, messagesService, userService, pmQueriesService,
+ commandsManager, storageService, messagesService, userService, chatService,
applicationTaskExecutor, webApp);
}
}
diff --git a/src/main/java/com/juick/service/PMQueriesService.java b/src/main/java/com/juick/service/ChatService.java
index bb57b7c3..b09e93b0 100644
--- a/src/main/java/com/juick/service/PMQueriesService.java
+++ b/src/main/java/com/juick/service/ChatService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, 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
@@ -26,8 +26,8 @@ import java.util.List;
/**
* Created by aalexeev on 11/13/16.
*/
-public interface PMQueriesService {
- boolean createPM(int uidFrom, int uid_to, String body);
+public interface ChatService {
+ boolean createMessage(int uidFrom, int uid_to, String body);
boolean addPMinRoster(int uid, String jid);
@@ -37,9 +37,9 @@ public interface PMQueriesService {
List<Chat> getLastChats(User user);
- List<Message> getPMMessages(int uid, int uidTo);
+ List<Message> getChat(int uid, int uidTo);
- List<Message> getLastPMInbox(int uid);
+ List<Message> getInbox(int uid);
- List<Message> getLastPMSent(int uid);
+ List<Message> getOutbox(int uid);
}
diff --git a/src/main/java/com/juick/service/PMQueriesServiceImpl.java b/src/main/java/com/juick/service/ChatServiceImpl.java
index c2e06da5..2d3fe31a 100644
--- a/src/main/java/com/juick/service/PMQueriesServiceImpl.java
+++ b/src/main/java/com/juick/service/ChatServiceImpl.java
@@ -31,11 +31,11 @@ import java.util.List;
* Created by aalexeev on 11/13/16.
*/
@Repository
-public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesService {
+public class ChatServiceImpl extends BaseJdbcService implements ChatService {
@Transactional
@Override
- public boolean createPM(final int uidFrom, final int uid_to, final String body) {
+ public boolean createMessage(final int uidFrom, final int uid_to, final String body) {
return getJdbcTemplate().update(
"INSERT INTO pm(user_id, user_id_to, txt) VALUES (?, ?, ?)",
uidFrom, uid_to, body) > 0;
@@ -89,7 +89,7 @@ public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesSe
@Transactional
@Override
- public List<Message> getPMMessages(final int uid, final int uidTo) {
+ public List<Message> getChat(final int uid, final int uidTo) {
SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
.addValue("uid", uid)
.addValue("uidTo", uidTo);
@@ -113,7 +113,7 @@ public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesSe
@Transactional(readOnly = true)
@Override
- public List<Message> getLastPMInbox(final int uid) {
+ public List<Message> getInbox(final int uid) {
return getJdbcTemplate().query(
"SELECT pm.user_id, users.nick, pm.txt, pm.ts " +
"FROM pm INNER JOIN users ON pm.user_id=users.id WHERE pm.user_id_to=? ORDER BY pm.ts DESC LIMIT 20",
@@ -131,7 +131,7 @@ public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesSe
@Transactional(readOnly = true)
@Override
- public List<Message> getLastPMSent(final int uid) {
+ public List<Message> getOutbox(final int uid) {
return getJdbcTemplate().query(
"SELECT pm.user_id_to, users.nick, pm.txt, " +
"pm.ts FROM pm INNER JOIN users ON pm.user_id_to=users.id " +
diff --git a/src/main/java/com/juick/www/api/PM.java b/src/main/java/com/juick/www/api/PM.java
index 55c1f2d0..96387dce 100644
--- a/src/main/java/com/juick/www/api/PM.java
+++ b/src/main/java/com/juick/www/api/PM.java
@@ -26,7 +26,7 @@ import com.juick.util.HttpBadRequestException;
import com.juick.util.HttpForbiddenException;
import com.juick.util.WebUtils;
import com.juick.www.WebApp;
-import com.juick.service.PMQueriesService;
+import com.juick.service.ChatService;
import com.juick.service.UserService;
import com.juick.service.component.SystemEvent;
import com.juick.service.security.annotation.Visitor;
@@ -49,7 +49,7 @@ public class PM {
@Inject
private UserService userService;
@Inject
- private PMQueriesService pmQueriesService;
+ private ChatService chatService;
@Inject
private ApplicationEventPublisher applicationEventPublisher;
@Inject
@@ -68,7 +68,7 @@ public class PM {
throw new HttpBadRequestException();
}
- List<Message> msgs = pmQueriesService.getPMMessages(visitor.getUid(), uid);
+ List<Message> msgs = chatService.getChat(visitor.getUid(), uid);
msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
return msgs;
}
@@ -91,7 +91,7 @@ public class PM {
throw new HttpForbiddenException();
}
- if (pmQueriesService.createPM(visitor.getUid(), userTo.getUid(), body)) {
+ if (chatService.createMessage(visitor.getUid(), userTo.getUid(), body)) {
Message jmsg = new Message();
jmsg.setUser(visitor);
jmsg.setText(body);
@@ -111,7 +111,7 @@ public class PM {
@RequestParam(defaultValue = "5") int cnt) {
// TODO: ignore cnt param for now but make sure paging param will not be cnt
- List<Chat> lastconv = pmQueriesService.getLastChats(visitor);
+ List<Chat> lastconv = chatService.getLastChats(visitor);
lastconv.forEach(c -> c.setAvatar(webApp.getAvatarUrl(c)));
PrivateChats pms = new PrivateChats();
pms.setUsers(lastconv);
diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java
index dadf7ed6..f45fe8f2 100644
--- a/src/main/java/com/juick/www/controllers/Site.java
+++ b/src/main/java/com/juick/www/controllers/Site.java
@@ -74,7 +74,7 @@ public class Site {
@Inject
private MessagesService messagesService;
@Inject
- private PMQueriesService pmQueriesService;
+ private ChatService chatService;
@Inject
private WebApp webApp;
@Inject
@@ -455,7 +455,7 @@ public class Site {
protected String doGetInbox(@Visitor User visitor, ModelMap model) {
visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String title = "PM: Inbox";
- List<Message> msgs = pmQueriesService.getLastPMInbox(visitor.getUid());
+ List<Message> msgs = chatService.getInbox(visitor.getUid());
msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
fillUserModel(model, visitor, visitor);
model.addAttribute("title", title);
@@ -469,7 +469,7 @@ public class Site {
protected String doGetSent(@Visitor User visitor, @RequestParam(required = false) String uname, ModelMap model) {
visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String title = "PM: Sent";
- List<Message> msgs = pmQueriesService.getLastPMSent(visitor.getUid());
+ List<Message> msgs = chatService.getOutbox(visitor.getUid());
msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
if (WebUtils.isNotUserName(uname)) {
uname = StringUtils.EMPTY;