Skip to content

Commit

Permalink
Removing conversations that contain a no valid topic (#194)
Browse files Browse the repository at this point in the history
* Adding a filter to not show conversations that contain no valid topics

* removing lint error for force violation issue

Co-authored-by: Naomi Plasterer <[email protected]>

* Update XMTP.podspec

Update pod version to trigger the build

* Moving validation to Topic object

* Update ConversationsTest.swift

Split assertions

* bump the pod spec again

---------

Co-authored-by: Giovani Gonzalez <[email protected]>
Co-authored-by: Naomi Plasterer <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent a0a6fe6 commit bf38bb9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/XMTP/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public actor Conversations {
}

newConversations
.filter { $0.peerAddress != client.address }
.filter { $0.peerAddress != client.address && Topic.isValidTopic(topic: $0.topic) }
.forEach { conversationsByTopic[$0.topic] = $0 }

// TODO(perf): use DB to persist + sort
Expand Down
4 changes: 4 additions & 0 deletions Sources/XMTP/Messages/Topic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public enum Topic {
private func wrap(_ value: String) -> String {
"/xmtp/0/\(value)/proto"
}

static func isValidTopic(topic: String) -> Bool {
return topic.allSatisfy(\.isASCII)
}
}
44 changes: 44 additions & 0 deletions Tests/XMTPTests/ConversationsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,48 @@ class ConversationsTests: XCTestCase {

await waitForExpectations(timeout: 3)
}

func testCanValidateTopicsInsideConversation() async throws {
let validId = "sdfsadf095b97a9284dcd82b2274856ccac8a21de57bebe34e7f9eeb855fb21126d3b8f"

// Creation of all known types of topics
let privateStore = Topic.userPrivateStoreKeyBundle(validId).description
let contact = Topic.contact(validId).description
let userIntro = Topic.userIntro(validId).description
let userInvite = Topic.userInvite(validId).description
let directMessageV1 = Topic.directMessageV1(validId, "sd").description
let directMessageV2 = Topic.directMessageV2(validId).description
let preferenceList = Topic.preferenceList(validId).description

// check if validation of topics accepts all types
XCTAssertTrue(Topic.isValidTopic(topic: privateStore))
XCTAssertTrue(Topic.isValidTopic(topic: contact))
XCTAssertTrue(Topic.isValidTopic(topic: userIntro))
XCTAssertTrue(Topic.isValidTopic(topic: userInvite))
XCTAssertTrue(Topic.isValidTopic(topic: directMessageV1))
XCTAssertTrue(Topic.isValidTopic(topic: directMessageV2))
XCTAssertTrue(Topic.isValidTopic(topic: preferenceList))
}

func testCannotValidateTopicsInsideConversation() async throws {
let invalidId = "��\\u0005�!\\u000b���5\\u00001\\u0007�蛨\\u001f\\u00172��.����K9K`�"

// Creation of all known types of topics
let privateStore = Topic.userPrivateStoreKeyBundle(invalidId).description
let contact = Topic.contact(invalidId).description
let userIntro = Topic.userIntro(invalidId).description
let userInvite = Topic.userInvite(invalidId).description
let directMessageV1 = Topic.directMessageV1(invalidId, "sd").description
let directMessageV2 = Topic.directMessageV2(invalidId).description
let preferenceList = Topic.preferenceList(invalidId).description

// check if validation of topics declines all types
XCTAssertFalse(Topic.isValidTopic(topic: privateStore))
XCTAssertFalse(Topic.isValidTopic(topic: contact))
XCTAssertFalse(Topic.isValidTopic(topic: userIntro))
XCTAssertFalse(Topic.isValidTopic(topic: userInvite))
XCTAssertFalse(Topic.isValidTopic(topic: directMessageV1))
XCTAssertFalse(Topic.isValidTopic(topic: directMessageV2))
XCTAssertFalse(Topic.isValidTopic(topic: preferenceList))
}
}
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.6.13-alpha0"
spec.version = "0.6.14-alpha0"
spec.summary = "XMTP SDK Cocoapod"

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

0 comments on commit bf38bb9

Please sign in to comment.