Skip to content

Commit

Permalink
Fix user mention not tappable if mention symbol is different or not p…
Browse files Browse the repository at this point in the history
…resent at all
  • Loading branch information
nuno-vieira committed Dec 7, 2023
1 parent acfd27c commit 34b6cdc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class TextViewMentionedUsersHandler {
else {
return nil
}
let name = String(text[range].dropFirst())
return mentionedUsers.first(where: { $0.name == name })

let mention = String(text[range])
return mentionedUsers.first(where: {
let name = $0.name ?? $0.id
return mention.contains(name)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,33 @@ final class TextViewMentionedUsersHandler_Tests: XCTestCase {

XCTAssertEqual(user?.name, "Lei@")
}

// Customers can customise how mentions are presented, and so they can chose not to show it.
func test_mentionedUserTapped_whenAtSignIsNotPresent() {
let textView = UITextView()
textView.text = "Lei@ Hello!"

let sut = TextViewMentionedUsersHandler()
let user = sut.mentionedUserTapped(
on: textView,
in: .init(location: 0, length: 5),
with: [.mock(id: "leia", name: "Lei@")]
)

XCTAssertEqual(user?.name, "Lei@")
}

func test_mentionedUserTapped_whenUserDoesNotHaveName() {
let textView = UITextView()
textView.text = "leia Hello!"

let sut = TextViewMentionedUsersHandler()
let user = sut.mentionedUserTapped(
on: textView,
in: .init(location: 0, length: 5),
with: [.mock(id: "leia", name: nil)]
)

XCTAssertEqual(user?.id, "leia")
}
}

0 comments on commit 34b6cdc

Please sign in to comment.