-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update the swift and kotlin side to support types
- Loading branch information
1 parent
ada1c44
commit ed1d791
Showing
7 changed files
with
77 additions
and
24 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
32 changes: 32 additions & 0 deletions
32
android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConsentWrapper.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,32 @@ | ||
package expo.modules.xmtpreactnativesdk.wrappers | ||
|
||
import com.google.gson.GsonBuilder | ||
import org.xmtp.android.library.ConsentListEntry | ||
import org.xmtp.android.library.ConsentState | ||
import org.xmtp.android.library.codecs.description | ||
import org.xmtp.android.library.messages.DecryptedMessage | ||
|
||
class ConsentWrapper { | ||
|
||
companion object { | ||
fun encode(model: ConsentListEntry): String { | ||
val gson = GsonBuilder().create() | ||
val message = encodeMap(model) | ||
return gson.toJson(message) | ||
} | ||
|
||
fun encodeMap(model: ConsentListEntry): Map<String, Any> = mapOf( | ||
"type" to model.entryType.name.lowercase(), | ||
"value" to model.value.lowercase(), | ||
"state" to consentStateToString(model.consentType), | ||
) | ||
|
||
fun consentStateToString(state: ConsentState): String { | ||
return when (state) { | ||
ConsentState.ALLOWED -> "allowed" | ||
ConsentState.DENIED -> "denied" | ||
ConsentState.UNKNOWN -> "unknown" | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Foundation | ||
import XMTP | ||
|
||
// Wrapper around XMTP.Conversation to allow passing these objects back into react native. | ||
struct ConsentWrapper { | ||
static func encodeToObj(_ entry: XMTP.ConsentListEntry) throws -> [String: Any] { | ||
return [ | ||
"type": entry.entryType, | ||
"value": entry.value, | ||
"state": consentStateToString(state: entry.consentType), | ||
] | ||
} | ||
|
||
static func encode(_ entry: XMTP.ConsentListEntry) throws -> String { | ||
let obj = try encodeToObj(entry) | ||
let data = try JSONSerialization.data(withJSONObject: obj) | ||
guard let result = String(data: data, encoding: .utf8) else { | ||
throw WrapperError.encodeError("could not encode consent") | ||
} | ||
return result | ||
} | ||
|
||
static func consentStateToString(state: ConsentState) -> String { | ||
switch state { | ||
case .allowed: return "allowed" | ||
case .denied: return "denied" | ||
case .unknown: return "unknown" | ||
} | ||
} | ||
|
||
} |
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