-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ongoing): add raid and pinned messages event parsers
- Loading branch information
Showing
15 changed files
with
337 additions
and
8 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
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
31 changes: 31 additions & 0 deletions
31
...pi-common/src/main/java/fr/outadoc/justchatting/component/chatapi/common/PinnedMessage.kt
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,31 @@ | ||
package fr.outadoc.justchatting.component.chatapi.common | ||
|
||
import androidx.compose.runtime.Immutable | ||
import kotlinx.datetime.Instant | ||
|
||
@Immutable | ||
data class PinnedMessage( | ||
val pinId: String, | ||
val pinnedBy: User, | ||
val message: Message, | ||
) { | ||
@Immutable | ||
data class User( | ||
val userId: String, | ||
val displayName: String, | ||
) | ||
|
||
@Immutable | ||
data class Message( | ||
val messageId: String, | ||
val sender: User, | ||
val content: Content, | ||
val startsAt: Instant, | ||
val endsAt: Instant, | ||
) { | ||
@Immutable | ||
data class Content( | ||
val text: String, | ||
) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ent-chatapi-common/src/main/java/fr/outadoc/justchatting/component/chatapi/common/Raid.kt
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,14 @@ | ||
package fr.outadoc.justchatting.component.chatapi.common | ||
|
||
import androidx.compose.runtime.Immutable | ||
|
||
@Immutable | ||
data class Raid( | ||
val targetId: String, | ||
val targetLogin: String, | ||
val targetDisplayName: String, | ||
val targetProfileImageUrl: String?, | ||
val transitionJitterSeconds: Int, | ||
val forceRaidNowSeconds: Int, | ||
val viewerCount: Int, | ||
) |
5 changes: 0 additions & 5 deletions
5
...n/src/main/java/fr/outadoc/justchatting/component/chatapi/domain/model/StreamsResponse.kt
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
...stchatting/component/twitch/websocket/pubsub/feature/pinnedmessage/PubSubPinnedMessage.kt
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,66 @@ | ||
package fr.outadoc.justchatting.component.twitch.websocket.pubsub.feature.pinnedmessage | ||
|
||
import fr.outadoc.justchatting.utils.core.InstantUnixEpochSerializer | ||
import kotlinx.datetime.Instant | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal sealed class PubSubPinnedMessage { | ||
|
||
@Serializable | ||
@SerialName("pin-message") | ||
data class Pin( | ||
@SerialName("data") | ||
val data: Data, | ||
) : PubSubPinnedMessage() { | ||
|
||
@Serializable | ||
data class Data( | ||
@SerialName("id") | ||
val pinId: String, | ||
@SerialName("pinned_by") | ||
val pinnedBy: User, | ||
@SerialName("message") | ||
val message: Message, | ||
) | ||
|
||
@Serializable | ||
data class User( | ||
@SerialName("id") | ||
val userId: String, | ||
@SerialName("display_name") | ||
val displayName: String, | ||
) | ||
|
||
@Serializable | ||
data class Message( | ||
@SerialName("id") | ||
val messageId: String, | ||
@SerialName("sender") | ||
val sender: User, | ||
@SerialName("content") | ||
val content: Content, | ||
@SerialName("starts_at") | ||
@Serializable(with = InstantUnixEpochSerializer::class) | ||
val startsAt: Instant, | ||
@SerialName("ends_at") | ||
@Serializable(with = InstantUnixEpochSerializer::class) | ||
val endsAt: Instant, | ||
) { | ||
@Serializable | ||
data class Content( | ||
@SerialName("text") | ||
val text: String, | ||
) | ||
} | ||
} | ||
|
||
@Serializable | ||
@SerialName("update-message") | ||
object Update : PubSubPinnedMessage() | ||
|
||
@Serializable | ||
@SerialName("unpin-message") | ||
object Unpin : PubSubPinnedMessage() | ||
} |
34 changes: 34 additions & 0 deletions
34
...hatting/component/twitch/websocket/pubsub/feature/pinnedmessage/PubSubPinnedMessageExt.kt
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,34 @@ | ||
package fr.outadoc.justchatting.component.twitch.websocket.pubsub.feature.pinnedmessage | ||
|
||
import fr.outadoc.justchatting.component.chatapi.common.PinnedMessage | ||
|
||
internal fun PubSubPinnedMessage.Pin.map(): PinnedMessage { | ||
return PinnedMessage( | ||
pinId = data.pinId, | ||
pinnedBy = data.pinnedBy.map(), | ||
message = data.message.map(), | ||
) | ||
} | ||
|
||
private fun PubSubPinnedMessage.Pin.Message.map(): PinnedMessage.Message { | ||
return PinnedMessage.Message( | ||
messageId = messageId, | ||
sender = sender.map(), | ||
content = content.map(), | ||
startsAt = startsAt, | ||
endsAt = endsAt, | ||
) | ||
} | ||
|
||
private fun PubSubPinnedMessage.Pin.Message.Content.map(): PinnedMessage.Message.Content { | ||
return PinnedMessage.Message.Content( | ||
text = text, | ||
) | ||
} | ||
|
||
private fun PubSubPinnedMessage.Pin.User.map(): PinnedMessage.User { | ||
return PinnedMessage.User( | ||
userId = userId, | ||
displayName = displayName, | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
...ting/component/twitch/websocket/pubsub/feature/pinnedmessage/PubSubPinnedMessagePlugin.kt
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,33 @@ | ||
package fr.outadoc.justchatting.component.twitch.websocket.pubsub.feature.pinnedmessage | ||
|
||
import fr.outadoc.justchatting.component.chatapi.common.ChatEvent | ||
import fr.outadoc.justchatting.component.chatapi.common.pubsub.PubSubPlugin | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.json.Json | ||
|
||
class PubSubPinnedMessagePlugin( | ||
private val json: Json, | ||
) : PubSubPlugin<PubSubPinnedMessage> { | ||
|
||
override fun getTopic(channelId: String): String = | ||
"pinned-chat-updates-v1.$channelId" | ||
|
||
override fun parseMessage(payload: String): List<ChatEvent> = | ||
when (val message = json.decodeFromString<PubSubPinnedMessage>(payload)) { | ||
is PubSubPinnedMessage.Pin -> { | ||
listOf( | ||
ChatEvent.PinnedMessageUpdate( | ||
pinnedMessage = message.map(), | ||
), | ||
) | ||
} | ||
|
||
is PubSubPinnedMessage.Update -> emptyList() | ||
|
||
is PubSubPinnedMessage.Unpin -> listOf( | ||
ChatEvent.PinnedMessageUpdate( | ||
pinnedMessage = null, | ||
), | ||
) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../outadoc/justchatting/component/twitch/websocket/pubsub/feature/raid/PubSubRaidMessage.kt
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,42 @@ | ||
package fr.outadoc.justchatting.component.twitch.websocket.pubsub.feature.raid | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal sealed class PubSubRaidMessage { | ||
|
||
@Serializable | ||
@SerialName("raid_update_v2") | ||
data class Update( | ||
@SerialName("raid") | ||
val raid: Raid, | ||
) : PubSubRaidMessage() | ||
|
||
@Serializable | ||
@SerialName("raid_go_v2") | ||
data class Go( | ||
@SerialName("raid") | ||
val raid: Raid, | ||
) : PubSubRaidMessage() | ||
|
||
@Serializable | ||
data class Raid( | ||
@SerialName("id") | ||
val raidId: String, | ||
@SerialName("target_id") | ||
val targetId: String, | ||
@SerialName("target_login") | ||
val targetLogin: String, | ||
@SerialName("target_display_name") | ||
val targetDisplayName: String, | ||
@SerialName("target_profile_image") | ||
val targetProfileImageUrl: String?, | ||
@SerialName("transition_jitter_seconds") | ||
val transitionJitterSeconds: Int, | ||
@SerialName("force_raid_now_seconds") | ||
val forceRaidNowSeconds: Int, | ||
@SerialName("viewer_count") | ||
val viewerCount: Int, | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
...tadoc/justchatting/component/twitch/websocket/pubsub/feature/raid/PubSubRaidMessageExt.kt
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,15 @@ | ||
package fr.outadoc.justchatting.component.twitch.websocket.pubsub.feature.raid | ||
|
||
import fr.outadoc.justchatting.component.chatapi.common.Raid | ||
|
||
internal fun PubSubRaidMessage.Raid.map(): Raid { | ||
return Raid( | ||
targetId = targetId, | ||
targetLogin = targetLogin, | ||
targetDisplayName = targetDisplayName, | ||
targetProfileImageUrl = targetProfileImageUrl, | ||
transitionJitterSeconds = transitionJitterSeconds, | ||
forceRaidNowSeconds = forceRaidNowSeconds, | ||
viewerCount = viewerCount, | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
...r/outadoc/justchatting/component/twitch/websocket/pubsub/feature/raid/PubSubRaidPlugin.kt
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,33 @@ | ||
package fr.outadoc.justchatting.component.twitch.websocket.pubsub.feature.raid | ||
|
||
import fr.outadoc.justchatting.component.chatapi.common.ChatEvent | ||
import fr.outadoc.justchatting.component.chatapi.common.pubsub.PubSubPlugin | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.json.Json | ||
|
||
class PubSubRaidPlugin( | ||
private val json: Json, | ||
) : PubSubPlugin<PubSubRaidMessage> { | ||
|
||
override fun getTopic(channelId: String): String = | ||
"raid.$channelId" | ||
|
||
override fun parseMessage(payload: String): List<ChatEvent> = | ||
when (val message = json.decodeFromString<PubSubRaidMessage>(payload)) { | ||
is PubSubRaidMessage.Update -> { | ||
listOf( | ||
ChatEvent.RaidUpdate( | ||
raid = message.raid.map(), | ||
), | ||
) | ||
} | ||
|
||
is PubSubRaidMessage.Go -> { | ||
listOf( | ||
ChatEvent.RaidUpdate( | ||
raid = message.raid.map(), | ||
), | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.