Remove incomplete SyncedExpiry implementation

This commit is contained in:
charles 2022-12-21 18:17:29 +11:00
parent 18ff597811
commit 1ba8f9f80d
10 changed files with 102 additions and 2869 deletions

View File

@ -1,58 +0,0 @@
package org.session.libsession.messaging.jobs
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.utilities.Data
class DisappearingMessagesJob(
val messageIds: List<Long> = emptyList(),
val startedAtMs: Long = 0,
val threadId: Long = 0
) : Job {
override var delegate: JobDelegate? = null
override var id: String? = null
override var failureCount: Int = 0
override val maxFailureCount: Int = 1
override fun execute() {
if (!ExpirationConfiguration.isNewConfigEnabled) return
try {
val ids = MessagingModuleConfiguration.shared.storage.getExpiringMessages(messageIds).map { it.first }
if (ids.isNotEmpty()) {
JobQueue.shared.add(SyncedExpiriesJob(ids, startedAtMs, threadId))
}
} catch (e: Exception) {
delegate?.handleJobFailed(this, e)
return
}
delegate?.handleJobSucceeded(this)
}
override fun serialize(): Data = Data.Builder()
.putLongArray(MESSAGE_IDS, messageIds.toLongArray())
.putLong(STARTED_AT_MS, startedAtMs)
.putLong(THREAD_ID, threadId)
.build()
override fun getFactoryKey(): String = KEY
class Factory : Job.Factory<DisappearingMessagesJob> {
override fun create(data: Data): DisappearingMessagesJob {
return DisappearingMessagesJob(
data.getLongArray(MESSAGE_IDS).toList(),
data.getLong(STARTED_AT_MS),
data.getLong(THREAD_ID)
)
}
}
companion object {
const val KEY = "DisappearingMessagesJob"
private const val MESSAGE_IDS = "messageIds"
private const val STARTED_AT_MS = "startedAtMs"
private const val THREAD_ID = "threadId"
}
}

View File

@ -115,8 +115,7 @@ class JobQueue : JobDelegate {
while (isActive) { while (isActive) {
when (val job = queue.receive()) { when (val job = queue.receive()) {
is NotifyPNServerJob, is AttachmentUploadJob, is MessageSendJob, is DisappearingMessagesJob, is NotifyPNServerJob, is AttachmentUploadJob, is MessageSendJob -> {
is SyncedExpiriesJob -> {
txQueue.send(job) txQueue.send(job)
} }
is AttachmentDownloadJob -> { is AttachmentDownloadJob -> {

View File

@ -1,84 +0,0 @@
package org.session.libsession.messaging.jobs
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.messages.control.SyncedExpiriesMessage
import org.session.libsession.messaging.messages.control.SyncedExpiry
import org.session.libsession.messaging.sending_receiving.MessageSender
import org.session.libsession.messaging.utilities.Data
import org.session.libsession.snode.SnodeAPI
import org.session.libsession.utilities.Address
class SyncedExpiriesJob(
val messageIds: List<Long> = emptyList(),
val startedAtMs: Long = 0,
val threadId: Long = 0
) : Job {
override var delegate: JobDelegate? = null
override var id: String? = null
override var failureCount: Int = 0
override val maxFailureCount: Int = 1
override fun execute() {
if (!ExpirationConfiguration.isNewConfigEnabled) return
val module = MessagingModuleConfiguration.shared
val userPublicKey = module.storage.getUserPublicKey() ?: return
try {
val messageIdsWithNoServerHashByExpiresIn = mutableMapOf<Long, List<Long>>()
module.storage.getExpiringMessages(messageIds).groupBy { it.second }.forEach { (expiresInSeconds, messageIds) ->
val serverHashesByMessageIds = module.messageDataProvider.getServerHashForMessages(messageIds.map { it.first })
val messageIdsWithNoHash = serverHashesByMessageIds.filter { it.second == null }.map { it.first }
if (messageIdsWithNoHash.isNotEmpty()) {
messageIdsWithNoServerHashByExpiresIn[expiresInSeconds] = messageIdsWithNoHash
}
val serverHashes = serverHashesByMessageIds.mapNotNull { it.second }
if (serverHashes.isEmpty()) return
val expirationTimestamp = startedAtMs + expiresInSeconds * 1000
val syncTarget = ""
val syncedExpiriesMessage = SyncedExpiriesMessage()
syncedExpiriesMessage.conversationExpiries = mapOf(
syncTarget to serverHashes.map { serverHash -> SyncedExpiry(serverHash, expirationTimestamp) }
)
MessageSender.send(syncedExpiriesMessage, Address.fromSerialized(userPublicKey))
SnodeAPI.updateExpiry(expirationTimestamp, serverHashes)
}
if (messageIdsWithNoServerHashByExpiresIn.isNotEmpty()) {
JobQueue.shared.add(
SyncedExpiriesJob(messageIdsWithNoServerHashByExpiresIn.flatMap { it.value }, startedAtMs, threadId)
)
}
} catch (e: Exception) {
delegate?.handleJobFailed(this, e)
return
}
delegate?.handleJobSucceeded(this)
}
override fun serialize(): Data = Data.Builder()
.putLongArray(MESSAGE_IDS, messageIds.toLongArray())
.putLong(STARTED_AT_MS, startedAtMs)
.putLong(THREAD_ID, threadId)
.build()
override fun getFactoryKey(): String = KEY
class Factory : Job.Factory<SyncedExpiriesJob> {
override fun create(data: Data): SyncedExpiriesJob {
return SyncedExpiriesJob(
data.getLongArray(MESSAGE_IDS).toList(),
data.getLong(STARTED_AT_MS),
data.getLong(THREAD_ID)
)
}
}
companion object {
const val KEY = "DisappearingMessagesJob"
private const val MESSAGE_IDS = "messageIds"
private const val STARTED_AT_MS = "startedAtMs"
private const val THREAD_ID = "threadId"
}
}

View File

@ -1,61 +0,0 @@
package org.session.libsession.messaging.messages.control
import org.session.libsignal.protos.SignalServiceProtos
import org.session.libsignal.protos.SignalServiceProtos.SyncedExpiries.SyncedConversationExpiries
import org.session.libsignal.utilities.Log
class SyncedExpiriesMessage(): ControlMessage() {
var conversationExpiries: Map<String, List<SyncedExpiry>> = emptyMap()
override val isSelfSendValid: Boolean = true
// region Validation
override fun isValid(): Boolean {
if (!super.isValid()) return false
return conversationExpiries.isNotEmpty()
}
// endregion
companion object {
const val TAG = "SyncedExpiriesMessage"
fun fromProto(proto: SignalServiceProtos.Content): SyncedExpiriesMessage? {
val syncedExpiriesProto = if (proto.hasSyncedExpiries()) proto.syncedExpiries else return null
val conversationExpiries = syncedExpiriesProto.conversationExpiriesList.associate {
it.syncTarget to it.expiriesList.map { syncedExpiry -> SyncedExpiry.fromProto(syncedExpiry) }
}
return SyncedExpiriesMessage(conversationExpiries)
}
}
constructor(conversationExpiries: Map<String, List<SyncedExpiry>>) : this() {
this.conversationExpiries = conversationExpiries
}
override fun toProto(): SignalServiceProtos.Content? {
val conversationExpiries = conversationExpiries
if (conversationExpiries.isEmpty()) {
Log.w(TAG, "Couldn't construct synced expiries proto from: $this")
return null
}
val conversationExpiriesProto = conversationExpiries.map { (syncTarget, syncedExpiries) ->
val expiriesProto = syncedExpiries.map(SyncedExpiry::toProto)
val syncedConversationExpiriesProto = SyncedConversationExpiries.newBuilder()
syncedConversationExpiriesProto.syncTarget = syncTarget
syncedConversationExpiriesProto.addAllExpiries(expiriesProto)
syncedConversationExpiriesProto.build()
}
val syncedExpiriesProto = SignalServiceProtos.SyncedExpiries.newBuilder()
syncedExpiriesProto.addAllConversationExpiries(conversationExpiriesProto)
val contentProto = SignalServiceProtos.Content.newBuilder()
return try {
contentProto.syncedExpiries = syncedExpiriesProto.build()
setExpirationConfigurationIfNeeded(contentProto)
contentProto.build()
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct synced expiries proto from: $this")
null
}
}
}

View File

@ -1,35 +0,0 @@
package org.session.libsession.messaging.messages.control
import org.session.libsignal.protos.SignalServiceProtos.SyncedExpiries
import org.session.libsignal.utilities.Log
class SyncedExpiry(
var serverHash: String? = null,
var expirationTimestamp: Long? = null
) {
fun toProto(): SyncedExpiries.SyncedConversationExpiries.SyncedExpiry? {
val syncedExpiryProto = SyncedExpiries.SyncedConversationExpiries.SyncedExpiry.newBuilder()
serverHash?.let { syncedExpiryProto.serverHash = it }
expirationTimestamp?.let { syncedExpiryProto.expirationTimestamp = it }
return try {
syncedExpiryProto.build()
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct synced expiry proto from: $this")
null
}
}
companion object {
const val TAG = "SyncedExpiry"
@JvmStatic
fun fromProto(proto: SyncedExpiries.SyncedConversationExpiries.SyncedExpiry): SyncedExpiry {
val result = SyncedExpiry()
result.serverHash = if (proto.hasServerHash()) proto.serverHash else null
result.expirationTimestamp = if (proto.hasServerHash()) proto.expirationTimestamp else null
return SyncedExpiry()
}
}
}

View File

@ -9,7 +9,6 @@ import org.session.libsession.messaging.messages.control.DataExtractionNotificat
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.messaging.messages.control.MessageRequestResponse import org.session.libsession.messaging.messages.control.MessageRequestResponse
import org.session.libsession.messaging.messages.control.ReadReceipt import org.session.libsession.messaging.messages.control.ReadReceipt
import org.session.libsession.messaging.messages.control.SyncedExpiriesMessage
import org.session.libsession.messaging.messages.control.TypingIndicator import org.session.libsession.messaging.messages.control.TypingIndicator
import org.session.libsession.messaging.messages.control.UnsendRequest import org.session.libsession.messaging.messages.control.UnsendRequest
import org.session.libsession.messaging.messages.visible.VisibleMessage import org.session.libsession.messaging.messages.visible.VisibleMessage
@ -139,7 +138,6 @@ object MessageReceiver {
UnsendRequest.fromProto(proto) ?: UnsendRequest.fromProto(proto) ?:
MessageRequestResponse.fromProto(proto) ?: MessageRequestResponse.fromProto(proto) ?:
CallMessage.fromProto(proto) ?: CallMessage.fromProto(proto) ?:
SyncedExpiriesMessage.fromProto(proto) ?:
VisibleMessage.fromProto(proto) ?: run { VisibleMessage.fromProto(proto) ?: run {
throw Error.UnknownMessage throw Error.UnknownMessage
} }

View File

@ -12,7 +12,6 @@ import org.session.libsession.messaging.messages.control.CallMessage
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
import org.session.libsession.messaging.messages.control.ConfigurationMessage import org.session.libsession.messaging.messages.control.ConfigurationMessage
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.messaging.messages.control.SyncedExpiriesMessage
import org.session.libsession.messaging.messages.control.UnsendRequest import org.session.libsession.messaging.messages.control.UnsendRequest
import org.session.libsession.messaging.messages.visible.LinkPreview import org.session.libsession.messaging.messages.visible.LinkPreview
import org.session.libsession.messaging.messages.visible.Profile import org.session.libsession.messaging.messages.visible.Profile
@ -127,11 +126,7 @@ object MessageSender {
// Convert it to protobuf // Convert it to protobuf
val proto = message.toProto() ?: throw Error.ProtoConversionFailed val proto = message.toProto() ?: throw Error.ProtoConversionFailed
// Serialize the protobuf // Serialize the protobuf
val plaintext = if (message is SyncedExpiriesMessage) { val plaintext = PushTransportDetails.getPaddedMessageBody(proto.toByteArray())
proto.toByteArray()
} else {
PushTransportDetails.getPaddedMessageBody(proto.toByteArray())
}
// Encrypt the serialized protobuf // Encrypt the serialized protobuf
val ciphertext = when (destination) { val ciphertext = when (destination) {
is Destination.Contact -> MessageEncrypter.encrypt(plaintext, destination.publicKey) is Destination.Contact -> MessageEncrypter.encrypt(plaintext, destination.publicKey)

View File

@ -4,7 +4,6 @@ import android.text.TextUtils
import org.session.libsession.avatars.AvatarHelper import org.session.libsession.avatars.AvatarHelper
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.jobs.BackgroundGroupAddJob import org.session.libsession.messaging.jobs.BackgroundGroupAddJob
import org.session.libsession.messaging.jobs.DisappearingMessagesJob
import org.session.libsession.messaging.jobs.JobQueue import org.session.libsession.messaging.jobs.JobQueue
import org.session.libsession.messaging.messages.ExpirationConfiguration import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.messages.Message import org.session.libsession.messaging.messages.Message
@ -15,7 +14,6 @@ import org.session.libsession.messaging.messages.control.DataExtractionNotificat
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.messaging.messages.control.MessageRequestResponse import org.session.libsession.messaging.messages.control.MessageRequestResponse
import org.session.libsession.messaging.messages.control.ReadReceipt import org.session.libsession.messaging.messages.control.ReadReceipt
import org.session.libsession.messaging.messages.control.SyncedExpiriesMessage
import org.session.libsession.messaging.messages.control.TypingIndicator import org.session.libsession.messaging.messages.control.TypingIndicator
import org.session.libsession.messaging.messages.control.UnsendRequest import org.session.libsession.messaging.messages.control.UnsendRequest
import org.session.libsession.messaging.messages.visible.Attachment import org.session.libsession.messaging.messages.visible.Attachment
@ -81,9 +79,7 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
runProfileUpdate = true runProfileUpdate = true
) )
is CallMessage -> handleCallMessage(message) is CallMessage -> handleCallMessage(message)
is SyncedExpiriesMessage -> handleSyncedExpiriesMessage(message)
} }
JobQueue.shared.add(DisappearingMessagesJob())
} }
fun MessageReceiver.updateExpirationConfigurationIfNeeded(message: Message, proto: SignalServiceProtos.Content, openGroupID: String?) { fun MessageReceiver.updateExpirationConfigurationIfNeeded(message: Message, proto: SignalServiceProtos.Content, openGroupID: String?) {
@ -120,21 +116,6 @@ private fun MessageReceiver.handleCallMessage(message: CallMessage) {
WebRtcUtils.SIGNAL_QUEUE.trySend(message) WebRtcUtils.SIGNAL_QUEUE.trySend(message)
} }
private fun MessageReceiver.handleSyncedExpiriesMessage(message: SyncedExpiriesMessage) {
val module = MessagingModuleConfiguration.shared
val userPublicKey = module.storage.getUserPublicKey() ?: return
if (userPublicKey != message.sender) return
message.conversationExpiries.forEach { (syncTarget, syncedExpiries) ->
val config = module.storage.getExpirationConfiguration(module.storage.getOrCreateThreadIdFor(syncTarget)) ?: return@forEach
syncedExpiries.forEach { syncedExpiry ->
module.messageDataProvider.getMessageTimestampForServerHash(syncedExpiry.serverHash!!)?.let { timestamp ->
val startedAtMs = syncedExpiry.expirationTimestamp!! - config.durationSeconds * 1000
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(timestamp, syncTarget, startedAtMs)
}
}
}
}
private fun MessageReceiver.handleTypingIndicator(message: TypingIndicator) { private fun MessageReceiver.handleTypingIndicator(message: TypingIndicator) {
when (message.kind!!) { when (message.kind!!) {
TypingIndicator.Kind.STARTED -> showTypingIndicatorIfNeeded(message.sender!!) TypingIndicator.Kind.STARTED -> showTypingIndicatorIfNeeded(message.sender!!)
@ -390,7 +371,6 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
storage.persist(message, quoteModel, linkPreviews, message.groupPublicKey, openGroupID, storage.persist(message, quoteModel, linkPreviews, message.groupPublicKey, openGroupID,
attachments, runIncrement, runThreadUpdate attachments, runIncrement, runThreadUpdate
) ?: return null ) ?: return null
JobQueue.shared.add(DisappearingMessagesJob())
val openGroupServerID = message.openGroupServerMessageID val openGroupServerID = message.openGroupServerMessageID
if (openGroupServerID != null) { if (openGroupServerID != null) {
val isSms = !(message.isMediaMessage() || attachments.isNotEmpty()) val isSms = !(message.isMediaMessage() || attachments.isNotEmpty())

View File

@ -59,26 +59,6 @@ message Content {
optional ExpirationType expirationType = 11; optional ExpirationType expirationType = 11;
optional uint32 expirationTimer = 12; optional uint32 expirationTimer = 12;
optional uint64 lastDisappearingMessageChangeTimestamp = 13; optional uint64 lastDisappearingMessageChangeTimestamp = 13;
optional SyncedExpiries syncedExpiries = 14;
}
message SyncedExpiries {
message SyncedConversationExpiries {
message SyncedExpiry {
// @required
required string serverHash = 1; // messageHash for desktop and serverHash for mobile
// @required
required uint64 expirationTimestamp = 2; // this is only used for deleteAfterRead
}
// @required
required string syncTarget = 1; // the conversationID those expiries are related to
repeated SyncedExpiry expiries = 2;
}
repeated SyncedConversationExpiries conversationExpiries = 1;
} }
message KeyPair { message KeyPair {