Expiration config tweaks

This commit is contained in:
charles 2022-12-16 15:21:48 +11:00
parent b18cebe03d
commit 9e004cd09a
4 changed files with 14 additions and 5 deletions

View File

@ -12,6 +12,8 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.messaging.sending_receiving.MessageSender
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
import org.thoughtcrime.securesms.database.Storage
@ -98,6 +100,11 @@ class ExpirationSettingsViewModel(
val expiryChangeTimestampMs = System.currentTimeMillis()
storage.setExpirationConfiguration(ExpirationConfiguration(threadId, expiresIn, expiryType, expiryChangeTimestampMs))
val message = ExpirationTimerUpdate(expiresIn)
val address = recipient.value?.address ?: return@launch
message.recipient = address.serialize()
message.sentTimestamp = System.currentTimeMillis()
MessageSender.send(message, address)
}
@dagger.assisted.AssistedFactory

View File

@ -18,6 +18,7 @@ import org.session.libsignal.utilities.Log;
import org.session.libsignal.utilities.guava.Optional;
import org.thoughtcrime.securesms.database.MmsDatabase;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
import org.thoughtcrime.securesms.mms.MmsException;
@ -70,10 +71,11 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM
@Override
public void setExpirationTimer(@NotNull ExpirationTimerUpdate message, @Nullable Integer expirationType) {
try {
long threadId = message.getThreadID();
ThreadDatabase threadDb = DatabaseComponent.get(context).threadDatabase();
long threadId = threadDb.getOrCreateThreadIdFor(Recipient.from(context, Address.fromSerialized(message.getSender()), false));
if (message.getGroupPublicKey() != null) {
Recipient recipient = Recipient.from(context, Address.fromSerialized(GroupUtil.doubleEncodeGroupID(message.getGroupPublicKey())), false);
threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient);
threadId = threadDb.getOrCreateThreadIdFor(recipient);
}
DatabaseComponent.get(context).expirationConfigurationDatabase().setExpirationConfiguration(
new ExpirationConfiguration(threadId, message.getDuration(), expirationType, System.currentTimeMillis())

View File

@ -46,9 +46,9 @@ abstract class Message {
return
}
builder.expirationTimer = config.durationSeconds
builder.lastDisappearingMessageChangeTimestamp = config.updatedTimestampMs
if (config.isEnabled) {
builder.expirationType = config.expirationType
builder.lastDisappearingMessageChangeTimestamp = config.updatedTimestampMs
}
}
}

View File

@ -92,7 +92,7 @@ fun updateExpirationConfigurationIfNeeded(message: Message, proto: SignalService
val threadID = storage.getOrCreateThreadIdFor(message.sender!!, message.groupPublicKey, openGroupID)
if (threadID <= 0) return
val localConfig = storage.getExpirationConfiguration(threadID)
if (localConfig == null || localConfig.updatedTimestampMs < proto.lastDisappearingMessageChangeTimestamp) return
if (localConfig == null || localConfig.updatedTimestampMs > proto.lastDisappearingMessageChangeTimestamp) return
val durationSeconds = if (proto.hasExpirationTimer()) proto.expirationTimer else 0
val type = if (proto.hasExpirationType()) proto.expirationType else null
val remoteConfig = ExpirationConfiguration(
@ -157,7 +157,7 @@ fun MessageReceiver.cancelTypingIndicatorsIfNeeded(senderPublicKey: String) {
}
private fun MessageReceiver.handleExpirationTimerUpdate(message: ExpirationTimerUpdate) {
if (ExpirationConfiguration.isNewConfigEnabled) return
if (!ExpirationConfiguration.isNewConfigEnabled) return
val recipient = Recipient.from(MessagingModuleConfiguration.shared.context, Address.fromSerialized(message.sender!!), false)
val type = when {
recipient.isLocalNumber -> ExpirationType.DELETE_AFTER_READ