Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit b75cbf2

Browse files
committed
Add subscription tiers to streamelements and comply with the new api subscription class
1 parent 95d22cc commit b75cbf2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/streamelements/impl/StreamElementsEventInputImpl.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.time.{LocalDateTime, OffsetDateTime, ZoneOffset}
55
import java.util.Currency
66

77
import org.codeoverflow.chatoverflow.api.io.dto.User
8+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.SubscriptionTier
89
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements.{StreamElementsDonation, StreamElementsFollow, StreamElementsProvider, StreamElementsSubscription}
910
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements.{StreamElementsDonationEvent, StreamElementsEvent, StreamElementsFollowEvent, StreamElementsSubscriptionEvent}
1011
import org.codeoverflow.chatoverflow.api.io.input.event.StreamElementsEventInput
@@ -53,12 +54,23 @@ class StreamElementsEventInputImpl extends EventInputImpl[StreamElementsEvent, S
5354
val json = event.json
5455
val data = json.getJSONObject("data")
5556

57+
val gifted = data.optBoolean("gifted", false)
5658
val sub = new StreamElementsSubscription(
5759
parseUser(data),
58-
data.getDouble("amount").toInt,
5960
parseTime(json),
60-
parseProvider(json),
61-
data.optBoolean("gifted", false)
61+
data.optDouble("amount", 1).toInt,
62+
{
63+
// (judging based on the events from the event simulator that can be seen in the browser console)
64+
// "plan" can be either a string or a number, so we need to handle both cases
65+
val plan = Option(data.opt("plan")).getOrElse("1000").toString
66+
if (plan.toLowerCase == "prime")
67+
SubscriptionTier.PRIME
68+
else
69+
SubscriptionTier.parse(plan.toInt / 1000)
70+
},
71+
gifted,
72+
if (gifted) new User(data.optString("sender")) else null,
73+
parseProvider(json)
6274
)
6375
call(new StreamElementsSubscriptionEvent(sub))
6476
}

0 commit comments

Comments
 (0)