Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import social.bigbone.api.entity.Status
import social.bigbone.api.entity.StatusEdit
import social.bigbone.api.entity.StatusSource
import social.bigbone.api.entity.Translation
import social.bigbone.api.entity.data.PollData
import social.bigbone.api.method.StatusMethods

/**
Expand Down Expand Up @@ -102,11 +103,8 @@ class RxStatusMethods(client: MastodonClient) {
@JvmOverloads
fun postPoll(
status: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
Expand All @@ -116,11 +114,8 @@ class RxStatusMethods(client: MastodonClient) {
try {
val result = statusMethods.postPoll(
status,
pollOptions,
pollExpiresIn,
pollData,
visibility,
pollMultiple,
pollHideTotals,
inReplyToId,
sensitive,
spoilerText,
Expand Down Expand Up @@ -158,11 +153,8 @@ class RxStatusMethods(client: MastodonClient) {
fun schedulePoll(
status: String,
scheduledAt: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
Expand All @@ -173,11 +165,8 @@ class RxStatusMethods(client: MastodonClient) {
val result = statusMethods.schedulePoll(
status,
scheduledAt,
pollOptions,
pollExpiresIn,
pollData,
visibility,
pollMultiple,
pollHideTotals,
inReplyToId,
sensitive,
spoilerText,
Expand Down Expand Up @@ -335,10 +324,7 @@ class RxStatusMethods(client: MastodonClient) {
fun editPoll(
statusId: String,
status: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
pollData: PollData,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
Expand All @@ -348,10 +334,7 @@ class RxStatusMethods(client: MastodonClient) {
val statusEdit = statusMethods.editPoll(
statusId,
status,
pollOptions,
pollExpiresIn,
pollMultiple,
pollHideTotals,
pollData,
sensitive,
spoilerText,
language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import social.bigbone.TestHelpers
import social.bigbone.TestHelpers.toISO8601DateTime
import social.bigbone.api.entity.Status
import social.bigbone.api.entity.Token
import social.bigbone.api.entity.data.PollData
import social.bigbone.api.exception.BigBoneRequestException
import java.time.Instant
import java.time.ZoneId
Expand Down Expand Up @@ -140,8 +141,10 @@ class V410StatusMethodsIntegrationTest {
// when
val postedPoll = user1Client.statuses.postPoll(
status = "Do you think this test will pass?",
pollOptions = listOf("Yes", "No"),
pollExpiresIn = 300
pollData = PollData(
options = listOf("Yes", "No"),
expiresIn = "300"
)
).execute()

// then
Expand All @@ -163,11 +166,13 @@ class V410StatusMethodsIntegrationTest {
// when
val postedPoll = user1Client.statuses.postPoll(
status = "Wird dieser Test erfolgreich sein?",
pollOptions = listOf("Ja", "Nein"),
pollExpiresIn = 300,
pollData = PollData(
options = listOf("Ja", "Nein"),
expiresIn = "300",
multiple = true,
hideTotals = true,
),
visibility = Status.Visibility.Private,
pollMultiple = true,
pollHideTotals = true,
inReplyToId = statusId,
sensitive = true,
spoilerText = "Das ist der Spoilertext zur Umfrage",
Expand Down Expand Up @@ -255,8 +260,10 @@ class V410StatusMethodsIntegrationTest {
val scheduledPoll = user1Client.statuses.schedulePoll(
status = "Will this poll be posted at $inSixMinutes?",
scheduledAt = inSixMinutes,
pollOptions = listOf("Yes", "No"),
pollExpiresIn = 300
pollData = PollData (
options = listOf("Yes", "No"),
expiresIn = "300"
),
).execute()

// then
Expand All @@ -280,15 +287,17 @@ class V410StatusMethodsIntegrationTest {
val scheduledPoll = user1Client.statuses.schedulePoll(
status = "Wird diese Umfrage um $inSixMinutes gepostet?",
scheduledAt = inSixMinutes,
pollOptions = listOf("Yes", "No"),
pollExpiresIn = 300,
pollData = PollData(
options = listOf("Yes", "No"),
expiresIn = "300",
multiple = true,
hideTotals = true
),
visibility = Status.Visibility.Private,
pollMultiple = true,
inReplyToId = statusId,
sensitive = true,
spoilerText = "Das ist ein Spoilertext",
language = "de",
pollHideTotals = true
language = "de"
).execute()

// then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package social.bigbone.api.entity

import com.google.gson.annotations.SerializedName
import social.bigbone.api.entity.data.PollData

/**
* Represents a status that will be published at a future scheduled date.
Expand Down Expand Up @@ -46,7 +47,7 @@ data class ScheduledStatus(
* Poll to be attached to the status.
*/
@SerializedName("poll")
val poll: Poll? = null,
val poll: PollData? = null,

/**
* IDs of the MediaAttachments that will be attached to the status.
Expand Down Expand Up @@ -108,34 +109,4 @@ data class ScheduledStatus(
@SerializedName("with_rate_limit")
val withRateLimit: Boolean = false
)

/**
* Poll to be attached to the status.
*/
data class Poll(
/**
* The poll options to be used.
* @see <a href="https://docs.joinmastodon.org/entities/ScheduledStatus/#params-poll">Mastodon API ScheduledStatus params-poll</a>
*/
@SerializedName("options")
val options: List<String> = emptyList(),

/**
* How many seconds the poll should last before closing (String cast from Integer).
*/
@SerializedName("expires_in")
val expiresIn: String = "",

/**
* Whether the poll allows multiple choices.
*/
@SerializedName("multiple")
val multiple: Boolean? = null,

/**
* Whether the poll should hide total votes until after voting has ended.
*/
@SerializedName("hide_totals")
val hideTotals: Boolean? = null
)
}
35 changes: 35 additions & 0 deletions bigbone/src/main/kotlin/social/bigbone/api/entity/data/PollData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package social.bigbone.api.entity.data

import com.google.gson.annotations.SerializedName

/**
* Poll data to be attached to the status. This data class is used when creating or editing poll statuses (see
* [social.bigbone.api.method.StatusMethods]) and as part of the [social.bigbone.api.entity.ScheduledStatus] entity
* data class.
*/
data class PollData(
/**
* The poll options to be used.
* @see <a href="https://docs.joinmastodon.org/entities/ScheduledStatus/#params-poll">Mastodon API ScheduledStatus params-poll</a>
*/
@SerializedName("options")
val options: List<String> = emptyList(),

/**
* How many seconds the poll should last before closing (String cast from Integer).
*/
@SerializedName("expires_in")
val expiresIn: String = "",

/**
* Whether the poll allows multiple choices.
*/
@SerializedName("multiple")
val multiple: Boolean? = null,

/**
* Whether the poll should hide total votes until after voting has ended.
*/
@SerializedName("hide_totals")
val hideTotals: Boolean? = null
)
64 changes: 24 additions & 40 deletions bigbone/src/main/kotlin/social/bigbone/api/method/StatusMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import social.bigbone.api.entity.Status
import social.bigbone.api.entity.StatusEdit
import social.bigbone.api.entity.StatusSource
import social.bigbone.api.entity.Translation
import social.bigbone.api.entity.data.PollData
import social.bigbone.api.exception.BigBoneRequestException

/**
Expand Down Expand Up @@ -137,11 +138,8 @@ class StatusMethods(private val client: MastodonClient) {
/**
* Publish a status containing a poll with the given parameters. To schedule a poll status, use [schedulePoll].
* @param status the text of the status
* @param pollOptions Possible answers to the poll.
* @param pollExpiresIn Duration that the poll should be open, in seconds.
* @param pollData containing all necessary poll data
* @param visibility either "direct", "private", "unlisted" or "public"
* @param pollMultiple Allow multiple choices? Defaults to false.
* @param pollHideTotals Hide vote counts until the poll ends? Defaults to false.
* @param inReplyToId the local id of the status you want to reply to
* @param sensitive set this to mark the media of the status as NSFW
* @param spoilerText text to be shown as a warning before the actual content
Expand All @@ -152,11 +150,8 @@ class StatusMethods(private val client: MastodonClient) {
@Throws(BigBoneRequestException::class)
fun postPoll(
status: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
Expand All @@ -167,11 +162,11 @@ class StatusMethods(private val client: MastodonClient) {
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
append("status", status)
append("poll[options]", pollOptions)
append("poll[expires_in]", pollExpiresIn)
append("poll[options]", pollData.options)
append("poll[expires_in]", pollData.expiresIn)
append("visibility", visibility.value)
append("poll[multiple]", pollMultiple)
append("poll[hide_totals", pollHideTotals)
append("poll[multiple]", pollData.multiple ?: false)
append("poll[hide_totals", pollData.hideTotals ?: false)
inReplyToId?.let { append("in_reply_to_id", it) }
append("sensitive", sensitive)
spoilerText?.let { append("spoiler_text", it) }
Expand Down Expand Up @@ -225,11 +220,8 @@ class StatusMethods(private val client: MastodonClient) {
* Schedule a status containing a poll with the given parameters. To post immediately, use [postPoll].
* @param status the text of the status
* @param scheduledAt ISO 8601 Datetime at which to schedule a status. Must be at least 5 minutes in the future.
* @param pollOptions Possible answers to the poll.
* @param pollExpiresIn Duration that the poll should be open, in seconds.
* @param pollData containing all necessary poll data
* @param visibility either "direct", "private", "unlisted" or "public"
* @param pollMultiple Allow multiple choices? Defaults to false.
* @param pollHideTotals Hide vote counts until the poll ends? Defaults to false.
* @param inReplyToId the local id of the status you want to reply to
* @param sensitive set this to mark the media of the status as NSFW
* @param spoilerText text to be shown as a warning before the actual content
Expand All @@ -241,11 +233,8 @@ class StatusMethods(private val client: MastodonClient) {
fun schedulePoll(
status: String,
scheduledAt: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
Expand All @@ -257,11 +246,11 @@ class StatusMethods(private val client: MastodonClient) {
parameters = Parameters().apply {
append("status", status)
append("scheduled_at", scheduledAt)
append("poll[options]", pollOptions)
append("poll[expires_in]", pollExpiresIn)
append("poll[options]", pollData.options)
append("poll[expires_in]", pollData.expiresIn)
append("visibility", visibility.value)
append("poll[multiple]", pollMultiple)
append("poll[hide_totals]", pollHideTotals)
append("poll[multiple]", pollData.multiple ?: false)
append("poll[hide_totals]", pollData.multiple ?: false)
inReplyToId?.let { append("in_reply_to_id", it) }
append("sensitive", sensitive)
spoilerText?.let { append("spoiler_text", it) }
Expand Down Expand Up @@ -426,7 +415,8 @@ class StatusMethods(private val client: MastodonClient) {

/**
* Edit a given status to change its text, sensitivity, media attachments. Use [getStatus] and/or [getStatusSource]
* to get previous status data to use in this update.
* to get previous status data to use in this update. Editing a status containing a poll using this method will
* remove the poll - use [editPoll] instead!
* @param statusId the ID of the Status in the database
* @param status the plain text content of the status
* @param mediaIds the array of media ids to attach to the status (maximum 4)
Expand Down Expand Up @@ -459,15 +449,12 @@ class StatusMethods(private val client: MastodonClient) {
}

/**
* Edit a given status to change its text, sensitivity, or poll. Note that editing a poll’s options will reset the votes.
* Use [editStatus] on a status containing a poll instead to not edit its poll options. Use [getStatus] and/or
* [getStatusSource] to get previous status data to use in this update.
* Edit a given status containing a poll to change its text, sensitivity, or poll. Use [getStatus] and/or
* [getStatusSource] to get previous status data to use in this update, including all necessary poll data that
* should not be changed. Note that changing a poll’s options will reset the votes.
* @param statusId the ID of the Status in the database
* @param status the plain text content of the status
* @param pollOptions Possible answers to the poll.
* @param pollExpiresIn Duration that the poll should be open, in seconds.
* @param pollMultiple Allow multiple choices? Defaults to false.
* @param pollHideTotals Hide vote counts until the poll ends? Defaults to false.
* @param pollData containing all necessary poll data
* @param sensitive whether the status should be marked as sensitive
* @param spoilerText the plain text subject or content warning of the status
* @param language ISO 639 language code for this status.
Expand All @@ -478,10 +465,7 @@ class StatusMethods(private val client: MastodonClient) {
fun editPoll(
statusId: String,
status: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
pollData: PollData,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
Expand All @@ -491,10 +475,10 @@ class StatusMethods(private val client: MastodonClient) {
method = MastodonClient.Method.PUT,
parameters = Parameters().apply {
append("status", status)
append("poll[options]", pollOptions)
append("poll[expires_in]", pollExpiresIn)
append("poll[multiple]", pollMultiple)
append("poll[hide_totals", pollHideTotals)
append("poll[options]", pollData.options)
append("poll[expires_in]", pollData.expiresIn)
append("poll[multiple]", pollData.multiple ?: false)
append("poll[hide_totals]", pollData.hideTotals ?: false)
append("sensitive", sensitive)
spoilerText?.let { append("spoiler_text", it) }
language?.let { append("language", it) }
Expand Down
Loading