fix: adding in more checks for open group inbox recipients before being saved to the shared configs. Prevent sending typing indicator for blocked users

This commit is contained in:
0x330a 2023-04-27 12:02:47 +10:00
parent 1f8fa4a904
commit 1cf4ef9e10
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
4 changed files with 22 additions and 1 deletions

View File

@ -212,6 +212,10 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
val threadDb = DatabaseComponent.get(context).threadDatabase() val threadDb = DatabaseComponent.get(context).threadDatabase()
getRecipientForThread(threadId)?.let { recipient -> getRecipientForThread(threadId)?.let { recipient ->
threadDb.markAllAsRead(threadId, recipient.isGroupRecipient, lastSeenTime) threadDb.markAllAsRead(threadId, recipient.isGroupRecipient, lastSeenTime)
// don't process configs for inbox recipients
if (recipient.isOpenGroupInboxRecipient) return
configFactory.convoVolatile?.let { config -> configFactory.convoVolatile?.let { config ->
val convo = when { val convo = when {
// recipient closed group // recipient closed group

View File

@ -204,6 +204,7 @@ object ConfigurationMessageUtilities {
recipient.isContactRecipient -> { recipient.isContactRecipient -> {
val sessionId = SessionId(recipient.address.serialize()) val sessionId = SessionId(recipient.address.serialize())
if (recipient.isLocalNumber) null // this is handled by the user profile NTS data 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 convoConfig.getOrConstructOneToOne(recipient.address.serialize())
} }
else -> null else -> null

View File

@ -54,6 +54,6 @@ object SessionMetaProtocol {
@JvmStatic @JvmStatic
fun shouldSendTypingIndicator(recipient: Recipient): Boolean { fun shouldSendTypingIndicator(recipient: Recipient): Boolean {
return !recipient.isGroupRecipient && recipient.isApproved return !recipient.isGroupRecipient && recipient.isApproved && !recipient.isBlocked
} }
} }

View File

@ -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.GroupInfo
import network.loki.messenger.libsession_util.util.UserPic import network.loki.messenger.libsession_util.util.UserPic
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage.Kind 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) { 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] * 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 = {}) { 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) val contact = getOrConstruct(sessionId)
updateFunction(contact) updateFunction(contact)
set(contact) set(contact)
@ -79,6 +88,13 @@ class Contacts(pointer: Long) : ConfigBase(pointer) {
* the [updateFunction] doesn't run if there is no contact * the [updateFunction] doesn't run if there is no contact
*/ */
fun updateIfExists(sessionId: String, updateFunction: Contact.()->Unit) { 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 val contact = get(sessionId) ?: return
updateFunction(contact) updateFunction(contact)
set(contact) set(contact)