Skip to content

Commit

Permalink
fix: adjust clip event for helix time truncation (#617)
Browse files Browse the repository at this point in the history
* fix: adjust clip event for helix time truncation

* chore: respect helix limitation of 1000 clips

* chore: use login to update missing channel name
  • Loading branch information
iProdigy committed Aug 4, 2022
1 parent 92b0511 commit 1f7e8d9
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -281,9 +282,9 @@ public TwitchClientHelper(TwitchHelix twitchHelix, EventManager eventManager, Sc
followBackoff.get().reset(); // API call was successful

// Prepare EventChannel
String channelName = currentChannelCache.getUserName(); // Prefer login (even if old) to display_name https://github.com/twitchdev/issues/issues/3#issuecomment-562713594
String channelName = currentChannelCache.getUserName();
if (channelName == null && !followList.isEmpty()) {
channelName = followList.get(0).getToName();
channelName = followList.get(0).getToLogin();
currentChannelCache.setUserName(channelName);
}
EventChannel channel = new EventChannel(channelId, channelName);
Expand Down Expand Up @@ -345,7 +346,8 @@ public TwitchClientHelper(TwitchHelix twitchHelix, EventManager eventManager, Sc
nextRequestCanBeImmediate = windowStart.compareAndSet(null, now);
} else {
// get all clips in range [startedAt, now]
final List<Clip> clips = getClips(channelId, startedAt, now);
// end time is adjusted for https://github.com/twitchdev/issues/issues/52
final List<Clip> clips = getClips(channelId, startedAt, now.plus(10, ChronoUnit.MINUTES));

// cache channel name if unknown and construct event channel to be passed to events
if (!clips.isEmpty() && clips.get(0) != null && currentChannelCache.getUserName() == null) {
Expand Down Expand Up @@ -610,7 +612,7 @@ private List<Clip> getClips(String channelId, Instant startedAt, Instant endedAt
},
ClipList::getData,
call -> call.getPagination() != null ? call.getPagination().getCursor() : null,
20
10
);
}

Expand Down

0 comments on commit 1f7e8d9

Please sign in to comment.