Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accidental poll removal on status edit. #168

Merged
merged 5 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rename new data class to PollData
  • Loading branch information
bocops committed Mar 30, 2023
commit 26ada7685e550f71cb55587a9946edb9433efff1
14 changes: 7 additions & 7 deletions bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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.Poll
import social.bigbone.api.entity.data.PollData
import social.bigbone.api.method.StatusMethods

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ class RxStatusMethods(client: MastodonClient) {
@JvmOverloads
fun postPoll(
status: String,
poll: Poll,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
sensitive: Boolean = false,
Expand All @@ -114,7 +114,7 @@ class RxStatusMethods(client: MastodonClient) {
try {
val result = statusMethods.postPoll(
status,
poll,
pollData,
visibility,
inReplyToId,
sensitive,
Expand Down Expand Up @@ -153,7 +153,7 @@ class RxStatusMethods(client: MastodonClient) {
fun schedulePoll(
status: String,
scheduledAt: String,
poll: Poll,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
sensitive: Boolean = false,
Expand All @@ -165,7 +165,7 @@ class RxStatusMethods(client: MastodonClient) {
val result = statusMethods.schedulePoll(
status,
scheduledAt,
poll,
pollData,
visibility,
inReplyToId,
sensitive,
Expand Down Expand Up @@ -324,7 +324,7 @@ class RxStatusMethods(client: MastodonClient) {
fun editPoll(
statusId: String,
status: String,
poll: Poll,
pollData: PollData,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
Expand All @@ -334,7 +334,7 @@ class RxStatusMethods(client: MastodonClient) {
val statusEdit = statusMethods.editPoll(
statusId,
status,
poll,
pollData,
sensitive,
spoilerText,
language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +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.Poll
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 @@ -141,7 +141,7 @@ class V410StatusMethodsIntegrationTest {
// when
val postedPoll = user1Client.statuses.postPoll(
status = "Do you think this test will pass?",
poll = Poll(
pollData = PollData(
options = listOf("Yes", "No"),
expiresIn = "300"
)
Expand All @@ -166,7 +166,7 @@ class V410StatusMethodsIntegrationTest {
// when
val postedPoll = user1Client.statuses.postPoll(
status = "Wird dieser Test erfolgreich sein?",
poll = Poll(
pollData = PollData(
options = listOf("Ja", "Nein"),
expiresIn = "300",
multiple = true,
Expand Down Expand Up @@ -260,7 +260,7 @@ class V410StatusMethodsIntegrationTest {
val scheduledPoll = user1Client.statuses.schedulePoll(
status = "Will this poll be posted at $inSixMinutes?",
scheduledAt = inSixMinutes,
poll = Poll (
pollData = PollData (
options = listOf("Yes", "No"),
expiresIn = "300"
),
Expand All @@ -287,7 +287,7 @@ class V410StatusMethodsIntegrationTest {
val scheduledPoll = user1Client.statuses.schedulePoll(
status = "Wird diese Umfrage um $inSixMinutes gepostet?",
scheduledAt = inSixMinutes,
poll = Poll(
pollData = PollData(
options = listOf("Yes", "No"),
expiresIn = "300",
multiple = true,
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: social.bigbone.api.entity.data.Poll? = null,
val poll: PollData? = null,

/**
* IDs of the MediaAttachments that will be attached to the status.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package social.bigbone.api.entity.data
import com.google.gson.annotations.SerializedName

/**
* Poll 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] data class.
* 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 Poll(
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>
Expand Down
38 changes: 19 additions & 19 deletions bigbone/src/main/kotlin/social/bigbone/api/method/StatusMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +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.Poll
import social.bigbone.api.entity.data.PollData
import social.bigbone.api.exception.BigBoneRequestException

/**
Expand Down Expand Up @@ -138,7 +138,7 @@ 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 poll containing all necessary poll data
* @param pollData containing all necessary poll data
* @param visibility either "direct", "private", "unlisted" or "public"
* @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
Expand All @@ -150,7 +150,7 @@ class StatusMethods(private val client: MastodonClient) {
@Throws(BigBoneRequestException::class)
fun postPoll(
status: String,
poll: Poll,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
sensitive: Boolean = false,
Expand All @@ -162,11 +162,11 @@ class StatusMethods(private val client: MastodonClient) {
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
append("status", status)
append("poll[options]", poll.options)
append("poll[expires_in]", poll.expiresIn)
append("poll[options]", pollData.options)
append("poll[expires_in]", pollData.expiresIn)
append("visibility", visibility.value)
append("poll[multiple]", poll.multiple ?: false)
append("poll[hide_totals", poll.hideTotals ?: false)
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 @@ -220,7 +220,7 @@ 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 poll containing all necessary poll data
* @param pollData containing all necessary poll data
* @param visibility either "direct", "private", "unlisted" or "public"
* @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
Expand All @@ -233,7 +233,7 @@ class StatusMethods(private val client: MastodonClient) {
fun schedulePoll(
status: String,
scheduledAt: String,
poll: Poll,
pollData: PollData,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
sensitive: Boolean = false,
Expand All @@ -246,11 +246,11 @@ class StatusMethods(private val client: MastodonClient) {
parameters = Parameters().apply {
append("status", status)
append("scheduled_at", scheduledAt)
append("poll[options]", poll.options)
append("poll[expires_in]", poll.expiresIn)
append("poll[options]", pollData.options)
append("poll[expires_in]", pollData.expiresIn)
append("visibility", visibility.value)
append("poll[multiple]", poll.multiple ?: false)
append("poll[hide_totals]", poll.multiple ?: false)
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 @@ -454,7 +454,7 @@ class StatusMethods(private val client: MastodonClient) {
* 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 poll containing all necessary poll data
* @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 @@ -465,7 +465,7 @@ class StatusMethods(private val client: MastodonClient) {
fun editPoll(
statusId: String,
status: String,
poll: Poll,
pollData: PollData,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
Expand All @@ -475,10 +475,10 @@ class StatusMethods(private val client: MastodonClient) {
method = MastodonClient.Method.PUT,
parameters = Parameters().apply {
append("status", status)
append("poll[options]", poll.options)
append("poll[expires_in]", poll.expiresIn)
append("poll[multiple]", poll.multiple ?: false)
append("poll[hide_totals]", poll.hideTotals ?: false)
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import social.bigbone.api.entity.Status
import social.bigbone.api.entity.data.Poll
import social.bigbone.api.entity.data.PollData
import social.bigbone.api.exception.BigBoneRequestException
import social.bigbone.testtool.MockClient

Expand Down Expand Up @@ -140,13 +140,13 @@ class StatusMethodsTest {
fun postPoll() {
val client = MockClient.mock("status_with_poll.json")
val statusMethods = StatusMethods(client)
val pollData = Poll(
val pollData = PollData(
options = listOf("foo", "bar", "baz"),
expiresIn = "3600"
)
val status = statusMethods.postPoll(
status = "a",
poll = pollData,
pollData = pollData,
visibility = Status.Visibility.Unlisted,
language = "en"
).execute()
Expand All @@ -161,13 +161,13 @@ class StatusMethodsTest {
Assertions.assertThrows(BigBoneRequestException::class.java) {
val client = MockClient.ioException()
val statusMethods = StatusMethods(client)
val pollData = Poll(
val pollData = PollData(
options = listOf("foo", "bar", "baz"),
expiresIn = "3600"
)
statusMethods.postPoll(
status = "a",
poll = pollData,
pollData = pollData,
visibility = Status.Visibility.Unlisted,
language = "en"
).execute()
Expand Down Expand Up @@ -215,7 +215,7 @@ class StatusMethodsTest {
fun schedulePoll() {
val client = MockClient.mock("scheduled_status_with_poll.json")
val statusMethods = StatusMethods(client)
val pollData = Poll(
val pollData = PollData(
options = listOf("foo", "bar", "baz"),
expiresIn = "3600",
multiple = true,
Expand All @@ -224,7 +224,7 @@ class StatusMethodsTest {
val scheduledStatus = statusMethods.schedulePoll(
status = "a",
scheduledAt = "2023-12-31T12:34:56.789Z",
poll = pollData,
pollData = pollData,
visibility = Status.Visibility.Unlisted,
inReplyToId = null,
sensitive = false,
Expand All @@ -241,7 +241,7 @@ class StatusMethodsTest {
fun schedulePollWithException() {
Assertions.assertThrows(BigBoneRequestException::class.java) {
val client = MockClient.ioException()
val pollData = Poll(
val pollData = PollData(
options = listOf("foo", "bar", "baz"),
expiresIn = "3600",
multiple = true,
Expand All @@ -251,7 +251,7 @@ class StatusMethodsTest {
statusMethods.schedulePoll(
status = "a",
scheduledAt = "2023-12-31T12:34:56.789Z",
poll = pollData,
pollData = pollData,
visibility = Status.Visibility.Unlisted,
inReplyToId = null,
sensitive = false,
Expand Down Expand Up @@ -470,7 +470,7 @@ class StatusMethodsTest {
fun editPoll() {
val client = MockClient.mock("status_with_poll.json")
val statusMethods = StatusMethods(client)
val pollData = Poll(
val pollData = PollData(
options = listOf("foo", "bar", "baz"),
expiresIn = "3600",
multiple = false,
Expand All @@ -479,7 +479,7 @@ class StatusMethodsTest {
val status = statusMethods.editPoll(
statusId = "statusId",
status = "a",
poll = pollData,
pollData = pollData,
language = "en"
).execute()
status.poll?.id shouldBeEqualTo "34830"
Expand All @@ -493,7 +493,7 @@ class StatusMethodsTest {
Assertions.assertThrows(BigBoneRequestException::class.java) {
val client = MockClient.ioException()
val statusMethods = StatusMethods(client)
val pollData = Poll(
val pollData = PollData(
options = listOf("foo", "bar", "baz"),
expiresIn = "3600",
multiple = false,
Expand All @@ -502,7 +502,7 @@ class StatusMethodsTest {
statusMethods.editPoll(
statusId = "statusId",
status = "a",
poll = pollData
pollData = pollData
).execute()
}
}
Expand Down