Skip to content

Commit

Permalink
Add data class for AnnouncementReactionReceived payload
Browse files Browse the repository at this point in the history
  • Loading branch information
PattaFeuFeu committed Dec 17, 2023
1 parent 27af088 commit 664ba8a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.serialization.Serializable
* Represents an emoji reaction to an Announcement.
* @see <a href="https://docs.joinmastodon.org/entities/Reaction/">Mastodon API Reaction</a>
*/

@Serializable
data class Reaction(
/**
Expand All @@ -17,7 +16,7 @@ data class Reaction(
val name: String = "",

/**
* The total number of users who have added this reaction.
* The total number of users who have added this reaction.
*/
@SerialName("count")
val count: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ sealed interface ParsedStreamEvent {
* An announcement has received an emoji reaction.
* Available since v3.1.0
*/
data class AnnouncementReactionReceived(val reactionPayload: String) : ParsedStreamEvent
data class AnnouncementReactionReceived(val reaction: StreamingAnnouncementReaction) : ParsedStreamEvent

/**
* An announcement has been deleted.
Expand Down Expand Up @@ -111,7 +111,7 @@ sealed interface ParsedStreamEvent {

"announcement.reaction" -> {
requireNotNull(payload) { "Payload was null for update $eventType but mustn't be." }
AnnouncementReactionReceived(reactionPayload = json.decodeFromString(payload))
AnnouncementReactionReceived(reaction = json.decodeFromString(payload))
}

"announcement.delete" -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package social.bigbone.api.entity.streaming

import kotlinx.serialization.SerialName
import social.bigbone.api.entity.Reaction

/**
* "Hash" returned as part of [ParsedStreamEvent.AnnouncementReactionReceived] containing information on the reaction.
*
* This is slightly different from [Reaction] and thus is in its own class here.
*
* @see <a href="https://docs.joinmastodon.org/methods/streaming/#events">Mastodon API streaming events</a>
*/
data class StreamingAnnouncementReaction(
/**
* The emoji used for the reaction. Either a unicode emoji, or a custom emoji’s shortcode.
*/
@SerialName("name")
val name: String,

/**
* The total number of users who have added this reaction.
*/
@SerialName("count")
val count: Int,

/**
* The ID of the announcement in the database.
*/
@SerialName("announcement_id")
val announcementId: String
)

0 comments on commit 664ba8a

Please sign in to comment.