kopia lustrzana https://github.com/ryukoposting/Signal-Android
74 wiersze
2.3 KiB
Kotlin
74 wiersze
2.3 KiB
Kotlin
package org.thoughtcrime.securesms.jobs
|
|
|
|
import org.signal.core.util.logging.Log
|
|
import org.thoughtcrime.securesms.database.SignalDatabase
|
|
import org.thoughtcrime.securesms.jobmanager.Data
|
|
import org.thoughtcrime.securesms.jobmanager.Job
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
|
import org.thoughtcrime.securesms.mms.OutgoingPaymentsActivatedMessages
|
|
import org.thoughtcrime.securesms.net.NotPushRegisteredException
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
|
import org.thoughtcrime.securesms.sms.MessageSender
|
|
|
|
/**
|
|
* Send payments activated message to all recipients of payment activation request
|
|
*/
|
|
class SendPaymentsActivatedJob(parameters: Parameters) : BaseJob(parameters) {
|
|
|
|
companion object {
|
|
private val TAG = Log.tag(SendPaymentsActivatedJob::class.java)
|
|
|
|
const val KEY = "SendPaymentsActivatedJob"
|
|
}
|
|
|
|
constructor() : this(parameters = Parameters.Builder().build())
|
|
|
|
override fun serialize(): Data = Data.Builder().build()
|
|
|
|
override fun getFactoryKey(): String = KEY
|
|
|
|
@Suppress("UsePropertyAccessSyntax")
|
|
override fun onRun() {
|
|
if (!Recipient.self().isRegistered) {
|
|
throw NotPushRegisteredException()
|
|
}
|
|
|
|
if (!SignalStore.paymentsValues().mobileCoinPaymentsEnabled()) {
|
|
Log.w(TAG, "Payments aren't enabled, not going to attempt to send activation messages.")
|
|
return
|
|
}
|
|
|
|
val threadIds: List<Long> = SignalDatabase.mms.getIncomingPaymentRequestThreads()
|
|
|
|
for (threadId in threadIds) {
|
|
val recipient = SignalDatabase.threads.getRecipientForThreadId(threadId)
|
|
if (recipient != null) {
|
|
MessageSender.send(
|
|
context,
|
|
OutgoingPaymentsActivatedMessages(recipient, System.currentTimeMillis(), 0),
|
|
threadId,
|
|
false,
|
|
null,
|
|
null
|
|
)
|
|
} else {
|
|
Log.w(TAG, "Unable to send activation message for thread: $threadId")
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onShouldRetry(e: Exception): Boolean {
|
|
return false
|
|
}
|
|
|
|
override fun onFailure() {
|
|
Log.w(TAG, "Failed to submit send of payments activated messages")
|
|
}
|
|
|
|
class Factory : Job.Factory<SendPaymentsActivatedJob> {
|
|
override fun create(parameters: Parameters, data: Data): SendPaymentsActivatedJob {
|
|
return SendPaymentsActivatedJob(parameters)
|
|
}
|
|
}
|
|
}
|