discord: fix npe from menu event timing out with elapsed total time
Setting the start time to null isn't necessary, since IN_MENU is marked shouldRestart, it always resets the start time when the status is changed to menu. This was clearing it, forcing a presence update, and then erroring when trying to compute the original start time. It also would have never really unset, even if it wasn't erroring later, due to IN_MENU also being unclearable, and so would have never been removed in the first place. Additionally the status reset test is also wrong since it is testing the end timestamp which has never been used by us, making the test useless.
This commit is contained in:
@@ -32,7 +32,6 @@ import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -250,27 +249,16 @@ class DiscordState
|
||||
|
||||
final Duration actionTimeout = Duration.ofMinutes(config.actionTimeout());
|
||||
final Instant now = Instant.now();
|
||||
final AtomicBoolean updatedAny = new AtomicBoolean();
|
||||
|
||||
final boolean removedAny = events.removeAll(events.stream()
|
||||
// Only include clearable events
|
||||
.filter(event -> event.getType().isShouldBeCleared())
|
||||
// Find only events that should time out
|
||||
.filter(event -> event.getType().isShouldTimeout() && now.isAfter(event.getUpdated().plus(actionTimeout)))
|
||||
// Reset start times on timed events that should restart
|
||||
.peek(event ->
|
||||
{
|
||||
if (event.getType().isShouldRestart())
|
||||
{
|
||||
event.setStart(null);
|
||||
updatedAny.set(true);
|
||||
}
|
||||
})
|
||||
// Now filter out events that should restart as we do not want to remove them
|
||||
.filter(event -> !event.getType().isShouldRestart())
|
||||
.filter(event -> event.getType().isShouldBeCleared())
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
if (removedAny || updatedAny.get())
|
||||
if (removedAny)
|
||||
{
|
||||
updatePresenceWithLatestEvent();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ package net.runelite.client.plugins.discord;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import net.runelite.api.Client;
|
||||
@@ -35,7 +34,6 @@ import net.runelite.client.discord.DiscordPresence;
|
||||
import net.runelite.client.discord.DiscordService;
|
||||
import net.runelite.client.ws.PartyService;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -44,6 +42,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@@ -90,13 +89,12 @@ public class DiscordStateTest
|
||||
when(discordConfig.elapsedTimeType()).thenReturn(DiscordConfig.ElapsedTimeType.ACTIVITY);
|
||||
|
||||
discordState.triggerEvent(DiscordGameEventType.IN_MENU);
|
||||
verify(discordService).updatePresence(any(DiscordPresence.class));
|
||||
verify(discordService).updatePresence(any(DiscordPresence.class)); // menu presence
|
||||
|
||||
discordState.checkForTimeout();
|
||||
ArgumentCaptor<DiscordPresence> captor = ArgumentCaptor.forClass(DiscordPresence.class);
|
||||
verify(discordService, times(2)).updatePresence(captor.capture());
|
||||
List<DiscordPresence> captured = captor.getAllValues();
|
||||
assertNull(captured.get(captured.size() - 1).getEndTimestamp());
|
||||
|
||||
// menu is not clearable and so no changes will be made
|
||||
verifyNoMoreInteractions(discordService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user