From 1cf4ef9e10794ba5f806907a979bd07cdd287622 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:02:47 +1000 Subject: [PATCH] fix: adding in more checks for open group inbox recipients before being saved to the shared configs. Prevent sending typing indicator for blocked users --- .../thoughtcrime/securesms/database/Storage.kt | 4 ++++ .../util/ConfigurationMessageUtilities.kt | 1 + .../securesms/util/SessionMetaProtocol.kt | 2 +- .../loki/messenger/libsession_util/Config.kt | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) 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 2ad173319d..da97d82970 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -212,6 +212,10 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val threadDb = DatabaseComponent.get(context).threadDatabase() getRecipientForThread(threadId)?.let { recipient -> threadDb.markAllAsRead(threadId, recipient.isGroupRecipient, lastSeenTime) + + // don't process configs for inbox recipients + if (recipient.isOpenGroupInboxRecipient) return + configFactory.convoVolatile?.let { config -> val convo = when { // recipient closed group diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt index edc1bc56ca..d01a07def2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt @@ -204,6 +204,7 @@ object ConfigurationMessageUtilities { recipient.isContactRecipient -> { val sessionId = SessionId(recipient.address.serialize()) if (recipient.isLocalNumber) null // this is handled by the user profile NTS data + if (recipient.isOpenGroupInboxRecipient) null // specifically exclude else convoConfig.getOrConstructOneToOne(recipient.address.serialize()) } else -> null diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/SessionMetaProtocol.kt b/app/src/main/java/org/thoughtcrime/securesms/util/SessionMetaProtocol.kt index 05b6fe86f8..d488ff5a09 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/SessionMetaProtocol.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/SessionMetaProtocol.kt @@ -54,6 +54,6 @@ object SessionMetaProtocol { @JvmStatic fun shouldSendTypingIndicator(recipient: Recipient): Boolean { - return !recipient.isGroupRecipient && recipient.isApproved + return !recipient.isGroupRecipient && recipient.isApproved && !recipient.isBlocked } } \ No newline at end of file diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt index 13c6a59487..77ef696f02 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt @@ -7,6 +7,8 @@ import network.loki.messenger.libsession_util.util.Conversation import network.loki.messenger.libsession_util.util.GroupInfo import network.loki.messenger.libsession_util.util.UserPic import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage.Kind +import org.session.libsignal.utilities.IdPrefix +import org.session.libsignal.utilities.Log sealed class ConfigBase(protected val /* yucky */ pointer: Long) { @@ -69,6 +71,13 @@ class Contacts(pointer: Long) : ConfigBase(pointer) { * Similar to [updateIfExists], but will create the underlying contact if it doesn't exist before passing to [updateFunction] */ fun upsertContact(sessionId: String, updateFunction: Contact.()->Unit = {}) { + if (sessionId.startsWith(IdPrefix.BLINDED.value)) { + Log.w("Loki", "Trying to create a contact with a blinded ID prefix") + return + } else if (sessionId.startsWith(IdPrefix.UN_BLINDED.value)) { + Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix") + return + } val contact = getOrConstruct(sessionId) updateFunction(contact) set(contact) @@ -79,6 +88,13 @@ class Contacts(pointer: Long) : ConfigBase(pointer) { * the [updateFunction] doesn't run if there is no contact */ fun updateIfExists(sessionId: String, updateFunction: Contact.()->Unit) { + if (sessionId.startsWith(IdPrefix.BLINDED.value)) { + Log.w("Loki", "Trying to create a contact with a blinded ID prefix") + return + } else if (sessionId.startsWith(IdPrefix.UN_BLINDED.value)) { + Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix") + return + } val contact = get(sessionId) ?: return updateFunction(contact) set(contact)