-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pubsub): parse whisper thread details (#845)
- Loading branch information
Showing
4 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
pubsub/src/main/java/com/github/twitch4j/pubsub/domain/WhisperThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.twitch4j.pubsub.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.Setter; | ||
|
||
import java.time.Instant; | ||
|
||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
public class WhisperThread { | ||
@JsonProperty("id") | ||
private String threadId; | ||
private Long lastRead; | ||
private Boolean archived; | ||
private Boolean muted; | ||
private SpamClassification spamInfo; | ||
@JsonAlias("allowlisted_until") | ||
@JsonProperty("whitelisted_until") | ||
private Instant allowlistedUntil; | ||
|
||
public String getOtherUserId() { | ||
int delimIndex = threadId.indexOf('_'); | ||
if (delimIndex < 0) return null; | ||
return threadId.substring(delimIndex + 1); | ||
} | ||
|
||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
public static class SpamClassification { | ||
private String likelihood; // e.g., "low" | ||
private Long lastMarkedNotSpam; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
pubsub/src/main/java/com/github/twitch4j/pubsub/events/WhisperThreadUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.twitch4j.pubsub.events; | ||
|
||
import com.github.twitch4j.common.events.TwitchEvent; | ||
import com.github.twitch4j.pubsub.domain.WhisperThread; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class WhisperThreadUpdateEvent extends TwitchEvent { | ||
String userId; | ||
WhisperThread data; | ||
} |
30 changes: 30 additions & 0 deletions
30
pubsub/src/test/java/com/github/twitch4j/pubsub/domain/WhisperThreadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.twitch4j.pubsub.domain; | ||
|
||
import com.github.twitch4j.common.util.TypeConvert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Instant; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class WhisperThreadTest { | ||
|
||
@Test | ||
void deserialize() { | ||
String json = "{\"id\":\"53888434_268669435\",\"last_read\":13006,\"archived\":false,\"muted\":false," + | ||
"\"spam_info\":{\"likelihood\":\"low\",\"last_marked_not_spam\":0}," + | ||
"\"whitelisted_until\":\"2023-06-09T06:51:19Z\"}"; | ||
WhisperThread data = TypeConvert.jsonToObject(json, WhisperThread.class); | ||
assertNotNull(data); | ||
assertEquals(13006, data.getLastRead()); | ||
assertFalse(data.getArchived()); | ||
assertFalse(data.getMuted()); | ||
assertNotNull(data.getSpamInfo()); | ||
assertEquals("low", data.getSpamInfo().getLikelihood()); | ||
assertEquals(Instant.parse("2023-06-09T06:51:19Z"), data.getAllowlistedUntil()); | ||
assertEquals("268669435", data.getOtherUserId()); | ||
} | ||
|
||
} |