Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user mention not tappable when contains "@" character #2928

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix date separator decoration view showing in the last message of the current page [#2899](https://github.com/GetStream/stream-chat-swift/pull/2899)
- Fix `JumpToUnreadMessagesButton` not localizable [#2917](https://github.com/GetStream/stream-chat-swift/pull/2917)
- Fix CocoaPods minimum iOS target not in sync with the Xcode project [#2924](https://github.com/GetStream/stream-chat-swift/pull/2924)
- Fix user mention not tappable when contains "@" character [#2928](https://github.com/GetStream/stream-chat-swift/pull/2928)

# [4.44.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.44.0)
_November 30, 2023_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TextViewMentionedUsersHandler {
else {
return nil
}
let name = String(text[range].replacingOccurrences(of: "@", with: ""))
let name = String(text[range].dropFirst())
nuno-vieira marked this conversation as resolved.
Show resolved Hide resolved
return mentionedUsers.first(where: { $0.name == name })
}
}
4 changes: 4 additions & 0 deletions StreamChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@
ADA8EBE928CFD52F00DB9B03 /* TextViewUserMentionsHandler_Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA8EBE828CFD52F00DB9B03 /* TextViewUserMentionsHandler_Mock.swift */; };
ADA8EBEB28CFD82C00DB9B03 /* ChatMessageContentViewDelegate_Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA8EBEA28CFD82C00DB9B03 /* ChatMessageContentViewDelegate_Mock.swift */; };
ADAA377125E43C3700C31528 /* ChatSuggestionsVC_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADD5A9E725DE8AF6006DC88A /* ChatSuggestionsVC_Tests.swift */; };
ADAA9F412B2240300078C3D4 /* TextViewMentionedUsersHandler_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAA9F402B2240300078C3D4 /* TextViewMentionedUsersHandler_Tests.swift */; };
ADAC47AA275A7C960027B672 /* ChatMessageContentView_Documentation_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAC47A9275A7C960027B672 /* ChatMessageContentView_Documentation_Tests.swift */; };
ADB22F7C25F1626200853C92 /* OnlineIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB22F7A25F1626200853C92 /* OnlineIndicatorView.swift */; };
ADB22F7D25F1626200853C92 /* ChatPresenceAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB22F7B25F1626200853C92 /* ChatPresenceAvatarView.swift */; };
Expand Down Expand Up @@ -3823,6 +3824,7 @@
ADA5A0F7276790C100E1C465 /* ChatMessageListDateSeparatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessageListDateSeparatorView.swift; sourceTree = "<group>"; };
ADA8EBE828CFD52F00DB9B03 /* TextViewUserMentionsHandler_Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewUserMentionsHandler_Mock.swift; sourceTree = "<group>"; };
ADA8EBEA28CFD82C00DB9B03 /* ChatMessageContentViewDelegate_Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessageContentViewDelegate_Mock.swift; sourceTree = "<group>"; };
ADAA9F402B2240300078C3D4 /* TextViewMentionedUsersHandler_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewMentionedUsersHandler_Tests.swift; sourceTree = "<group>"; };
ADAC47A9275A7C960027B672 /* ChatMessageContentView_Documentation_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessageContentView_Documentation_Tests.swift; sourceTree = "<group>"; };
ADB22F7A25F1626200853C92 /* OnlineIndicatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnlineIndicatorView.swift; sourceTree = "<group>"; };
ADB22F7B25F1626200853C92 /* ChatPresenceAvatarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatPresenceAvatarView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7193,6 +7195,7 @@
A3960E0427DA5512003AB2B0 /* Utils */ = {
isa = PBXGroup;
children = (
ADAA9F402B2240300078C3D4 /* TextViewMentionedUsersHandler_Tests.swift */,
AD4C15552A55874700A32955 /* ImageLoading_Tests.swift */,
BDDD1EAB2632E32000BA007B /* AppearanceProvider_Tests.swift */,
C1320E07276B2E0800A06B35 /* Array+SafeSubscript_Tests.swift */,
Expand Down Expand Up @@ -10041,6 +10044,7 @@
401105462A12735900F877C7 /* WaveformView_Tests.swift in Sources */,
ADEE651E29BF715600186129 /* ChatMessageListVCDelegate_Mock.swift in Sources */,
AD050BA8265D600B006649A5 /* QuotedChatMessageView+SwiftUI_Tests.swift in Sources */,
ADAA9F412B2240300078C3D4 /* TextViewMentionedUsersHandler_Tests.swift in Sources */,
40824D2F2A1271D7003B61FD /* RecordButton_Tests.swift in Sources */,
A3D9D69627EDE87900725066 /* Components_Mock.swift in Sources */,
AD25070D272C0C8D00BC14C4 /* ChatMessageReactionAuthorsVC_Tests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

@testable import StreamChat
@testable import StreamChatUI
import XCTest

final class TextViewMentionedUsersHandler_Tests: XCTestCase {
func test_mentionedUserTapped_whenRangeIncludesMention() {
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: "Leia")]
)

XCTAssertEqual(user?.name, "Leia")
}

func test_mentionedUserTapped_whenRangeDoesNotIncludeMention() {
let textView = UITextView()
textView.text = "@Leia Hello!"

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

XCTAssertEqual(user?.name, nil)
}

func test_mentionedUserTapped_whenIncludesSpecialCharacter() {
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@")
}
}
Loading