From cd6150df90a6ab86f20221c61c58c6864dc408fc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 26 Apr 2023 10:10:46 +0300 Subject: Expose 'vip' and 'ignored' user lists over '/me' API endpoint --- src/main/java/com/juick/CommandsManager.java | 2 +- src/main/java/com/juick/service/PostgresSearchService.java | 2 +- src/main/java/com/juick/service/SphinxSearchService.java | 2 +- src/main/java/com/juick/service/UserService.java | 3 ++- src/main/java/com/juick/service/UserServiceImpl.java | 14 +++++++++++++- src/main/java/com/juick/www/api/Mastodon.java | 3 +-- src/main/java/com/juick/www/api/Users.java | 6 ++++++ src/main/java/com/juick/www/controllers/Site.java | 4 ++-- 8 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/juick/CommandsManager.java b/src/main/java/com/juick/CommandsManager.java index a7a880c5..588d0073 100644 --- a/src/main/java/com/juick/CommandsManager.java +++ b/src/main/java/com/juick/CommandsManager.java @@ -211,7 +211,7 @@ public class CommandsManager { @UserCommand(pattern = "^bl$", patternFlags = Pattern.CASE_INSENSITIVE, help = "BL - Show your blacklist") public CommandResult commandBLShow(User user_from, URI attachment, String... arguments) { - List blusers = userService.getUserBLUsers(user_from.getUid()); + List blusers = userService.getUserIgnoredUsers(user_from.getUid()); List bltags = tagService.getUserBLTags(user_from.getUid()); StringBuilder txt = new StringBuilder(StringUtils.EMPTY); diff --git a/src/main/java/com/juick/service/PostgresSearchService.java b/src/main/java/com/juick/service/PostgresSearchService.java index 79986670..a243b3f3 100644 --- a/src/main/java/com/juick/service/PostgresSearchService.java +++ b/src/main/java/com/juick/service/PostgresSearchService.java @@ -61,7 +61,7 @@ public class PostgresSearchService extends BaseJdbcService implements SearchServ public List search(final int visitorId, final int userId, final String searchString, final int page) { - var usersFilter = userService.getUserBLUsers(visitorId).stream().map(User::getUid).toList(); + var usersFilter = userService.getUserIgnoredUsers(visitorId).stream().map(User::getUid).toList(); var offset = page * maxResult; var query = escapeQuery(searchString); var isOneWord = query.split("[^\\S\\+]+").length == 1; diff --git a/src/main/java/com/juick/service/SphinxSearchService.java b/src/main/java/com/juick/service/SphinxSearchService.java index 3775d09f..8a608b44 100644 --- a/src/main/java/com/juick/service/SphinxSearchService.java +++ b/src/main/java/com/juick/service/SphinxSearchService.java @@ -60,7 +60,7 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic sphinxQuery.put("limit", String.valueOf(maxResult)); sphinxQuery.put("mode", "any"); sphinxQuery.put("sort", sortHint(WebUtils.encodeSphinx(searchString))); - String usersFilter = userService.getUserBLUsers(visitor.getUid()).stream().map(u -> String.valueOf(u.getUid())).collect(Collectors.joining(",")); + String usersFilter = userService.getUserIgnoredUsers(visitor.getUid()).stream().map(u -> String.valueOf(u.getUid())).collect(Collectors.joining(",")); sphinxQuery.put("!filter", "user_id," + usersFilter); if (page > 0) { sphinxQuery.put("offset", String.valueOf(page * maxResult)); diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java index 0cbe104f..fe5ce23f 100644 --- a/src/main/java/com/juick/service/UserService.java +++ b/src/main/java/com/juick/service/UserService.java @@ -99,7 +99,8 @@ public interface UserService { List getUserFriends(int uid); - List getUserBLUsers(int uid); + List getUserIgnoredUsers(int uid); + List getUserVipUsers(int uid); @CacheEvict(value = "twitter_user", key="{ #user.getUid() }") boolean linkTwitterAccount(User user, String accessToken, String accessTokenSecret, String screenName); diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index 442bd03c..c586886b 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -497,7 +497,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional(readOnly = true) @Override - public List getUserBLUsers(final int uid) { + public List getUserIgnoredUsers(final int uid) { return getJdbcTemplate().query("SELECT users.id,users.nick FROM users INNER JOIN bl_users " + "ON(bl_users.bl_user_id=users.id) WHERE bl_users.user_id=? ORDER BY users.nick", (rs, num) -> { @@ -507,6 +507,18 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return u; }, uid); } + @Transactional(readOnly = true) + @Override + public List getUserVipUsers(final int uid) { + return getJdbcTemplate().query("SELECT users.id,users.nick FROM users INNER JOIN wl_users " + + "ON(wl_users.wl_user_id=users.id) WHERE wl_users.user_id=? ORDER BY users.nick", + (rs, num) -> { + User u = new User(); + u.setUid(rs.getInt(1)); + u.setName(rs.getString(2)); + return u; + }, uid); + } @Transactional @Override diff --git a/src/main/java/com/juick/www/api/Mastodon.java b/src/main/java/com/juick/www/api/Mastodon.java index 91de2162..eeca1fda 100644 --- a/src/main/java/com/juick/www/api/Mastodon.java +++ b/src/main/java/com/juick/www/api/Mastodon.java @@ -28,7 +28,6 @@ import com.juick.model.Message; import com.juick.model.User; import com.juick.service.ChatService; import com.juick.service.MessagesService; -import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.HttpBadRequestException; import com.juick.util.MessageUtils; @@ -214,7 +213,7 @@ public class Mastodon { User user = userService.getUserByUID(Integer.parseInt(userId)).orElseThrow(HttpBadRequestException::new); var readers = userService.getUserReaders(Integer.parseInt(visitorId)); var friends = userService.getUserFriends(Integer.parseInt(visitorId)); - var bl = userService.getUserBLUsers(Integer.parseInt(visitorId)); + var bl = userService.getUserIgnoredUsers(Integer.parseInt(visitorId)); var isFriend = friends.contains(user); var isReader = readers.contains(user); var isMuting = bl.contains(user); diff --git a/src/main/java/com/juick/www/api/Users.java b/src/main/java/com/juick/www/api/Users.java index 4fb53ca1..34382f8e 100644 --- a/src/main/java/com/juick/www/api/Users.java +++ b/src/main/java/com/juick/www/api/Users.java @@ -283,5 +283,11 @@ public class Users { public ApplicationStatus getFacebookStatus() { return userService.getFbCrossPostStatus(this.getUid()); } + public List getVip() { + return userService.getUserVipUsers(this.getUid()); + } + public List getIgnored() { + return userService.getUserIgnoredUsers(this.getUid()); + } } } diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index 00c27607..8b35593c 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -87,7 +87,7 @@ public class Site { model.addAttribute("isInBLAny", userService.isInBLAny(user.getUid(), visitor.getUid())); model.addAttribute("statsIRead", userService.getUserFriends(user.getUid()).size()); model.addAttribute("statsMyReaders", userService.getUserReaders(user.getUid()).size()); - model.addAttribute("statsMyBL", userService.getUserBLUsers(user.getUid()).size()); + model.addAttribute("statsMyBL", userService.getUserIgnoredUsers(user.getUid()).size()); model.addAttribute("statsMessages", userService.getStatsMessages(user.getUid())); model.addAttribute("statsReplies", userService.getStatsReplies(user.getUid())); model.addAttribute("iread", userService.getUserReadLeastPopular(user.getUid(), 8)); @@ -388,7 +388,7 @@ public class Site { model.addAttribute("headers", ""); model.addAttribute("visitor", visitor); fillUserModel(model, user, visitor); - model.addAttribute("users", userService.getUserBLUsers(user.getUid())); + model.addAttribute("users", userService.getUserIgnoredUsers(user.getUid())); return "views/users"; } -- cgit v1.2.3