Skip to content

Commit

Permalink
Merge branch 'beta' into np/merge-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jul 10, 2024
2 parents ac0e0ad + 90828ef commit 69c1764
Show file tree
Hide file tree
Showing 79 changed files with 11,603 additions and 1,944 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json", "./example/tsconfig.json"]
},
plugins: ["@typescript-eslint"],
extends: ['universe/native', 'universe/web'],
ignorePatterns: ['build'],
plugins: ['prettier'],
globals: {
__dirname: true,
},
rules: {
"@typescript-eslint/no-floating-promises": ["error"],
},
}
13 changes: 13 additions & 0 deletions .github/workflows/tsc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Typescript
on:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- run: yarn
- run: yarn tsc
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ android/keystores/debug.keystore

# Typedocs
docs/
**/.yarn/*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,7 @@ The `env` parameter accepts one of three valid values: `dev`, `production`, or `
- `local`: Use to have a client communicate with an XMTP node you are running locally. For example, an XMTP node developer can set `env` to `local` to generate client traffic to test a node running locally.

The `production` network is configured to store messages indefinitely. XMTP may occasionally delete messages and keys from the `dev` network, and will provide advance notice in the [XMTP Discord community](https://discord.gg/xmtp).

## Enabling group chat

Coming soon...
16 changes: 14 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,19 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.14.1"
implementation "org.xmtp:android:0.14.6"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"}
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
// xmtp-android local testing setup below (comment org.xmtp:android above)
// implementation files('<PATH TO XMTP-ANDROID>/xmtp-android/library/build/outputs/aar/library-debug.aar')
// implementation 'com.google.crypto.tink:tink-android:1.8.0'
// implementation 'io.grpc:grpc-kotlin-stub:1.4.1'
// implementation 'io.grpc:grpc-okhttp:1.62.2'
// implementation 'io.grpc:grpc-protobuf-lite:1.62.2'
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0'
// implementation 'org.web3j:crypto:5.0.0'
// implementation "net.java.dev.jna:jna:5.14.0@aar"
// api 'com.google.protobuf:protobuf-kotlin-lite:3.22.3'
// api 'org.xmtp:proto-kotlin:3.62.1'
}
1,164 changes: 1,042 additions & 122 deletions android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.JsonParser

class AuthParamsWrapper(
val environment: String,
val appVersion: String?,
val enableV3: Boolean = false,
val dbDirectory: String?,
val historySyncUrl: String?,
) {
companion object {
fun authParamsFromJson(authParams: String): AuthParamsWrapper {
val jsonOptions = JsonParser.parseString(authParams).asJsonObject
return AuthParamsWrapper(
jsonOptions.get("environment").asString,
if (jsonOptions.has("appVersion")) jsonOptions.get("appVersion").asString else null,
if (jsonOptions.has("enableV3")) jsonOptions.get("enableV3").asBoolean else false,
if (jsonOptions.has("dbDirectory")) jsonOptions.get("dbDirectory").asString else null,
if (jsonOptions.has("historySyncUrl")) jsonOptions.get("historySyncUrl").asString else null
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.GsonBuilder
import org.xmtp.android.library.Client

class ClientWrapper {
companion object {
fun encodeToObj(client: Client): Map<String, String> {
return mapOf(
"inboxId" to client.inboxId,
"address" to client.address,
"installationId" to client.installationId
)
}

fun encode(client: Client): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(client)
return gson.toJson(obj)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import org.xmtp.android.library.Client
import org.xmtp.android.library.codecs.Attachment
import org.xmtp.android.library.codecs.AttachmentCodec
import org.xmtp.android.library.codecs.ContentTypeAttachment
import org.xmtp.android.library.codecs.ContentTypeGroupUpdated
import org.xmtp.android.library.codecs.ContentTypeId
import org.xmtp.android.library.codecs.ContentTypeReaction
import org.xmtp.android.library.codecs.ContentTypeReadReceipt
import org.xmtp.android.library.codecs.ContentTypeRemoteAttachment
import org.xmtp.android.library.codecs.ContentTypeReply
import org.xmtp.android.library.codecs.ContentTypeText
import org.xmtp.android.library.codecs.EncodedContent
import org.xmtp.android.library.codecs.GroupUpdated
import org.xmtp.android.library.codecs.GroupUpdatedCodec
import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.ReadReceipt
Expand Down Expand Up @@ -51,6 +54,7 @@ class ContentJson(
Client.register(RemoteAttachmentCodec())
Client.register(ReplyCodec())
Client.register(ReadReceiptCodec())
Client.register(GroupUpdatedCodec())
}

fun fromJsonObject(obj: JsonObject): ContentJson {
Expand Down Expand Up @@ -171,6 +175,29 @@ class ContentJson(
"readReceipt" to ""
)

ContentTypeGroupUpdated.id -> mapOf(
"initiatedByInboxId" to (content as GroupUpdated).initiatedByInboxId,
"groupUpdated" to mapOf(
"membersAdded" to content.addedInboxesList.map {
mapOf(
"inboxId" to it.inboxId
)
},
"membersRemoved" to content.removedInboxesList.map {
mapOf(
"inboxId" to it.inboxId
)
},
"metadataFieldsChanged" to content.metadataFieldChangesList.map {
mapOf(
"oldValue" to it.oldValue,
"newValue" to it.newValue,
"fieldName" to it.fieldName,
)
},
)
)

else -> {
val json = JsonObject()
encodedContent?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package expo.modules.xmtpreactnativesdk.wrappers

import android.util.Base64
import com.google.gson.GsonBuilder
import org.xmtp.android.library.Client
import org.xmtp.android.library.Conversation

class ConversationContainerWrapper {

companion object {
fun encodeToObj(client: Client, conversation: Conversation): Map<String, Any?> {
when (conversation.version) {
Conversation.Version.GROUP -> {
val group = (conversation as Conversation.Group).group
return GroupWrapper.encodeToObj(client, group)
}
else -> {
return ConversationWrapper.encodeToObj(client, conversation)
}
}
}

fun encode(client: Client, conversation: Conversation): String {
val gson = GsonBuilder().create()
val obj = ConversationContainerWrapper.encodeToObj(client, conversation)
return gson.toJson(obj)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConversationWrapper {
"context" to context,
"topic" to conversation.topic,
"peerAddress" to conversation.peerAddress,
"version" to if (conversation.version == Conversation.Version.V1) "v1" else "v2",
"version" to "DIRECT",
"conversationID" to (conversation.conversationId ?: ""),
"keyMaterial" to (conversation.keyMaterial?.let { Base64.encodeToString(it, Base64.NO_WRAP) } ?: ""),
"consentProof" to if (conversation.consentProof != null) Base64.encodeToString(conversation.consentProof?.toByteArray(), Base64.NO_WRAP) else null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.JsonParser

class CreateGroupParamsWrapper(
val groupName: String,
val groupImageUrlSquare: String,
val groupDescription: String,
val groupPinnedFrameUrl: String,
) {
companion object {
fun createGroupParamsFromJson(authParams: String): CreateGroupParamsWrapper {
val jsonOptions = JsonParser.parseString(authParams).asJsonObject
return CreateGroupParamsWrapper(
if (jsonOptions.has("name")) jsonOptions.get("name").asString else "",
if (jsonOptions.has("imageUrlSquare")) jsonOptions.get("imageUrlSquare").asString else "",
if (jsonOptions.has("description")) jsonOptions.get("description").asString else "",
if (jsonOptions.has("pinnedFrameUrl")) jsonOptions.get("pinnedFrameUrl").asString else "",
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class DecodedMessageWrapper {
"content" to ContentJson(model.encodedContent).toJsonMap(),
"senderAddress" to model.senderAddress,
"sent" to model.sentAt.time,
"fallback" to fallback
"fallback" to fallback,
"deliveryStatus" to model.deliveryStatus.toString()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.GsonBuilder
import org.xmtp.android.library.Client
import org.xmtp.android.library.Group
import org.xmtp.android.library.toHex

class GroupWrapper {

companion object {
fun encodeToObj(client: Client, group: Group): Map<String, Any> {
return mapOf(
"clientAddress" to client.address,
"id" to group.id,
"createdAt" to group.createdAt.time,
"peerInboxIds" to group.peerInboxIds(),
"version" to "GROUP",
"topic" to group.topic,
"creatorInboxId" to group.creatorInboxId(),
"isActive" to group.isActive(),
)
}

fun encode(client: Client, group: Group): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(client, group)
return gson.toJson(obj)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.GsonBuilder
import org.xmtp.android.library.libxmtp.Member
import org.xmtp.android.library.libxmtp.PermissionLevel

class MemberWrapper {
companion object {
fun encodeToObj(member: Member): Map<String, Any> {
val permissionString = when (member.permissionLevel) {
PermissionLevel.MEMBER -> "member"
PermissionLevel.ADMIN -> "admin"
PermissionLevel.SUPER_ADMIN -> "super_admin"
}
return mapOf(
"inboxId" to member.inboxId,
"addresses" to member.addresses,
"permissionLevel" to permissionString
)
}

fun encode(member: Member): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(member)
return gson.toJson(obj)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.GsonBuilder
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionOption
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionPolicySet

class PermissionPolicySetWrapper {

companion object {
fun fromPermissionOption(permissionOption: PermissionOption): String {
return when (permissionOption) {
PermissionOption.Allow -> "allow"
PermissionOption.Deny -> "deny"
PermissionOption.Admin -> "admin"
PermissionOption.SuperAdmin -> "superAdmin"
PermissionOption.Unknown -> "unknown"
}
}
fun encodeToObj(policySet: PermissionPolicySet): Map<String, Any> {
return mapOf(
"addMemberPolicy" to fromPermissionOption(policySet.addMemberPolicy),
"removeMemberPolicy" to fromPermissionOption(policySet.removeMemberPolicy),
"addAdminPolicy" to fromPermissionOption(policySet.addAdminPolicy),
"removeAdminPolicy" to fromPermissionOption(policySet.removeAdminPolicy),
"updateGroupNamePolicy" to fromPermissionOption(policySet.updateGroupNamePolicy),
"updateGroupDescriptionPolicy" to fromPermissionOption(policySet.updateGroupDescriptionPolicy),
"updateGroupImagePolicy" to fromPermissionOption(policySet.updateGroupImagePolicy),
"updateGroupPinnedFrameUrlPolicy" to fromPermissionOption(policySet.updateGroupPinnedFrameUrlPolicy),
)
}

fun encodeToJsonString(policySet: PermissionPolicySet): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(policySet)
return gson.toJson(obj)
}
}
}
6 changes: 6 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { XmtpProvider } from 'xmtp-react-native-sdk'

import ConversationCreateScreen from './src/ConversationCreateScreen'
import ConversationScreen from './src/ConversationScreen'
import GroupScreen from './src/GroupScreen'
import HomeScreen from './src/HomeScreen'
import LaunchScreen from './src/LaunchScreen'
import { Navigator } from './src/Navigation'
Expand Down Expand Up @@ -90,6 +91,11 @@ export default function App() {
options={{ title: 'Conversation' }}
initialParams={{ topic: '' }}
/>
<Navigator.Screen
name="group"
component={GroupScreen}
options={{ title: 'Group' }}
/>
<Navigator.Screen
name="conversationCreate"
component={ConversationCreateScreen}
Expand Down
Loading

0 comments on commit 69c1764

Please sign in to comment.