Skip to content

Commit

Permalink
Merge pull request #395 from xmtp/np/v3-identity
Browse files Browse the repository at this point in the history
feat: New V3 Identity
  • Loading branch information
nplasterer authored May 30, 2024
2 parents 98f6e3b + 3542e80 commit 4ec2a7b
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 353 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.11.3"
implementation "org.xmtp:android:0.12.0"
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"
Expand Down
142 changes: 94 additions & 48 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
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 All @@ -30,9 +33,6 @@ import org.xmtp.android.library.codecs.description
import org.xmtp.android.library.codecs.getReactionAction
import org.xmtp.android.library.codecs.getReactionSchema
import org.xmtp.android.library.codecs.id
import uniffi.xmtpv3.org.xmtp.android.library.codecs.ContentTypeGroupMembershipChange
import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChangeCodec
import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChanges
import java.net.URL

class ContentJson(
Expand All @@ -54,7 +54,7 @@ class ContentJson(
Client.register(RemoteAttachmentCodec())
Client.register(ReplyCodec())
Client.register(ReadReceiptCodec())
Client.register(GroupMembershipChangeCodec())
Client.register(GroupUpdatedCodec())
}

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

ContentTypeGroupMembershipChange.id -> mapOf(
"groupChange" to mapOf(
"membersAdded" to (content as GroupMembershipChanges).membersAddedList.map {
ContentTypeGroupUpdated.id -> mapOf(
"groupUpdated" to mapOf(
"membersAdded" to (content as GroupUpdated).addedInboxesList.map {
mapOf(
"address" to it.accountAddress,
"initiatedByAddress" to it.initiatedByAccountAddress
"inboxId" to it.inboxId,
"initiatedByInboxId" to content.initiatedByInboxId
)},
"membersRemoved" to content.membersRemovedList.map {
"membersRemoved" to content.removedInboxesList.map {
mapOf(
"address" to it.accountAddress,
"initiatedByAddress" to it.initiatedByAccountAddress
"inboxId" to it.inboxId,
"initiatedByInboxId" to content.initiatedByInboxId
)},
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package expo.modules.xmtpreactnativesdk.wrappers

import android.util.Base64
import android.util.Base64.NO_WRAP
import com.google.gson.GsonBuilder
import org.xmtp.android.library.Client
import org.xmtp.android.library.Conversation
Expand All @@ -14,18 +12,19 @@ class GroupWrapper {
companion object {
fun encodeToObj(client: Client, group: Group): Map<String, Any> {
val permissionString = when (group.permissionLevel()) {
GroupPermissions.EVERYONE_IS_ADMIN -> "everyone_admin"
GroupPermissions.GROUP_CREATOR_IS_ADMIN -> "creator_admin"
GroupPermissions.ALL_MEMBERS -> "all_members"
GroupPermissions.ADMIN_ONLY -> "admin_only"
}
return mapOf(
"clientAddress" to client.address,
"id" to group.id.toHex(),
"createdAt" to group.createdAt.time,
"peerAddresses" to Conversation.Group(group).peerAddresses,
"peerInboxIds" to group.peerInboxIds(),
"version" to "GROUP",
"topic" to group.topic,
"permissionLevel" to permissionString,
"adminAddress" to group.adminAddress()
"creatorInboxId" to group.creatorInboxId(),
"name" to group.name,
"isActive" to group.isActive()
)
}

Expand Down
16 changes: 8 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.4.4-beta5)
- LibXMTP (0.5.0-beta1)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.5):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.10.11):
- XMTP (0.11.0):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.4.4-beta5)
- LibXMTP (= 0.5.0-beta1)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.10.11)
- XMTP (= 0.11.0)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: e2fb601691981900099551ff3e05621bd73dccf1
LibXMTP: 38800678de153b444c5a9b41a991080ee33e11ed
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb
Expand Down Expand Up @@ -763,10 +763,10 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 1deb40ac712ba315dcfdecd590a9b924d8c2241a
XMTPReactNative: a7d7c609861e0b31ca7f624f58969dcb92c19990
XMTP: 2fb42dccbf89949175e99309f337ec11d828b989
XMTPReactNative: 53915a0488e11be25777aa0b96d7091fa3c3c05b
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.15.2
COCOAPODS: 1.14.2
18 changes: 9 additions & 9 deletions example/src/GroupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
StaticAttachmentContent,
ReplyContent,
useClient,
GroupChangeContent,
GroupUpdatedContent,
} from 'xmtp-react-native-sdk'
import { ConversationSendPayload } from 'xmtp-react-native-sdk/lib/types'

Expand Down Expand Up @@ -1074,42 +1074,42 @@ function formatAddress(address: string) {
return `${address.slice(0, 6)}${address.slice(-4)}`
}

function GroupChangeContents({ content }: { content: GroupChangeContent }) {
function GroupUpdatedContents({ content }: { content: GroupUpdatedContent }) {
return (
<>
{content.membersAdded.length > 0 &&
(content.membersAdded.length === 1 ? (
<Text style={{ opacity: 0.5, fontStyle: 'italic' }}>
{`${formatAddress(
content.membersAdded[0].address
content.membersAdded[0].inboxId
)} has been added by ${formatAddress(
content.membersAdded[0].initiatedByAddress
content.membersAdded[0].initiatedByInboxId
)}`}
</Text>
) : (
<Text style={{ opacity: 0.5, fontStyle: 'italic' }}>
{`${
content.membersAdded.length
} members have been added by ${formatAddress(
content.membersAdded[0].initiatedByAddress
content.membersAdded[0].initiatedByInboxId
)}`}
</Text>
))}
{content.membersRemoved.length > 0 &&
(content.membersRemoved.length === 1 ? (
<Text style={{ opacity: 0.5, fontStyle: 'italic' }}>
{`${formatAddress(
content.membersRemoved[0].address
content.membersRemoved[0].inboxId
)} has been removed by ${formatAddress(
content.membersRemoved[0].initiatedByAddress
content.membersRemoved[0].initiatedByInboxId
)}`}
</Text>
) : (
<Text style={{ opacity: 0.5, fontStyle: 'italic', flexWrap: 'wrap' }}>
{`${
content.membersRemoved.length
} members have been removed by ${formatAddress(
content.membersRemoved[0].initiatedByAddress
content.membersRemoved[0].initiatedByInboxId
)}`}
</Text>
))}
Expand Down Expand Up @@ -1172,7 +1172,7 @@ function MessageContents({
)
}
if (contentTypeId === 'xmtp.org/group_membership_change:1.0') {
return <GroupChangeContents content={content} />
return <GroupUpdatedContents content={content} />
}

return (
Expand Down
4 changes: 2 additions & 2 deletions example/src/contentTypes/contentTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
GroupChangeCodec,
GroupUpdatedCodec,
ReactionCodec,
ReplyCodec,
RemoteAttachmentCodec,
Expand All @@ -11,7 +11,7 @@ export const supportedCodecs = [
new ReplyCodec(),
new RemoteAttachmentCodec(),
new StaticAttachmentCodec(),
new GroupChangeCodec(),
new GroupUpdatedCodec(),
]

export type SupportedContentTypes = typeof supportedCodecs
Loading

0 comments on commit 4ec2a7b

Please sign in to comment.