Skip to content

Commit

Permalink
add group functions for setting and getting consent
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 13, 2024
1 parent 42ab04d commit d5bb86d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class Client() {
private var v3Client: FfiXmtpClient? = null
var dbPath: String = ""
lateinit var inboxId: String
var hasV3Client: Boolean = false
var hasV2Client: Boolean = false

companion object {
private const val TAG = "Client"
Expand Down Expand Up @@ -277,6 +279,7 @@ class Client() {
options: ClientOptions? = null,
account: SigningKey? = null,
): Client {
hasV2Client = true
val address = v1Bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
val newOptions = options ?: ClientOptions()
val v2Client =
Expand Down Expand Up @@ -356,6 +359,7 @@ class Client() {
}

if (v3Client != null) {
hasV3Client = true
options.preAuthenticateToInboxCallback?.let {
runBlocking {
it.invoke()
Expand Down Expand Up @@ -395,6 +399,7 @@ class Client() {
apiClient: ApiClient,
options: ClientOptions? = null,
): PrivateKeyBundleV1 {
hasV2Client = true
val keys = loadPrivateKeys(account, apiClient, options)
return if (keys != null) {
keys
Expand Down
22 changes: 21 additions & 1 deletion library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@ import org.xmtp.android.library.messages.Topic
import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.contents.PrivatePreferences.PrivatePreferencesAction
import uniffi.xmtpv3.FfiConsentState
import uniffi.xmtpv3.FfiGroupPermissionsOptions
import java.util.Date

enum class ConsentState {
ALLOWED,
DENIED,
UNKNOWN,
UNKNOWN;

companion object {
fun toFfiConsentState(option: ConsentState): FfiConsentState {
return when (option) {
ConsentState.ALLOWED -> FfiConsentState.ALLOWED
ConsentState.DENIED -> FfiConsentState.DENIED
else -> FfiConsentState.UNKNOWN
}
}

fun fromFfiConsentState(option: FfiConsentState): ConsentState {
return when (option) {
FfiConsentState.ALLOWED -> ConsentState.ALLOWED
FfiConsentState.DENIED -> ConsentState.DENIED
else -> ConsentState.UNKNOWN
}
}
}
}

data class ConsentListEntry(
Expand Down
9 changes: 9 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
return MessageV3(client, message)
}

fun updateConsentState(state: ConsentState) {
val consentState = ConsentState.toFfiConsentState(state)
libXMTPGroup.updateConsentState(consentState)
}

fun consentState(): ConsentState {
return ConsentState.fromFfiConsentState(libXMTPGroup.consentState())
}

fun isActive(): Boolean {
return libXMTPGroup.isActive()
}
Expand Down

0 comments on commit d5bb86d

Please sign in to comment.