further clean up on session restoration
parent
690687064f
commit
2f57090cfa
@ -1,71 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.loki.api
|
|
||||||
|
|
||||||
import org.session.libsession.messaging.jobs.Data
|
|
||||||
import org.session.libsession.messaging.threads.Address
|
|
||||||
import org.thoughtcrime.securesms.jobmanager.Job
|
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
|
||||||
import org.thoughtcrime.securesms.jobs.BaseJob
|
|
||||||
import org.session.libsignal.utilities.logging.Log
|
|
||||||
import org.session.libsession.messaging.threads.recipients.Recipient
|
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender
|
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage
|
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class ResetThreadSessionJob private constructor(
|
|
||||||
parameters: Parameters,
|
|
||||||
private val address: Address,
|
|
||||||
private val threadId: Long)
|
|
||||||
: BaseJob(parameters) {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val KEY = "ResetThreadSessionJob"
|
|
||||||
const val DATA_KEY_ADDRESS = "address"
|
|
||||||
const val DATA_KEY_THREAD_ID = "thread_id"
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(address: Address, threadId: Long) : this(Parameters.Builder()
|
|
||||||
.addConstraint(NetworkConstraint.KEY)
|
|
||||||
.setQueue(KEY)
|
|
||||||
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
|
||||||
.setMaxAttempts(Parameters.UNLIMITED)
|
|
||||||
.build(),
|
|
||||||
address,
|
|
||||||
threadId)
|
|
||||||
|
|
||||||
override fun serialize(): Data {
|
|
||||||
return Data.Builder()
|
|
||||||
.putParcelable(DATA_KEY_ADDRESS, address)
|
|
||||||
.putLong(DATA_KEY_THREAD_ID, threadId)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getFactoryKey(): String { return KEY }
|
|
||||||
|
|
||||||
public override fun onRun() {
|
|
||||||
val recipient = Recipient.from(context, address, false)
|
|
||||||
|
|
||||||
// Only reset sessions for private chats.
|
|
||||||
if (recipient.isGroupRecipient) return
|
|
||||||
|
|
||||||
Log.v(KEY, "Resetting session for thread: \"$threadId\", recipient: \"${address.serialize()}\"")
|
|
||||||
|
|
||||||
val message = OutgoingEndSessionMessage(OutgoingTextMessage(recipient, "TERMINATE", 0, -1))
|
|
||||||
MessageSender.send(context, message, threadId, false, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
public override fun onShouldRetry(e: Exception): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCanceled() { }
|
|
||||||
|
|
||||||
class Factory : Job.Factory<ResetThreadSessionJob> {
|
|
||||||
|
|
||||||
override fun create(parameters: Parameters, data: Data): ResetThreadSessionJob {
|
|
||||||
val address = data.getParcelable(DATA_KEY_ADDRESS, Address.CREATOR)!!
|
|
||||||
val threadId = data.getLong(DATA_KEY_THREAD_ID)
|
|
||||||
return ResetThreadSessionJob(parameters, address, threadId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.loki.database
|
|
||||||
|
|
||||||
interface LokiThreadDatabaseDelegate {
|
|
||||||
|
|
||||||
fun handleSessionRestoreDevicesChanged(threadID: Long)
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.loki.views
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import kotlinx.android.synthetic.main.session_restore_banner.view.*
|
|
||||||
|
|
||||||
import network.loki.messenger.R
|
|
||||||
import org.session.libsession.messaging.threads.recipients.Recipient
|
|
||||||
|
|
||||||
class SessionRestoreBannerView : LinearLayout {
|
|
||||||
lateinit var recipient: Recipient
|
|
||||||
var onDismiss: (() -> Unit)? = null
|
|
||||||
var onRestore: (() -> Unit)? = null
|
|
||||||
|
|
||||||
constructor(context: Context) : super(context, null)
|
|
||||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs, 0)
|
|
||||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
|
||||||
|
|
||||||
init {
|
|
||||||
LayoutInflater.from(context).inflate(R.layout.session_restore_banner, this, true)
|
|
||||||
restoreButton.setOnClickListener { onRestore?.invoke() }
|
|
||||||
dismissButton.setOnClickListener { onDismiss?.invoke() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun update(recipient: Recipient) {
|
|
||||||
this.recipient = recipient
|
|
||||||
messageTextView.text = context.getString(R.string.session_reset_banner_message, recipient.toShortString())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun show() {
|
|
||||||
sessionRestoreBanner.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hide() {
|
|
||||||
sessionRestoreBanner.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue