forked from oxen-io/session-android
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscribe to group config messages (#969)
- Loading branch information
1 parent
ad7792f
commit 01b1d26
Showing
15 changed files
with
189 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/org/thoughtcrime/securesms/groups/GroupRevokedMessageHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.thoughtcrime.securesms.groups | ||
|
||
import network.loki.messenger.libsession_util.util.Sodium | ||
import org.session.libsession.database.StorageProtocol | ||
import org.session.libsession.messaging.groups.GroupManagerV2 | ||
import org.session.libsession.utilities.ConfigFactoryProtocol | ||
import org.session.libsignal.utilities.AccountId | ||
import org.session.libsignal.utilities.IdPrefix | ||
import org.session.libsignal.utilities.Log | ||
import javax.inject.Inject | ||
import javax.inject.Provider | ||
|
||
class GroupRevokedMessageHandler @Inject constructor( | ||
private val configFactoryProtocol: ConfigFactoryProtocol, | ||
private val storage: StorageProtocol, | ||
private val groupManagerV2: Provider<GroupManagerV2>, | ||
) { | ||
suspend fun handleRevokeMessage( | ||
groupId: AccountId, | ||
rawMessages: List<ByteArray>, | ||
) { | ||
rawMessages.forEach { data -> | ||
val decoded = configFactoryProtocol.decryptForUser( | ||
data, | ||
Sodium.KICKED_DOMAIN, | ||
groupId, | ||
) | ||
|
||
if (decoded != null) { | ||
// The message should be in the format of "<sessionIdPubKeyBinary><messageGenerationASCII>", | ||
// where the pub key is 32 bytes, so we need to have at least 33 bytes of data | ||
if (decoded.size < 33) { | ||
Log.w(TAG, "Received an invalid kicked message, expecting at least 33 bytes, got ${decoded.size}") | ||
return@forEach | ||
} | ||
|
||
val sessionId = AccountId(IdPrefix.STANDARD, decoded.copyOfRange(0, 32)) // copyOfRange: [start,end) | ||
val messageGeneration = decoded.copyOfRange(32, decoded.size).decodeToString().toIntOrNull() | ||
if (messageGeneration == null) { | ||
Log.w(TAG, "Received an invalid kicked message: missing message generation") | ||
return@forEach | ||
} | ||
|
||
val currentKeysGeneration = configFactoryProtocol.withGroupConfigs(groupId) { | ||
it.groupKeys.currentGeneration() | ||
} | ||
|
||
val isForMe = sessionId.hexString == storage.getUserPublicKey() | ||
Log.d(TAG, "Received kicked message, for us? ${isForMe}, message key generation = $messageGeneration, our key generation = $currentKeysGeneration") | ||
|
||
if (isForMe && messageGeneration >= currentKeysGeneration) { | ||
groupManagerV2.get().handleKicked(groupId) | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TAG = "GroupRevokedMessageHandler" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.