Skip to content

Commit

Permalink
Inconsistency with timestamps (#343)
Browse files Browse the repository at this point in the history
* rename for consistency

* small rename

* fix the timestamp issue

* small rename

* bump to the pod

* fix up some of the example app

* get the app building again

* remove forced trys

* one more tweak
  • Loading branch information
nplasterer authored May 30, 2024
1 parent c6272ce commit 8f0186e
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 70 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.12.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.5.0-beta1"),
.package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.5.0-beta2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
22 changes: 11 additions & 11 deletions Sources/XMTPiOS/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public enum ConsentState: String, Codable {

public struct ConsentListEntry: Codable, Hashable {
public enum EntryType: String, Codable {
case address, groupId, inboxId
case address, group_id, inbox_id
}

static func address(_ address: String, type: ConsentState = .unknown) -> ConsentListEntry {
ConsentListEntry(value: address, entryType: .address, consentType: type)
}

static func groupId(groupId: String, type: ConsentState = ConsentState.unknown) -> ConsentListEntry {
ConsentListEntry(value: groupId, entryType: .groupId, consentType: type)
ConsentListEntry(value: groupId, entryType: .group_id, consentType: type)
}

static func inboxId(_ inboxId: String, type: ConsentState = .unknown) -> ConsentListEntry {
ConsentListEntry(value: inboxId, entryType: .inboxId, consentType: type)
ConsentListEntry(value: inboxId, entryType: .inbox_id, consentType: type)
}

public var value: String
Expand Down Expand Up @@ -138,7 +138,7 @@ public class ConsentList {
case .unknown:
payload.messageType = nil
}
case .groupId:
case .group_id:
switch entry.consentType {
case .allowed:
if let valueData = entry.value.data(using: .utf8) {
Expand All @@ -151,7 +151,7 @@ public class ConsentList {
case .unknown:
payload.messageType = nil
}
case .inboxId:
case .inbox_id:
switch entry.consentType {
case .allowed:
payload.allowInboxID.inboxIds.append(entry.value)
Expand Down Expand Up @@ -285,11 +285,11 @@ public actor Contacts {
return await consentList.groupState(groupId: groupId) == .denied
}

public func isInboxIdAllowed(inboxId: String) async -> Bool {
public func isInboxAllowed(inboxId: String) async -> Bool {
return await consentList.inboxIdState(inboxId: inboxId) == .allowed
}

public func isInboxIdDenied(inboxId: String) async -> Bool {
public func isInboxDenied(inboxId: String) async -> Bool {
return await consentList.inboxIdState(inboxId: inboxId) == .denied
}

Expand Down Expand Up @@ -327,7 +327,7 @@ public actor Contacts {
try await consentList.publish(entries: entries)
}

public func allowGroup(groupIds: [Data]) async throws {
public func allowGroups(groupIds: [Data]) async throws {
var entries: [ConsentListEntry] = []

try await withThrowingTaskGroup(of: ConsentListEntry.self) { group in
Expand All @@ -344,7 +344,7 @@ public actor Contacts {
try await consentList.publish(entries: entries)
}

public func denyGroup(groupIds: [Data]) async throws {
public func denyGroups(groupIds: [Data]) async throws {
var entries: [ConsentListEntry] = []

try await withThrowingTaskGroup(of: ConsentListEntry.self) { group in
Expand All @@ -361,7 +361,7 @@ public actor Contacts {
try await consentList.publish(entries: entries)
}

public func allowInboxId(inboxIds: [String]) async throws {
public func allowInboxes(inboxIds: [String]) async throws {
var entries: [ConsentListEntry] = []

try await withThrowingTaskGroup(of: ConsentListEntry.self) { group in
Expand All @@ -378,7 +378,7 @@ public actor Contacts {
try await consentList.publish(entries: entries)
}

public func denyInboxId(inboxIds: [String]) async throws {
public func denyInboxes(inboxIds: [String]) async throws {
var entries: [ConsentListEntry] = []

try await withThrowingTaskGroup(of: ConsentListEntry.self) { group in
Expand Down
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public actor Conversations {

let group = try await v3Client.conversations().createGroup(accountAddresses: addresses, permissions: permissions).fromFFI(client: client)

try await client.contacts.allowGroup(groupIds: [group.id])
try await client.contacts.allowGroups(groupIds: [group.id])

return group
}
Expand Down Expand Up @@ -433,12 +433,12 @@ public actor Conversations {
})?.value
}

public func fromWelcome(envelopeBytes: Data) throws -> Group? {
public func fromWelcome(envelopeBytes: Data) async throws -> Group? {
guard let v3Client = client.v3Client else {
return nil
}

let group = try v3Client.conversations().processStreamedWelcomeMessage(envelopeBytes: envelopeBytes)
let group = try await v3Client.conversations().processStreamedWelcomeMessage(envelopeBytes: envelopeBytes)
return Group(ffiGroup: group, client: client)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public struct Group: Identifiable, Equatable, Hashable {
let groupState = await client.contacts.consentList.groupState(groupId: id)

if groupState == ConsentState.unknown {
try await client.contacts.allowGroup(groupIds: [id])
try await client.contacts.allowGroups(groupIds: [id])
}

let messageId = try await ffiGroup.send(contentBytes: encodedContent.serializedData())
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Mls/MessageV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public struct MessageV3: Identifiable {
id: id.toHex,
encodedContent: encodedContent,
senderAddress: senderInboxId,
sentAt: Date(),
sentAt: sentAt,
topic: Topic.groupMessage(convoId.toHex).description,
deliveryStatus: deliveryStatus
)
Expand Down
53 changes: 23 additions & 30 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,20 @@ class GroupTests: XCTestCase {

try await aliceGroup.addMembers(addresses: [fixtures.fred.address])
try await bobGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 3)

XCTAssertEqual(try aliceGroup.members.count, 3)
XCTAssertEqual(try bobGroup.members.count, 3)

try await aliceGroup.removeMembers(addresses: [fixtures.fred.address])
try await bobGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 2)

XCTAssertEqual(try aliceGroup.members.count, 2)
XCTAssertEqual(try bobGroup.members.count, 2)

try await bobGroup.addMembers(addresses: [fixtures.fred.address])
try await aliceGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 3)

XCTAssertEqual(try aliceGroup.members.count, 3)
XCTAssertEqual(try bobGroup.members.count, 3)

XCTAssertEqual(try bobGroup.permissionLevel(), .allMembers)
Expand All @@ -125,7 +122,7 @@ class GroupTests: XCTestCase {
XCTAssert(try !aliceGroup.isAdmin(inboxId: fixtures.aliceClient.inboxID))

}
//

func testCanCreateAGroupWithAdminPermissions() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address], permissions: GroupPermissions.adminOnly)
Expand All @@ -142,34 +139,30 @@ class GroupTests: XCTestCase {

try await bobGroup.addMembers(addresses: [fixtures.fred.address])
try await aliceGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 3)

XCTAssertEqual(try aliceGroup.members.count, 3)
XCTAssertEqual(try bobGroup.members.count, 3)

await assertThrowsAsyncError(
try await aliceGroup.removeMembers(addresses: [fixtures.fred.address])
)
try await bobGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 3)

XCTAssertEqual(try aliceGroup.members.count, 3)
XCTAssertEqual(try bobGroup.members.count, 3)

try await bobGroup.removeMembers(addresses: [fixtures.fred.address])
try await aliceGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 2)

XCTAssertEqual(try aliceGroup.members.count, 2)
XCTAssertEqual(try bobGroup.members.count, 2)

await assertThrowsAsyncError(
try await aliceGroup.addMembers(addresses: [fixtures.fred.address])
)
try await bobGroup.sync()
// Issue members is not returning correctly for non group creators:
// https://github.com/xmtp/libxmtp/issues/769
// XCTAssertEqual(try aliceGroup.members.count, 2)

XCTAssertEqual(try aliceGroup.members.count, 2)
XCTAssertEqual(try bobGroup.members.count, 2)

XCTAssertEqual(try bobGroup.permissionLevel(), .adminOnly)
Expand Down Expand Up @@ -684,22 +677,22 @@ class GroupTests: XCTestCase {
func testCanAllowAndDenyInboxId() async throws {
let fixtures = try await localFixtures()

let isAllowed = await fixtures.bobClient.contacts.isInboxIdAllowed(inboxId: fixtures.aliceClient.inboxID)
let isDenied = await fixtures.bobClient.contacts.isInboxIdDenied(inboxId: fixtures.aliceClient.inboxID)
let isAllowed = await fixtures.bobClient.contacts.isInboxAllowed(inboxId: fixtures.aliceClient.inboxID)
let isDenied = await fixtures.bobClient.contacts.isInboxDenied(inboxId: fixtures.aliceClient.inboxID)
XCTAssert(!isAllowed)
XCTAssert(!isDenied)

try await fixtures.bobClient.contacts.allowInboxId(inboxIds: [fixtures.aliceClient.inboxID])
try await fixtures.bobClient.contacts.allowInboxes(inboxIds: [fixtures.aliceClient.inboxID])

let isAllowed2 = await fixtures.bobClient.contacts.isInboxIdAllowed(inboxId: fixtures.aliceClient.inboxID)
let isDenied2 = await fixtures.bobClient.contacts.isInboxIdDenied(inboxId: fixtures.aliceClient.inboxID)
let isAllowed2 = await fixtures.bobClient.contacts.isInboxAllowed(inboxId: fixtures.aliceClient.inboxID)
let isDenied2 = await fixtures.bobClient.contacts.isInboxDenied(inboxId: fixtures.aliceClient.inboxID)
XCTAssert(isAllowed2)
XCTAssert(!isDenied2)

try await fixtures.bobClient.contacts.denyInboxId(inboxIds: [fixtures.aliceClient.inboxID])
try await fixtures.bobClient.contacts.denyInboxes(inboxIds: [fixtures.aliceClient.inboxID])

let isAllowed3 = await fixtures.bobClient.contacts.isInboxIdAllowed(inboxId: fixtures.aliceClient.inboxID)
let isDenied3 = await fixtures.bobClient.contacts.isInboxIdDenied(inboxId: fixtures.aliceClient.inboxID)
let isAllowed3 = await fixtures.bobClient.contacts.isInboxAllowed(inboxId: fixtures.aliceClient.inboxID)
let isDenied3 = await fixtures.bobClient.contacts.isInboxDenied(inboxId: fixtures.aliceClient.inboxID)
XCTAssert(!isAllowed3)
XCTAssert(isDenied3)
}
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.11.0"
spec.version = "0.11.1"
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.12.0"
spec.dependency 'LibXMTP', '= 0.5.0-beta1'
spec.dependency 'LibXMTP', '= 0.5.0-beta2'
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" : "4b534c876ba1d67ed50ca45de915fcdd71812cd6",
"version" : "0.5.0-beta0"
"revision" : "6540f22eab6748748ede67c5a94d8188060fcbf9",
"version" : "0.5.0-beta2"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions XMTPiOSExample/XMTPiOSExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct ContentView: View {
bundle: keys,
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupMembershipChangedCodec()],
codecs: [GroupUpdatedCodec()],
mlsAlpha: true
)
)
Expand Down Expand Up @@ -96,7 +96,7 @@ struct ContentView: View {
account: wallet,
options: .init(
api: .init(env: .local, isSecure: false, appVersion: "XMTPTest/v1.0.0"),
codecs: [GroupMembershipChangedCodec()],
codecs: [GroupUpdatedCodec()],
mlsAlpha: true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ConversationDetailView: View {
}
}
}
.navigationTitle(conversation.peerAddress)
.navigationTitle((try? conversation.peerAddress) ?? "")
.navigationBarTitleDisplayMode(.inline)
}

Expand All @@ -54,7 +54,7 @@ struct ConversationDetailView: View {
self.messages = messages
}
} catch {
print("Error loading messages for \(conversation.peerAddress)")
print("Error loading messages for \(conversation.topic)")
}
}
}
15 changes: 13 additions & 2 deletions XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ struct ConversationListView: View {
VStack(alignment: .leading) {
switch item {
case .conversation(let conversation):
Text(Util.abbreviate(address: conversation.peerAddress))
if let abbreviatedAddress = try? Util.abbreviate(address: conversation.peerAddress) {
Text(abbreviatedAddress)
} else {
Text("Unknown Address")
.foregroundStyle(.secondary)
}
case .group(let group):
Text(group.memberAddresses.sorted().map { Util.abbreviate(address: $0) }.joined(separator: ", "))
let memberAddresses = try? group.members.map(\.inboxId).sorted().map { Util.abbreviate(address: $0) }
if let addresses = memberAddresses {
Text(addresses.joined(separator: ", "))
} else {
Text("Unknown Members")
.foregroundStyle(.secondary)
}
}

Text(item.createdAt.formatted())
Expand Down
10 changes: 5 additions & 5 deletions XMTPiOSExample/XMTPiOSExample/Views/GroupSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct GroupSettingsView: View {
Button("Remove", role: .destructive) {
Task {
try await group.removeMembers(addresses: [member])
await syncGroupMembers()
try await syncGroupMembers()
}
}
}
Expand Down Expand Up @@ -108,15 +108,15 @@ struct GroupSettingsView: View {
}
.navigationTitle("Group Settings")
.task {
await syncGroupMembers()
try? await syncGroupMembers()
}
}
}

private func syncGroupMembers() async {
private func syncGroupMembers() async throws {
try? await group.sync()
await MainActor.run {
self.groupMembers = group.memberAddresses
try await MainActor.run {
self.groupMembers = try group.members.map(\.inboxId)
}
}
}
2 changes: 1 addition & 1 deletion XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct LoginView: View {
account: signer,
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupMembershipChangedCodec()],
codecs: [GroupUpdatedCodec()],
mlsAlpha: true
)
)
Expand Down
12 changes: 5 additions & 7 deletions XMTPiOSExample/XMTPiOSExample/Views/NewConversationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ enum ConversationOrGroup: Hashable {
}

var id: String {
get throws {
switch self {
case .conversation(let conversation):
return try conversation.peerAddress
case .group(let group):
return try group.members.map(\.inboxId).joined(separator: ",")
}
switch self {
case .conversation(let conversation):
return conversation.topic
case .group(let group):
return group.id.toHexString()
}
}

Expand Down

0 comments on commit 8f0186e

Please sign in to comment.