aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-10-11 12:47:02 +0300
committerGravatar Vitaly Takmazov2017-10-11 12:47:02 +0300
commit753d79d6bbabfdac33c6c382717fe0acaec2a3bd (patch)
tree006a2b957d4a599315d1472ae1d4f7e726136ee2 /juick-server-jdbc/src/main/java
parent0ad4b98456e5de96a9fea6e128a20a4624c72c6a (diff)
telegram: do not duplicate subscription requests
Diffstat (limited to 'juick-server-jdbc/src/main/java')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java11
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java24
2 files changed, 23 insertions, 12 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
index 18e9485c..79163d1c 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
@@ -18,6 +18,7 @@
package com.juick.service;
import com.juick.Tag;
+import com.juick.User;
import com.juick.server.helpers.TagStats;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
@@ -274,4 +275,14 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
"SELECT tag_id FROM messages_tags WHERE message_id = ?",
Integer.class, mid);
}
+
+ @Override
+ public boolean blacklistTag(User user, Tag tag) {
+ int rowcount = getNamedParameterJdbcTemplate().update("DELETE FROM bl_tags WHERE tag_id = :tid AND user_id = :uid",
+ new MapSqlParameterSource().addValue("tid", tag.TID).addValue("uid", user.getUid()));
+ return rowcount <= 0 && getNamedParameterJdbcTemplate()
+ .update("INSERT INTO bl_tags(user_id, tag_id) VALUES(:uid,:tid)",
+ new MapSqlParameterSource().addValue("tid", tag.TID)
+ .addValue("uid", user.getUid())) > 0;
+ }
}
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
index 1ccb8f25..325396e4 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
@@ -17,13 +17,17 @@
package com.juick.service;
+import com.juick.User;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
+import java.util.Collections;
import java.util.List;
import java.util.UUID;
+import java.util.stream.Collectors;
/**
* Created by vt on 24/11/2016.
@@ -74,17 +78,13 @@ public class TelegramServiceImpl extends BaseJdbcService implements TelegramServ
@Transactional(readOnly = true)
@Override
- public List<Long> getSubscribers(final int uid) {
- return getJdbcTemplate().queryForList("" +
- "SELECT tg_id FROM telegram INNER JOIN subscr_users " +
- "ON (subscr_users.user_id=? AND telegram.user_id=subscr_users.suser_id)", Long.class, uid);
- }
-
- @Transactional(readOnly = true)
- @Override
- public List<Long> getSubscribersToComments(final int mid, final int ignore_uid) {
- return getJdbcTemplate().queryForList(
- "SELECT tg_id FROM telegram INNER JOIN subscr_messages " +
- "ON (telegram.user_id=subscr_messages.suser_id) WHERE message_id=? AND suser_id!=?", Long.class, mid, ignore_uid);
+ public List<Long> getTelegramIdentifiers(List<User> users) {
+ List<Integer> uids = users.stream().map(User::getUid).collect(Collectors.toList());
+ if (uids.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return getNamedParameterJdbcTemplate().queryForList("" +
+ "SELECT tg_id FROM telegram WHERE user_id IN(:uids)", new MapSqlParameterSource()
+ .addValue("uids", uids), Long.class);
}
}