mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-18 21:03:11 +00:00
[AB-224] fixing not properly ignoring ignored starboard posts leading to re-creation of them
This commit is contained in:
@@ -70,6 +70,11 @@ public abstract class StarboardListener {
|
|||||||
|
|
||||||
protected void handleStarboardPostChange(CachedMessage message, CachedReactions reaction, ServerUser userReacting, boolean adding) {
|
protected void handleStarboardPostChange(CachedMessage message, CachedReactions reaction, ServerUser userReacting, boolean adding) {
|
||||||
Optional<StarboardPost> starboardPostOptional = starboardPostManagementService.findByMessageId(message.getMessageId());
|
Optional<StarboardPost> starboardPostOptional = starboardPostManagementService.findByMessageId(message.getMessageId());
|
||||||
|
boolean starboardPostExists = starboardPostOptional.isPresent();
|
||||||
|
if(starboardPostExists && starboardPostOptional.get().isIgnored()) {
|
||||||
|
log.info("Starboard post {} for message {} in server {} is ignored. Doing nothing.", starboardPostOptional.get().getId(), message.getMessageId(), message.getServerId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(reaction != null) {
|
if(reaction != null) {
|
||||||
AUserInAServer author = userInServerManagementService.loadOrCreateUser(message.getServerId(), message.getAuthor().getAuthorId());
|
AUserInAServer author = userInServerManagementService.loadOrCreateUser(message.getServerId(), message.getAuthor().getAuthorId());
|
||||||
List<AUserInAServer> userExceptAuthor = getUsersExcept(reaction.getUsers(), author);
|
List<AUserInAServer> userExceptAuthor = getUsersExcept(reaction.getUsers(), author);
|
||||||
@@ -78,7 +83,7 @@ public abstract class StarboardListener {
|
|||||||
if (userExceptAuthor.size() >= starMinimum) {
|
if (userExceptAuthor.size() >= starMinimum) {
|
||||||
log.info("Post reached starboard minimum. Message {} in channel {} in server {} will be starred/updated.",
|
log.info("Post reached starboard minimum. Message {} in channel {} in server {} will be starred/updated.",
|
||||||
message.getMessageId(), message.getChannelId(), message.getServerId());
|
message.getMessageId(), message.getChannelId(), message.getServerId());
|
||||||
if(starboardPostOptional.isPresent()) {
|
if(starboardPostExists) {
|
||||||
updateStarboardPost(message, userAddingReaction, adding, starboardPostOptional.get(), userExceptAuthor);
|
updateStarboardPost(message, userAddingReaction, adding, starboardPostOptional.get(), userExceptAuthor);
|
||||||
} else {
|
} else {
|
||||||
metricService.incrementCounter(STARBOARD_STARS_THRESHOLD_REACHED);
|
metricService.incrementCounter(STARBOARD_STARS_THRESHOLD_REACHED);
|
||||||
@@ -89,14 +94,14 @@ public abstract class StarboardListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(starboardPostOptional.isPresent()) {
|
if(starboardPostExists) {
|
||||||
metricService.incrementCounter(STARBOARD_STARS_THRESHOLD_FELL);
|
metricService.incrementCounter(STARBOARD_STARS_THRESHOLD_FELL);
|
||||||
log.info("Removing starboard post for message {} in channel {} in server {}. It fell under the threshold {}", message.getMessageId(), message.getChannelId(), message.getServerId(), starMinimum);
|
log.info("Removing starboard post for message {} in channel {} in server {}. It fell under the threshold {}", message.getMessageId(), message.getChannelId(), message.getServerId(), starMinimum);
|
||||||
starboardPostOptional.ifPresent(starboardPost -> completelyRemoveStarboardPost(starboardPost, userReacting));
|
starboardPostOptional.ifPresent(starboardPost -> completelyRemoveStarboardPost(starboardPost, userReacting));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(starboardPostOptional.isPresent()) {
|
if(starboardPostExists) {
|
||||||
log.info("Removing starboard post for message {} in channel {} in server {}", message.getMessageId(), message.getChannelId(), message.getServerId());
|
log.info("Removing starboard post for message {} in channel {} in server {}", message.getMessageId(), message.getChannelId(), message.getServerId());
|
||||||
starboardPostOptional.ifPresent(starboardPost -> completelyRemoveStarboardPost(starboardPost, userReacting));
|
starboardPostOptional.ifPresent(starboardPost -> completelyRemoveStarboardPost(starboardPost, userReacting));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,18 @@ public class StarAddedListenerTest {
|
|||||||
verify(starboardPostReactorManagementService, times(1)).addReactor(post, userInServerActing);
|
verify(starboardPostReactorManagementService, times(1)).addReactor(post, userInServerActing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddingEmoteToExistingIgnoredPost() {
|
||||||
|
Long requiredStars = 1L;
|
||||||
|
setupActingAndAuthor();
|
||||||
|
when(post.isIgnored()).thenReturn(true);
|
||||||
|
executeAddingTest(requiredStars, post);
|
||||||
|
verify(metricService, times(1)).incrementCounter(any());
|
||||||
|
verify(starboardService, times(0)).updateStarboardPost(eq(post), any(CachedMessage.class), anyList());
|
||||||
|
verify(starboardPostReactorManagementService, times(0)).addReactor(post, userInServerActing);
|
||||||
|
}
|
||||||
|
|
||||||
private void setupActingAndAuthor() {
|
private void setupActingAndAuthor() {
|
||||||
when(userInServerActing.getUserReference()).thenReturn(userActing);
|
when(userInServerActing.getUserReference()).thenReturn(userActing);
|
||||||
when(userActing.getId()).thenReturn(USER_ACTING_ID);
|
when(userActing.getId()).thenReturn(USER_ACTING_ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user