From 95646ed04eb9da9a9af6cbf2f2c9a622150d5f49 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 16 Mar 2021 16:31:52 +1100 Subject: [PATCH 1/8] make error description show in the message detail activity --- .../thoughtcrime/securesms/database/Storage.kt | 6 ++++++ .../messaging/jobs/AttachmentDownloadJob.kt | 2 +- .../messaging/jobs/AttachmentUploadJob.kt | 2 +- .../sending_receiving/MessageReceiver.kt | 2 +- .../messaging/sending_receiving/MessageSender.kt | 16 +++++++--------- .../libsession/messaging/utilities/DotNetAPI.kt | 2 +- .../messaging/utilities/MessageWrapper.kt | 2 +- .../org/session/libsession/snode/SnodeAPI.kt | 2 +- .../service/loki/crypto/MnemonicCodec.kt | 2 +- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 6a0d42777d..3cb1887381 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -44,6 +44,7 @@ import org.session.libsession.messaging.messages.signal.IncomingGroupMessage import org.session.libsession.messaging.messages.signal.IncomingTextMessage import org.session.libsession.messaging.messages.signal.OutgoingTextMessage import org.session.libsession.utilities.preferences.ProfileKeyUtil +import org.session.libsignal.service.loki.utilities.prettifiedDescription class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), StorageProtocol { override fun getUserPublicKey(): String? { @@ -368,6 +369,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val smsDatabase = DatabaseFactory.getSmsDatabase(context) smsDatabase.markAsSentFailed(messageRecord.getId()) } + if (error.localizedMessage != null) { + DatabaseFactory.getLokiMessageDatabase(context).setErrorMessage(messageRecord.getId(), error.localizedMessage!!) + } else { + DatabaseFactory.getLokiMessageDatabase(context).setErrorMessage(messageRecord.getId(), error.javaClass.simpleName) + } } override fun getGroup(groupID: String): GroupRecord? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt index 37eafe8b1b..f46a124ca8 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt @@ -17,7 +17,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long) private val MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024 // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object NoAttachment : Error("No such attachment.") } diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt index 847d4a3b88..94b7a9d26a 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt @@ -25,7 +25,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess override var failureCount: Int = 0 // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object NoAttachment : Error("No such attachment.") } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt index 5b661327cb..8412ddcc61 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt @@ -11,7 +11,7 @@ object MessageReceiver { private val lastEncryptionKeyPairRequest = mutableMapOf() - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object DuplicateMessage: Error("Duplicate message.") object InvalidMessage: Error("Invalid message.") object UnknownMessage: Error("Unknown message type.") diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 39a0237000..ebab94b9aa 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -34,7 +34,7 @@ import org.session.libsignal.utilities.logging.Log object MessageSender { // Error - sealed class Error(val description: String) : Exception() { + sealed class Error(val description: String) : Exception(description) { object InvalidMessage : Error("Invalid message.") object ProtoConversionFailed : Error("Couldn't convert message to proto.") object ProofOfWorkCalculationFailed : Error("Proof of work calculation failed.") @@ -202,6 +202,11 @@ object MessageSender { val preconditionFailure = Exception("Destination should not be contacts or closed groups!") message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } message.sender = storage.getUserPublicKey() + // Set the failure handler (need it here already for precondition failure handling) + fun handleFailure(error: Exception) { + handleFailedMessageSend(message, error) + deferred.reject(error) + } try { val server: String val channel: Long @@ -214,19 +219,12 @@ object MessageSender { channel = destination.channel } } - // Set the failure handler (need it here already for precondition failure handling) - fun handleFailure(error: Exception) { - handleFailedMessageSend(message, error) - deferred.reject(error) - } // Validate the message if (message !is VisibleMessage || !message.isValid()) { - handleFailure(Error.InvalidMessage) throw Error.InvalidMessage } // Convert the message to an open group message val openGroupMessage = OpenGroupMessage.from(message, server) ?: kotlin.run { - handleFailure(Error.InvalidMessage) throw Error.InvalidMessage } // Send the result @@ -238,7 +236,7 @@ object MessageSender { handleFailure(it) } } catch (exception: Exception) { - deferred.reject(exception) + handleFailure(exception) } return deferred.promise } diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt index 49853b33e2..0856e43862 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt @@ -42,7 +42,7 @@ open class DotNetAPI { internal enum class HTTPVerb { GET, PUT, POST, DELETE, PATCH } // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object Generic : Error("An error occurred.") object InvalidURL : Error("Invalid URL.") object ParsingFailed : Error("Invalid file server response.") diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt index 9305852258..b11cbe1774 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt @@ -10,7 +10,7 @@ import java.security.SecureRandom object MessageWrapper { // region Types - sealed class Error(val description: String) : Exception() { + sealed class Error(val description: String) : Exception(description) { object FailedToWrapData : Error("Failed to wrap data.") object FailedToWrapMessageInEnvelope : Error("Failed to wrap message in envelope.") object FailedToWrapEnvelopeInWebSocketMessage : Error("Failed to wrap envelope in web socket message.") diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 1b17a02211..98b711af60 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -45,7 +45,7 @@ object SnodeAPI { internal var powDifficulty = 1 // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object Generic : Error("An error occurred.") object ClockOutOfSync : Error("The user's clock is out of sync with the service node network.") object RandomSnodePoolUpdatingFailed : Error("Failed to update random service node pool.") diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt index 192218d399..b3c15dd132 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt @@ -50,7 +50,7 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) { } } - sealed class DecodingError(val description: String) : Exception() { + sealed class DecodingError(val description: String) : Exception(description) { object Generic : DecodingError("Something went wrong. Please check your mnemonic and try again.") object InputTooShort : DecodingError("Looks like you didn't enter enough words. Please check your mnemonic and try again.") object MissingLastWord : DecodingError("You seem to be missing the last word of your mnemonic. Please check what you entered and try again.") From 39aef68b0428813b4775318099031b89480d10f9 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 17 Mar 2021 10:48:20 +1100 Subject: [PATCH 2/8] refactor precondition failure error --- .../messaging/sending_receiving/MessageSender.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index ff07ae0ddc..9ccd58fc72 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -50,6 +50,9 @@ object MessageSender { object NoPrivateKey : Error("Couldn't find a private key associated with the given group public key.") object InvalidClosedGroupUpdate : Error("Invalid group update.") + // Precondition + class PreconditionFailure(val reason: String): Error(reason) + internal val isRetryable: Boolean = when (this) { is InvalidMessage -> false is ProtoConversionFailed -> false @@ -73,7 +76,6 @@ object MessageSender { val promise = deferred.promise val storage = MessagingConfiguration.shared.storage val userPublicKey = storage.getUserPublicKey() - val preconditionFailure = Exception("Destination should not be open groups!") // Set the timestamp, sender and recipient message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } /* Visible messages will already have their sent timestamp set */ message.sender = userPublicKey @@ -90,7 +92,7 @@ object MessageSender { when (destination) { is Destination.Contact -> message.recipient = destination.publicKey is Destination.ClosedGroup -> message.recipient = destination.groupPublicKey - is Destination.OpenGroup -> throw preconditionFailure + is Destination.OpenGroup -> throw Error.PreconditionFailure("Destination should not be open groups!") } // Validate the message if (!message.isValid()) { throw Error.InvalidMessage } @@ -128,7 +130,7 @@ object MessageSender { val encryptionKeyPair = MessagingConfiguration.shared.storage.getLatestClosedGroupEncryptionKeyPair(destination.groupPublicKey)!! ciphertext = MessageSenderEncryption.encryptWithSessionProtocol(plaintext, encryptionKeyPair.hexEncodedPublicKey) } - is Destination.OpenGroup -> throw preconditionFailure + is Destination.OpenGroup -> throw Error.PreconditionFailure("Destination should not be open groups!") } // Wrap the result val kind: SignalServiceProtos.Envelope.Type @@ -142,7 +144,7 @@ object MessageSender { kind = SignalServiceProtos.Envelope.Type.CLOSED_GROUP_CIPHERTEXT senderPublicKey = destination.groupPublicKey } - is Destination.OpenGroup -> throw preconditionFailure + is Destination.OpenGroup -> throw Error.PreconditionFailure("Destination should not be open groups!") } val wrappedMessage = MessageWrapper.wrap(kind, message.sentTimestamp!!, senderPublicKey, ciphertext) // Calculate proof of work @@ -200,7 +202,6 @@ object MessageSender { private fun sendToOpenGroupDestination(destination: Destination, message: Message): Promise { val deferred = deferred() val storage = MessagingConfiguration.shared.storage - val preconditionFailure = Exception("Destination should not be contacts or closed groups!") message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } message.sender = storage.getUserPublicKey() // Set the failure handler (need it here already for precondition failure handling) @@ -212,8 +213,8 @@ object MessageSender { val server: String val channel: Long when (destination) { - is Destination.Contact -> throw preconditionFailure - is Destination.ClosedGroup -> throw preconditionFailure + is Destination.Contact -> throw Error.PreconditionFailure("Destination should not be contacts!") + is Destination.ClosedGroup -> throw Error.PreconditionFailure("Destination should not be closed groups!") is Destination.OpenGroup -> { message.recipient = "${destination.server}.${destination.channel}" server = destination.server From 436598a80b91db390406bb3be7e06f33473c56ac Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 17 Mar 2021 11:30:03 +1100 Subject: [PATCH 3/8] resume pending jobs on app starting --- .../org/thoughtcrime/securesms/loki/activities/HomeActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index bcbdc18ef8..281d42b552 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -30,6 +30,7 @@ import org.session.libsession.messaging.sending_receiving.MessageSender import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode +import org.session.libsession.messaging.jobs.JobQueue import org.session.libsession.utilities.* import org.session.libsignal.service.loki.utilities.mentions.MentionsManager import org.session.libsignal.service.loki.utilities.toHexString @@ -139,6 +140,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), if (userPublicKey != null) { MentionsManager.configureIfNeeded(userPublicKey, threadDB, userDB) application.publicChatManager.startPollersIfNeeded() + JobQueue.shared.resumePendingJobs() } IP2Country.configureIfNeeded(this) application.registerForFCMIfNeeded(false) From 1e9e580a2ffadd92e209a097e7ab0171b6dd4df1 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 17 Mar 2021 12:06:44 +1100 Subject: [PATCH 4/8] minor refactor --- .../securesms/loki/database/SessionJobDatabase.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt index 9ae1659ca0..1d4b81486c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt @@ -85,10 +85,7 @@ class SessionJobDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa } } -class SessionJobHelper() { - - companion object { - val dataSerializer: Data.Serializer = JsonDataSerializer() - val sessionJobInstantiator: SessionJobInstantiator = SessionJobInstantiator(SessionJobManagerFactories.getSessionJobFactories()) - } +object SessionJobHelper { + val dataSerializer: Data.Serializer = JsonDataSerializer() + val sessionJobInstantiator: SessionJobInstantiator = SessionJobInstantiator(SessionJobManagerFactories.getSessionJobFactories()) } \ No newline at end of file From 80382cc454685d71e38a446acbd75d750e74fb17 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 17 Mar 2021 16:09:01 +1100 Subject: [PATCH 5/8] minor refactor --- .../securesms/loki/database/SessionJobDatabase.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt index 1d4b81486c..dda3b7d7eb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt @@ -12,11 +12,11 @@ import org.thoughtcrime.securesms.loki.utilities.* class SessionJobDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) { companion object { - private val sessionJobTable = "session_job_database" - val jobID = "job_id" - val jobType = "job_type" - val failureCount = "failure_count" - val serializedData = "serialized_data" + private const val sessionJobTable = "session_job_database" + const val jobID = "job_id" + const val jobType = "job_type" + const val failureCount = "failure_count" + const val serializedData = "serialized_data" @JvmStatic val createSessionJobTableCommand = "CREATE TABLE $sessionJobTable ($jobID INTEGER PRIMARY KEY, $jobType STRING, $failureCount INTEGER DEFAULT 0, $serializedData TEXT);" } From 333533785bfb2a31ca66a64ccf2a6115f7c15246 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 17 Mar 2021 16:22:43 +1100 Subject: [PATCH 6/8] fix crash on attachment send failure --- .../messaging/sending_receiving/MessageSender.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 9ccd58fc72..7344b3f17c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -246,7 +246,8 @@ object MessageSender { // Result Handling fun handleSuccessfulMessageSend(message: Message, destination: Destination, isSyncMessage: Boolean = false) { val storage = MessagingConfiguration.shared.storage - val messageId = storage.getMessageIdInDatabase(message.sentTimestamp!!, message.sender!!) ?: return + val userPublicKey = storage.getUserPublicKey()!! + val messageId = storage.getMessageIdInDatabase(message.sentTimestamp!!, message.sender?:userPublicKey) ?: return // Ignore future self-sends storage.addReceivedMessageTimestamp(message.sentTimestamp!!) // Track the open group server message ID @@ -254,17 +255,16 @@ object MessageSender { storage.setOpenGroupServerMessageID(messageId, message.openGroupServerMessageID!!) } // Mark the message as sent - storage.markAsSent(message.sentTimestamp!!, message.sender!!) - storage.markUnidentified(message.sentTimestamp!!, message.sender!!) + storage.markAsSent(message.sentTimestamp!!, message.sender?:userPublicKey) + storage.markUnidentified(message.sentTimestamp!!, message.sender?:userPublicKey) // Start the disappearing messages timer if needed if (message is VisibleMessage && !isSyncMessage) { - SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, message.sender!!) + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, message.sender?:userPublicKey) } // Sync the message if: // • it's a visible message // • the destination was a contact // • we didn't sync it already - val userPublicKey = storage.getUserPublicKey()!! if (destination is Destination.Contact && !isSyncMessage) { if (message is VisibleMessage) { message.syncTarget = destination.publicKey } if (message is ExpirationTimerUpdate) { message.syncTarget = destination.publicKey } @@ -274,7 +274,8 @@ object MessageSender { fun handleFailedMessageSend(message: Message, error: Exception) { val storage = MessagingConfiguration.shared.storage - storage.setErrorMessage(message.sentTimestamp!!, message.sender!!, error) + val userPublicKey = storage.getUserPublicKey()!! + storage.setErrorMessage(message.sentTimestamp!!, message.sender?:userPublicKey, error) } // Convenience From e378d11692e3439ed22cf179e8226a0bc9e5522e Mon Sep 17 00:00:00 2001 From: Brice-W Date: Tue, 23 Mar 2021 10:11:10 +1100 Subject: [PATCH 7/8] few little fixes --- .../messages/control/ClosedGroupControlMessage.kt | 3 +-- .../messages/control/DataExtractionNotification.kt | 12 +++++------- .../messaging/messages/control/ReadReceipt.kt | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt index d7e440fe98..70c75ddce3 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt @@ -38,7 +38,7 @@ class ClosedGroupControlMessage() : ControlMessage() { object MemberLeft : Kind() object EncryptionKeyPairRequest: Kind() - val description: String = run { + val description: String = when(this) { is New -> "new" is Update -> "update" @@ -49,7 +49,6 @@ class ClosedGroupControlMessage() : ControlMessage() { MemberLeft -> "memberLeft" EncryptionKeyPairRequest -> "encryptionKeyPairRequest" } - } } companion object { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt index a612584af8..1888f66a49 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt @@ -14,12 +14,11 @@ class DataExtractionNotification(): ControlMessage() { class Screenshot() : Kind() class MediaSaved(val timestanp: Long) : Kind() - val description: String = run { + val description: String = when(this) { is Screenshot -> "screenshot" is MediaSaved -> "mediaSaved" } - } } companion object { @@ -27,12 +26,11 @@ class DataExtractionNotification(): ControlMessage() { fun fromProto(proto: SignalServiceProtos.Content): DataExtractionNotification? { val dataExtractionNotification = proto.dataExtractionNotification ?: return null - val kind: Kind - when(dataExtractionNotification.type) { - SignalServiceProtos.DataExtractionNotification.Type.SCREENSHOT -> kind = Kind.Screenshot() + val kind: Kind = when(dataExtractionNotification.type) { + SignalServiceProtos.DataExtractionNotification.Type.SCREENSHOT -> Kind.Screenshot() SignalServiceProtos.DataExtractionNotification.Type.MEDIA_SAVED -> { - val timestamp = if (dataExtractionNotification.hasTimestamp()) dataExtractionNotification.timestamp else 0 - kind = Kind.MediaSaved(timestamp) + val timestamp = if (dataExtractionNotification.hasTimestamp()) dataExtractionNotification.timestamp else return null + Kind.MediaSaved(timestamp) } } return DataExtractionNotification(kind) diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt index 0ee1f0acf9..b430f09c41 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt @@ -35,7 +35,7 @@ class ReadReceipt() : ControlMessage() { override fun toProto(): SignalServiceProtos.Content? { val timestamps = timestamps if (timestamps == null) { - Log.w(ExpirationTimerUpdate.TAG, "Couldn't construct read receipt proto from: $this") + Log.w(TAG, "Couldn't construct read receipt proto from: $this") return null } val receiptProto = SignalServiceProtos.ReceiptMessage.newBuilder() @@ -46,7 +46,7 @@ class ReadReceipt() : ControlMessage() { contentProto.receiptMessage = receiptProto.build() return contentProto.build() } catch (e: Exception) { - Log.w(ExpirationTimerUpdate.TAG, "Couldn't construct read receipt proto from: $this") + Log.w(TAG, "Couldn't construct read receipt proto from: $this") return null } } From 0bea7fa56d1d1349f32992719bcbeabe5354bbd1 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Tue, 23 Mar 2021 10:43:32 +1100 Subject: [PATCH 8/8] clean --- .../org/session/libsession/messaging/jobs/MessageReceiveJob.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageReceiveJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageReceiveJob.kt index d11bc2d3d2..4ce46b4577 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageReceiveJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageReceiveJob.kt @@ -15,7 +15,6 @@ class MessageReceiveJob(val data: ByteArray, val isBackgroundPoll: Boolean, val // Settings override val maxFailureCount: Int = 10 companion object { - val TAG = MessageReceiveJob::class.simpleName val KEY: String = "MessageReceiveJob"