Skip to content

Commit

Permalink
fix: allow IEventSubSocket#register with null transport (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Jul 20, 2023
1 parent 637a5f1 commit d57c52d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
@@ -1,27 +1,82 @@
package com.github.twitch4j.eventsub.socket;

import com.github.twitch4j.eventsub.EventSubSubscription;
import com.github.twitch4j.eventsub.EventSubSubscriptionStatus;
import com.github.twitch4j.eventsub.EventSubTransport;
import com.github.twitch4j.eventsub.condition.EventSubCondition;
import com.github.twitch4j.eventsub.subscriptions.SubscriptionType;
import lombok.EqualsAndHashCode;
import lombok.Value;

import java.time.Instant;

@Value
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false, cacheStrategy = EqualsAndHashCode.CacheStrategy.LAZY)
class SubscriptionWrapper extends EventSubSubscription {
@EqualsAndHashCode.Exclude
EventSubSubscription subscription;
String rawType;
String rawVersion;
EventSubCondition condition;

private SubscriptionWrapper(EventSubSubscription sub) {
super(sub.getId(), sub.getStatus(), sub.getType(), sub.getCondition(),
sub.getCreatedAt(), sub.getTransport(), sub.getCost(), sub.isBatchingEnabled(),
sub.getRawType(), sub.getRawVersion());
super();
this.subscription = sub;
this.rawType = sub.getRawType();
this.rawVersion = sub.getRawVersion();
this.condition = sub.getCondition();
}

@Override
@EqualsAndHashCode.Include
public String getRawType() {
return subscription.getRawType();
}

@Override
@EqualsAndHashCode.Include
public String getRawVersion() {
return subscription.getRawVersion();
}

@Override
@EqualsAndHashCode.Include
public EventSubCondition getCondition() {
return subscription.getCondition();
}

@Override
public String getId() {
return subscription.getId();
}

@Override
public EventSubSubscriptionStatus getStatus() {
return subscription.getStatus();
}

@Override
public SubscriptionType<?, ?, ?> getType() {
return subscription.getType();
}

@Override
public Instant getCreatedAt() {
return subscription.getCreatedAt();
}

@Override
public EventSubTransport getTransport() {
return subscription.getTransport();
}

@Override
@Deprecated
public void setTransport(EventSubTransport transport) {
subscription.setTransport(transport);
}

@Override
public Integer getCost() {
return subscription.getCost();
}

@Override
public Boolean isBatchingEnabled() {
return subscription.isBatchingEnabled();
}

static SubscriptionWrapper wrap(EventSubSubscription sub) {
Expand Down
Expand Up @@ -370,6 +370,7 @@ private EventSubSubscription unsubscribeNoHelix(@NotNull EventSubSubscription re
return subscriptions.remove(SubscriptionWrapper.wrap(remove));
}

@Synchronized
private void onInitialConnection(final String websocketId) {
final Collection<EventSubSubscription> oldSubs = new ArrayDeque<>(subscriptions.size());
subscriptions.keySet().removeIf(oldSubs::add);
Expand Down

0 comments on commit d57c52d

Please sign in to comment.