Handle a null timestamp in local/first actions (#6379)

This commit is contained in:
Rob Pilling 2023-04-15 20:11:05 +01:00 committed by GitHub
parent 0bdf9d9e28
commit e0227f9b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -70,7 +70,8 @@ public class EpisodeActionFilter {
EpisodeAction secondAction) { EpisodeAction secondAction) {
return secondAction != null return secondAction != null
&& secondAction.getTimestamp() != null && secondAction.getTimestamp() != null
&& secondAction.getTimestamp().after(firstAction.getTimestamp()); && (firstAction.getTimestamp() == null
|| secondAction.getTimestamp().after(firstAction.getTimestamp()));
} }
} }

View File

@ -184,4 +184,29 @@ public class EpisodeActionFilterTest extends TestCase {
.getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions);
assertEquals(0, uniqueList.size()); assertEquals(0, uniqueList.size());
} }
public void testPresentRemoteTimestampOverridesMissingLocalTimestamp() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date arbitraryTime = format.parse("2021-01-01 08:00:00");
List<EpisodeAction> episodeActions = new ArrayList<>();
episodeActions.add(new EpisodeAction
.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY)
// no timestamp
.position(10)
.build()
);
List<EpisodeAction> remoteActions = new ArrayList<>();
remoteActions.add(new EpisodeAction
.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY)
.timestamp(arbitraryTime)
.position(10)
.build()
);
Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter
.getRemoteActionsOverridingLocalActions(remoteActions, episodeActions);
assertSame(1, uniqueList.size());
}
} }