Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: syncAllGroups returns num of groups synced. possible fork fixes #482

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.15.5"
implementation "org.xmtp:android:0.15.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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,9 @@ class XMTPModule : Module() {
logV("syncAllGroups")
val client = clients[inboxId] ?: throw XMTPException("No client")
client.conversations.syncAllGroups()
// Expo Modules do not support UInt, so we need to convert to Int
val numGroupsSyncedInt: Int = client.conversations.syncAllGroups()?.toInt() ?: throw IllegalArgumentException("Value cannot be null")
numGroupsSyncedInt
}
}

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.5.8-beta0)
- LibXMTP (0.5.8-beta1)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.9):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.14.8):
- XMTP (0.14.9):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.8-beta0)
- LibXMTP (= 0.5.8-beta1)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.14.8)
- XMTP (= 0.14.9)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: f4fbf472602ab8db976984a32cec71161bcc376c
LibXMTP: b7f9a97c56120771b3e99017f3454063f0388fb6
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 817ba1eea17421547e01e087285606eb270a8dcb
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 98158fdc19763dccdf0bb6da7bf52de1a190c836
XMTPReactNative: 2b5bd98ff66306912bc14e5c240c895179e75981
XMTP: ba28e0b3732e20beff61d2f9b7fe38561f5a6f72
XMTPReactNative: 8c15853c59fffddffa1c19b68acd766929ca10b2
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
33 changes: 32 additions & 1 deletion example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Wallet } from 'ethers'
import { Platform } from 'expo-modules-core'
import RNFS from 'react-native-fs'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

Expand Down Expand Up @@ -987,7 +988,7 @@
throw Error('Unexpected num groups (should be 1): ' + groups.length)
}

assert(groups[0].members.length == 2, 'should be 2')

Check warning on line 991 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '===' and instead saw '=='

// bo creates a group with alix so a stream callback is fired
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -2159,11 +2160,41 @@
`messages should be empty before sync but was ${boGroup?.messages?.length}`
)

await bo.conversations.syncAllGroups()
const numGroupsSynced = await bo.conversations.syncAllGroups()
assert(
(await boGroup?.messages())?.length === 1,
`messages should be 4 after sync but was ${boGroup?.messages?.length}`
)
assert(
numGroupsSynced === 50,
`should have synced 50 groups but synced ${numGroupsSynced}`
)

for (const group of groups) {
await group.removeMembers([bo.address])
}

// First syncAllGroups after removal will still sync each group to set group inactive
// For some reason on Android (RN only), first syncAllGroups already returns 0
const numGroupsSynced2 = await bo.conversations.syncAllGroups()
if (Platform.OS === 'ios') {
assert(
numGroupsSynced2 === 50,
`should have synced 50 groups but synced ${numGroupsSynced2}`
)
} else {
assert(
numGroupsSynced2 === 0,
`should have synced 0 groups but synced ${numGroupsSynced2}`
)
}

// Next syncAllGroups will not sync inactive groups
const numGroupsSynced3 = await bo.conversations.syncAllGroups()
assert(
numGroupsSynced3 === 0,
`should have synced 0 groups but synced ${numGroupsSynced3}`
)
return true
})

Expand Down
4 changes: 2 additions & 2 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,11 @@ public class XMTPModule: Module {
try await client.conversations.sync()
}

AsyncFunction("syncAllGroups") { (inboxId: String) in
AsyncFunction("syncAllGroups") { (inboxId: String) -> UInt32 in
guard let client = await clientsManager.getClient(key: inboxId) else {
throw Error.noClient
}
try await client.conversations.syncAllGroups()
return try await client.conversations.syncAllGroups()
}

AsyncFunction("syncGroup") { (inboxId: String, id: String) in
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.14.8"
s.dependency "XMTP", "= 0.14.9"
end
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ export async function syncGroups(inboxId: string) {
await XMTPModule.syncGroups(inboxId)
}

export async function syncAllGroups(inboxId: string) {
await XMTPModule.syncAllGroups(inboxId)
export async function syncAllGroups(inboxId: string): Promise<number> {
return await XMTPModule.syncAllGroups(inboxId)
}

export async function syncGroup(inboxId: string, id: string) {
Expand Down
9 changes: 4 additions & 5 deletions src/lib/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,12 @@ export default class Conversations<
}

/**
* Executes a network request to fetch the latest list of messages for all local groups associated with the client
* and save them to the local state.
* Executes a network request to sync all active groups associated with the client
*
* @warning call {@linkcode Conversations.syncGroups | syncGroups()} first to get the latest list of groups locally
* @returns {Promise<number>} A Promise that resolves to the number of groups synced.
*/
async syncAllGroups() {
await XMTPModule.syncAllGroups(this.client.inboxId)
async syncAllGroups(): Promise<number> {
return await XMTPModule.syncAllGroups(this.client.inboxId)
}

/**
Expand Down
Loading