mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-12 13:37:56 +00:00
Fix disappear after read
This commit is contained in:
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
@@ -22,6 +23,8 @@ import javax.inject.Inject
|
||||
@AndroidEntryPoint
|
||||
class ControlMessageView : LinearLayout {
|
||||
|
||||
private val TAG = "ControlMessageView"
|
||||
|
||||
private lateinit var binding: ViewControlMessageBinding
|
||||
|
||||
constructor(context: Context) : super(context) { initialize() }
|
||||
@@ -47,6 +50,7 @@ class ControlMessageView : LinearLayout {
|
||||
binding.apply {
|
||||
expirationTimerView.isVisible = true
|
||||
|
||||
Log.d(TAG, "bind() called, messageBody = $messageBody")
|
||||
|
||||
expirationTimerView.setExpirationTime(message.expireStarted, message.expiresIn)
|
||||
|
||||
|
@@ -1,3 +1,12 @@
|
||||
package org.thoughtcrime.securesms.database
|
||||
|
||||
data class ExpirationInfo(val id: Long, val expiresIn: Long, val expireStarted: Long, val isMms: Boolean)
|
||||
data class ExpirationInfo(
|
||||
val id: Long,
|
||||
val timestamp: Long,
|
||||
val expiresIn: Long,
|
||||
val expireStarted: Long,
|
||||
val isMms: Boolean
|
||||
) {
|
||||
private fun isDisappearAfterSend() = timestamp == expireStarted
|
||||
fun isDisappearAfterRead() = expiresIn > 0 && !isDisappearAfterSend()
|
||||
}
|
||||
|
@@ -305,6 +305,8 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
||||
}
|
||||
|
||||
override fun markExpireStarted(messageId: Long, startedTimestamp: Long) {
|
||||
Log.d(TAG, "markExpireStarted() called with: messageId = $messageId, startedTimestamp = $startedTimestamp")
|
||||
|
||||
val contentValues = ContentValues()
|
||||
contentValues.put(EXPIRE_STARTED, startedTimestamp)
|
||||
val db = databaseHelper.writableDatabase
|
||||
@@ -351,13 +353,14 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
||||
)
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
if (MmsSmsColumns.Types.isSecureType(cursor.getLong(3))) {
|
||||
val syncMessageId =
|
||||
SyncMessageId(fromSerialized(cursor.getString(1)), cursor.getLong(2))
|
||||
val timestamp = cursor.getLong(2)
|
||||
val syncMessageId = SyncMessageId(fromSerialized(cursor.getString(1)), timestamp)
|
||||
val expirationInfo = ExpirationInfo(
|
||||
cursor.getLong(0),
|
||||
cursor.getLong(4),
|
||||
cursor.getLong(5),
|
||||
true
|
||||
id = cursor.getLong(0),
|
||||
timestamp = timestamp,
|
||||
expiresIn = cursor.getLong(4),
|
||||
expireStarted = cursor.getLong(5),
|
||||
isMms = true
|
||||
)
|
||||
result.add(MarkedMessageInfo(syncMessageId, expirationInfo))
|
||||
}
|
||||
|
@@ -363,8 +363,9 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
cursor = database.query(TABLE_NAME, new String[] {ID, ADDRESS, DATE_SENT, TYPE, EXPIRES_IN, EXPIRE_STARTED}, where, arguments, null, null, null);
|
||||
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
SyncMessageId syncMessageId = new SyncMessageId(Address.fromSerialized(cursor.getString(1)), cursor.getLong(2));
|
||||
ExpirationInfo expirationInfo = new ExpirationInfo(cursor.getLong(0), cursor.getLong(4), cursor.getLong(5), false);
|
||||
long timestamp = cursor.getLong(2);
|
||||
SyncMessageId syncMessageId = new SyncMessageId(Address.fromSerialized(cursor.getString(1)), timestamp);
|
||||
ExpirationInfo expirationInfo = new ExpirationInfo(cursor.getLong(0), timestamp, cursor.getLong(4), cursor.getLong(5), false);
|
||||
|
||||
results.add(new MarkedMessageInfo(syncMessageId, expirationInfo));
|
||||
}
|
||||
|
@@ -94,6 +94,8 @@ import org.thoughtcrime.securesms.util.SessionMetaProtocol
|
||||
import java.security.MessageDigest
|
||||
import network.loki.messenger.libsession_util.util.Contact as LibSessionContact
|
||||
|
||||
private const val TAG = "Storage"
|
||||
|
||||
open class Storage(
|
||||
context: Context,
|
||||
helper: SQLCipherOpenHelper,
|
||||
@@ -240,6 +242,7 @@ open class Storage(
|
||||
}
|
||||
|
||||
override fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean) {
|
||||
Log.d(TAG, "markConversationAsRead() called with: threadId = $threadId, lastSeenTime = $lastSeenTime, force = $force")
|
||||
val threadDb = DatabaseComponent.get(context).threadDatabase()
|
||||
getRecipientForThread(threadId)?.let { recipient ->
|
||||
val currentLastRead = threadDb.getLastSeenAndHasSent(threadId).first()
|
||||
@@ -1722,6 +1725,8 @@ open class Storage(
|
||||
}
|
||||
|
||||
override fun setExpirationConfiguration(config: ExpirationConfiguration) {
|
||||
Log.d(TAG, "setExpirationConfiguration() called with: config = $config")
|
||||
|
||||
val recipient = getRecipientForThread(config.threadId) ?: return
|
||||
|
||||
val expirationDb = DatabaseComponent.get(context).expirationConfigurationDatabase()
|
||||
|
@@ -58,7 +58,7 @@ class MarkReadReceiver : BroadcastReceiver() {
|
||||
) {
|
||||
if (markedReadMessages.isEmpty()) return
|
||||
|
||||
Log.d(TAG, "process() called with: context = $context, markedReadMessages = $markedReadMessages")
|
||||
Log.d(TAG, "process() called with: markedReadMessages = $markedReadMessages")
|
||||
|
||||
sendReadReceipts(context, markedReadMessages)
|
||||
|
||||
@@ -133,13 +133,16 @@ class MarkReadReceiver : BroadcastReceiver() {
|
||||
expirationInfo: ExpirationInfo,
|
||||
expiresIn: Long = expirationInfo.expiresIn
|
||||
) {
|
||||
Log.d(TAG, "scheduleDeletion() called with: context = $context, expirationInfo = $expirationInfo, expiresIn = $expiresIn")
|
||||
Log.d(TAG, "MarkReadReceiver#scheduleDeletion() called with: expirationInfo = $expirationInfo, expiresIn = $expiresIn")
|
||||
|
||||
if (expiresIn <= 0 || expirationInfo.expireStarted > 0) return
|
||||
val now = nowWithOffset
|
||||
|
||||
val now = SnodeAPI.nowWithOffset
|
||||
val db = DatabaseComponent.get(context!!).run { if (expirationInfo.isMms) mmsDatabase() else smsDatabase() }
|
||||
db.markExpireStarted(expirationInfo.id, now)
|
||||
val expireStarted = expirationInfo.expireStarted
|
||||
|
||||
if (expirationInfo.isDisappearAfterRead() && expireStarted == 0L || now < expireStarted) {
|
||||
val db = DatabaseComponent.get(context!!).run { if (expirationInfo.isMms) mmsDatabase() else smsDatabase() }
|
||||
db.markExpireStarted(expirationInfo.id, now)
|
||||
}
|
||||
|
||||
ApplicationContext.getInstance(context).expiringMessageManager.scheduleDeletion(
|
||||
expirationInfo.id,
|
||||
|
Reference in New Issue
Block a user