Skip to content

Commit

Permalink
Group isActive (#247)
Browse files Browse the repository at this point in the history
* bump the pod spec

* fix up non compiling tests

* add isactive check to iOS

* sync the group before

* add test for is active

* get the test passing

* add version
  • Loading branch information
nplasterer authored Feb 13, 2024
1 parent 5643e41 commit e11bc35
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let package = Package(
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"),
.package(url: "https://github.com/bufbuild/connect-swift", exact: "0.3.0"),
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
.package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.1-beta2"),
.package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.1-beta3"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
3 changes: 3 additions & 0 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public final class Client {
let privateKeyBundleV1: PrivateKeyBundleV1
let apiClient: ApiClient
let v3Client: LibXMTP.FfiXmtpClient?
public let libXMTPVersion: String = getVersionInfo()

/// Access ``Conversations`` for this Client.
public lazy var conversations: Conversations = .init(client: self)
Expand Down Expand Up @@ -149,6 +150,8 @@ public final class Client {
} else {
try await v3Client.registerIdentity(recoverableWalletSignature: nil)
}

print("LibXMTP \(getVersionInfo())")

return v3Client
} else {
Expand Down
4 changes: 4 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public struct Group: Identifiable, Equatable, Hashable {
public func hash(into hasher: inout Hasher) {
id.hash(into: &hasher)
}

public func isActive() throws -> Bool {
return try ffiGroup.isActive()
}

public var memberAddresses: [String] {
do {
Expand Down
51 changes: 47 additions & 4 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class GroupTests: XCTestCase {
let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address])

try await group.sync()
let members = group.members.map(\.localizedLowercase).sorted()
let members = group.memberAddresses.map(\.localizedLowercase).sorted()

XCTAssertEqual([fixtures.bob.address.localizedLowercase, fixtures.alice.address.localizedLowercase].sorted(), members)
}
Expand All @@ -120,7 +120,7 @@ class GroupTests: XCTestCase {
try await group.addMembers(addresses: [fixtures.fred.address])

try await group.sync()
let members = group.members.map(\.localizedLowercase).sorted()
let members = group.memberAddresses.map(\.localizedLowercase).sorted()

XCTAssertEqual([
fixtures.bob.address.localizedLowercase,
Expand All @@ -137,7 +137,7 @@ class GroupTests: XCTestCase {
let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address, fixtures.fred.address])

try await group.sync()
let members = group.members.map(\.localizedLowercase).sorted()
let members = group.memberAddresses.map(\.localizedLowercase).sorted()

XCTAssertEqual([
fixtures.bob.address.localizedLowercase,
Expand All @@ -149,7 +149,7 @@ class GroupTests: XCTestCase {

try await group.sync()

let newMembers = group.members.map(\.localizedLowercase).sorted()
let newMembers = group.memberAddresses.map(\.localizedLowercase).sorted()
XCTAssertEqual([
fixtures.bob.address.localizedLowercase,
fixtures.alice.address.localizedLowercase,
Expand All @@ -158,6 +158,49 @@ class GroupTests: XCTestCase {
let groupChangedMessage: GroupMembershipChanges = try await group.messages().last!.content()
XCTAssertEqual(groupChangedMessage.membersRemoved.map(\.accountAddress.localizedLowercase), [fixtures.fred.address.localizedLowercase])
}

func testIsActive() async throws {
let fixtures = try await localFixtures()
let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address, fixtures.fred.address])

try await group.sync()
let members = group.memberAddresses.map(\.localizedLowercase).sorted()

XCTAssertEqual([
fixtures.bob.address.localizedLowercase,
fixtures.alice.address.localizedLowercase,
fixtures.fred.address.localizedLowercase
].sorted(), members)

try await fixtures.fredClient.conversations.sync()
let fredGroup = try await fixtures.fredClient.conversations.groups().first
try await fredGroup?.sync()

var isAliceActive = try group.isActive()
var isFredActive = try fredGroup!.isActive()

XCTAssert(isAliceActive)
XCTAssert(isFredActive)

try await group.removeMembers(addresses: [fixtures.fred.address])

try await group.sync()

let newMembers = group.memberAddresses.map(\.localizedLowercase).sorted()
XCTAssertEqual([
fixtures.bob.address.localizedLowercase,
fixtures.alice.address.localizedLowercase,
].sorted(), newMembers)

try await fredGroup?.sync()

isAliceActive = try group.isActive()
isFredActive = try fredGroup!.isActive()

XCTAssert(isAliceActive)
XCTAssert(!isFredActive)
}


func testCannotStartGroupWithSelf() async throws {
let fixtures = try await localFixtures()
Expand Down
4 changes: 2 additions & 2 deletions XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "XMTP"
spec.version = "0.8.3"
spec.version = "0.8.4"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -44,5 +44,5 @@ Pod::Spec.new do |spec|
spec.dependency "web3.swift"
spec.dependency "GzipSwift"
spec.dependency "Connect-Swift", "= 0.3.0"
spec.dependency 'LibXMTP', '= 0.4.1-beta2'
spec.dependency 'LibXMTP', '= 0.4.1-beta3'
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/xmtp/libxmtp-swift",
"state" : {
"revision" : "82398e41e54b52c346852a478102c7f620fd17a4",
"version" : "0.4.1-beta2"
"revision" : "d2d0312dd504f5c866e64d6c66c44729be43279c",
"version" : "0.4.1-beta3"
}
},
{
Expand Down

0 comments on commit e11bc35

Please sign in to comment.