mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Release polls behind feature flag.
This commit is contained in:
41
app/src/main/java/org/thoughtcrime/securesms/polls/Poll.kt
Normal file
41
app/src/main/java/org/thoughtcrime/securesms/polls/Poll.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package org.thoughtcrime.securesms.polls
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import androidx.core.os.bundleOf
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Class to represent a poll when it's being created but not yet saved to the database
|
||||
*/
|
||||
@Parcelize
|
||||
data class Poll(
|
||||
val question: String,
|
||||
val allowMultipleVotes: Boolean,
|
||||
val pollOptions: List<String>,
|
||||
val authorId: Long = -1
|
||||
) : Parcelable {
|
||||
|
||||
companion object {
|
||||
const val KEY_QUESTION = "question"
|
||||
const val KEY_ALLOW_MULTIPLE = "allow_multiple"
|
||||
const val KEY_OPTIONS = "options"
|
||||
|
||||
@JvmStatic
|
||||
fun fromBundle(bundle: Bundle): Poll {
|
||||
return Poll(
|
||||
bundle.getString(KEY_QUESTION)!!,
|
||||
bundle.getBoolean(KEY_ALLOW_MULTIPLE),
|
||||
bundle.getStringArrayList(KEY_OPTIONS)!!
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toBundle(): Bundle {
|
||||
return bundleOf(
|
||||
KEY_QUESTION to question,
|
||||
KEY_ALLOW_MULTIPLE to allowMultipleVotes,
|
||||
KEY_OPTIONS to ArrayList(pollOptions.toList())
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.thoughtcrime.securesms.polls
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Represents a poll option and a list of recipients who have voted for that option
|
||||
*/
|
||||
@Parcelize
|
||||
data class PollOption(
|
||||
val id: Long,
|
||||
val text: String,
|
||||
val voterIds: List<Long>,
|
||||
val isSelected: Boolean = false,
|
||||
val isPending: Boolean = false
|
||||
) : Parcelable
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.thoughtcrime.securesms.polls
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Data class representing a poll entry in the db, its options, and any voting
|
||||
*/
|
||||
@Parcelize
|
||||
data class PollRecord(
|
||||
val id: Long,
|
||||
val question: String,
|
||||
val pollOptions: List<PollOption>,
|
||||
val allowMultipleVotes: Boolean,
|
||||
val hasEnded: Boolean,
|
||||
val authorId: Long,
|
||||
val messageId: Long
|
||||
) : Parcelable
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.polls
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
|
||||
/**
|
||||
* Tracks general information of a poll vote including who they are and what poll they voted in. Primarily used in notifications.
|
||||
*/
|
||||
data class PollVote(
|
||||
val pollId: Long,
|
||||
val voterId: RecipientId,
|
||||
val question: String,
|
||||
val dateReceived: Long = 0
|
||||
)
|
||||
Reference in New Issue
Block a user