Skip to content

Commit

Permalink
Fix peer addresses actually returns peer addresses (#263)
Browse files Browse the repository at this point in the history
* peer addresses was not removing self from list

* bump the pod

* dry it up
  • Loading branch information
nplasterer authored Feb 22, 2024
1 parent a3f8178 commit 880ec58
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
12 changes: 2 additions & 10 deletions Sources/XMTPiOS/Conversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ public enum Conversation: Sendable {
case let .v2(conversationV2):
return conversationV2.peerAddress
case let .group(group):
var addresses = group.memberAddresses
if let index = addresses.firstIndex(of: clientAddress) {
addresses.remove(at: index)
}
return addresses.joined(separator: ",")
return group.peerAddresses.joined(separator: ",")
}
}

Expand All @@ -101,11 +97,7 @@ public enum Conversation: Sendable {
case let .v2(conversationV2):
return [conversationV2.peerAddress]
case let .group(group):
var addresses = group.memberAddresses
if let index = addresses.firstIndex(of: clientAddress) {
addresses.remove(at: index)
}
return addresses
return group.peerAddresses
}
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ public struct Group: Identifiable, Equatable, Hashable {
return []
}
}

public var peerAddresses: [String] {
var addresses = memberAddresses.map(\.localizedLowercase)
if let index = addresses.firstIndex(of: client.address.localizedLowercase) {
addresses.remove(at: index)
}
return addresses
}

public var createdAt: Date {
Date(millisecondsSinceEpoch: ffiGroup.createdAtNs())
Expand Down
3 changes: 3 additions & 0 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ class GroupTests: XCTestCase {

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


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

func testCanAddGroupMembers() async throws {
Expand Down
2 changes: 1 addition & 1 deletion 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.12"
spec.version = "0.8.13"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit 880ec58

Please sign in to comment.