mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Fix expiry info disappearance
This commit is contained in:
parent
42923b5c2b
commit
304bf42c0d
@ -117,8 +117,8 @@ public class ConversationItemFooter extends LinearLayout {
|
|||||||
long id = messageRecord.getId();
|
long id = messageRecord.getId();
|
||||||
boolean mms = messageRecord.isMms();
|
boolean mms = messageRecord.isMms();
|
||||||
|
|
||||||
if (mms) DatabaseComponent.get(getContext()).mmsDatabase().markExpireStarted(id);
|
if (mms) DatabaseComponent.get(getContext()).mmsDatabase().markExpireStarted(id, System.currentTimeMillis());
|
||||||
else DatabaseComponent.get(getContext()).smsDatabase().markExpireStarted(id);
|
else DatabaseComponent.get(getContext()).smsDatabase().markExpireStarted(id, System.currentTimeMillis());
|
||||||
|
|
||||||
expirationManager.scheduleDeletion(id, mms, messageRecord.getExpiresIn());
|
expirationManager.scheduleDeletion(id, mms, messageRecord.getExpiresIn());
|
||||||
return null;
|
return null;
|
||||||
|
@ -16,6 +16,7 @@ import org.session.libsession.messaging.messages.ExpirationConfiguration
|
|||||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||||
import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol
|
import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
||||||
import org.thoughtcrime.securesms.database.Storage
|
import org.thoughtcrime.securesms.database.Storage
|
||||||
@ -26,6 +27,7 @@ class ExpirationSettingsViewModel(
|
|||||||
private val threadId: Long,
|
private val threadId: Long,
|
||||||
private val afterReadOptions: List<RadioOption>,
|
private val afterReadOptions: List<RadioOption>,
|
||||||
private val afterSendOptions: List<RadioOption>,
|
private val afterSendOptions: List<RadioOption>,
|
||||||
|
private val textSecurePreferences: TextSecurePreferences,
|
||||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||||
private val threadDb: ThreadDatabase,
|
private val threadDb: ThreadDatabase,
|
||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
@ -110,6 +112,7 @@ class ExpirationSettingsViewModel(
|
|||||||
storage.setExpirationConfiguration(ExpirationConfiguration(threadId, expirationTimer, expiryType, expiryChangeTimestampMs))
|
storage.setExpirationConfiguration(ExpirationConfiguration(threadId, expirationTimer, expiryType, expiryChangeTimestampMs))
|
||||||
|
|
||||||
val message = ExpirationTimerUpdate(expirationTimer)
|
val message = ExpirationTimerUpdate(expirationTimer)
|
||||||
|
message.sender = textSecurePreferences.getLocalNumber()
|
||||||
message.recipient = address.serialize()
|
message.recipient = address.serialize()
|
||||||
message.sentTimestamp = expiryChangeTimestampMs
|
message.sentTimestamp = expiryChangeTimestampMs
|
||||||
messageExpirationManager.setExpirationTimer(message, expiryType)
|
messageExpirationManager.setExpirationTimer(message, expiryType)
|
||||||
@ -134,6 +137,7 @@ class ExpirationSettingsViewModel(
|
|||||||
@Assisted private val threadId: Long,
|
@Assisted private val threadId: Long,
|
||||||
@Assisted("afterRead") private val afterReadOptions: List<RadioOption>,
|
@Assisted("afterRead") private val afterReadOptions: List<RadioOption>,
|
||||||
@Assisted("afterSend") private val afterSendOptions: List<RadioOption>,
|
@Assisted("afterSend") private val afterSendOptions: List<RadioOption>,
|
||||||
|
private val textSecurePreferences: TextSecurePreferences,
|
||||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||||
private val threadDb: ThreadDatabase,
|
private val threadDb: ThreadDatabase,
|
||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
@ -144,6 +148,7 @@ class ExpirationSettingsViewModel(
|
|||||||
threadId,
|
threadId,
|
||||||
afterReadOptions,
|
afterReadOptions,
|
||||||
afterSendOptions,
|
afterSendOptions,
|
||||||
|
textSecurePreferences,
|
||||||
messageExpirationManager,
|
messageExpirationManager,
|
||||||
threadDb,
|
threadDb,
|
||||||
storage
|
storage
|
||||||
|
@ -295,7 +295,11 @@ class VisibleMessageView : LinearLayout {
|
|||||||
val expirationManager = ApplicationContext.getInstance(context).expiringMessageManager
|
val expirationManager = ApplicationContext.getInstance(context).expiringMessageManager
|
||||||
val id = message.getId()
|
val id = message.getId()
|
||||||
val mms = message.isMms
|
val mms = message.isMms
|
||||||
if (mms) mmsDb.markExpireStarted(id) else smsDb.markExpireStarted(id)
|
if (mms) {
|
||||||
|
mmsDb.markExpireStarted(id, System.currentTimeMillis())
|
||||||
|
} else {
|
||||||
|
smsDb.markExpireStarted(id, System.currentTimeMillis())
|
||||||
|
}
|
||||||
expirationManager.scheduleDeletion(id, mms, message.expiresIn)
|
expirationManager.scheduleDeletion(id, mms, message.expiresIn)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.database
|
|||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds.BaseTypes
|
||||||
import com.annimon.stream.Stream
|
import com.annimon.stream.Stream
|
||||||
import com.google.android.mms.pdu_alt.NotificationInd
|
import com.google.android.mms.pdu_alt.NotificationInd
|
||||||
import com.google.android.mms.pdu_alt.PduHeaders
|
import com.google.android.mms.pdu_alt.PduHeaders
|
||||||
@ -645,6 +646,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
if (threadId == -1L) throw MmsException(e)
|
if (threadId == -1L) throw MmsException(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
deleteExpirationTimerMessages(threadId)
|
||||||
val contentValues = ContentValues()
|
val contentValues = ContentValues()
|
||||||
contentValues.put(DATE_SENT, retrieved.sentTimeMillis)
|
contentValues.put(DATE_SENT, retrieved.sentTimeMillis)
|
||||||
contentValues.put(ADDRESS, retrieved.from.serialize())
|
contentValues.put(ADDRESS, retrieved.from.serialize())
|
||||||
@ -737,6 +739,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
threadId = get(context).threadDatabase().getOrCreateThreadIdFor(retrieved.recipient)
|
threadId = get(context).threadDatabase().getOrCreateThreadIdFor(retrieved.recipient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
deleteExpirationTimerMessages(threadId)
|
||||||
val messageId = insertMessageOutbox(retrieved, threadId, false, null, serverTimestamp, runThreadUpdate)
|
val messageId = insertMessageOutbox(retrieved, threadId, false, null, serverTimestamp, runThreadUpdate)
|
||||||
if (messageId == -1L) {
|
if (messageId == -1L) {
|
||||||
return Optional.absent()
|
return Optional.absent()
|
||||||
@ -1252,6 +1255,12 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteExpirationTimerMessages(threadId: Long) {
|
||||||
|
val where = "$THREAD_ID = ? AND ($MESSAGE_BOX & ${MmsSmsColumns.Types.EXPIRATION_TIMER_UPDATE_BIT}) <> 0"
|
||||||
|
val updated = writableDatabase.delete(TABLE_NAME, where, arrayOf("$threadId"))
|
||||||
|
notifyConversationListeners(threadId)
|
||||||
|
}
|
||||||
|
|
||||||
object Status {
|
object Status {
|
||||||
const val DOWNLOAD_INITIALIZED = 1
|
const val DOWNLOAD_INITIALIZED = 1
|
||||||
const val DOWNLOAD_NO_CONNECTIVITY = 2
|
const val DOWNLOAD_NO_CONNECTIVITY = 2
|
||||||
|
@ -95,8 +95,8 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
|||||||
if (expirationInfo.getExpiresIn() > 0 && expirationInfo.getExpireStarted() <= 0) {
|
if (expirationInfo.getExpiresIn() > 0 && expirationInfo.getExpireStarted() <= 0) {
|
||||||
ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
|
ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
|
||||||
|
|
||||||
if (expirationInfo.isMms()) DatabaseComponent.get(context).mmsDatabase().markExpireStarted(expirationInfo.getId());
|
if (expirationInfo.isMms()) DatabaseComponent.get(context).mmsDatabase().markExpireStarted(expirationInfo.getId(), System.currentTimeMillis());
|
||||||
else DatabaseComponent.get(context).smsDatabase().markExpireStarted(expirationInfo.getId());
|
else DatabaseComponent.get(context).smsDatabase().markExpireStarted(expirationInfo.getId(), System.currentTimeMillis());
|
||||||
|
|
||||||
expirationManager.scheduleDeletion(expirationInfo.getId(), expirationInfo.isMms(), expirationInfo.getExpiresIn());
|
expirationManager.scheduleDeletion(expirationInfo.getId(), expirationInfo.isMms(), expirationInfo.getExpiresIn());
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,9 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM
|
|||||||
} else {
|
} else {
|
||||||
insertIncomingExpirationTimerMessage(message, expireStartedAt);
|
insertIncomingExpirationTimerMessage(message, expireStartedAt);
|
||||||
}
|
}
|
||||||
|
if (message.getSentTimestamp() != null && senderPublicKey != null) {
|
||||||
|
startAnyExpiration(message.getSentTimestamp(), senderPublicKey, expireStartedAt);
|
||||||
|
}
|
||||||
if (message.getId() != null) {
|
if (message.getId() != null) {
|
||||||
DatabaseComponent.get(context).smsDatabase().deleteMessage(message.getId());
|
DatabaseComponent.get(context).smsDatabase().deleteMessage(message.getId());
|
||||||
}
|
}
|
||||||
@ -148,16 +150,16 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startAnyExpiration(long timestamp, @NotNull String author) {
|
public void startAnyExpiration(long timestamp, @NotNull String author, long expireStartedAt) {
|
||||||
MessageRecord messageRecord = DatabaseComponent.get(context).mmsSmsDatabase().getMessageFor(timestamp, author);
|
MessageRecord messageRecord = DatabaseComponent.get(context).mmsSmsDatabase().getMessageFor(timestamp, author);
|
||||||
if (messageRecord != null) {
|
if (messageRecord != null) {
|
||||||
boolean mms = messageRecord.isMms();
|
boolean mms = messageRecord.isMms();
|
||||||
ExpirationConfiguration config = DatabaseComponent.get(context).expirationConfigurationDatabase().getExpirationConfiguration(messageRecord.getThreadId());
|
ExpirationConfiguration config = DatabaseComponent.get(context).expirationConfigurationDatabase().getExpirationConfiguration(messageRecord.getThreadId());
|
||||||
if (config == null || !config.isEnabled()) return;
|
if (config == null || !config.isEnabled()) return;
|
||||||
if (mms) {
|
if (mms) {
|
||||||
mmsDatabase.markExpireStarted(messageRecord.getId());
|
mmsDatabase.markExpireStarted(messageRecord.getId(), expireStartedAt);
|
||||||
} else {
|
} else {
|
||||||
smsDatabase.markExpireStarted(messageRecord.getId());
|
smsDatabase.markExpireStarted(messageRecord.getId(), expireStartedAt);
|
||||||
}
|
}
|
||||||
scheduleDeletion(messageRecord.getId(), mms, config.getDurationSeconds() * 1000L);
|
scheduleDeletion(messageRecord.getId(), mms, config.getDurationSeconds() * 1000L);
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ object MessageSender {
|
|||||||
storage.markUnidentified(message.sentTimestamp!!, userPublicKey)
|
storage.markUnidentified(message.sentTimestamp!!, userPublicKey)
|
||||||
// Start the disappearing messages timer if needed
|
// Start the disappearing messages timer if needed
|
||||||
if (message is VisibleMessage && !isSyncMessage) {
|
if (message is VisibleMessage && !isSyncMessage) {
|
||||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, userPublicKey)
|
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, userPublicKey, System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
} ?: run {
|
} ?: run {
|
||||||
storage.updateReactionIfNeeded(message, message.sender?:userPublicKey, openGroupSentTimestamp)
|
storage.updateReactionIfNeeded(message, message.sender?:userPublicKey, openGroupSentTimestamp)
|
||||||
|
@ -128,7 +128,7 @@ private fun MessageReceiver.handleSyncedExpiriesMessage(message: SyncedExpiriesM
|
|||||||
val config = storage.getExpirationConfiguration(storage.getOrCreateThreadIdFor(syncTarget)) ?: return@forEach
|
val config = storage.getExpirationConfiguration(storage.getOrCreateThreadIdFor(syncTarget)) ?: return@forEach
|
||||||
syncedExpiries.forEach { syncedExpiry ->
|
syncedExpiries.forEach { syncedExpiry ->
|
||||||
val startedAtMs = syncedExpiry.expirationTimestamp!! - config.durationSeconds * 1000
|
val startedAtMs = syncedExpiry.expirationTimestamp!! - config.durationSeconds * 1000
|
||||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(startedAtMs, syncTarget)
|
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(startedAtMs, syncTarget, System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class SSKEnvironment(
|
|||||||
|
|
||||||
interface MessageExpirationManagerProtocol {
|
interface MessageExpirationManagerProtocol {
|
||||||
fun setExpirationTimer(message: ExpirationTimerUpdate, expiryType: Int)
|
fun setExpirationTimer(message: ExpirationTimerUpdate, expiryType: Int)
|
||||||
fun startAnyExpiration(timestamp: Long, author: String)
|
fun startAnyExpiration(timestamp: Long, author: String, expireStartedAt: Long)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user