diff options
5 files changed, 19 insertions, 17 deletions
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index b29337b2..8f8c3e62 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -141,6 +141,7 @@ public interface MessagesService { boolean deleteReply(URI userUri, URI replyUri); - String getMessageProperty(Integer mid, String key); - void setMessageProperty(Integer mid, String key, String value); + String getMessageProperty(Integer mid, Integer rid, String key); + + void setMessageProperty(Integer mid, Integer rid, 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 2bae04e6..798502b3 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -1186,10 +1186,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public String getMessageProperty(Integer mid, String key) { + public String getMessageProperty(Integer mid, Integer rid, String key) { List<String> results = jdbcTemplate.queryForList( - "SELECT property_value FROM messages_properties WHERE message_id=? AND property_key=?", - String.class, mid, key); + "SELECT property_value FROM messages_properties WHERE message_id=? AND reply_id=? AND property_key=?", + String.class, mid, rid, key); if (results.size() > 0) { return results.get(0); } @@ -1198,22 +1198,23 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional @Override - public void setMessageProperty(Integer mid, String key, String value) { + public void setMessageProperty(Integer mid, Integer rid, String key, String value) { SqlParameterSource parameterSource = new MapSqlParameterSource() .addValue("mid", mid) + .addValue("rid", rid) .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); + getNamedParameterJdbcTemplate().update("INSERT INTO messages_properties(message_id, reply_id, property_key, property_value) " + + "VALUES(:mid, :rid, :key, :value)", parameterSource); } catch (DataIntegrityViolationException ex) { getNamedParameterJdbcTemplate().update("UPDATE messages_properties SET property_value=:value " + - "WHERE message_id=:mid AND property_key=:key", parameterSource); + "WHERE message_id=:mid AND reply_id=:rid AND property_key=:key", parameterSource); } } else { getNamedParameterJdbcTemplate().update("DELETE FROM messages_properties " + - "WHERE message_id=:mid AND property_key=:key", parameterSource); + "WHERE message_id=:mid AND reply_id=:rid AND property_key=:key", parameterSource); } } } diff --git a/src/main/java/com/juick/service/TelegramServiceImpl.java b/src/main/java/com/juick/service/TelegramServiceImpl.java index 99cbabf6..8fb13838 100644 --- a/src/main/java/com/juick/service/TelegramServiceImpl.java +++ b/src/main/java/com/juick/service/TelegramServiceImpl.java @@ -18,7 +18,6 @@ package com.juick.service; import com.juick.User; -import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/resources/db/migration/V1.20__reply id in messages_properties.sql b/src/main/resources/db/migration/V1.20__reply id in messages_properties.sql new file mode 100644 index 00000000..2ca5e018 --- /dev/null +++ b/src/main/resources/db/migration/V1.20__reply id in messages_properties.sql @@ -0,0 +1 @@ +ALTER TABLE messages_properties ADD COLUMN reply_id smallint(5) unsigned NOT NULL
\ No newline at end of file diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 65e19b89..cc0044b9 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -2023,11 +2023,11 @@ public class ServerTests { @Test public void messagePropertiesTest() { int mid = messagesService.createMessage(ugnich.getUid(), "YO", null, null); - messagesService.setMessageProperty(mid, "tg_id", "YO"); - assertThat(messagesService.getMessageProperty(mid, "tg_id"), is("YO")); - messagesService.setMessageProperty(mid, "tg_id", "YO2"); - assertThat(messagesService.getMessageProperty(mid, "tg_id"), is("YO2")); - messagesService.setMessageProperty(mid, "tg_id", ""); - assertThat(messagesService.getMessageProperty(mid, "tg_id"), is(StringUtils.EMPTY)); + messagesService.setMessageProperty(mid, 0,"tg_id", "YO"); + assertThat(messagesService.getMessageProperty(mid, 0,"tg_id"), is("YO")); + messagesService.setMessageProperty(mid, 0,"tg_id", "YO2"); + assertThat(messagesService.getMessageProperty(mid, 0,"tg_id"), is("YO2")); + messagesService.setMessageProperty(mid, 0, "tg_id", ""); + assertThat(messagesService.getMessageProperty(mid, 0,"tg_id"), is(StringUtils.EMPTY)); } } |