2021-07-02 13:28:45 +00:00
|
|
|
package org.thoughtcrime.securesms.conversation.drafts
|
|
|
|
|
2022-11-29 15:47:12 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DraftTable
|
|
|
|
import org.thoughtcrime.securesms.database.DraftTable.Drafts
|
2021-07-02 13:28:45 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State object responsible for holding Voice Note draft state. The intention is to allow
|
|
|
|
* other pieces of draft state to be held here as well in the future, and to serve as a
|
|
|
|
* management pattern going forward for drafts.
|
|
|
|
*/
|
|
|
|
data class DraftState(
|
2022-08-05 21:00:11 +00:00
|
|
|
val recipientId: RecipientId = RecipientId.UNKNOWN,
|
|
|
|
val threadId: Long = -1,
|
|
|
|
val distributionType: Int = 0,
|
2022-11-29 15:47:12 +00:00
|
|
|
val textDraft: DraftTable.Draft? = null,
|
2023-01-25 15:31:36 +00:00
|
|
|
val bodyRangesDraft: DraftTable.Draft? = null,
|
2022-11-29 15:47:12 +00:00
|
|
|
val quoteDraft: DraftTable.Draft? = null,
|
|
|
|
val locationDraft: DraftTable.Draft? = null,
|
2023-02-06 15:04:40 +00:00
|
|
|
val voiceNoteDraft: DraftTable.Draft? = null
|
2022-08-05 21:00:11 +00:00
|
|
|
) {
|
|
|
|
|
|
|
|
fun copyAndClearDrafts(threadId: Long = this.threadId): DraftState {
|
|
|
|
return DraftState(recipientId = recipientId, threadId = threadId, distributionType = distributionType)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun toDrafts(): Drafts {
|
|
|
|
return Drafts().apply {
|
|
|
|
addIfNotNull(textDraft)
|
2023-01-25 15:31:36 +00:00
|
|
|
addIfNotNull(bodyRangesDraft)
|
2022-08-05 21:00:11 +00:00
|
|
|
addIfNotNull(quoteDraft)
|
|
|
|
addIfNotNull(locationDraft)
|
|
|
|
addIfNotNull(voiceNoteDraft)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun copyAndSetDrafts(threadId: Long, drafts: Drafts): DraftState {
|
|
|
|
return copy(
|
|
|
|
threadId = threadId,
|
2022-11-29 15:47:12 +00:00
|
|
|
textDraft = drafts.getDraftOfType(DraftTable.Draft.TEXT),
|
2023-01-25 15:31:36 +00:00
|
|
|
bodyRangesDraft = drafts.getDraftOfType(DraftTable.Draft.BODY_RANGES),
|
2022-11-29 15:47:12 +00:00
|
|
|
quoteDraft = drafts.getDraftOfType(DraftTable.Draft.QUOTE),
|
|
|
|
locationDraft = drafts.getDraftOfType(DraftTable.Draft.LOCATION),
|
2023-02-06 15:04:40 +00:00
|
|
|
voiceNoteDraft = drafts.getDraftOfType(DraftTable.Draft.VOICE_NOTE)
|
2022-08-05 21:00:11 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|