diff --git a/server/src/main/java/edu/sjsu/moth/server/db/Follow.java b/server/src/main/java/edu/sjsu/moth/server/db/Follow.java index 1efd55b..ae3e913 100644 --- a/server/src/main/java/edu/sjsu/moth/server/db/Follow.java +++ b/server/src/main/java/edu/sjsu/moth/server/db/Follow.java @@ -5,12 +5,12 @@ public class Follow { public static class FollowKey{ - public String followerId; - public String followedId; + public String follower_id; + public String followed_id; public FollowKey(String follower_id, String followed_id){ - this.followerId = follower_id; - this.followedId = followed_id; + this.follower_id = follower_id; + this.followed_id = followed_id; } } diff --git a/server/src/main/java/edu/sjsu/moth/server/db/FollowRepository.java b/server/src/main/java/edu/sjsu/moth/server/db/FollowRepository.java index 1436bb6..65d47ed 100644 --- a/server/src/main/java/edu/sjsu/moth/server/db/FollowRepository.java +++ b/server/src/main/java/edu/sjsu/moth/server/db/FollowRepository.java @@ -8,9 +8,9 @@ public interface FollowRepository extends ReactiveMongoRepository { @Query("{'id.followedId': ?0}") - Mono> findAllByIdFollowedId(String followed_id); + Mono> findAllByFollowedId(String followed_id); @Query("{'id.followerId': ?0}") - Mono> findAllByIdFollowerId(String follower_id); + Mono> findAllByFollowerId(String follower_id); // Mono countAllByIdFollowedId(String followed_id); // Mono countAllByIdFollowerId(String follower_id); } diff --git a/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java b/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java index eb81a26..a9bc575 100644 --- a/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java +++ b/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java @@ -106,9 +106,9 @@ public Mono usersFollow(String id, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, String followType) { - var items = followType.equals("following") ? followRepository.findAllByIdFollowerId(id) - .map(list -> list.stream().map(f -> f.id.followedId).toList()) : followRepository.findAllByIdFollowedId(id) - .map(list -> list.stream().map(f -> f.id.followerId).toList()); + var items = followType.equals("following") ? followRepository.findAllByFollowerId(id) + .map(list -> list.stream().map(f -> f.id.followed_id).toList()) : followRepository.findAllByFollowedId(id) + .map(list -> list.stream().map(f -> f.id.follower_id).toList()); String returnID = MothController.BASE_URL + "/users/" + id + followType; int pageSize = limit != null ? limit : DEFAULT_PAGE_SIZE; if (page == null) { @@ -153,8 +153,8 @@ public Mono updateAccount(Account a) { public Mono filterAccountSearch(String query, Principal user, Boolean following, String max_id, String min_id, Integer limit, Integer offset, SearchResult result) { - return followRepository.findAllByIdFollowerId(((Account) user).id).flatMap(f -> { - var followers = f.stream().map(follow -> follow.id.followedId).collect(Collectors.toSet()); + return followRepository.findAllByFollowerId(((Account) user).id).flatMap(f -> { + var followers = f.stream().map(follow -> follow.id.followed_id).collect(Collectors.toSet()); return accountRepository.findByAcctLike(query) .filter(account -> following == null || !following || followers.contains(account.id)) .take(limit) diff --git a/server/src/main/java/edu/sjsu/moth/server/service/StatusService.java b/server/src/main/java/edu/sjsu/moth/server/service/StatusService.java index 9068ad2..d7b0318 100644 --- a/server/src/main/java/edu/sjsu/moth/server/service/StatusService.java +++ b/server/src/main/java/edu/sjsu/moth/server/service/StatusService.java @@ -6,6 +6,7 @@ import edu.sjsu.moth.generated.Status; import edu.sjsu.moth.server.db.ExternalStatus; import edu.sjsu.moth.server.db.ExternalStatusRepository; +import edu.sjsu.moth.server.db.Follow; import edu.sjsu.moth.server.db.FollowRepository; import edu.sjsu.moth.server.db.StatusRepository; import org.jetbrains.annotations.NotNull; @@ -18,6 +19,7 @@ import java.security.Principal; import java.util.ArrayList; +import java.util.Collections; import java.util.List; @Configuration @@ -125,11 +127,11 @@ public Mono filterStatusSearch(String query, Principal user, Strin private Flux filterStatusByViewable(Principal user, Status status, boolean isFollowingTimeline) { return accountService.getAccount(user.getName()) .switchIfEmpty(Mono.error(new UsernameNotFoundException(user.getName()))) - .flatMapMany(acct -> followRepository.findAllByIdFollowerId(acct.id) - .defaultIfEmpty(new Mono.just()) - .map(list -> list.stream().map(f -> f.id.followedId).toList()) - .flatMapMany(followings -> ((!isFollowingTimeline && status.visibility.equals("public")) || followings.contains( - status.id)) ? Flux.just(status) : Flux.empty())); + .flatMapMany(acct -> followRepository.findAllByFollowerId(acct.id) + .defaultIfEmpty(Collections.emptyList()) + .map(list -> list.stream().map(f -> f.id.followed_id).toList()) + .flatMapMany(followings -> ((status.account.id.equals(acct.id)) || (!isFollowingTimeline && status.visibility.equals("public")) || followings.contains( + status.account.id)) ? Flux.just(status) : Flux.empty())); } } \ No newline at end of file