aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/MessagesServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index ddf7234e..b135f3c2 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -21,6 +21,8 @@ import com.juick.model.*;
import com.juick.model.User;
import com.juick.www.WebApp;
import com.juick.util.MessageUtils;
+import com.juick.util.TagUtils;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -131,9 +133,9 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
*/
@Transactional
@Override
- public int createMessage(final int uid, final String txt, final String attachment, final List<Tag> tags) {
+ public int createMessage(final int uid, final String txt, final String attachment, @Nonnull final Set<Tag> tags) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(getJdbcTemplate()).withTableName("messages")
- .usingColumns("user_id", "attach", "ts").usingGeneratedKeyColumns("message_id");
+ .usingColumns("user_id", "attach", "ts", "readonly").usingGeneratedKeyColumns("message_id");
Map<String, Object> insertMap = new HashMap<>();
insertMap.put("user_id", uid);
Instant now = Instant.now();
@@ -141,15 +143,17 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
if (StringUtils.isNotEmpty(attachment)) {
insertMap.put("attach", attachment);
}
+ insertMap.put("readonly", TagUtils.hasTag(tags, "readonly"));
int mid = simpleJdbcInsert.executeAndReturnKey(insertMap).intValue();
if (mid > 0) {
if (CollectionUtils.isNotEmpty(tags)) {
+ var newTags = new ArrayList<>(tags);
getJdbcTemplate().batchUpdate("INSERT INTO messages_tags(message_id, tag_id) VALUES (?, ?)",
new BatchPreparedStatementSetter() {
@Override
public void setValues(@Nonnull PreparedStatement ps, int i) throws SQLException {
ps.setInt(1, mid);
- ps.setInt(2, tags.get(i).TID);
+ ps.setInt(2, newTags.get(i).TID);
}
@Override
@@ -343,6 +347,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
return !list.isEmpty() && list.get(0) == 1;
}
+ @Override
+ public void setReadOnly(final int mid, final boolean readonly) {
+ getJdbcTemplate().update("UPDATE messages SET readonly=?", readonly);
+ }
+
@Transactional(readOnly = true)
@Override
public boolean isSubscribed(final int uid, final int mid) {