Skip to content

Commit

Permalink
do the ios side
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 11, 2024
1 parent 12df7cf commit 6371ad4
Show file tree
Hide file tree
Showing 11 changed files with 985 additions and 1,621 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:3.0.1"
implementation "org.xmtp:android:3.0.3"
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
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,8 @@ class XMTPModule : Module() {
val client = clients[inboxId] ?: throw XMTPException("No client")
val params = ConversationParamsWrapper.conversationParamsFromJson(groupParams ?: "")
val order = getConversationSortOrder(sortOrder ?: "")
val sortedGroupList = if (order == ConversationOrder.LAST_MESSAGE) {
client.conversations.listGroups()
.sortedByDescending { group ->
group.messages(limit = 1).firstOrNull()?.sent
}
.let { groups ->
if (limit != null && limit > 0) groups.take(limit) else groups
}
} else {
client.conversations.listGroups(limit = limit)
}
sortedGroupList.map { group ->
val groups = client.conversations.listGroups(order = order, limit = limit)
groups.map { group ->
GroupWrapper.encode(client, group, params)
}
}
Expand All @@ -471,18 +461,8 @@ class XMTPModule : Module() {
val client = clients[inboxId] ?: throw XMTPException("No client")
val params = ConversationParamsWrapper.conversationParamsFromJson(groupParams ?: "")
val order = getConversationSortOrder(sortOrder ?: "")
val sortedDmList = if (order == ConversationOrder.LAST_MESSAGE) {
client.conversations.listDms()
.sortedByDescending { dm ->
dm.messages(limit = 1).firstOrNull()?.sent
}
.let { dms ->
if (limit != null && limit > 0) dms.take(limit) else dms
}
} else {
client.conversations.listDms(limit = limit)
}
sortedDmList.map { dm ->
val dms = client.conversations.listDms(order = order, limit = limit)
dms.map { dm ->
DmWrapper.encode(client, dm, params)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DecodedMessageWrapper {
"contentTypeId" to model.encodedContent.type.description,
"content" to ContentJson(model.encodedContent).toJsonMap(),
"senderAddress" to model.senderAddress,
"sentNs" to model.sent.time,
"sentNs" to model.sentNs,
"fallback" to fallback,
"deliveryStatus" to model.deliveryStatus.toString()
)
Expand Down
14 changes: 7 additions & 7 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.6.0)
- LibXMTP (3.0.0)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (2.0.0):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (3.0.0):
- XMTP (3.0.1):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.6.0)
- LibXMTP (= 3.0.0)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 3.0.0)
- XMTP (= 3.0.1)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: 059c6d51b2c59419941ecff600aa586bbe083673
LibXMTP: 4ef99026c3b353bd27195b48580e1bd34d083c3a
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: f7d1d5945c8765f97f39c3d121f353d46735d801
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 15d027733802cb4a0fed06529701ce920c0d2f17
XMTPReactNative: 02ae4f694b984cd320d444281f9940e35b02de6b
XMTP: 00937113c4e6055980dcff9a51f8b70de83605aa
XMTPReactNative: 21011caca6d56cf3128b672fcba791b2009bb704
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
8 changes: 2 additions & 6 deletions ios/Wrappers/AuthParamsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ import XMTP
struct AuthParamsWrapper {
let environment: String
let appVersion: String?
let enableV3: Bool
let dbDirectory: String?
let historySyncUrl: String?
let walletType: WalletType
let chainId: Int64?
let blockNumber: Int64?

init(environment: String, appVersion: String?, enableV3: Bool, dbDirectory: String?, historySyncUrl: String?, walletType: WalletType, chainId: Int64?, blockNumber: Int64?) {
init(environment: String, appVersion: String?, dbDirectory: String?, historySyncUrl: String?, walletType: WalletType, chainId: Int64?, blockNumber: Int64?) {
self.environment = environment
self.appVersion = appVersion
self.enableV3 = enableV3
self.dbDirectory = dbDirectory
self.historySyncUrl = historySyncUrl
self.walletType = walletType
Expand All @@ -32,12 +30,11 @@ struct AuthParamsWrapper {
static func authParamsFromJson(_ authParams: String) -> AuthParamsWrapper {
guard let data = authParams.data(using: .utf8),
let jsonOptions = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
return AuthParamsWrapper(environment: "dev", appVersion: nil, enableV3: false, dbDirectory: nil, historySyncUrl: nil, walletType: WalletType.EOA, chainId: nil, blockNumber: nil)
return AuthParamsWrapper(environment: "dev", appVersion: nil, dbDirectory: nil, historySyncUrl: nil, walletType: WalletType.EOA, chainId: nil, blockNumber: nil)
}

let environment = jsonOptions["environment"] as? String ?? "dev"
let appVersion = jsonOptions["appVersion"] as? String
let enableV3 = jsonOptions["enableV3"] as? Bool ?? false
let dbDirectory = jsonOptions["dbDirectory"] as? String
let historySyncUrl = jsonOptions["historySyncUrl"] as? String
let walletTypeString = jsonOptions["walletType"] as? String ?? "EOA"
Expand All @@ -56,7 +53,6 @@ struct AuthParamsWrapper {
return AuthParamsWrapper(
environment: environment,
appVersion: appVersion,
enableV3: enableV3,
dbDirectory: dbDirectory,
historySyncUrl: historySyncUrl,
walletType: walletType,
Expand Down
32 changes: 0 additions & 32 deletions ios/Wrappers/ConversationContainerWrapper.swift

This file was deleted.

40 changes: 9 additions & 31 deletions ios/Wrappers/ConversationWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
//
// ConversationWrapper.swift
//
// Created by Pat Nakajima on 4/21/23.
//

import Foundation
import XMTP

// Wrapper around XMTP.Conversation to allow passing these objects back into react native.
struct ConversationWrapper {
static func encodeToObj(_ conversation: XMTP.Conversation, client: XMTP.Client) throws -> [String: Any] {
var context = [:] as [String: Any]
if case let .v2(cv2) = conversation {
context = [
"conversationID": cv2.context.conversationID,
"metadata": cv2.context.metadata,
]
static func encodeToObj(_ conversation: XMTP.Conversation, client: XMTP.Client) async throws -> [String: Any] {
switch conversation {
case .group(let group):
return try await GroupWrapper.encodeToObj(group, client: client)
case .dm(let dm):
return try await DmWrapper.encodeToObj(dm, client: client)
}
var consentProof: String? = nil
if (conversation.consentProof != nil) {
consentProof = try conversation.consentProof?.serializedData().base64EncodedString()
}
return [
"clientAddress": client.address,
"topic": conversation.topic,
"createdAt": UInt64(conversation.createdAt.timeIntervalSince1970 * 1000),
"context": context,
"peerAddress": try conversation.peerAddress,
"version": "DIRECT",
"conversationID": conversation.conversationID ?? "",
"keyMaterial": conversation.keyMaterial?.base64EncodedString() ?? "",
"consentProof": consentProof ?? ""
]
}

static func encode(_ conversation: XMTP.Conversation, client: XMTP.Client) throws -> String {
let obj = try encodeToObj(conversation, client: client)
static func encode(_ conversation: XMTP.Conversation, client: XMTP.Client) async throws -> String {
let obj = try await encodeToObj(conversation, client: client)
let data = try JSONSerialization.data(withJSONObject: obj)
guard let result = String(data: data, encoding: .utf8) else {
throw WrapperError.encodeError("could not encode conversation")
Expand Down
6 changes: 3 additions & 3 deletions ios/Wrappers/DecodedMessageWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XMTP
// Wrapper around XMTP.DecodedMessage to allow passing these objects back
// into react native.
struct DecodedMessageWrapper {
static func encodeToObj(_ model: XMTP.DecryptedMessage, client: Client) throws -> [String: Any] {
static func encodeToObj(_ model: XMTP.DecodedMessage, client: Client) throws -> [String: Any] {
// Swift Protos don't support null values and will always put the default ""
// Check if there is a fallback, if there is then make it the set fallback, if not null
let fallback = model.encodedContent.hasFallback ? model.encodedContent.fallback : nil
Expand All @@ -14,13 +14,13 @@ struct DecodedMessageWrapper {
"contentTypeId": model.encodedContent.type.description,
"content": try ContentJson.fromEncoded(model.encodedContent, client: client).toJsonMap() as Any,
"senderAddress": model.senderAddress,
"sent": UInt64(model.sentAt.timeIntervalSince1970 * 1000),
"sentNs": model.sentNs,
"fallback": fallback,
"deliveryStatus": model.deliveryStatus.rawValue.uppercased(),
]
}

static func encode(_ model: XMTP.DecryptedMessage, client: Client) throws -> String {
static func encode(_ model: XMTP.DecodedMessage, client: Client) throws -> String {
let obj = try encodeToObj(model, client: client)
return try obj.toJson()
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct GroupWrapper {
result["consentState"] = ConsentWrapper.consentStateToString(state: try group.consentState())
}
if conversationParams.lastMessage {
if let lastMessage = try await group.decryptedMessages(limit: 1).first {
if let lastMessage = try await group.messages(limit: 1).first {
result["lastMessage"] = try DecodedMessageWrapper.encode(lastMessage, client: client)
}
}
Expand Down
Loading

0 comments on commit 6371ad4

Please sign in to comment.