aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-06 21:53:13 +0300
committerGravatar Vitaly Takmazov2019-04-06 23:10:23 +0300
commit384c61ceae3301c6bc92ee6f591ed9d186b15204 (patch)
treec337cb96e242d81794999435b526e423a3fa6415 /src/main/java/com/juick
parent347674599f4ee8e2682c8ab7a80d87e0080f310c (diff)
Message properties
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/server/TelegramBotManager.java6
-rw-r--r--src/main/java/com/juick/server/www/controllers/AnythingFilter.java2
-rw-r--r--src/main/java/com/juick/service/MessagesService.java3
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java39
4 files changed, 45 insertions, 5 deletions
diff --git a/src/main/java/com/juick/server/TelegramBotManager.java b/src/main/java/com/juick/server/TelegramBotManager.java
index 56b5b4f9..22864af8 100644
--- a/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/src/main/java/com/juick/server/TelegramBotManager.java
@@ -268,7 +268,7 @@ public class TelegramBotManager implements NotificationListener {
telegramPhoto.caption(msg);
isSendTxt = false;
}
- bot.execute(telegramPhoto, new Callback<SendPhoto, SendResponse>() {
+ bot.execute(telegramPhoto, new Callback<>() {
@Override
public void onResponse(SendPhoto request, SendResponse response) {
processTelegramResponse(chatId, response, source);
@@ -286,7 +286,7 @@ public class TelegramBotManager implements NotificationListener {
telegramMessage.replyToMessageId(replyTo);
}
telegramMessage.parseMode(ParseMode.Markdown).disableWebPagePreview(true);
- bot.execute(telegramMessage, new Callback<SendMessage, SendResponse>() {
+ bot.execute(telegramMessage, new Callback<>() {
@Override
public void onResponse(SendMessage request, SendResponse response) {
processTelegramResponse(chatId, response, source);
@@ -338,7 +338,7 @@ public class TelegramBotManager implements NotificationListener {
String.format("You are subscribed to all Juick messages. " +
"[Create or link](http://juick.com/signup?type=durov&hash=%s) " +
"an existing Juick account to get your subscriptions and ability to post messages", hash))
- .parseMode(ParseMode.Markdown), new Callback<SendMessage, SendResponse>() {
+ .parseMode(ParseMode.Markdown), new Callback<>() {
@Override
public void onResponse(SendMessage request, SendResponse response) {
logger.info("got response: {}", response.message());
diff --git a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java b/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
index 57b298eb..1f4cf75a 100644
--- a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
+++ b/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
@@ -53,7 +53,7 @@ public class AnythingFilter extends OncePerRequestFilter {
}
com.juick.User user = userService.getUserByName(anything);
if (user.getUid() > 0) {
- ((HttpServletResponse)servletResponse).sendRedirect("/" + user.getName() + "/");
+ servletResponse.sendRedirect("/" + user.getName() + "/");
} else {
filterChain.doFilter(servletRequest, servletResponse);
}
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index 080319cc..b29337b2 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -140,4 +140,7 @@ public interface MessagesService {
boolean replyExists(URI replyUri);
boolean deleteReply(URI userUri, URI replyUri);
+
+ String getMessageProperty(Integer mid, String key);
+ void setMessageProperty(Integer mid, String key, String value);
}
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index def6324a..3e09d204 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -33,6 +33,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.ConnectionCallback;
@@ -1162,21 +1163,57 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
}
+ @Transactional
@Override
public boolean updateReplyUri(Message reply, URI replyUri) {
return jdbcTemplate.update("UPDATE replies SET reply_uri=?, html=0 WHERE message_id=? AND reply_id=?",
replyUri.toASCIIString(), reply.getMid(), reply.getRid()) > 0;
}
+ @Transactional(readOnly = true)
@Override
public boolean replyExists(URI replyUri) {
return jdbcTemplate.queryForList("SELECT reply_id FROM replies WHERE reply_uri=?",
Integer.class, replyUri.toASCIIString()).size() > 0;
}
+ @Transactional
@Override
public boolean deleteReply(URI userUri, URI replyUri) {
- return jdbcTemplate.update("DELETE FROM replies WHERE user_uri=? AND reply_uri=?",
+ return jdbcTemplate.update("DELETE FROM replies WHERE user_uri=? AND reply_uri=?",
userUri.toASCIIString(), replyUri.toASCIIString()) > 0;
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public String getMessageProperty(Integer mid, String key) {
+ List<String> results = jdbcTemplate.queryForList(
+ "SELECT property_value FROM messages_properties WHERE message_id=? AND property_key=?",
+ String.class, mid, key);
+ if (results.size() > 0) {
+ return results.get(0);
+ }
+ return StringUtils.EMPTY;
+ }
+
+ @Transactional
+ @Override
+ public void setMessageProperty(Integer mid, String key, String value) {
+ SqlParameterSource parameterSource = new MapSqlParameterSource()
+ .addValue("mid", mid)
+ .addValue("key", key)
+ .addValue("value", value);
+ if (StringUtils.isNotEmpty(value)) {
+ try {
+ getNamedParameterJdbcTemplate().update("INSERT INTO messages_properties(message_id, property_key, property_value) " +
+ "VALUES(:mid, :key, :value)", parameterSource);
+ } catch (DataIntegrityViolationException ex) {
+ getNamedParameterJdbcTemplate().update("UPDATE messages_properties SET property_value=:value " +
+ "WHERE message_id=:mid AND property_key=:key", parameterSource);
+ }
+ } else {
+ getNamedParameterJdbcTemplate().update("DELETE FROM messages_properties " +
+ "WHERE message_id=:mid AND property_key=:key", parameterSource);
+ }
+ }
}